mkfs_ext2: another update by Vladimir
[oweals/busybox.git] / util-linux / mkfs_ext2_test.sh
1 #!/bin/sh
2
3 system_mke2fs='/sbin/mke2fs'
4 bbox_mke2fs='./busybox mke2fs'
5
6 gen_image() { # params: mke2fs_invocation image_name
7     >$2
8     dd seek=$((kilobytes-1)) bs=1K count=1 </dev/zero of=$2 >/dev/null 2>&1 || exit 1
9     $1 -F $2 $kilobytes >$2.raw_out 2>&1 || return 1
10     cat $2.raw_out \
11     | grep -v '^mke2fs [0-9]*\.[0-9]*\.[0-9]* ' \
12     | grep -v '^Maximum filesystem' \
13     | grep -v '^Writing inode tables' \
14     | grep -v '^Writing superblocks and filesystem accounting information' \
15     | grep -v '^This filesystem will be automatically checked every' \
16     | grep -v '^180 days, whichever comes first' \
17     | sed 's/blocks* unused./blocks unused/' \
18     | sed 's/block groups*/block groups/' \
19     | sed 's/ *$//' \
20     | sed 's/blocks (.*%) reserved/blocks reserved/' \
21     | grep -v '^$' \
22     >$2.out
23 }
24
25 test_mke2fs() {
26     echo Testing $kilobytes
27
28     gen_image "$system_mke2fs" image_std || return 1
29     gen_image "$bbox_mke2fs"   image_bb  || return 1
30
31     diff -ua image_bb.out image_std.out >image.out.diff || {
32         cat image.out.diff
33         return 1
34     }
35
36     e2fsck -f -n image_bb >image_bb_e2fsck.out 2>&1 || {
37         echo "e2fsck error on image_bb"
38         cat image_bb_e2fsck.out
39         exit 1
40     }
41 }
42
43 # -:bbox +:standard
44
45 # kilobytes=60 is the minimal allowed size
46 kilobytes=60
47 while true; do
48     test_mke2fs || exit 1
49     : $((kilobytes++))
50     test $kilobytes = 200 && break
51 done
52
53 # Transition from one block group to two
54 # fails in [8378..8410] range
55 kilobytes=$((1 * 8*1024 - 50))
56 while true; do
57     test_mke2fs #|| exit 1
58     : $((kilobytes++))
59     test $kilobytes = $((1 * 8*1024 + 300)) && break
60 done
61
62 # Transition from 2 block groups to 3
63 # works
64 kilobytes=$((2 * 8*1024 - 50))
65 while true; do
66     test_mke2fs || exit 1
67     : $((kilobytes++))
68     test $kilobytes = $((2 * 8*1024 + 400)) && break
69 done
70
71 # Transition from 3 block groups to 4
72 # fails in [24825..24922] range
73 kilobytes=$((3 * 8*1024 - 50))
74 while true; do
75     test_mke2fs #|| exit 1
76     : $((kilobytes++))
77     test $kilobytes = $((3 * 8*1024 + 500)) && break
78 done
79
80 # Transition from 4 block groups to 5
81 # works
82 kilobytes=$((4 * 8*1024 - 50))
83 while true; do
84     test_mke2fs || exit 1
85     : $((kilobytes++))
86     test $kilobytes = $((4 * 8*1024 + 600)) && break
87 done
88
89 # Transition from 5 block groups to 6
90 # fails in [41230..41391] range
91 kilobytes=$((5 * 8*1024 - 50))
92 while true; do
93     test_mke2fs #|| exit 1
94     : $((kilobytes++))
95     test $kilobytes = $((5 * 8*1024 + 700)) && break
96 done
97 exit
98
99 # Random sizes
100 while true; do
101     kilobytes=$(( (RANDOM*RANDOM) % 1000000 + 60))
102     test_mke2fs || exit 1
103 done