Codebase list genext2fs / 9544435b-f3de-4cb6-abf7-94b7c2911742/main test-gen.lib
9544435b-f3de-4cb6-abf7-94b7c2911742/main

Tree @9544435b-f3de-4cb6-abf7-94b7c2911742/main (Download .tar.gz)

test-gen.lib @9544435b-f3de-4cb6-abf7-94b7c2911742/mainraw · history · blame

#!/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
}