Cryptomount testing
cover Cryptomount testing
This patch series adds a variety of functional cryptomount LUKS1/2 tests by creating a LUKS container on the host and verifying that data inside can be read accurately from a virtualized GRUB. This should be especially useful when we eventually get around to upgrading the gcrypt library.
Glenn
Glenn Washburn (6):
grub-shell: Set exit status to qemu exit status
grub-shell: Only cleanup working directory file if QEMU does not fail
or timeout
grub-shell: Allow specifying non-default trim line contents
grub-shell: Trim line should always be matched from the beginning of
the line
grub-shell: Add halt_cmd variable to testcase namespace
tests: Add cryptomount functional test
Makefile.util.def | 12 + tests/grub_cmd_cryptomount.in | 185 ++++++++++++++ tests/util/grub-shell-luks-tester.in | 366 +++++++++++++++++++++++++++ tests/util/grub-shell.in | 49 +++- 4 files changed, 600 insertions(+), 12 deletions(-) create mode 100644 tests/grub_cmd_cryptomount.in create mode 100644 tests/util/grub-shell-luks-tester.in
Signature · 1 line
2.34.1
PATCH 1/6 grub-shell: Set exit status to qemu exit status
This allows us to test if unexpected output in test scripts is because of a bug in grub, because there was an error in qemu, or qemu was killed due to a timeout.
--- tests/util/grub-shell.in | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-)
tests/util/grub-shell.in +17 -4
@@ -502,6 +502,12 @@ copy_extra_files() { done } +setup_qemu_logger() { + cat < "$work_directory/qemu-pipe" | tr -d "\r" | tee "${goutfile}" | do_trim & +} + +ret=0 +mkfifo "$work_directory/qemu-pipe" if [ x$boot = xnet ]; then netdir="$work_directory/netdir" mkdir -p "$netdir"
@@ -509,7 +515,8 @@ if [ x$boot = xnet ]; then cp "${cfgfile}" "$netdir/boot/grub/grub.cfg" cp "${source}" "$netdir/boot/grub/testcase.cfg" [ -z "$files" ] || copy_extra_files "$netdir" $files - timeout -s KILL $timeout "${qemu}" ${qemuopts} ${serial_null} -serial file:/dev/stdout -boot n -net "user,tftp=$netdir,bootfile=/boot/grub/${grub_modinfo_target_cpu}-${grub_modinfo_platform}/core.$netbootext" -net nic | cat | tr -d "\r" | tee "${goutfile}" | do_trim + setup_qemu_logger + timeout -s KILL $timeout "${qemu}" ${qemuopts} ${serial_null} -serial file:/dev/stdout -boot n -net "user,tftp=$netdir,bootfile=/boot/grub/${grub_modinfo_target_cpu}-${grub_modinfo_platform}/core.$netbootext" -net nic > "$work_directory/qemu-pipe" || ret=$? elif [ x$boot = xemu ]; then rootdir="$work_directory/rootdir" grubdir="$rootdir/boot/grub"
@@ -528,12 +535,18 @@ elif [ x$boot = xemu ]; then [ -z "$files" ] || copy_extra_files "$rootdir" $files roottar="$work_directory/root.tar" (cd "$rootdir"; tar cf "$roottar" .) - "${builddir}/grub-core/grub-emu" -m "$device_map" --memdisk "$roottar" -r memdisk -d "/boot/grub" | tr -d "\r" | tee "${goutfile}" | do_trim + setup_qemu_logger + "${builddir}/grub-core/grub-emu" -m "$device_map" --memdisk "$roottar" -r memdisk -d "/boot/grub" > "$work_directory/qemu-pipe" || ret=$? test -n "$debug" || rm -rf "$rootdir" test -n "$debug" || rm -f "$roottar" else - timeout -s KILL $timeout "${qemu}" ${qemuopts} ${serial_null} -serial file:/dev/stdout -${device}"${isofile}" ${bootdev} | cat | tr -d "\r" | tee "${goutfile}" | do_trim + setup_qemu_logger + timeout -s KILL $timeout "${qemu}" ${qemuopts} ${serial_null} -serial file:/dev/stdout -${device}"${isofile}" ${bootdev} > "$work_directory/qemu-pipe" || ret=$? fi + +wait +rm -f "$work_directory/qemu-pipe" + if [ x$boot = xcoreboot ]; then test -n "$debug" || rm -f "${imgfile}" fi
@@ -541,6 +554,6 @@ test -n "$debug" || rm -f "${isofile}" test -n "$debug" || rm -rf "${rom_directory}" test -n "$debug" || rm -f "${tmpfile}" "${cfgfile}" "${goutfile}" -exit 0 +exit $ret
Signature · 1 line
2.34.1
PATCH 2/6 grub-shell: Only cleanup working directory file if QEMU does not fail or timeout
In reply to Glenn WashburnThis keeps the generated files to aid in diagnosing the source of the failure.
--- tests/util/grub-shell.in | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
tests/util/grub-shell.in +8 -2
@@ -537,8 +537,6 @@ elif [ x$boot = xemu ]; then (cd "$rootdir"; tar cf "$roottar" .) setup_qemu_logger "${builddir}/grub-core/grub-emu" -m "$device_map" --memdisk "$roottar" -r memdisk -d "/boot/grub" > "$work_directory/qemu-pipe" || ret=$? - test -n "$debug" || rm -rf "$rootdir" - test -n "$debug" || rm -f "$roottar" else setup_qemu_logger timeout -s KILL $timeout "${qemu}" ${qemuopts} ${serial_null} -serial file:/dev/stdout -${device}"${isofile}" ${bootdev} > "$work_directory/qemu-pipe" || ret=$?
@@ -547,8 +545,16 @@ fi wait rm -f "$work_directory/qemu-pipe" +if [ "$ret" -ne 0 ]; then + # If QEMU failure, keep generated files to reproduce + exit $ret +fi + if [ x$boot = xcoreboot ]; then test -n "$debug" || rm -f "${imgfile}" +elif [ x$boot = xemu ]; then + test -n "$debug" || rm -rf "$rootdir" + test -n "$debug" || rm -f "$roottar" fi test -n "$debug" || rm -f "${isofile}" test -n "$debug" || rm -rf "${rom_directory}"
Signature · 1 line
2.34.1
PATCH 3/6 grub-shell: Allow specifying non-default trim line contents
In reply to Glenn WashburnThis will be useful for tests that have unwanted output from setup. This is not documented because its only intended to be internal at the moment. Also, --no-trim is allowed to explicitly turn off trim.
--- tests/util/grub-shell.in | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
tests/util/grub-shell.in +9 -5
@@ -32,6 +32,7 @@ PATH="${builddir}:$PATH" export PATH trim=0 +trim_head=664cbea8-132f-4770-8aa4-1696d59ac35c # Usage: usage # Print the usage.
@@ -226,8 +227,13 @@ for option in "$@"; do echo "$0 (GNU GRUB ${PACKAGE_VERSION})" exit 0 ;; --trim) - trim=1 + trim=1 ;; + --trim=*) + trim=2 + trim_head=`echo "$option" | sed -e 's/--trim=//' -e 's/,/ /g'` ;; + --no-trim) + trim=0 ;; --debug) debug=1 ;; --modules=*)
@@ -353,8 +359,6 @@ terminal_input ${term} terminal_output ${term} EOF -trim_head=664cbea8-132f-4770-8aa4-1696d59ac35c - if [ $trim = 1 ]; then echo "echo $trim_head" >>${cfgfile} fi
@@ -479,8 +483,8 @@ fi do_trim () { - if [ $trim = 1 ]; then - awk '{ if (have_head == 1) print $0; } /664cbea8-132f-4770-8aa4-1696d59ac35c/ { have_head=1; }' + if [ $trim = 1 ] || [ $trim = 2 ]; then + awk '{ if (have_head == 1) print $0; } /'"$trim_head"'/ { have_head=1; }' else cat fi
Signature · 1 line
2.34.1
PATCH 4/6 grub-shell: Trim line should always be matched from the beginning of the line
In reply to Glenn WashburnWhen turning on shell tracing the trim line will be output before we actually want to start the trim. However, in this case the trim line never starts from the beginning of the line. So start trimming from the correct line by matching from the beginning of the line.
--- tests/util/grub-shell.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tests/util/grub-shell.in +2 -2
@@ -360,7 +360,7 @@ terminal_output ${term} EOF if [ $trim = 1 ]; then - echo "echo $trim_head" >>${cfgfile} + echo "echo; echo $trim_head" >>${cfgfile} fi rom_directory="$work_directory/rom_directory"
@@ -484,7 +484,7 @@ fi do_trim () { if [ $trim = 1 ] || [ $trim = 2 ]; then - awk '{ if (have_head == 1) print $0; } /'"$trim_head"'/ { have_head=1; }' + awk '{ if (have_head == 1) print $0; } /^'"$trim_head"'/ { have_head=1; }' else cat fi
Signature · 1 line
2.34.1
PATCH 5/6 grub-shell: Add halt_cmd variable to testcase namespace
In reply to Glenn WashburnThis allows test case scripts to use the appropriate halt command for the built architecture to end execution early. Otherwise, test case scripts have no way to know the appropriate mechanism for halting the test case early.
--- tests/util/grub-shell.in | 2 ++ 1 file changed, 2 insertions(+)
tests/util/grub-shell.in +2 -0
@@ -331,6 +331,8 @@ fi cfgfile="$work_directory/grub.cfg" cat <<EOF >${cfgfile} grubshell=yes +halt_cmd=${halt_cmd} +export halt_cmd enable_progress_indicator=0 export enable_progress_indicator EOF
Signature · 1 line
2.34.1
PATCH 6/6 tests: Add cryptomount functional test
In reply to Glenn WashburnThe grub_cmd_cryptomount make check test performs some functional testing of cryptomount and by extension the underlying cryptodisk infrastructure.
A utility test script named grub-shell-luks-tester is created to handle the complexities of the testing, making it simpler to add new test cases in grub_cmd_cryptomount.
--- Makefile.util.def | 12 + tests/grub_cmd_cryptomount.in | 185 ++++++++++++++ tests/util/grub-shell-luks-tester.in | 366 +++++++++++++++++++++++++++ 3 files changed, 563 insertions(+) create mode 100644 tests/grub_cmd_cryptomount.in create mode 100644 tests/util/grub-shell-luks-tester.in
Makefile.util.def +12 -0
@@ -743,6 +743,12 @@ script = { installdir = noinst; }; +script = { + name = grub-shell-luks-tester; + common = tests/util/grub-shell-luks-tester.in; + installdir = noinst; +}; + script = { name = grub-fs-tester; common = tests/util/grub-fs-tester.in;
@@ -1039,6 +1045,12 @@ script = { common = tests/grub_script_return.in; }; +script = { + testcase = nonnative; + name = grub_cmd_cryptomount; + common = tests/grub_cmd_cryptomount.in; +}; + script = { testcase = nonnative; name = grub_cmd_regexp;
tests/grub_cmd_cryptomount.in new file +185 -0
185 lines not on this page · raw message
tests/util/grub-shell-luks-tester.in new file +366 -0
366 lines not on this page · raw message
Signature · 1 line
2.34.1
Quoted 7 lines · Glenn Washburn
This patch series adds a variety of functional cryptomount LUKS1/2 tests by creating a LUKS container on the host and verifying that data inside can be read accurately from a virtualized GRUB. This should be especially useful when we eventually get around to upgrading the gcrypt library.
Glenn
Quoted 9 lines
Glenn Washburn (6):
grub-shell: Set exit status to qemu exit status
grub-shell: Only cleanup working directory file if QEMU does not fail
or timeout
grub-shell: Allow specifying non-default trim line contents
grub-shell: Trim line should always be matched from the beginning of
the line
grub-shell: Addhalt_cmdvariable to testcase namespace
tests: Add cryptomount functional test
For all the patches Reviewed-by: Daniel Kiper <[email protected]>...
Thank you for adding the LUKS tests.
Daniel
Quoted 18 lines · Daniel Kiper
Quoted 7 lines · Glenn Washburn
This patch series adds a variety of functional cryptomount LUKS1/2 tests by creating a LUKS container on the host and verifying that data inside can be read accurately from a virtualized GRUB. This should be especially useful when we eventually get around to upgrading the gcrypt library.
Glenn
Quoted 9 lines
Glenn Washburn (6):
grub-shell: Set exit status to qemu exit status
grub-shell: Only cleanup working directory file if QEMU does not fail
or timeout
grub-shell: Allow specifying non-default trim line contents
grub-shell: Trim line should always be matched from the beginning of
the line
grub-shell: Addhalt_cmdvariable to testcase namespace
tests: Add cryptomount functional test
Quoted 5 lines
For all the patches Reviewed-by: Daniel Kiper <[email protected]>...
Thank you for adding the LUKS tests.
Daniel
Seconded, thanks a bunch for these!
Patrick