All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 00/15] Grub-shell improvements
@ 2022-02-10 21:51 Glenn Washburn
  2022-02-10 21:51 ` [PATCH v3 01/15] grub-shell: Allow specifying non-default trim line contents Glenn Washburn
                   ` (14 more replies)
  0 siblings, 15 replies; 16+ messages in thread
From: Glenn Washburn @ 2022-02-10 21:51 UTC (permalink / raw)
  To: Daniel Kiper, grub-devel; +Cc: Glenn Washburn

Updates since v2:
* Remove the QEMU output log if not running in debug mode
* The change in v1 to use firmware files had a crucial bug in that the pflash
  devine was missing a unit number, which I believe was being defaulted to 0.
  This was causing the VARS pflash devices to be used instead of (as opposed to
  in addition to) the CODE pflash causing the QEMU boot to hang.
* Better handling for when the VARS file doesn't exist
* Remove the QEMU output pipe after waiting for all processes to terminate and
  do the wait before potentially removing files in working directory
* Added 3 new patches 8, 9, and 10, which in order
 1. Prevent removing working directory files if QEMU did not finish successfully
 2. Create run.sh in working directory to easily re-run the QEMU part of the
    test that generated the working directory
 3. Separate out GRUB_QEMU_OPTS so that its easy to see what, if any, extra QEMU
    options were passed during the test (which could be why its failing)

Updates since v1:
* Improve QEMU logging patch to make sure all data is written to the pipe before
  exiting (otherwise tests can fail because they don't get the last bit of QEMU
  output).
* Improve QEMU firmware handling to prefer using the -bios option (for older
  setups) and prefer firmware files found in the source directory so that
  system firmware can be overridden and systems without packages providing the
  firmware can be used.

Most of these patches aid in debugging test failures. Some, like the trim
patches, extend grub-shell functionality for some new tests cases not in this
patch series. I've included these patches as a group even though most of these
patches to not rely on each other. I expect that there will be some that may
not be desired for inclusion, but hope that the ones that can, will be
selectively applied.

Patch #14 is meant to address an obvious problem, a using non-existant QEMU
machine type. But I'm not sure its correct because I haven't gotten the
affected tests working.

Patch #15 improves EFI target tests by loading the EFI bios via pflash devices,
as is standard on many distros, if no binary usable with -bios is available.
Assumptions about the name and location of these firmware binaries are based
on Debian, however properly named firmware binaries found in the source
directory will be used first.

Glenn

Glenn Washburn (15):
  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: Only show grub-mkrescue output if it returns an error
  grub-shell: Allow setting default timeout via
    GRUB_SHELL_DEFAULT_TIMEOUT envvar
  grub-shell: Put all generated files into working dir and use better
    file names
  grub-shell: Add grub output logfile with grub-shell --debug
  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: Create run.sh in working directory for easily running test
    again
  grub-shell: Add $GRUB_QEMU_OPTS to run.sh to easily see unofficial
    QEMU arguments
  tests: Allow turning on shell tracing from environment variables
  grub-shell: Add --verbose to mkrescue when $debug is greater than 2
  grub-shell: Only turn on qemu head when large debug value is specified
  grub-shell: Use malta qemu-mips machine type instead off non-existant
    indy
  grub-shell: Add flexibility in QEMU firmware handling

 tests/util/grub-fs-tester.in |   2 +
 tests/util/grub-shell.in     | 229 ++++++++++++++++++++++++++++++-----
 2 files changed, 198 insertions(+), 33 deletions(-)

Range-diff against v2:
 1:  52df3299f =  1:  52df3299f grub-shell: Allow specifying non-default trim line contents
 2:  7c8264aeb =  2:  7c8264aeb grub-shell: Trim line should always be matched from the beginning of the line
 3:  c17da94e7 =  3:  c17da94e7 grub-shell: Only show grub-mkrescue output if it returns an error
 4:  27717b949 =  4:  27717b949 grub-shell: Allow setting default timeout via GRUB_SHELL_DEFAULT_TIMEOUT envvar
 5:  17dd72798 =  5:  17dd72798 grub-shell: Put all generated files into working dir and use better file names
 6:  428698acd !  6:  9be47ff05 grub-shell: Add grub output logfile with grub-shell --debug
    @@ tests/util/grub-shell.in: elif [ x$boot = xemu ]; then
      fi
      if [ x$boot = xcoreboot ]; then
          test -n "$debug" || rm -f "${imgfile}"
    + fi
    + test -n "$debug" || rm -f "${isofile}"
    + test -n "$debug" || rm -rf "${rom_directory}"
    +-test -n "$debug" || rm -f "${tmpfile}" "${cfgfile}"
    ++test -n "$debug" || rm -f "${tmpfile}" "${cfgfile}" "${goutfile}"
    ++
    + exit 0
    + 
    + 
 7:  cdd28473c !  7:  65e3da9c1 grub-shell: Set exit status to qemu exit status
    @@ tests/util/grub-shell.in: elif [ x$boot = xemu ]; then
     +    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}"
    -@@ tests/util/grub-shell.in: fi
    - test -n "$debug" || rm -f "${isofile}"
    + fi
    +@@ tests/util/grub-shell.in: test -n "$debug" || rm -f "${isofile}"
      test -n "$debug" || rm -rf "${rom_directory}"
    - test -n "$debug" || rm -f "${tmpfile}" "${cfgfile}"
    + test -n "$debug" || rm -f "${tmpfile}" "${cfgfile}" "${goutfile}"
    + 
     -exit 0
    -+rm -f "$work_directory/qemu-pipe"
    -+wait
     +exit $ret
      
      
 -:  --------- >  8:  250cdc08a grub-shell: Only cleanup working directory file if QEMU does not fail or timeout
 -:  --------- >  9:  39c6078bd grub-shell: Create run.sh in working directory for easily running test again
 -:  --------- > 10:  74539e4a7 grub-shell: Add $GRUB_QEMU_OPTS to run.sh to easily see unofficial QEMU arguments
 8:  d82bb5b49 = 11:  aed2c4949 tests: Allow turning on shell tracing from environment variables
 9:  16e95b1aa = 12:  34a61113c grub-shell: Add --verbose to mkrescue when $debug is greater than 2
10:  20e3f04db = 13:  2d390a7bc grub-shell: Only turn on qemu head when large debug value is specified
11:  10c55d9f3 = 14:  799fbdfd0 grub-shell: Use malta qemu-mips machine type instead off non-existant indy
12:  059ef632e ! 15:  80171fcab grub-shell: Add flexibility in QEMU firmware handling
    @@ Commit message
         it stores firmware files. If no firmware files are found, print an error
         message telling the user that those files must exist and exit with error.
     
    +    Do not load the system 32-bit ARM firmware VARS file because it must be
    +    writable to prevent a data exception and boot failure. So in order to use
    +    the VARS file, it must be copied to a writable location, but its quite large
    +    at 64M and is not needed to boot successfully.
    +
      ## tests/util/grub-shell.in ##
     @@ tests/util/grub-shell.in: case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
      	boot=cd
    @@ tests/util/grub-shell.in: case "${grub_modinfo_target_cpu}-${grub_modinfo_platfo
     +	if [ -f "$bios" ]; then
     +	    qemuopts="-bios $bios $qemuopts"
     +	elif [ -f "$pflash_code" ]; then
    -+	    qemuopts="-drive if=pflash,format=raw,readonly=on,file=$pflash_code $qemuopts"
    -+	    qemuopts="-drive if=pflash,format=raw,readonly=on,file=$pflash_vars $qemuopts"
    ++	    qemuopts="-drive if=pflash,format=raw,unit=0,readonly=on,file=$pflash_code $qemuopts"
    ++	    if [ -f "$pflash_vars" ]; then
    ++		qemuopts="-drive if=pflash,format=raw,unit=1,readonly=on,file=$pflash_vars $qemuopts"
    ++	    fi
     +	else
     +	    bios=/usr/share/qemu/OVMF32.fd
     +	    pflash_code=/usr/share/OVMF/OVMF32_CODE_4M.secboot.fd
    @@ tests/util/grub-shell.in: case "${grub_modinfo_target_cpu}-${grub_modinfo_platfo
     +	    if [ -f "$bios" ]; then
     +		qemuopts="-bios $bios $qemuopts"
     +	    elif [ -f "$pflash_code" ]; then
    -+		qemuopts="-drive if=pflash,format=raw,readonly=on,file=$pflash_code $qemuopts"
    -+		qemuopts="-drive if=pflash,format=raw,readonly=on,file=$pflash_vars $qemuopts"
    ++		qemuopts="-drive if=pflash,format=raw,unit=0,readonly=on,file=$pflash_code $qemuopts"
    ++		qemuopts="-drive if=pflash,format=raw,unit=1,readonly=on,file=$pflash_vars $qemuopts"
     +	    else
     +		echo "Firmware not found, please make sure $bios or both $pflash_code and $pflash_vars exist." >&2
     +		exit 1
    @@ tests/util/grub-shell.in: case "${grub_modinfo_target_cpu}-${grub_modinfo_platfo
     +	if [ -f "$bios" ]; then
     +	    qemuopts="-bios $bios $qemuopts"
     +	elif [ -f "$pflash_code" ]; then
    -+	    qemuopts="-drive if=pflash,format=raw,readonly=on,file=$pflash_code $qemuopts"
    -+	    qemuopts="-drive if=pflash,format=raw,readonly=on,file=$pflash_vars $qemuopts"
    ++	    qemuopts="-drive if=pflash,format=raw,unit=0,readonly=on,file=$pflash_code $qemuopts"
    ++	    if [ -f "$pflash_vars" ]; then
    ++		qemuopts="-drive if=pflash,format=raw,unit=1,readonly=on,file=$pflash_vars $qemuopts"
    ++	    fi
     +	else
     +	    bios=/usr/share/qemu/OVMF.fd
     +	    pflash_code=/usr/share/OVMF/OVMF_CODE.fd
    @@ tests/util/grub-shell.in: case "${grub_modinfo_target_cpu}-${grub_modinfo_platfo
     +	    if [ -f "$bios" ]; then
     +		qemuopts="-bios $bios $qemuopts"
     +	    elif [ -f "$pflash_code" ]; then
    -+		qemuopts="-drive if=pflash,format=raw,readonly=on,file=$pflash_code $qemuopts"
    -+		qemuopts="-drive if=pflash,format=raw,readonly=on,file=$pflash_vars $qemuopts"
    ++		qemuopts="-drive if=pflash,format=raw,unit=0,readonly=on,file=$pflash_code $qemuopts"
    ++		qemuopts="-drive if=pflash,format=raw,unit=1,readonly=on,file=$pflash_vars $qemuopts"
     +	    else
     +		echo "Firmware not found, please make sure $bios or both $pflash_code and $pflash_vars exist." >&2
     +		exit 1
    @@ tests/util/grub-shell.in: case "${grub_modinfo_target_cpu}-${grub_modinfo_platfo
     +	if [ -f "$bios" ]; then
     +	    qemuopts="-bios $bios $qemuopts"
     +	elif [ -f "$pflash_code" ]; then
    -+	    qemuopts="-drive if=pflash,format=raw,readonly=on,file=$pflash_code $qemuopts"
    -+	    qemuopts="-drive if=pflash,format=raw,readonly=on,file=$pflash_vars $qemuopts"
    ++	    qemuopts="-drive if=pflash,format=raw,unit=0,readonly=on,file=$pflash_code $qemuopts"
    ++	    if [ -f "$pflash_vars" ]; then
    ++		qemuopts="-drive if=pflash,format=raw,unit=1,readonly=on,file=$pflash_vars $qemuopts"
    ++	    fi
     +	else
     +	    bios=/usr/share/qemu-efi-aarch64/QEMU_EFI.fd
     +	    pflash_code=/usr/share/AAVMF/AAVMF_CODE.fd
    @@ tests/util/grub-shell.in: case "${grub_modinfo_target_cpu}-${grub_modinfo_platfo
     +	    if [ -f "$bios" ]; then
     +		qemuopts="-bios $bios $qemuopts"
     +	    elif [ -f "$pflash_code" ]; then
    -+		qemuopts="-drive if=pflash,format=raw,readonly=on,file=$pflash_code $qemuopts"
    -+		qemuopts="-drive if=pflash,format=raw,readonly=on,file=$pflash_vars $qemuopts"
    ++		qemuopts="-drive if=pflash,format=raw,unit=0,readonly=on,file=$pflash_code $qemuopts"
    ++		qemuopts="-drive if=pflash,format=raw,unit=1,readonly=on,file=$pflash_vars $qemuopts"
     +	    else
     +		echo "Firmware not found, please make sure $bios or both $pflash_code and $pflash_vars exist." >&2
     +		exit 1
    @@ tests/util/grub-shell.in: case "${grub_modinfo_target_cpu}-${grub_modinfo_platfo
     +	if [ -f "$bios" ]; then
     +	    qemuopts="-bios $bios $qemuopts"
     +	elif [ -f "$pflash_code" ]; then
    -+	    qemuopts="-drive if=pflash,format=raw,readonly=on,file=$pflash_code $qemuopts"
    -+	    qemuopts="-drive if=pflash,format=raw,readonly=on,file=$pflash_vars $qemuopts"
    ++	    qemuopts="-drive if=pflash,format=raw,unit=0,readonly=on,file=$pflash_code $qemuopts"
    ++	    if [ -f "$pflash_vars" ]; then
    ++		qemuopts="-drive if=pflash,format=raw,unit=1,file=$pflash_vars $qemuopts"
    ++	    fi
     +	else
     +	    bios=/usr/share/AAVMF/AAVMF32.fd
     +	    pflash_code=/usr/share/AAVMF/AAVMF32_CODE.fd
    @@ tests/util/grub-shell.in: case "${grub_modinfo_target_cpu}-${grub_modinfo_platfo
     +	    if [ -f "$bios" ]; then
     +		qemuopts="-bios $bios $qemuopts"
     +	    elif [ -f "$pflash_code" ]; then
    -+		qemuopts="-drive if=pflash,format=raw,readonly=on,file=$pflash_code $qemuopts"
    -+		qemuopts="-drive if=pflash,format=raw,readonly=on,file=$pflash_vars $qemuopts"
    ++		# NOTE: Do not use the pflash VARS file because it cannot be
    ++		# used in readonly. So it would need to be copied to a writable
    ++		# path, but its large at 64M and not needed for running tests.
    ++		qemuopts="-drive if=pflash,format=raw,unit=0,readonly=on,file=$pflash_code $qemuopts"
     +	    else
     +		echo "Firmware not found, please make sure $bios or both $pflash_code and $pflash_vars exist." >&2
     +		exit 1
-- 
2.27.0



^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v3 01/15] grub-shell: Allow specifying non-default trim line contents
  2022-02-10 21:51 [PATCH v3 00/15] Grub-shell improvements Glenn Washburn
@ 2022-02-10 21:51 ` Glenn Washburn
  2022-02-10 21:51 ` [PATCH v3 02/15] grub-shell: Trim line should always be matched from the beginning of the line Glenn Washburn
                   ` (13 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Glenn Washburn @ 2022-02-10 21:51 UTC (permalink / raw)
  To: Daniel Kiper, grub-devel; +Cc: Glenn Washburn

This 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.

Signed-off-by: Glenn Washburn <development@efficientek.com>
---
 tests/util/grub-shell.in | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/tests/util/grub-shell.in b/tests/util/grub-shell.in
index 93e9f5148..b409962f1 100644
--- a/tests/util/grub-shell.in
+++ b/tests/util/grub-shell.in
@@ -32,6 +32,7 @@ PATH="${builddir}:$PATH"
 export PATH
 
 trim=0
+trim_head=664cbea8-132f-4770-8aa4-1696d59ac35c
 
 # Usage: usage
 # Print the usage.
@@ -212,8 +213,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=*)
@@ -336,8 +342,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
@@ -452,8 +456,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
-- 
2.27.0



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v3 02/15] grub-shell: Trim line should always be matched from the beginning of the line
  2022-02-10 21:51 [PATCH v3 00/15] Grub-shell improvements Glenn Washburn
  2022-02-10 21:51 ` [PATCH v3 01/15] grub-shell: Allow specifying non-default trim line contents Glenn Washburn
@ 2022-02-10 21:51 ` Glenn Washburn
  2022-02-10 21:51 ` [PATCH v3 03/15] grub-shell: Only show grub-mkrescue output if it returns an error Glenn Washburn
                   ` (12 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Glenn Washburn @ 2022-02-10 21:51 UTC (permalink / raw)
  To: Daniel Kiper, grub-devel; +Cc: Glenn Washburn

When 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.

Signed-off-by: Glenn Washburn <development@efficientek.com>
---
 tests/util/grub-shell.in | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tests/util/grub-shell.in b/tests/util/grub-shell.in
index b409962f1..602b16f3e 100644
--- a/tests/util/grub-shell.in
+++ b/tests/util/grub-shell.in
@@ -343,7 +343,7 @@ terminal_output ${term}
 EOF
 
 if [ $trim = 1 ]; then
-    echo "echo $trim_head" >>${cfgfile}
+    echo "echo; echo $trim_head" >>${cfgfile}
 fi
 
 rom_directory=`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
@@ -457,7 +457,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
-- 
2.27.0



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v3 03/15] grub-shell: Only show grub-mkrescue output if it returns an error
  2022-02-10 21:51 [PATCH v3 00/15] Grub-shell improvements Glenn Washburn
  2022-02-10 21:51 ` [PATCH v3 01/15] grub-shell: Allow specifying non-default trim line contents Glenn Washburn
  2022-02-10 21:51 ` [PATCH v3 02/15] grub-shell: Trim line should always be matched from the beginning of the line Glenn Washburn
@ 2022-02-10 21:51 ` Glenn Washburn
  2022-02-10 21:51 ` [PATCH v3 04/15] grub-shell: Allow setting default timeout via GRUB_SHELL_DEFAULT_TIMEOUT envvar Glenn Washburn
                   ` (11 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Glenn Washburn @ 2022-02-10 21:51 UTC (permalink / raw)
  To: Daniel Kiper, grub-devel; +Cc: Glenn Washburn

The previous behavior ignored an error and the output from grub-mkrescue.
This made it a pain to discover that grub-mkrescue was the reason that tests
which rely on grub-shell were failing.  Even after discovering grub-mkrescue
was the culprit, there was no output to indicate why it was failing.  It
turns out that grub-mkrescue is a thin wrapper around xorriso. So if you do
not have xorriso installed it will fail with an error message about not
being able to find xorriso.

This change will allow grub-mkrescue output to be written to stderr, only if
grub-mkrescue fails.  If grub-mkrescue succeeds, there will be no output
from grub-mkrescue so as not to interfere with the functioning of tests.
This change should have no effect on the running of tests or other uses of
grub-shell as it only modifies the error path.

Also, if grub-mkrescue fails, the script exits early.  Since grub-shell
needs the iso image created by grub-mkresue to boot the qemu instance, a
failure here should be considered fatal.

Signed-off-by: Glenn Washburn <development@efficientek.com>
---
 tests/util/grub-shell.in | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/tests/util/grub-shell.in b/tests/util/grub-shell.in
index 602b16f3e..9d8c417da 100644
--- a/tests/util/grub-shell.in
+++ b/tests/util/grub-shell.in
@@ -60,6 +60,17 @@ Report bugs to <bug-grub@gnu.org>.
 EOF
 }
 
+# Exec given argv and only show its output on STDERR if it returns an
+# error status.
+exec_show_error () {
+    v=`$@ 2>&1`
+    ret=$?
+    if [ "$ret" != 0 ]; then
+        echo "$v" >&2
+        exit $ret
+    fi
+}
+
 . "${builddir}/grub-core/modinfo.sh"
 qemuopts="${GRUB_QEMU_OPTS}"
 serial_port=com0
@@ -383,13 +394,15 @@ if test -z "$debug"; then
 fi
 
 if [ x$boot != xnet ] && [ x$boot != xemu ]; then
-    pkgdatadir="@builddir@" "@builddir@/grub-mkrescue" "--output=${isofile}" "--override-directory=${builddir}/grub-core" \
+    pkgdatadir="@builddir@" \
+    exec_show_error "@builddir@/grub-mkrescue" "--output=${isofile}" \
+	"--override-directory=${builddir}/grub-core" \
 	--rom-directory="${rom_directory}" \
 	--locale-directory="@srcdir@/po" \
 	--themes-directory="@srcdir@/themes" \
 	$mkimage_extra_arg ${mkrescue_args} \
 	"/boot/grub/grub.cfg=${cfgfile}" "/boot/grub/testcase.cfg=${source}" \
-	${files} >/dev/null 2>&1
+	${files} || exit $?
 fi
 if [ x$boot = xhd ]; then
     if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = arm64-efi ] || [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = arm-efi ]; then
-- 
2.27.0



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v3 04/15] grub-shell: Allow setting default timeout via GRUB_SHELL_DEFAULT_TIMEOUT envvar
  2022-02-10 21:51 [PATCH v3 00/15] Grub-shell improvements Glenn Washburn
                   ` (2 preceding siblings ...)
  2022-02-10 21:51 ` [PATCH v3 03/15] grub-shell: Only show grub-mkrescue output if it returns an error Glenn Washburn
@ 2022-02-10 21:51 ` Glenn Washburn
  2022-02-10 21:51 ` [PATCH v3 05/15] grub-shell: Put all generated files into working dir and use better file names Glenn Washburn
                   ` (10 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Glenn Washburn @ 2022-02-10 21:51 UTC (permalink / raw)
  To: Daniel Kiper, grub-devel; +Cc: Glenn Washburn

Signed-off-by: Glenn Washburn <development@efficientek.com>
---
 tests/util/grub-shell.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/util/grub-shell.in b/tests/util/grub-shell.in
index 9d8c417da..e80471126 100644
--- a/tests/util/grub-shell.in
+++ b/tests/util/grub-shell.in
@@ -211,7 +211,7 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
 	console=console;;
 esac
 
-timeout=60
+timeout=${GRUB_SHELL_DEFAULT_TIMEOUT:-60}
 mkimage_extra_arg=
 
 # Check the arguments.
-- 
2.27.0



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v3 05/15] grub-shell: Put all generated files into working dir and use better file names
  2022-02-10 21:51 [PATCH v3 00/15] Grub-shell improvements Glenn Washburn
                   ` (3 preceding siblings ...)
  2022-02-10 21:51 ` [PATCH v3 04/15] grub-shell: Allow setting default timeout via GRUB_SHELL_DEFAULT_TIMEOUT envvar Glenn Washburn
@ 2022-02-10 21:51 ` Glenn Washburn
  2022-02-10 21:51 ` [PATCH v3 06/15] grub-shell: Add grub output logfile with grub-shell --debug Glenn Washburn
                   ` (9 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Glenn Washburn @ 2022-02-10 21:51 UTC (permalink / raw)
  To: Daniel Kiper, grub-devel; +Cc: Glenn Washburn

When running tests there are many invocations of grub-shell, and because the
output files are all random names in the same tmp directory, it becomes more
work to figure out which files went with which grub-shell invocations. So
all generated files from one invocation of grub-shell are put into a
randomly named directory, so as not to collide with other grub-shell
invocations. And now that the generated files can be put in a location where
they will not get stepped on, and they can be named sensible names.

Signed-off-by: Glenn Washburn <development@efficientek.com>
---
 tests/util/grub-shell.in | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/tests/util/grub-shell.in b/tests/util/grub-shell.in
index e80471126..8c6ed76d7 100644
--- a/tests/util/grub-shell.in
+++ b/tests/util/grub-shell.in
@@ -71,6 +71,8 @@ exec_show_error () {
     fi
 }
 
+work_directory=${WORKDIR:-`mktemp -d "${TMPDIR:-/tmp}/grub-shell.XXXXXXXXXX"`} || exit 1
+
 . "${builddir}/grub-core/modinfo.sh"
 qemuopts="${GRUB_QEMU_OPTS}"
 serial_port=com0
@@ -80,7 +82,7 @@ pseries=n
 disk="hda "
 case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
     *-emu)
-	device_map=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
+	device_map="$work_directory/device.map"
 	boot=emu
 	console=console
 	disk=0
@@ -318,14 +320,14 @@ for option in "$@"; do
 done
 
 if [ "x${source}" = x ] ; then
-    tmpfile=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
+    tmpfile="$work_directory/testcase.cfg"
     while read REPLY; do
 	echo "$REPLY" >> ${tmpfile}
     done
     source=${tmpfile}
 fi
 
-cfgfile=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
+cfgfile="$work_directory/grub.cfg"
 cat <<EOF >${cfgfile}
 grubshell=yes
 enable_progress_indicator=0
@@ -357,7 +359,8 @@ if [ $trim = 1 ]; then
     echo "echo; echo $trim_head" >>${cfgfile}
 fi
 
-rom_directory=`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
+rom_directory="$work_directory/rom_directory"
+mkdir -p "$rom_directory"
 
 for mod in ${modules}
 do
@@ -378,7 +381,7 @@ test -z "$debug" || echo "GRUB script: ${cfgfile}" >&2
 test -z "$debug" || echo "GRUB testcase script: ${tmpfile}" >&2
 test -z "$debug" || echo "Boot device: ${boot}" >&2
 
-isofile=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
+isofile="$work_directory/grub.iso"
 test -z "$debug" || echo "GRUB ISO file: ${isofile}" >&2
 test -z "$debug" || echo "GRUB ROM directory: ${rom_directory}" >&2
 
@@ -450,7 +453,7 @@ if [ x$boot = xmips_qemu ]; then
 fi
 
 if [ x$boot = xcoreboot ]; then
-    imgfile=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
+    imgfile="$work_directory/coreboot.img"
     cp "${GRUB_COREBOOT_ROM}" "${imgfile}"
     "${GRUB_CBFSTOOL}" "${imgfile}" add-payload -f "${rom_directory}/coreboot.elf" -n fallback/payload
     bootdev="-bios ${imgfile}"
@@ -493,14 +496,15 @@ copy_extra_files() {
 }
 
 if [ x$boot = xnet ]; then
-    netdir=`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
+    netdir="$work_directory/netdir"
+    mkdir -p "$netdir"
     pkgdatadir="@builddir@" "@builddir@/grub-mknetdir" "--grub-mkimage=${builddir}/grub-mkimage" "--directory=${builddir}/grub-core" "--net-directory=$netdir" ${mkrescue_args} > /dev/null
     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" | do_trim
 elif [ x$boot = xemu ]; then
-    rootdir="$(mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX")"
+    rootdir="$work_directory/rootdir"
     grubdir="$rootdir/boot/grub"
     mkdir -p "$grubdir/fonts"
     mkdir -p "$grubdir/themes"
@@ -515,7 +519,7 @@ elif [ x$boot = xemu ]; then
     cp "${cfgfile}" "$grubdir/grub.cfg"
     cp "${source}" "$grubdir/testcase.cfg"
     [ -z "$files" ] || copy_extra_files "$rootdir" $files
-    roottar="$(mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX")"
+    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" | do_trim
     test -n "$debug" || rm -rf "$rootdir"
-- 
2.27.0



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v3 06/15] grub-shell: Add grub output logfile with grub-shell --debug
  2022-02-10 21:51 [PATCH v3 00/15] Grub-shell improvements Glenn Washburn
                   ` (4 preceding siblings ...)
  2022-02-10 21:51 ` [PATCH v3 05/15] grub-shell: Put all generated files into working dir and use better file names Glenn Washburn
@ 2022-02-10 21:51 ` Glenn Washburn
  2022-02-10 21:51 ` [PATCH v3 07/15] grub-shell: Set exit status to qemu exit status Glenn Washburn
                   ` (8 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Glenn Washburn @ 2022-02-10 21:51 UTC (permalink / raw)
  To: Daniel Kiper, grub-devel; +Cc: Glenn Washburn

This allows seeing full qemu output of grub-shell, which can be invaluable
when debugging failing tests.

Signed-off-by: Glenn Washburn <development@efficientek.com>
---
 tests/util/grub-shell.in | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/tests/util/grub-shell.in b/tests/util/grub-shell.in
index 8c6ed76d7..f52aeb068 100644
--- a/tests/util/grub-shell.in
+++ b/tests/util/grub-shell.in
@@ -379,6 +379,9 @@ echo "${halt_cmd}" >>${cfgfile}
 
 test -z "$debug" || echo "GRUB script: ${cfgfile}" >&2
 test -z "$debug" || echo "GRUB testcase script: ${tmpfile}" >&2
+
+goutfile="$work_directory/grub-qemu.log"
+test -z "$debug" || echo "GRUB output log: ${goutfile}" >&2
 test -z "$debug" || echo "Boot device: ${boot}" >&2
 
 isofile="$work_directory/grub.iso"
@@ -502,7 +505,7 @@ 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" | do_trim
+    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
 elif [ x$boot = xemu ]; then
     rootdir="$work_directory/rootdir"
     grubdir="$rootdir/boot/grub"
@@ -521,18 +524,19 @@ 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" | do_trim
+    @builddir@/grub-core/grub-emu -m "$device_map" --memdisk "$roottar" -r memdisk -d "/boot/grub" | tr -d "\r" | tee "${goutfile}" | do_trim
     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" | do_trim
+    timeout -s KILL $timeout "${qemu}" ${qemuopts} ${serial_null} -serial file:/dev/stdout -${device}"${isofile}" ${bootdev} | cat | tr -d "\r" | tee "${goutfile}" | do_trim
 fi
 if [ x$boot = xcoreboot ]; then
     test -n "$debug" || rm -f "${imgfile}"
 fi
 test -n "$debug" || rm -f "${isofile}"
 test -n "$debug" || rm -rf "${rom_directory}"
-test -n "$debug" || rm -f "${tmpfile}" "${cfgfile}"
+test -n "$debug" || rm -f "${tmpfile}" "${cfgfile}" "${goutfile}"
+
 exit 0
 
 
-- 
2.27.0



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v3 07/15] grub-shell: Set exit status to qemu exit status
  2022-02-10 21:51 [PATCH v3 00/15] Grub-shell improvements Glenn Washburn
                   ` (5 preceding siblings ...)
  2022-02-10 21:51 ` [PATCH v3 06/15] grub-shell: Add grub output logfile with grub-shell --debug Glenn Washburn
@ 2022-02-10 21:51 ` Glenn Washburn
  2022-02-10 21:51 ` [PATCH v3 08/15] grub-shell: Only cleanup working directory file if QEMU does not fail or timeout Glenn Washburn
                   ` (7 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Glenn Washburn @ 2022-02-10 21:51 UTC (permalink / raw)
  To: Daniel Kiper, grub-devel; +Cc: Glenn Washburn

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.

Signed-off-by: Glenn Washburn <development@efficientek.com>
---
 tests/util/grub-shell.in | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/tests/util/grub-shell.in b/tests/util/grub-shell.in
index f52aeb068..3ba539c70 100644
--- a/tests/util/grub-shell.in
+++ b/tests/util/grub-shell.in
@@ -498,6 +498,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"
@@ -505,7 +511,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"
@@ -524,12 +531,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
@@ -537,6 +550,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
 
 
-- 
2.27.0



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v3 08/15] grub-shell: Only cleanup working directory file if QEMU does not fail or timeout
  2022-02-10 21:51 [PATCH v3 00/15] Grub-shell improvements Glenn Washburn
                   ` (6 preceding siblings ...)
  2022-02-10 21:51 ` [PATCH v3 07/15] grub-shell: Set exit status to qemu exit status Glenn Washburn
@ 2022-02-10 21:51 ` Glenn Washburn
  2022-02-10 21:51 ` [PATCH v3 09/15] grub-shell: Create run.sh in working directory for easily running test again Glenn Washburn
                   ` (6 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Glenn Washburn @ 2022-02-10 21:51 UTC (permalink / raw)
  To: Daniel Kiper, grub-devel; +Cc: Glenn Washburn

This keeps the generated files to aid in diagnosing the source of the
failure.

Signed-off-by: Glenn Washburn <development@efficientek.com>
---
 tests/util/grub-shell.in | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/tests/util/grub-shell.in b/tests/util/grub-shell.in
index 3ba539c70..96869184c 100644
--- a/tests/util/grub-shell.in
+++ b/tests/util/grub-shell.in
@@ -533,8 +533,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=$?
@@ -543,8 +541,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}"
-- 
2.27.0



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v3 09/15] grub-shell: Create run.sh in working directory for easily running test again
  2022-02-10 21:51 [PATCH v3 00/15] Grub-shell improvements Glenn Washburn
                   ` (7 preceding siblings ...)
  2022-02-10 21:51 ` [PATCH v3 08/15] grub-shell: Only cleanup working directory file if QEMU does not fail or timeout Glenn Washburn
@ 2022-02-10 21:51 ` Glenn Washburn
  2022-02-10 21:51 ` [PATCH v3 10/15] grub-shell: Add $GRUB_QEMU_OPTS to run.sh to easily see unofficial QEMU arguments Glenn Washburn
                   ` (5 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Glenn Washburn @ 2022-02-10 21:51 UTC (permalink / raw)
  To: Daniel Kiper, grub-devel; +Cc: Glenn Washburn

Now it becomes trivial to re-run a test from the output in its working
directory. This also makes it easy to send a reproducible failing test to
the mailing list. This has allowed a a refactor so that the duplicated
code to call QEMU has be condensed (eg. the use of timeout and file
descriptor redirection).

Signed-off-by: Glenn Washburn <development@efficientek.com>
---
 tests/util/grub-shell.in | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/tests/util/grub-shell.in b/tests/util/grub-shell.in
index 96869184c..48c7fde48 100644
--- a/tests/util/grub-shell.in
+++ b/tests/util/grub-shell.in
@@ -511,8 +511,10 @@ 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
-    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=$?
+    cat >"$work_directory/run.sh" <<EOF
+#! @BUILD_SHEBANG@
+exec "${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
+EOF
 elif [ x$boot = xemu ]; then
     rootdir="$work_directory/rootdir"
     grubdir="$rootdir/boot/grub"
@@ -531,11 +533,23 @@ elif [ x$boot = xemu ]; then
     [ -z "$files" ] || copy_extra_files "$rootdir" $files
     roottar="$work_directory/root.tar"
     (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=$?
+    cat >"$work_directory/run.sh" <<EOF
+#! @BUILD_SHEBANG@
+exec @builddir@/grub-core/grub-emu -m "$device_map" --memdisk "$roottar" -r memdisk -d "/boot/grub"
+EOF
 else
+    cat >"$work_directory/run.sh" <<EOF
+#! @BUILD_SHEBANG@
+SDIR=\$(realpath -e \${0%/*})
+cd "\$SDIR"
+exec "${qemu}" ${qemuopts} ${serial_null} -serial file:/dev/stdout -${device}"\${SDIR}/${isofile##*/}" ${bootdev}
+EOF
+fi
+
+if [ -f "$work_directory/run.sh" ]; then
     setup_qemu_logger
-    timeout -s KILL $timeout "${qemu}" ${qemuopts} ${serial_null} -serial file:/dev/stdout -${device}"${isofile}" ${bootdev} > "$work_directory/qemu-pipe" || ret=$?
+    chmod +x "$work_directory/run.sh"
+    timeout -s KILL $timeout "$work_directory/run.sh" > "$work_directory/qemu-pipe" || ret=$?
 fi
 
 wait
@@ -555,6 +569,7 @@ fi
 test -n "$debug" || rm -f "${isofile}"
 test -n "$debug" || rm -rf "${rom_directory}"
 test -n "$debug" || rm -f "${tmpfile}" "${cfgfile}" "${goutfile}"
+test -n "$debug" || rm -f "$work_directory/run.sh"
 
 exit $ret
 
-- 
2.27.0



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v3 10/15] grub-shell: Add $GRUB_QEMU_OPTS to run.sh to easily see unofficial QEMU arguments
  2022-02-10 21:51 [PATCH v3 00/15] Grub-shell improvements Glenn Washburn
                   ` (8 preceding siblings ...)
  2022-02-10 21:51 ` [PATCH v3 09/15] grub-shell: Create run.sh in working directory for easily running test again Glenn Washburn
@ 2022-02-10 21:51 ` Glenn Washburn
  2022-02-10 21:51 ` [PATCH v3 11/15] tests: Allow turning on shell tracing from environment variables Glenn Washburn
                   ` (4 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Glenn Washburn @ 2022-02-10 21:51 UTC (permalink / raw)
  To: Daniel Kiper, grub-devel; +Cc: Glenn Washburn

Signed-off-by: Glenn Washburn <development@efficientek.com>
---
 tests/util/grub-shell.in | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/tests/util/grub-shell.in b/tests/util/grub-shell.in
index 48c7fde48..fdabc6171 100644
--- a/tests/util/grub-shell.in
+++ b/tests/util/grub-shell.in
@@ -74,7 +74,7 @@ exec_show_error () {
 work_directory=${WORKDIR:-`mktemp -d "${TMPDIR:-/tmp}/grub-shell.XXXXXXXXXX"`} || exit 1
 
 . "${builddir}/grub-core/modinfo.sh"
-qemuopts="${GRUB_QEMU_OPTS}"
+qemuopts=
 serial_port=com0
 serial_null=
 halt_cmd=halt
@@ -513,7 +513,8 @@ if [ x$boot = xnet ]; then
     [ -z "$files" ] || copy_extra_files "$netdir" $files
     cat >"$work_directory/run.sh" <<EOF
 #! @BUILD_SHEBANG@
-exec "${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
+GRUB_QEMU_OPTS=\${GRUB_QEMU_OPTS:-"$GRUB_QEMU_OPTS"}
+exec "${qemu}" ${qemuopts} \${GRUB_QEMU_OPTS} ${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
 EOF
 elif [ x$boot = xemu ]; then
     rootdir="$work_directory/rootdir"
@@ -541,8 +542,9 @@ else
     cat >"$work_directory/run.sh" <<EOF
 #! @BUILD_SHEBANG@
 SDIR=\$(realpath -e \${0%/*})
+GRUB_QEMU_OPTS=\${GRUB_QEMU_OPTS:-"$GRUB_QEMU_OPTS"}
 cd "\$SDIR"
-exec "${qemu}" ${qemuopts} ${serial_null} -serial file:/dev/stdout -${device}"\${SDIR}/${isofile##*/}" ${bootdev}
+exec "${qemu}" ${qemuopts} \${GRUB_QEMU_OPTS} ${serial_null} -serial file:/dev/stdout -${device}"\${SDIR}/${isofile##*/}" ${bootdev}
 EOF
 fi
 
-- 
2.27.0



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v3 11/15] tests: Allow turning on shell tracing from environment variables
  2022-02-10 21:51 [PATCH v3 00/15] Grub-shell improvements Glenn Washburn
                   ` (9 preceding siblings ...)
  2022-02-10 21:51 ` [PATCH v3 10/15] grub-shell: Add $GRUB_QEMU_OPTS to run.sh to easily see unofficial QEMU arguments Glenn Washburn
@ 2022-02-10 21:51 ` Glenn Washburn
  2022-02-10 21:51 ` [PATCH v3 12/15] grub-shell: Add --verbose to mkrescue when $debug is greater than 2 Glenn Washburn
                   ` (3 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Glenn Washburn @ 2022-02-10 21:51 UTC (permalink / raw)
  To: Daniel Kiper, grub-devel; +Cc: Glenn Washburn

This allows turning on shell tracing when its not practical or not possible
to use commandline arguments. Turn on tracing when the envvar is an integer
greater than 1, since these can log a lot of messages.

Signed-off-by: Glenn Washburn <development@efficientek.com>
---
 tests/util/grub-fs-tester.in | 2 ++
 tests/util/grub-shell.in     | 5 ++++-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/tests/util/grub-fs-tester.in b/tests/util/grub-fs-tester.in
index 2dcd09f5e..6b8028f9b 100644
--- a/tests/util/grub-fs-tester.in
+++ b/tests/util/grub-fs-tester.in
@@ -2,6 +2,8 @@
 
 set -e
 
+[ "${GRUB_TEST_DEFAULT_DEBUG:-0}" -gt 1 ] && set -x
+
 fs="$1"
 
 GRUBFSTEST="@builddir@/grub-fstest"
diff --git a/tests/util/grub-shell.in b/tests/util/grub-shell.in
index fdabc6171..a1c7b9265 100644
--- a/tests/util/grub-shell.in
+++ b/tests/util/grub-shell.in
@@ -215,6 +215,7 @@ esac
 
 timeout=${GRUB_SHELL_DEFAULT_TIMEOUT:-60}
 mkimage_extra_arg=
+debug=${GRUB_SHELL_DEFAULT_DEBUG:-$GRUB_TEST_DEFAULT_DEBUG}
 
 # Check the arguments.
 for option in "$@"; do
@@ -234,7 +235,7 @@ for option in "$@"; do
     --no-trim)
 	trim=0 ;;
     --debug)
-        debug=1 ;;
+        debug=$((debug+1)) ;;
     --modules=*)
 	ms=`echo "$option" | sed -e 's/--modules=//' -e 's/,/ /g'`
 	modules="$modules $ms" ;;
@@ -319,6 +320,8 @@ for option in "$@"; do
     esac
 done
 
+[ "${debug:-0}" -gt 1 ] && set -x
+
 if [ "x${source}" = x ] ; then
     tmpfile="$work_directory/testcase.cfg"
     while read REPLY; do
-- 
2.27.0



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v3 12/15] grub-shell: Add --verbose to mkrescue when $debug is greater than 2
  2022-02-10 21:51 [PATCH v3 00/15] Grub-shell improvements Glenn Washburn
                   ` (10 preceding siblings ...)
  2022-02-10 21:51 ` [PATCH v3 11/15] tests: Allow turning on shell tracing from environment variables Glenn Washburn
@ 2022-02-10 21:51 ` Glenn Washburn
  2022-02-10 21:51 ` [PATCH v3 13/15] grub-shell: Only turn on qemu head when large debug value is specified Glenn Washburn
                   ` (2 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Glenn Washburn @ 2022-02-10 21:51 UTC (permalink / raw)
  To: Daniel Kiper, grub-devel; +Cc: Glenn Washburn

Signed-off-by: Glenn Washburn <development@efficientek.com>
---
 tests/util/grub-shell.in | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tests/util/grub-shell.in b/tests/util/grub-shell.in
index a1c7b9265..fe1cf768d 100644
--- a/tests/util/grub-shell.in
+++ b/tests/util/grub-shell.in
@@ -404,7 +404,9 @@ fi
 
 if [ x$boot != xnet ] && [ x$boot != xemu ]; then
     pkgdatadir="@builddir@" \
-    exec_show_error "@builddir@/grub-mkrescue" "--output=${isofile}" \
+    exec_show_error "@builddir@/grub-mkrescue" \
+	${debug:+$([ "$debug" -gt 2 ] && echo -n "--verbose")} \
+	"--output=${isofile}" \
 	"--override-directory=${builddir}/grub-core" \
 	--rom-directory="${rom_directory}" \
 	--locale-directory="@srcdir@/po" \
-- 
2.27.0



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v3 13/15] grub-shell: Only turn on qemu head when large debug value is specified
  2022-02-10 21:51 [PATCH v3 00/15] Grub-shell improvements Glenn Washburn
                   ` (11 preceding siblings ...)
  2022-02-10 21:51 ` [PATCH v3 12/15] grub-shell: Add --verbose to mkrescue when $debug is greater than 2 Glenn Washburn
@ 2022-02-10 21:51 ` Glenn Washburn
  2022-02-10 21:51 ` [PATCH v3 14/15] grub-shell: Use malta qemu-mips machine type instead off non-existant indy Glenn Washburn
  2022-02-10 21:51 ` [PATCH v3 15/15] grub-shell: Add flexibility in QEMU firmware handling Glenn Washburn
  14 siblings, 0 replies; 16+ messages in thread
From: Glenn Washburn @ 2022-02-10 21:51 UTC (permalink / raw)
  To: Daniel Kiper, grub-devel; +Cc: Glenn Washburn

There are several levels of debug and more may be added. But the qemu head
should be one of the highest debug levels. Set debug to a high value of 10
to turn on the head. We do not want to accidentally turn it on when adding
a new debug level to the testing system.

Signed-off-by: Glenn Washburn <development@efficientek.com>
---
 tests/util/grub-shell.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/util/grub-shell.in b/tests/util/grub-shell.in
index fe1cf768d..3e07b5679 100644
--- a/tests/util/grub-shell.in
+++ b/tests/util/grub-shell.in
@@ -391,7 +391,7 @@ isofile="$work_directory/grub.iso"
 test -z "$debug" || echo "GRUB ISO file: ${isofile}" >&2
 test -z "$debug" || echo "GRUB ROM directory: ${rom_directory}" >&2
 
-if test -z "$debug"; then
+if test "${debug:-0}" -lt 10; then
   qemuopts="${qemuopts} -nographic -monitor file:/dev/null"
   # SeaBIOS 1.11.0 added support for VGA emulation over a serial port.  If
   # this is configured in SeaBIOS, then -nographic causes some extra junk to
-- 
2.27.0



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v3 14/15] grub-shell: Use malta qemu-mips machine type instead off non-existant indy
  2022-02-10 21:51 [PATCH v3 00/15] Grub-shell improvements Glenn Washburn
                   ` (12 preceding siblings ...)
  2022-02-10 21:51 ` [PATCH v3 13/15] grub-shell: Only turn on qemu head when large debug value is specified Glenn Washburn
@ 2022-02-10 21:51 ` Glenn Washburn
  2022-02-10 21:51 ` [PATCH v3 15/15] grub-shell: Add flexibility in QEMU firmware handling Glenn Washburn
  14 siblings, 0 replies; 16+ messages in thread
From: Glenn Washburn @ 2022-02-10 21:51 UTC (permalink / raw)
  To: Daniel Kiper, grub-devel; +Cc: Glenn Washburn

Signed-off-by: Glenn Washburn <development@efficientek.com>
---
 tests/util/grub-shell.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/util/grub-shell.in b/tests/util/grub-shell.in
index 3e07b5679..3df74cbe2 100644
--- a/tests/util/grub-shell.in
+++ b/tests/util/grub-shell.in
@@ -119,7 +119,7 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
     mips-arc)
 	boot=cd
 	qemu=qemu-system-mips64
-	qemuopts="-M indy $qemuopts"
+	qemuopts="-M malta $qemuopts"
 	serial_port=arc/serial0/line0
 	console=
 	trim=1
-- 
2.27.0



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v3 15/15] grub-shell: Add flexibility in QEMU firmware handling
  2022-02-10 21:51 [PATCH v3 00/15] Grub-shell improvements Glenn Washburn
                   ` (13 preceding siblings ...)
  2022-02-10 21:51 ` [PATCH v3 14/15] grub-shell: Use malta qemu-mips machine type instead off non-existant indy Glenn Washburn
@ 2022-02-10 21:51 ` Glenn Washburn
  14 siblings, 0 replies; 16+ messages in thread
From: Glenn Washburn @ 2022-02-10 21:51 UTC (permalink / raw)
  To: Daniel Kiper, grub-devel; +Cc: Glenn Washburn

The current qemu firmware paths for arm-efi and arm64-efi are not available
on Ubuntu/Debian but are hardcoded. Switch to first looking for firmware
files in the source directory and if not found, look for them in locations
where Debian installs them. Prefer to use the firmware file usable with the
QEMU '-bios' option and if not found use the newer pflash firmware files.
This allows supporting older systems more easily. By looking for files in
the source directory first, system firmware files can be overridden and it
can be ensured that the tests can be run regardless of the distro and where
it stores firmware files. If no firmware files are found, print an error
message telling the user that those files must exist and exit with error.

Do not load the system 32-bit ARM firmware VARS file because it must be
writable to prevent a data exception and boot failure. So in order to use
the VARS file, it must be copied to a writable location, but its quite large
at 64M and is not needed to boot successfully.

Signed-off-by: Glenn Washburn <development@efficientek.com>
---
 tests/util/grub-shell.in | 105 +++++++++++++++++++++++++++++++++++++--
 1 file changed, 101 insertions(+), 4 deletions(-)

diff --git a/tests/util/grub-shell.in b/tests/util/grub-shell.in
index 3df74cbe2..46f847ab7 100644
--- a/tests/util/grub-shell.in
+++ b/tests/util/grub-shell.in
@@ -180,21 +180,92 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
 	boot=cd
 	console=console
 	trim=1
-	qemuopts="-bios OVMF-ia32.fd $qemuopts"
+	bios=${srcdir}/OVMF32.fd
+	pflash_code=${srcdir}/OVMF32_CODE.fd
+	pflash_vars=${srcdir}/OVMF32_VARS.fd
+	if [ -f "$bios" ]; then
+	    qemuopts="-bios $bios $qemuopts"
+	elif [ -f "$pflash_code" ]; then
+	    qemuopts="-drive if=pflash,format=raw,unit=0,readonly=on,file=$pflash_code $qemuopts"
+	    if [ -f "$pflash_vars" ]; then
+		qemuopts="-drive if=pflash,format=raw,unit=1,readonly=on,file=$pflash_vars $qemuopts"
+	    fi
+	else
+	    bios=/usr/share/qemu/OVMF32.fd
+	    pflash_code=/usr/share/OVMF/OVMF32_CODE_4M.secboot.fd
+	    pflash_vars=/usr/share/OVMF/OVMF32_VARS_4M.fd
+	    if [ -f "$bios" ]; then
+		qemuopts="-bios $bios $qemuopts"
+	    elif [ -f "$pflash_code" ]; then
+		qemuopts="-drive if=pflash,format=raw,unit=0,readonly=on,file=$pflash_code $qemuopts"
+		qemuopts="-drive if=pflash,format=raw,unit=1,readonly=on,file=$pflash_vars $qemuopts"
+	    else
+		echo "Firmware not found, please make sure $bios or both $pflash_code and $pflash_vars exist." >&2
+		exit 1
+	    fi
+	fi
+	qemuopts="-machine q35,accel=tcg $qemuopts"
 	;;
     x86_64-efi)
 	qemu=qemu-system-x86_64
 	boot=cd
 	console=console
 	trim=1
-	qemuopts="-bios OVMF.fd $qemuopts"
+	bios=${srcdir}/OVMF.fd
+	pflash_code=${srcdir}/OVMF_CODE.fd
+	pflash_vars=${srcdir}/OVMF_VARS.fd
+	if [ -f "$bios" ]; then
+	    qemuopts="-bios $bios $qemuopts"
+	elif [ -f "$pflash_code" ]; then
+	    qemuopts="-drive if=pflash,format=raw,unit=0,readonly=on,file=$pflash_code $qemuopts"
+	    if [ -f "$pflash_vars" ]; then
+		qemuopts="-drive if=pflash,format=raw,unit=1,readonly=on,file=$pflash_vars $qemuopts"
+	    fi
+	else
+	    bios=/usr/share/qemu/OVMF.fd
+	    pflash_code=/usr/share/OVMF/OVMF_CODE.fd
+	    pflash_vars=/usr/share/OVMF/OVMF_VARS.fd
+	    if [ -f "$bios" ]; then
+		qemuopts="-bios $bios $qemuopts"
+	    elif [ -f "$pflash_code" ]; then
+		qemuopts="-drive if=pflash,format=raw,unit=0,readonly=on,file=$pflash_code $qemuopts"
+		qemuopts="-drive if=pflash,format=raw,unit=1,readonly=on,file=$pflash_vars $qemuopts"
+	    else
+		echo "Firmware not found, please make sure $bios or both $pflash_code and $pflash_vars exist." >&2
+		exit 1
+	    fi
+	fi
 	;;
     arm64-efi)
 	qemu=qemu-system-aarch64
 	boot=hd
 	console=console
 	trim=1
-	qemuopts="-machine virt -cpu cortex-a57 -bios /usr/share/qemu-efi/QEMU_EFI.fd $qemuopts"
+	bios=${srcdir}/AAVMF.fd
+	pflash_code=${srcdir}/AAVMF_CODE.fd
+	pflash_vars=${srcdir}/AAVMF_VARS.fd
+	if [ -f "$bios" ]; then
+	    qemuopts="-bios $bios $qemuopts"
+	elif [ -f "$pflash_code" ]; then
+	    qemuopts="-drive if=pflash,format=raw,unit=0,readonly=on,file=$pflash_code $qemuopts"
+	    if [ -f "$pflash_vars" ]; then
+		qemuopts="-drive if=pflash,format=raw,unit=1,readonly=on,file=$pflash_vars $qemuopts"
+	    fi
+	else
+	    bios=/usr/share/qemu-efi-aarch64/QEMU_EFI.fd
+	    pflash_code=/usr/share/AAVMF/AAVMF_CODE.fd
+	    pflash_vars=/usr/share/AAVMF/AAVMF_VARS.fd
+	    if [ -f "$bios" ]; then
+		qemuopts="-bios $bios $qemuopts"
+	    elif [ -f "$pflash_code" ]; then
+		qemuopts="-drive if=pflash,format=raw,unit=0,readonly=on,file=$pflash_code $qemuopts"
+		qemuopts="-drive if=pflash,format=raw,unit=1,readonly=on,file=$pflash_vars $qemuopts"
+	    else
+		echo "Firmware not found, please make sure $bios or both $pflash_code and $pflash_vars exist." >&2
+		exit 1
+	    fi
+	fi
+	qemuopts="-machine virt -cpu cortex-a57 $qemuopts"
 	disk="device virtio-blk-device,drive=hd1 -drive if=none,id=hd1,file="
 	serial_port=
 	;;
@@ -203,7 +274,33 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
 	boot=hd
 	console=console
 	trim=1
-	qemuopts="-machine virt -bios /usr/share/ovmf-arm/QEMU_EFI.fd $qemuopts"
+	bios=${srcdir}/AAVMF32.fd
+	pflash_code=${srcdir}/AAVMF32_CODE.fd
+	pflash_vars=${srcdir}/AAVMF32_VARS.fd
+	if [ -f "$bios" ]; then
+	    qemuopts="-bios $bios $qemuopts"
+	elif [ -f "$pflash_code" ]; then
+	    qemuopts="-drive if=pflash,format=raw,unit=0,readonly=on,file=$pflash_code $qemuopts"
+	    if [ -f "$pflash_vars" ]; then
+		qemuopts="-drive if=pflash,format=raw,unit=1,file=$pflash_vars $qemuopts"
+	    fi
+	else
+	    bios=/usr/share/AAVMF/AAVMF32.fd
+	    pflash_code=/usr/share/AAVMF/AAVMF32_CODE.fd
+	    pflash_vars=/usr/share/AAVMF/AAVMF32_VARS.fd
+	    if [ -f "$bios" ]; then
+		qemuopts="-bios $bios $qemuopts"
+	    elif [ -f "$pflash_code" ]; then
+		# NOTE: Do not use the pflash VARS file because it cannot be
+		# used in readonly. So it would need to be copied to a writable
+		# path, but its large at 64M and not needed for running tests.
+		qemuopts="-drive if=pflash,format=raw,unit=0,readonly=on,file=$pflash_code $qemuopts"
+	    else
+		echo "Firmware not found, please make sure $bios or both $pflash_code and $pflash_vars exist." >&2
+		exit 1
+	    fi
+	fi
+	qemuopts="-machine virt $qemuopts"
 	disk="device virtio-blk-device,drive=hd1 -drive if=none,id=hd1,file="
 	serial_port=efi0
 	;;
-- 
2.27.0



^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2022-02-10 21:54 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-10 21:51 [PATCH v3 00/15] Grub-shell improvements Glenn Washburn
2022-02-10 21:51 ` [PATCH v3 01/15] grub-shell: Allow specifying non-default trim line contents Glenn Washburn
2022-02-10 21:51 ` [PATCH v3 02/15] grub-shell: Trim line should always be matched from the beginning of the line Glenn Washburn
2022-02-10 21:51 ` [PATCH v3 03/15] grub-shell: Only show grub-mkrescue output if it returns an error Glenn Washburn
2022-02-10 21:51 ` [PATCH v3 04/15] grub-shell: Allow setting default timeout via GRUB_SHELL_DEFAULT_TIMEOUT envvar Glenn Washburn
2022-02-10 21:51 ` [PATCH v3 05/15] grub-shell: Put all generated files into working dir and use better file names Glenn Washburn
2022-02-10 21:51 ` [PATCH v3 06/15] grub-shell: Add grub output logfile with grub-shell --debug Glenn Washburn
2022-02-10 21:51 ` [PATCH v3 07/15] grub-shell: Set exit status to qemu exit status Glenn Washburn
2022-02-10 21:51 ` [PATCH v3 08/15] grub-shell: Only cleanup working directory file if QEMU does not fail or timeout Glenn Washburn
2022-02-10 21:51 ` [PATCH v3 09/15] grub-shell: Create run.sh in working directory for easily running test again Glenn Washburn
2022-02-10 21:51 ` [PATCH v3 10/15] grub-shell: Add $GRUB_QEMU_OPTS to run.sh to easily see unofficial QEMU arguments Glenn Washburn
2022-02-10 21:51 ` [PATCH v3 11/15] tests: Allow turning on shell tracing from environment variables Glenn Washburn
2022-02-10 21:51 ` [PATCH v3 12/15] grub-shell: Add --verbose to mkrescue when $debug is greater than 2 Glenn Washburn
2022-02-10 21:51 ` [PATCH v3 13/15] grub-shell: Only turn on qemu head when large debug value is specified Glenn Washburn
2022-02-10 21:51 ` [PATCH v3 14/15] grub-shell: Use malta qemu-mips machine type instead off non-existant indy Glenn Washburn
2022-02-10 21:51 ` [PATCH v3 15/15] grub-shell: Add flexibility in QEMU firmware handling Glenn Washburn

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.