genimage/test/ext.test
Michael Olbrich 0887e44090 tests: ext: use different output files to compare to instead of trying to patch the output
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
2024-06-28 09:25:34 +02:00

122 lines
3.1 KiB
Bash
Executable File

#!/bin/bash
test_description="extX Image Tests"
. "$(dirname "${0}")/test-setup.sh"
check_root() {
diff -ru "${root_orig}" "${root_test}"
}
func_check() {
local ret="$?"
set +x
if [ "${ret}" != 0 ]; then
echo "Failed to execute '${FUNCNAME[1]}'!" >&2
return "${ret}"
fi
}
compare_label() {
if [ "${1}" != "${2}" ]; then
echo "Filesystem Label does not match: exprected: '${2}' found '${1}'"
return 1
fi
}
version_leq() {
first="$(printf "${1}\n${2}" | sort -V | head -n1)"
test "${first}" == "${1}"
}
check_ext() {
[ "$verbose" = "t" ] && set -x
# UUID is randomly generated
uuid="Filesystem UUID"
# Hash Seed is randomly generated
seed="Directory Hash Seed:"
# checksum depends on random data
csum1="Checksum: \|Group 0: (Blocks 1-4095) csum"
# format change
csum2="Group 0: (Blocks 1-4095) \\[ITABLE_ZEROED\\]\| Checksum .*, unused inodes 205"
dumpe2fs "${1}" | grep -v "^\($uuid\|$seed\|$csum1\|$csum2\)" > "dump" &&
# some architectures (including arm64) use unsigned char
sed -i 's/un\(signed_directory_hash\)/\1/' "dump" &&
if [ "${4}" = "genext2fs" ]; then
if [ "$(genext2fs --version)" = "genext2fs 1.4.1" ]; then
version=0
else
dumpe2fs_version="$(dumpe2fs -V |& sed -n 's/^dumpe2fs \([^ ]*\) .*/\1/p')"
if version_leq "${dumpe2fs_version}" "1.46.2"; then
# Debian Bullseye
version=1
else
version=2
fi
fi
else
mke2fs_version="$(mke2fs -V |& sed -n 's/^mke2fs \([^ ]*\) .*/\1/p')"
if version_leq "${mke2fs_version}" "1.45.5"; then
# Ubuntu 20.04
version=0
elif version_leq "${mke2fs_version}" "1.46.5"; then
# Ubuntu 22.04
version=1
elif version_leq "${mke2fs_version}" "1.47.0"; then
# Ubuntu 24.04
version=2
else
# at least 1.47.0
version=3
fi
fi
export TEST_CMP="diff --ignore-space-change -u" &&
test_cmp "${testdir}/${2}.${version}.dump" "dump" &&
e2fsck -nf "${1}" &&
# old versions of debugfs cannot dump '/'
debugfs -R "ls -p" "${1}" | (
IFS=/
while read a b c d e x f; do
case "${x}" in
.|..|lost+found|"") continue ;;
esac
debugfs -R "rdump \"${x}\" \"${root_test}\"" "${1}" || break
done
) &&
check_size "${1}" "${3}" &&
check_root
func_check
}
exec_test_set_prereq genext2fs
exec_test_set_prereq e2fsck
test_expect_success genext2fs,e2fsck "ext2" "
run_genimage_root ext2.config test.ext2 &&
check_ext images/test.ext2 ext2test 4194304 genext2fs
"
test_expect_success genext2fs,e2fsck "ext2percent" "
run_genimage_root ext2percent.config test.ext2 &&
check_ext images/test.ext2 ext2test-percent 69632 genext2fs
"
test_expect_success genext2fs,e2fsck "ext3" "
run_genimage_root ext3.config test.ext3 &&
check_ext images/test.ext3 ext3test 4194304 genext2fs
"
test_expect_success genext2fs,e2fsck "ext4" "
run_genimage ext4.config test.ext4 &&
check_ext images/test.ext4 ext4test 4194304 genext2fs
"
# make sure mke2fs supports '-d root-directory'
[ "$(mke2fs |& sed -n 's/.*\(-d \).*/\1/p')" = "-d " ] && test_set_prereq mke2fs
test_expect_success mke2fs,e2fsck "mke2fs" "
run_genimage_root mke2fs.config mke2fs.ext4 &&
check_ext images/mke2fs.ext4 mke2fs 33554432 mke2fs
"
test_done
# vim: syntax=sh