mkfs_ext2: further work by Vladimir
[oweals/busybox.git] / util-linux / mkfs_ext2_test.sh
1 #!/bin/sh
2
3 run_test() { # params: mke2fs_invocation image_name
4     >$2
5     dd seek=$((kilobytes-1)) bs=1K count=1 </dev/zero of=$2 >/dev/null 2>&1 || exit 1
6     $1 -F $2 $kilobytes >$2.raw_out 2>&1 || return 1
7     cat $2.raw_out \
8     | grep -v '^mke2fs [0-9]*\.[0-9]*\.[0-9]* ' \
9     | grep -v '^Maximum filesystem' \
10     | grep -v '^Writing inode tables' \
11     | grep -v '^Writing superblocks and filesystem accounting information' \
12     | grep -v '^This filesystem will be automatically checked every' \
13     | grep -v '^180 days, whichever comes first' \
14     | sed 's/inodes, [0-9]* blocks/inodes, N blocks/' \
15     | sed 's/blocks* unused./blocks unused/' \
16     | sed 's/block groups*/block groups/' \
17     | sed 's/ *$//' \
18     | sed 's/blocks (.*%) reserved/blocks reserved/' \
19     | grep -v '^$' \
20     >$2.out
21 }
22
23 test_mke2fs() {
24     echo Testing $kilobytes
25
26     run_test '/sbin/mke2fs' image_std || return 1
27     run_test './busybox mke2fs' image_bb || return 1
28
29     diff -ua image_bb.out image_std.out >image.out.diff || {
30         cat image.out.diff
31         return 1
32     }
33
34     e2fsck -f -n image_bb >/dev/null 2>&1 || {
35         echo "e2fsck error on image_bb"
36         e2fsck -f -n image_bb
37         exit 1
38     }
39 }
40
41 # Should start from kilobytes=60, but e2fsck complains on it:
42 # e2fsck 1.41.4 (27-Jan-2009)
43 # Pass 1: Checking inodes, blocks, and sizes
44 # Pass 2: Checking directory structure
45 # Pass 3: Checking directory connectivity
46 # Pass 4: Checking reference counts
47 # Pass 5: Checking group summary information
48 # Inode bitmap differences:  +(9--11)
49 # Free inodes count wrong for group #0 (5, counted=8).
50 # Directories count wrong for group #0 (2, counted=1).
51 # Free inodes count wrong (5, counted=8).
52 # image_bb: 11/16 files (0.0% non-contiguous), 9/60 blocks
53 kilobytes=68
54 while true; do
55     test_mke2fs #|| exit 1
56     : $((kilobytes++))
57 done
58 exit
59
60 # Specific sizes with known differences:
61 # -:bbox +:standard
62
63 # -6240 inodes, 24908 blocks
64 # +6240 inodes, 24577 blocks
65 # -4 block group
66 # +3 block group
67 # -1560 inodes per group
68 # +2080 inodes per group
69 kilobytes=24908 test_mke2fs
70
71 # -304 inodes, N blocks
72 # +152 inodes, N blocks
73 # -304 inodes per group
74 # +152 inodes per group
75 kilobytes=1218 test_mke2fs
76
77 # -14464 inodes, N blocks
78 # +14448 inodes, N blocks
79 # -8 block group
80 # +7 block group
81 # -1808 inodes per group
82 # +2064 inodes per group
83 kilobytes=57696 test_mke2fs
84
85 # -warning: 239 blocks unused.
86 # +warning: 242 blocks unused.
87 kilobytes=49395 test_mke2fs
88
89 ## This size results in "warning: 75 blocks unused"
90 #kilobytes=98380 test_mke2fs
91
92 while true; do
93     kilobytes=$(( (RANDOM*RANDOM) % 1000000 + 60))
94     test_mke2fs || exit 1
95 done