-
Notifications
You must be signed in to change notification settings - Fork 32
/
test-gen.lib
100 lines (90 loc) · 2.94 KB
/
test-gen.lib
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/sh
# These routines contain the filesystem generation code.
# This code is sourced by the other scripts so that digest
# generation is consistent.
LC_ALL=C
export LC_ALL
origin_dir="$(dirname "$(realpath "$0")")"
test_dir=t_tmp_dir
test_img=t_tmp_ext2.img
gen_cleanup () {
rm -rf $test_dir $test_img
}
gen_setup () {
gen_cleanup
mkdir $test_dir || exit 1
}
calc_digest () {
digest=`md5sum $test_img 2>/dev/null | cut -f 1 -d " "`
if [ x$digest != x ] ; then
echo $digest
else
digest=`md5 $test_img 2>/dev/null | cut -f 4 -d " "`
echo $digest
fi
}
# dgen - Exercises the -d option of genext2fs.
# Creates an image with a file of given size.
dgen () {
blocks=$1; blocksz=$2; size=$3
echo Testing $blocks blocks of $blocksz bytes with file of size $size
gen_setup
cd $test_dir
if [ x$size = x0 ]; then
> file.$size
else
dd if=/dev/zero of=file.$size bs=$size count=1 2>/dev/null
fi
chmod 777 file.$size
TZ=UTC-11 touch -t 200502070321.43 file.$size .
cd ..
./genext2fs -B $blocksz -N 17 -b $blocks -d $test_dir -f -o Linux -q $test_img
}
# fgen - Exercises the -D option of genext2fs.
# Creates an image with the devices listed in the given spec file.
fgen () {
stdin=$1; blocks=$2; fname=$4
echo Testing $blocks blocks with with devices file $fname
gen_setup
cp $origin_dir/$fname $test_dir
TZ=UTC-11 touch -t 200502070321.43 $test_dir/$fname
if [ "$stdin" = "y" ]; then
./genext2fs -N 92 -b $blocks -D - -f -o Linux $test_img < $test_dir/$fname
else
./genext2fs -N 92 -b $blocks -D $test_dir/$fname -f -o Linux $test_img
fi
}
# lgen - Exercises the -d option of genext2fs, with symlink
# and a device table
# Creates an image with a symlink of variable length, then
# uses a device table to change its uid/gid
# NB: some systems including early versions of Mac OS X cannot
# change symlink timestamps; this test will fail on those systems.
lgen () {
stdin=$1; blocks=$2; blocksz=$3; appendage=$4; devtable=$5
echo Testing $blocks blocks of $blocksz bytes with symlink ...$appendage and devices file $devtable
gen_setup
cd $test_dir
target=12345678901234567890123456789012345678901234567890$appendage
ln -s $target symlink
TZ=UTC-11 touch -h -t 201309241353.59 symlink .
cd ..
if [ "$stdin" = "y" ]; then
./genext2fs -B $blocksz -N 234 -b $blocks -d $test_dir -D - -f -o Linux -q $test_img < $origin_dir/$devtable
else
./genext2fs -B $blocksz -N 234 -b $blocks -d $test_dir -D $origin_dir/$devtable -f -o Linux -q $test_img
fi
}
# agen - Exercises the -a option of genext2fs.
# Creates an image with a file of given size.
agen () {
stdin=$1; blocks=$2; blocksz=$3; tarball=$4
echo Testing $blocks blocks of $blocksz bytes with tarball
gen_setup
echo $tarball | base64 -d | gzip -dc > "$test_dir/input.tar"
if [ "$stdin" = "y" ]; then
./genext2fs -B $blocksz -N 17 -b $blocks -a - -f -o Linux $test_img < "$test_dir/input.tar"
else
./genext2fs -B $blocksz -N 17 -b $blocks -a "$test_dir/input.tar" -f -o Linux $test_img
fi
}