aboutsummaryrefslogtreecommitdiff
path: root/test-gen.lib
blob: c6e73b9f5940fc7998a53336a783c554164c38ab (plain)
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
#!/bin/sh

# These routines contain the filesystem generation code.
# This code is sourced by the other scripts so that digest
# generation is consistent.

# dgen - Exercises the -d directory option of genext2fs
# Creates an image with a file of given size
# Usage: dgen file-size number-of-blocks 
dgen () {
	size=$1; blocks=$2
	rm -rf test
	mkdir -p test
	cd test
	if [ x$size = x0 ]; then
		> file.$1
	else
		dd if=/dev/zero of=file.$1 bs=$size count=1 2>/dev/null
	fi
        chmod 777 file.$1
	TZ=UTC-11 touch -t 200502070321.43 file.$1 .
	cd ..
	./genext2fs -N 17 -b $blocks -d test -f -q ext2.img 
}

# fgen - Exercises the -f spec-file option of genext2fs
# Creates an image with the devices mentioned in the given spec file 
# Usage: fgen spec-file number-of-blocks 
fgen () {
	fname=$1; blocks=$2; 
	mkdir -p test
	cp $fname test
	TZ=UTC-11 touch -t 200502070321.43 test/$fname
	./genext2fs -N 92 -b $blocks -D test/$fname -f ext2.img
}

# gen_cleanup - Remove the files generated by the above functions
# Usage: gen_cleanup
gen_cleanup () {
	rm -rf ext2.img test
}

# calc_digest - Return the MD5 digest of the test image
# Usage: calc_digest
calc_digest () {
	digest=`md5sum ext2.img 2>/dev/null | cut -f 1 -d " "`
	if [ x$digest != x ] ; then
 		echo $digest
	else
		digest=`md5 ext2.img 2>/dev/null | cut -f 4 -d " "`
		echo $digest
	fi
}

LC_ALL=C
export LC_ALL