Debian Codegraph @

tests/discards-test

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`.
2
3 [scip-shell system . . `[`. -z "$CRYPTSETUP_PATH" ] && CRYPTSETUP_PATH=".."
4 CRYPTSETUP=$CRYPTSETUP_PATH/cryptsetup
5 DEV_NAME="discard-t3st"
6 DEV=""
7 PWD1="93R4P4pIqAH8"
8
9 if [scip-shell system . . `[`. -n "$CRYPTSETUP_TESTS_RUN_IN_MESON" ]; then
10 CRYPTSETUP_VALGRIND=$CRYPTSETUP
11 else
12 CRYPTSETUP_VALGRIND=../.libs/cryptsetup
13 CRYPTSETUP_LIB_VALGRIND=../.libs
14 fi
15
16 cleanupscip-shell shell shell-project 0.0.0 cleanup().() {
17 [scip-shell system . . `[`. -b /dev/mapper/$DEV_NAME ] && dmsetup remove --retry $DEV_NAME
18 udevadm settle >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1
19 rmmod scsi_debug >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1
20 sleepscip-shell system . . sleep. 1
21 }
22
23 failscip-shell shell shell-project 0.0.0 fail().()
24 {
25 echoscip-shell system . . echo. "FAILED backtrace:"
26 while caller $frame; do ((frame++)); done
27 cleanupscip-shell shell shell-project 0.0.0 cleanup().
28 exit 100
29 }
30
31 _sigchldscip-shell shell shell-project 0.0.0 _sigchld().() { local c=$?; [scip-shell system . . `[`. $c -eq 139 ] && failscip-shell shell shell-project 0.0.0 fail(). "Segfault"; [scip-shell system . . `[`. $c -eq 134 ] && failscip-shell shell shell-project 0.0.0 fail(). "Aborted"; }
32 trap _sigchld CHLD
33
34 skipscip-shell shell shell-project 0.0.0 skip().()
35 {
36 [scip-shell system . . `[`. -n "$1" ] && echoscip-shell system . . echo. "$1"
37 exit 77
38 }
39
40 valgrind_setupscip-shell shell shell-project 0.0.0 valgrind_setup().()
41 {
42 command -v valgrind >/dev/nullscip-shell filesystem . . `/dev/null`. || failscip-shell shell shell-project 0.0.0 fail(). "Cannot find valgrind."
43 [scip-shell system . . `[`. ! -f $CRYPTSETUP_VALGRIND ] && failscip-shell shell shell-project 0.0.0 fail(). "Unable to get location of cryptsetup executable."
44 [scip-shell system . . `[`. ! -f valg.sh ] && failscip-shell shell shell-project 0.0.0 fail(). "Unable to get location of valg runner script."
45 if [scip-shell system . . `[`. -z "$CRYPTSETUP_TESTS_RUN_IN_MESON" ]; then
46 export LD_LIBRARY_PATH="$CRYPTSETUP_LIB_VALGRIND:$LD_LIBRARY_PATH"
47 fi
48 }
49
50 valgrind_runscip-shell shell shell-project 0.0.0 valgrind_run().()
51 {
52 INFOSTRING="$(basenamescip-shell system . . basename. ${BASH_SOURCE[1]})-line-${BASH_LINENO[0]}" ./valg.sh ${CRYPTSETUP_VALGRIND} "$@"
53 }
54
55 add_devicescip-shell shell shell-project 0.0.0 add_device().() {
56 rmmod scsi_debug >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1
57 if [scip-shell system . . `[`. -d /sys/module/scsi_debugscip-shell filesystem . . `/sys/module/scsi_debug`. ] ; then
58 echoscip-shell system . . echo. "Cannot use scsi_debug module (in use or compiled-in), test skipped."
59 exit 77
60 fi
61 modprobe scsi_debug $@ delay=0 >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1
62 if [scip-shell system . . `[`. $? -ne 0 ] ; then
63 echoscip-shell system . . echo. "This kernel seems to not support proper scsi_debug module, test skipped."
64 exit 77
65 fi
66
67 sleepscip-shell system . . sleep. 1
68 DEV=$(grepscip-shell system . . grep. -l -e scsi_debug /sys/block/*/device/model | cutscip-shell system . . cut. -f4 -d /scip-shell filesystem . . `/`.)
69
70 DEV="/dev/$DEV"
71 [scip-shell system . . `[`. -b $DEV ] || failscip-shell shell shell-project 0.0.0 fail(). "Cannot find $DEV."
72 }
73
74 check_versionscip-shell shell shell-project 0.0.0 check_version().()
75 {
76 VER_STR=$(dmsetup targets | grepscip-shell system . . grep. crypt | cutscip-shell system . . cut. -f 2 -dv)
77 [scip-shell system . . `[`. -z "$VER_STR" ] && failscip-shell shell shell-project 0.0.0 fail(). "Failed to parse dm-crypt version."
78
79 VER_MAJ=$(echoscip-shell system . . echo. $VER_STR | cutscip-shell system . . cut. -f 1 -d.)
80 VER_MIN=$(echoscip-shell system . . echo. $VER_STR | cutscip-shell system . . cut. -f 2 -d.)
81
82 # option supported in 1.11
83 testscip-shell system . . test. $VER_MAJ -gt 1 && return 0
84 testscip-shell system . . test. $VER_MIN -ge 11 && return 0
85 return 1
86 }
87
88 [scip-shell system . . `[`. ! -x "$CRYPTSETUP" ] && skipscip-shell shell shell-project 0.0.0 skip(). "Cannot find $CRYPTSETUP, test skipped."
89 [scip-shell system . . `[`. -n "$VALG" ] && valgrind_setupscip-shell shell shell-project 0.0.0 valgrind_setup(). && CRYPTSETUP=valgrind_run
90 if [scip-shell system . . `[`. $(idscip-shell system . . id. -u) != 0 ]; then
91 echoscip-shell system . . echo. "WARNING: You must be root to run this test, test skipped."
92 exit 77
93 fi
94
95 modprobe dm-crypt >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1
96 if ! check_versionscip-shell shell shell-project 0.0.0 check_version(). ; then
97 echoscip-shell system . . echo. "Probably old kernel, test skipped."
98 exit 77
99 fi
100
101 add_devicescip-shell shell shell-project 0.0.0 add_device(). dev_size_mb=16 sector_size=512 num_tgts=1 lbpu=1
102
103 # FIXME test hash of device (unmap -> zero)
104 # for now just check that flag is enabled
105
106 echoscip-shell system . . echo. "[1] Allowing discards for LUKS device"
107 echoscip-shell system . . echo. $PWD1 | $CRYPTSETUP luksFormat --type luks1 $DEV -q -i1 || failscip-shell shell shell-project 0.0.0 fail().
108 echoscip-shell system . . echo. $PWD1 | $CRYPTSETUP luksOpen $DEV $DEV_NAME --allow-discards || failscip-shell shell shell-project 0.0.0 fail().
109 $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. flags | grepscip-shell system . . grep. discards >/dev/nullscip-shell filesystem . . `/dev/null`. || failscip-shell shell shell-project 0.0.0 fail().
110 $CRYPTSETUP resize $DEV_NAME --size 100 || failscip-shell shell shell-project 0.0.0 fail().
111 $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. flags | grepscip-shell system . . grep. discards >/dev/nullscip-shell filesystem . . `/dev/null`. || failscip-shell shell shell-project 0.0.0 fail().
112 dmsetup table $DEV_NAME | grepscip-shell system . . grep. allow_discards >/dev/nullscip-shell filesystem . . `/dev/null`. || failscip-shell shell shell-project 0.0.0 fail().
113 $CRYPTSETUP luksClose $DEV_NAME || failscip-shell shell shell-project 0.0.0 fail().
114
115 echoscip-shell system . . echo. "[2] Allowing discards for plain device"
116 echoscip-shell system . . echo. $PWD1 | $CRYPTSETUP create -q $DEV_NAME $DEV --cipher aes-cbc-essiv:sha256 --key-size 256 --hash sha256 --allow-discards || failscip-shell shell shell-project 0.0.0 fail().
117 $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. flags | grepscip-shell system . . grep. discards >/dev/nullscip-shell filesystem . . `/dev/null`. || failscip-shell shell shell-project 0.0.0 fail().
118 $CRYPTSETUP resize $DEV_NAME --size 100 || failscip-shell shell shell-project 0.0.0 fail().
119 $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. flags | grepscip-shell system . . grep. discards >/dev/nullscip-shell filesystem . . `/dev/null`. || failscip-shell shell shell-project 0.0.0 fail().
120 dmsetup table $DEV_NAME | grepscip-shell system . . grep. allow_discards >/dev/nullscip-shell filesystem . . `/dev/null`. || failscip-shell shell shell-project 0.0.0 fail().
121 $CRYPTSETUP remove $DEV_NAME || failscip-shell shell shell-project 0.0.0 fail().
122
123 cleanupscip-shell shell shell-project 0.0.0 cleanup().