| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | |
| 3 | WIPE_UNIT=./unit-wipe |
| 4 | FILE=./wipe_localfile |
| 5 | FILE_RAND=./wipe_random_localfile |
| 6 | MB_BYTES=$((1024*1024)) |
| 7 | DEVSIZEMB=8 |
| 8 | DEVSIZE=$((DEVSIZEMB*$MB_BYTES)) |
| 9 | |
| 10 | HASH_EMPTY=2daeb1f36095b44b318410b3f4e8b5d989dcc7bb023d1426c492dab0a3053e74 |
| 11 | |
| 12 | cleanupscip-shell shell shell-project 0.0.0 cleanup().() { |
| 13 | rmscip-shell system . . rm. -f $FILE $FILE_RAND 2> /dev/nullscip-shell filesystem . . `/dev/null`. |
| 14 | sleepscip-shell system . . sleep. 1 |
| 15 | rmmod scsi_debug >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 |
| 16 | } |
| 17 | |
| 18 | failscip-shell shell shell-project 0.0.0 fail().() |
| 19 | { |
| 20 | if [scip-shell system . . `[`. -n "$1" ] ; then echoscip-shell system . . echo. "FAIL $1" ; else echoscip-shell system . . echo. "FAIL" ; fi |
| 21 | echoscip-shell system . . echo. "FAILED backtrace:" |
| 22 | while caller $frame; do ((frame++)); done |
| 23 | cleanupscip-shell shell shell-project 0.0.0 cleanup(). |
| 24 | exit 100 |
| 25 | } |
| 26 | |
| 27 | _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"; } |
| 28 | trap _sigchld CHLD |
| 29 | |
| 30 | skipscip-shell shell shell-project 0.0.0 skip().() |
| 31 | { |
| 32 | echoscip-shell system . . echo. "TEST SKIPPED: $1" |
| 33 | cleanupscip-shell shell shell-project 0.0.0 cleanup(). |
| 34 | exit 77 |
| 35 | } |
| 36 | |
| 37 | add_devicescip-shell shell shell-project 0.0.0 add_device().() |
| 38 | { |
| 39 | rmmod scsi_debug >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 |
| 40 | if [scip-shell system . . `[`. -d /sys/module/scsi_debugscip-shell filesystem . . `/sys/module/scsi_debug`. ] ; then |
| 41 | skipscip-shell shell shell-project 0.0.0 skip(). "Cannot use scsi_debug module (in use or compiled-in)." |
| 42 | fi |
| 43 | modprobe scsi_debug dev_size_mb=$DEVSIZEMB num_tgts=1 delay=0 >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 |
| 44 | if [scip-shell system . . `[`. $? -ne 0 ] ; then |
| 45 | skipscip-shell shell shell-project 0.0.0 skip(). "This kernel seems to not support proper scsi_debug module." |
| 46 | fi |
| 47 | sleepscip-shell system . . sleep. 1 |
| 48 | DEV=$(grepscip-shell system . . grep. -l -e scsi_debug /sys/block/*/device/model | cutscip-shell system . . cut. -f4 -d /scip-shell filesystem . . `/`.) |
| 49 | DEV="/dev/$DEV" |
| 50 | [scip-shell system . . `[`. -b $DEV ] || failscip-shell shell shell-project 0.0.0 fail(). "Cannot find $DEV." |
| 51 | } |
| 52 | |
| 53 | check_hashscip-shell shell shell-project 0.0.0 check_hash().() # $1 dev, $2 hash |
| 54 | { |
| 55 | local HASH=$(sha256sumscip-shell system . . sha256sum. $1 | cutscip-shell system . . cut. -d' ' -f 1) |
| 56 | [scip-shell system . . `[`. $HASH == "$2" ] |
| 57 | } |
| 58 | |
| 59 | init_hash_ddscip-shell shell shell-project 0.0.0 init_hash_dd().() # $1 dev, $dev orig |
| 60 | { |
| 61 | ddscip-shell system . . dd. if=/dev/urandomscip-shell filesystem . . `/dev/urandom`. of=$2 bs=1M count=$DEVSIZEMB conv=notrunc 2> /dev/nullscip-shell filesystem . . `/dev/null`. |
| 62 | ddscip-shell system . . dd. if=$2 of=$1 bs=1M conv=notrunc 2> /dev/nullscip-shell filesystem . . `/dev/null`. |
| 63 | HASH_0=$(sha256sumscip-shell system . . sha256sum. $1 | cutscip-shell system . . cut. -d' ' -f 1) |
| 64 | # second MB wiped |
| 65 | ddscip-shell system . . dd. if=/dev/zeroscip-shell filesystem . . `/dev/zero`. of=$1 bs=1M seek=1 count=1 conv=notrunc 2> /dev/nullscip-shell filesystem . . `/dev/null`. |
| 66 | HASH_1=$(sha256sumscip-shell system . . sha256sum. $1 | cutscip-shell system . . cut. -d' ' -f 1) |
| 67 | # 4,5,6 MB wiped |
| 68 | ddscip-shell system . . dd. if=/dev/zeroscip-shell filesystem . . `/dev/zero`. of=$1 bs=1M seek=4 count=3 conv=notrunc 2> /dev/nullscip-shell filesystem . . `/dev/null`. |
| 69 | HASH_2=$(sha256sumscip-shell system . . sha256sum. $1 | cutscip-shell system . . cut. -d' ' -f 1) |
| 70 | ddscip-shell system . . dd. if=$2 of=$1 bs=1M conv=notrunc 2> /dev/nullscip-shell filesystem . . `/dev/null`. |
| 71 | } |
| 72 | |
| 73 | add_filescip-shell shell shell-project 0.0.0 add_file().() |
| 74 | { |
| 75 | ddscip-shell system . . dd. if=/dev/zeroscip-shell filesystem . . `/dev/zero`. of=$FILE bs=1M count=$DEVSIZEMB 2> /dev/nullscip-shell filesystem . . `/dev/null`. || failscip-shell shell shell-project 0.0.0 fail(). |
| 76 | ddscip-shell system . . dd. if=/dev/zeroscip-shell filesystem . . `/dev/zero`. of=$FILE_RAND bs=1M count=$DEVSIZEMB 2> /dev/nullscip-shell filesystem . . `/dev/null`. || failscip-shell shell shell-project 0.0.0 fail(). |
| 77 | check_hashscip-shell shell shell-project 0.0.0 check_hash(). $FILE $HASH_EMPTY || failscip-shell shell shell-project 0.0.0 fail(). |
| 78 | check_hashscip-shell shell shell-project 0.0.0 check_hash(). $FILE_RAND $HASH_EMPTY || failscip-shell shell shell-project 0.0.0 fail(). |
| 79 | ddscip-shell system . . dd. if=$FILE of=/dev/nullscip-shell filesystem . . `/dev/null`. bs=4096 count=1 iflag=direct >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 || FILE_NODIO=1 |
| 80 | } |
| 81 | |
| 82 | test_wipe_fullscip-shell shell shell-project 0.0.0 test_wipe_full().() # $1 dev, $2 block size, [$3 flags] |
| 83 | { |
| 84 | # wipe random and back to zero |
| 85 | $WIPE_UNIT $1 random 0 $DEVSIZE $2 $3 || failscip-shell shell shell-project 0.0.0 fail(). |
| 86 | check_hashscip-shell shell shell-project 0.0.0 check_hash(). $1 $HASH_EMPTY && failscip-shell shell shell-project 0.0.0 fail(). "Failed random wipe" |
| 87 | $WIPE_UNIT $1 zero 0 $DEVSIZE $2 $3 || failscip-shell shell shell-project 0.0.0 fail(). |
| 88 | check_hashscip-shell shell shell-project 0.0.0 check_hash(). $1 $HASH_EMPTY || failscip-shell shell shell-project 0.0.0 fail(). "Failed zero wipe" |
| 89 | } |
| 90 | |
| 91 | # wipe MB blocks, with zero, random and special and back to original |
| 92 | test_wipe_blocksscip-shell shell shell-project 0.0.0 test_wipe_blocks().() # $1 dev $2 block sizem [$3 flags] |
| 93 | { |
| 94 | init_hash_ddscip-shell shell shell-project 0.0.0 init_hash_dd(). $1 $FILE_RAND |
| 95 | check_hashscip-shell shell shell-project 0.0.0 check_hash(). $1 $HASH_0 || failscip-shell shell shell-project 0.0.0 fail(). |
| 96 | |
| 97 | $WIPE_UNIT $1 zero $((1*$MB_BYTES)) $((1*$MB_BYTES)) $2 $3 || failscip-shell shell shell-project 0.0.0 fail(). |
| 98 | check_hashscip-shell shell shell-project 0.0.0 check_hash(). $1 $HASH_1 || failscip-shell shell shell-project 0.0.0 fail(). |
| 99 | $WIPE_UNIT $1 random $((1*$MB_BYTES)) $((1*$MB_BYTES)) $2 $3 || failscip-shell shell shell-project 0.0.0 fail(). |
| 100 | check_hashscip-shell shell shell-project 0.0.0 check_hash(). $1 $HASH_1 && failscip-shell shell shell-project 0.0.0 fail(). |
| 101 | $WIPE_UNIT $1 special $((1*$MB_BYTES)) $((1*$MB_BYTES)) $2 $3 || failscip-shell shell shell-project 0.0.0 fail(). |
| 102 | check_hashscip-shell shell shell-project 0.0.0 check_hash(). $1 $HASH_1 && failscip-shell shell shell-project 0.0.0 fail(). |
| 103 | $WIPE_UNIT $1 zero $((1*$MB_BYTES)) $((1*$MB_BYTES)) $2 $3 || failscip-shell shell shell-project 0.0.0 fail(). |
| 104 | check_hashscip-shell shell shell-project 0.0.0 check_hash(). $1 $HASH_1 || failscip-shell shell shell-project 0.0.0 fail(). |
| 105 | |
| 106 | $WIPE_UNIT $1 zero $((4*$MB_BYTES)) $((3*$MB_BYTES)) $2 $3 || failscip-shell shell shell-project 0.0.0 fail(). |
| 107 | check_hashscip-shell shell shell-project 0.0.0 check_hash(). $1 $HASH_2 || failscip-shell shell shell-project 0.0.0 fail(). |
| 108 | $WIPE_UNIT $1 random $((4*$MB_BYTES)) $((3*$MB_BYTES)) $2 $3 || failscip-shell shell shell-project 0.0.0 fail(). |
| 109 | check_hashscip-shell shell shell-project 0.0.0 check_hash(). $1 $HASH_2 && failscip-shell shell shell-project 0.0.0 fail(). |
| 110 | $WIPE_UNIT $1 special $((4*$MB_BYTES)) $((3*$MB_BYTES)) $2 $3 || failscip-shell shell shell-project 0.0.0 fail(). |
| 111 | check_hashscip-shell shell shell-project 0.0.0 check_hash(). $1 $HASH_2 && failscip-shell shell shell-project 0.0.0 fail(). |
| 112 | $WIPE_UNIT $1 zero $((4*$MB_BYTES)) $((3*$MB_BYTES)) $2 $3 || failscip-shell shell shell-project 0.0.0 fail(). |
| 113 | check_hashscip-shell shell shell-project 0.0.0 check_hash(). $1 $HASH_2 || failscip-shell shell shell-project 0.0.0 fail(). |
| 114 | } |
| 115 | |
| 116 | testscip-shell system . . test. -x $WIPE_UNIT || skipscip-shell shell shell-project 0.0.0 skip(). "Run \"make `basenamescip-shell system . . basename. $WIPE_UNIT`\" first" |
| 117 | |
| 118 | cleanupscip-shell shell shell-project 0.0.0 cleanup(). |
| 119 | add_filescip-shell shell shell-project 0.0.0 add_file(). |
| 120 | |
| 121 | echoscip-shell system . . echo. -n "[1] Wipe full file " |
| 122 | for bs in 0 $MB_BYTES $((4*$MB_BYTES)); do |
| 123 | if [scip-shell system . . `[`. -n "$FILE_NODIO" ]; then |
| 124 | echoscip-shell system . . echo. -n [$bs/DIO N/A] |
| 125 | else |
| 126 | echoscip-shell system . . echo. -n [$bs/DIO] |
| 127 | test_wipe_fullscip-shell shell shell-project 0.0.0 test_wipe_full(). $FILE $bs |
| 128 | fi |
| 129 | echoscip-shell system . . echo. -n [$bs] |
| 130 | test_wipe_fullscip-shell shell shell-project 0.0.0 test_wipe_full(). $FILE $bs no-dio |
| 131 | done |
| 132 | echoscip-shell system . . echo. "[OK]" |
| 133 | |
| 134 | echoscip-shell system . . echo. -n "[2] Wipe blocks in file " |
| 135 | for bs in 0 $MB_BYTES $((4*$MB_BYTES)); do |
| 136 | if [scip-shell system . . `[`. -n "$FILE_NODIO" ]; then |
| 137 | echoscip-shell system . . echo. -n [$bs/DIO N/A] |
| 138 | else |
| 139 | echoscip-shell system . . echo. -n [$bs/DIO] |
| 140 | test_wipe_blocksscip-shell shell shell-project 0.0.0 test_wipe_blocks(). $FILE $bs |
| 141 | fi |
| 142 | echoscip-shell system . . echo. -n [$bs] |
| 143 | test_wipe_blocksscip-shell shell shell-project 0.0.0 test_wipe_blocks(). $FILE $bs no-dio |
| 144 | done |
| 145 | echoscip-shell system . . echo. "[OK]" |
| 146 | |
| 147 | [scip-shell system . . `[`. $(idscip-shell system . . id. -u) -eq 0 ] || { |
| 148 | echoscip-shell system . . echo. "WARNING: You must be root to run remaining tests." |
| 149 | cleanupscip-shell shell shell-project 0.0.0 cleanup(). |
| 150 | exit 0 |
| 151 | } |
| 152 | |
| 153 | add_devicescip-shell shell shell-project 0.0.0 add_device(). |
| 154 | |
| 155 | echoscip-shell system . . echo. -n "[3] Wipe full block device " |
| 156 | for bs in 0 $MB_BYTES $((4*$MB_BYTES)); do |
| 157 | echoscip-shell system . . echo. -n [$bs/DIO] |
| 158 | test_wipe_fullscip-shell shell shell-project 0.0.0 test_wipe_full(). $DEV $bs |
| 159 | echoscip-shell system . . echo. -n [$bs] |
| 160 | test_wipe_fullscip-shell shell shell-project 0.0.0 test_wipe_full(). $DEV $bs no-dio |
| 161 | done |
| 162 | echoscip-shell system . . echo. "[OK]" |
| 163 | |
| 164 | echoscip-shell system . . echo. -n "[4] Wipe blocks in block device " |
| 165 | for bs in 0 $MB_BYTES $((4*$MB_BYTES)); do |
| 166 | echoscip-shell system . . echo. -n [$bs/DIO] |
| 167 | test_wipe_blocksscip-shell shell shell-project 0.0.0 test_wipe_blocks(). $DEV $bs |
| 168 | echoscip-shell system . . echo. -n [$bs] |
| 169 | test_wipe_blocksscip-shell shell shell-project 0.0.0 test_wipe_blocks(). $DEV $bs no-dio |
| 170 | done |
| 171 | echoscip-shell system . . echo. "[OK]" |
| 172 | |
| 173 | cleanupscip-shell shell shell-project 0.0.0 cleanup(). |