Whamcloud - gitweb
LU-17310 tests: make m_assume_storage_prezeroed more robust
[tools/e2fsprogs.git] / tests / m_assume_storage_prezeroed / script
1 test_description="test prezeroed storage metadata allocation"
2 FILE_SIZE=16M
3
4 LOG=$test_name.log
5 OUT=$test_name.out
6 EXP=$test_dir/expect
7
8 if test "$(id -u)" -ne 0 ; then
9     echo "$test_name: $test_description: skipped (not root)"
10 elif ! command -v losetup >/dev/null ; then
11     echo "$test_name: $test_description: skipped (no losetup)"
12 else
13     dd if=/dev/zero of=$TMPFILE bs=1 count=0 seek=$FILE_SIZE >> $LOG 2>&1
14
15     LOOP=$(losetup --show -f $TMPFILE)
16     if [ ! -b "$LOOP" ]; then
17          echo "$test_name: $DESCRIPTION: skipped (no loop devices)"
18          rm -f $TMPFILE
19          exit 0
20     fi
21
22     cmd="$MKE2FS -o Linux -t ext4 -b 4096"
23     echo "$cmd $LOOP" >> $LOG
24     $cmd $LOOP >> $LOG 2>&1
25     losetup -d $LOOP
26     sync
27     stat $TMPFILE >> $LOG 2>&1
28     BLOCKS_DEF=$(stat -c "%b" $TMPFILE)
29
30     > $TMPFILE
31     dd if=/dev/zero of=$TMPFILE bs=1 count=0 seek=$FILE_SIZE >> $LOG 2>&1
32     LOOP=$(losetup --show -f $TMPFILE)
33     if [ ! -b "$LOOP" ]; then
34          echo "$test_name: $DESCRIPTION: skipped (no loop devices)"
35          rm -f $TMPFILE
36          exit 0
37     fi
38
39     cmd+=" -E assume_storage_prezeroed=1"
40     echo "$cmd $LOOP" >> $LOG
41     $cmd $TMPFILE >> $LOG 2>&1
42     losetup -d $LOOP
43     sync
44     stat $TMPFILE >> $LOG 2>&1
45     BLOCKS_ASP=$(stat -c "%b" $TMPFILE)
46
47     echo "blocks_dev: $BLOCKS_DEF blocks_asp: ${BLOCKS_ASP}" >> $LOG
48
49     # should use less than 1/20 of the blocks with assume_storage_prezeroed
50     if (( $BLOCKS_DEF > $BLOCKS_ASP * 40 )) ; then
51         echo "$test_name: $test_description: ok"
52         touch $test_name.ok
53     else
54         echo "$test_name: $test_description: failed"
55         cat $LOG > $test_name.failed
56         diff $EXP $OUT >> $test_name.failed
57     fi
58 fi
59 unset LOG OUT EXP FILE_SIZE LOOP