Skip to contentSkip to conversation

Various test fixes proposed by Thomas Schmitt

PATCH In review Glenn Washburn 3 participants 10 messages Mar 3, 2025 – Mar 16, 2025

lore
Share & tools
lore
#0 lore raw

v2 cover Various test fixes proposed by Thomas Schmitt

Thomas Schmitt proposed variations on these fixes[1]. I've broken his patch into several patches with improvements.

Glenn

[1] https://lore.kernel.org/all/[email protected]/

v2:
* Add patch #2 to allow grub-shell-luks-tester to cleanup properly on expected failure.
* Add patch #5 to remove empty directories left by the cryptomount tests.

Glenn Washburn (5):
tests/util/grub-shell-luks-tester: Add missing line to create RET
variable in cleanup
tests: Cleanup generated files on expected failure in
grub_cmd_cryptomount
tests/grub_cmd_cryptomount: Cleanup the cryptsetup script unless debug
is enabled
tests/grub_cmd_cryptomount: Default TMPDIR to /tmp tests/util/grub-shell: Remove the work directory on successful run and
debug is not on

Thomas Schmitt (1):
tests/grub_cmd_cryptomount: Remove temporary directories if successful
and debug is not on

 tests/grub_cmd_cryptomount.in        | 18 ++++++++++++++++--
 tests/util/grub-shell-luks-tester.in |  7 ++++++-
 tests/util/grub-shell.in             |  1 +
 3 files changed, 23 insertions(+), 3 deletions(-)

Range-diff against v1:

1:  50ea280aa138 = 1:  e686c1848ab1 tests/util/grub-shell-luks-tester: Add missing line to create RET variable in cleanup
-:  ------------ > 2:  f94ebf9f040e tests: Cleanup generated files on expected failure in grub_cmd_cryptomount
2:  4d8fca393bfd ! 3:  1d1faee928cf tests: Cleaup the cryptsetup script in grub_cmd_cryptomount unless debug is enabled

@@ Metadata
Author: Glenn Washburn <[email protected]>

## Commit message ##
- tests: Cleaup the cryptsetup script in grub_cmd_cryptomount unless debug is enabled
+ tests/grub_cmd_cryptomount: Cleanup the cryptsetup script unless debug is enabled

This fixes an issue where the grub_cmd_cryptomount test leaves a file with an ambiguous name in the / directory when TMPDIR is not set.
3: e32175b06be6 ! 4: 5f1b424919b2 tests: Default TMPDIR to /tmp in grub_cmd_cryptomount tests
@@ Metadata
Author: Glenn Washburn <[email protected]>

## Commit message ##
- tests: Default TMPDIR to /tmp in grub_cmd_cryptomount tests
+ tests/grub_cmd_cryptomount: Default TMPDIR to /tmp

This fixes behavior where grub_cmd_cryptomount temporary files, which are some times not cleaned up, are left in the / directory. Set TMPDIR if your
@@ tests/grub_cmd_cryptomount.in: _testcase() {
+ TMPDIR=${_TMPDIR}/echo -n "$(date +%s).${LOGPREFIX}" | sed -e 's,[ /],_,g' -e 's,:$,,g'
+ export TMPDIR
mkdir -p "$TMPDIR"
+ set -- "$@" $([ "${EXPECTEDRES}" -eq 1 ] && echo "--xfail")

- output="$@" 2>&1 || res=$?

-:  ------------ > 5:  779233064126 tests/grub_cmd_cryptomount: Remove temporary directories if successful and debug is not on
4:  6ef75566e50b = 6:  e9fc44e07539 tests/util/grub-shell: Remove the work directory on successful run and debug is not on
Signature · 7 lines
2.34.1


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#1 lore raw

PATCH v2 1/6 tests/util/grub-shell-luks-tester: Add missing line to create RET variable in cleanup

Set the RET variable to the exit status of the script, as was assumed in the cleanup() function.

---
 tests/util/grub-shell-luks-tester.in | 1 +
 1 file changed, 1 insertion(+)
tests/util/grub-shell-luks-tester.in +1 -0
index b2a8a91b41f2..855ad39c19c3 100644
@@ -143,6 +143,7 @@ fi
 
 # Make sure that the dm-crypto device is shutdown
 cleanup() {
+    RET=$?
     if [ -e "$luksdev" ]; then
         cryptsetup close "$luksdev"
     fi
Signature · 7 lines
2.34.1


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#2 lore raw

PATCH v2 2/6 tests: Cleanup generated files on expected failure in grub_cmd_cryptomount

In reply to Glenn Washburn

grub-shell-luks-tester only cleans up generated files when the test it runs returns success. Sometimes tests are run that should fail. Add a --xfail argument to grub-shell-luks-tester and pass it from grub_cmd_cryptomount when invoking a test that is expected to fail.

---
 tests/grub_cmd_cryptomount.in        | 1 +
 tests/util/grub-shell-luks-tester.in | 6 +++++-
 2 files changed, 6 insertions(+), 1 deletion(-)
tests/grub_cmd_cryptomount.in +1 -0
index f4d8f35473d0..63ed8e51bec3 100644
@@ -48,6 +48,7 @@ _testcase() {
     _TMPDIR=$TMPDIR
     TMPDIR=$TMPDIR/`echo -n "$(date +%s).$LOGPREFIX" | sed -e 's,[ /],_,g' -e 's,:$,,g'`
     mkdir -p "$TMPDIR"
+    set -- "$@" $([ "${EXPECTEDRES}" -eq 1 ] && echo "--xfail")
 
     output=`"$@" 2>&1` || res=$?
     TMPDIR=$_TMPDIR
tests/util/grub-shell-luks-tester.in +5 -1
index 855ad39c19c3..abb0013e4387 100644
@@ -36,6 +36,7 @@ keyfile=
 keyfile_offset=
 keyfile_size=
 KEYFILE_SIZE_MAX=4096
+expected_res=0
 
 debug="${GRUB_SHELL_LUKS_DEFAULT_DEBUG:-$GRUB_TEST_DEFAULT_DEBUG}"
 GRUB_SHELL_LUKS_TIMEOUT=${GRUB_SHELL_LUKS_TIMEOUT:-${GRUB_SHELL_DEFAULT_TIMEOUT:-600s}}
@@ -58,6 +59,7 @@ running in a QEMU instance.
   --detached-header       Use a detached header
   --keyfile[=FILE]        Use a randomly generated key file of size $KEYFILE_SIZE_MAX if not
                           given a FILE to use as the key file.
+  --xfail                 Expected failure, so cleanup as if on success
 
 $0 creates a LUKS disk with cryptsetup, then verify that it is accessible by
 grub running in a QEMU instance.
@@ -118,6 +120,8 @@ for option in "$@"; do
     --disksize=*)
         qs=`echo "$option" | sed -e 's/--disksize=//'`
         disksize="$qs" ;;
+    --xfail)
+        expected_res=1 ;;
     -*)
 	echo "Unrecognized option \`$option'" 1>&2
 	usage
@@ -147,7 +151,7 @@ cleanup() {
     if [ -e "$luksdev" ]; then
         cryptsetup close "$luksdev"
     fi
-    if [ -z "$debug" ] && [ "${RET:-1}" -eq 0 ]; then
+    if [ -z "$debug" ] && [ "$RET" -eq "$expected_res" ]; then
         rm -rf "$lukstestdir" || :
     fi
 }
Signature · 7 lines
2.34.1


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#3 lore raw

PATCH v2 3/6 tests/grub_cmd_cryptomount: Cleanup the cryptsetup script unless debug is enabled

In reply to Glenn Washburn

This fixes an issue where the grub_cmd_cryptomount test leaves a file with an ambiguous name in the / directory when TMPDIR is not set.

---
 tests/grub_cmd_cryptomount.in | 3 +++
 1 file changed, 3 insertions(+)
tests/grub_cmd_cryptomount.in +3 -0
index 63ed8e51bec3..2fba8a8e0e3a 100644
@@ -37,6 +37,8 @@ fi
 
 COMMON_OPTS='${V:+--debug=$V} --cs-opts="--pbkdf-force-iterations 1000"'
 
+debug=${GRUB_SHELL_DEFAULT_DEBUG:-$GRUB_TEST_DEFAULT_DEBUG}
+
 _testcase() {
     local EXPECTEDRES=$1
     local LOGPREFIX=$2
@@ -183,4 +185,5 @@ eval testcase "'LUKS2 test with second key slot and first slot using different p
     @builddir@/grub-shell-luks-tester $LUKS2_COMMON_OPTS $COMMON_OPTS \
         "--cs-script='$csscript'"
 
+test -n "$debug" || rm "$csscript"
 exit 0
Signature · 7 lines
2.34.1


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#4 lore raw

PATCH v2 4/6 tests/grub_cmd_cryptomount: Default TMPDIR to /tmp

In reply to Glenn Washburn

This fixes behavior where grub_cmd_cryptomount temporary files, which are some times not cleaned up, are left in the / directory. Set TMPDIR if your system does not have /tmp or it can not be used for some reason.

---
 tests/grub_cmd_cryptomount.in | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
tests/grub_cmd_cryptomount.in +3 -2
index 2fba8a8e0e3a..8dc99127d39e 100644
@@ -47,8 +47,9 @@ _testcase() {
     shift 2
 
     # Create a subdir in TMPDIR for each testcase
-    _TMPDIR=$TMPDIR
-    TMPDIR=$TMPDIR/`echo -n "$(date +%s).$LOGPREFIX" | sed -e 's,[ /],_,g' -e 's,:$,,g'`
+    _TMPDIR=${TMPDIR:-/tmp}
+    TMPDIR=${_TMPDIR}/`echo -n "$(date +%s).${LOGPREFIX}" | sed -e 's,[ /],_,g' -e 's,:$,,g'`
+    export TMPDIR
     mkdir -p "$TMPDIR"
     set -- "$@" $([ "${EXPECTEDRES}" -eq 1 ] && echo "--xfail")
 
Signature · 7 lines
2.34.1


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#5 lore raw

PATCH v2 5/6 tests/grub_cmd_cryptomount: Remove temporary directories if successful and debug is not on

In reply to Glenn Washburn

From: Thomas Schmitt <[email protected]>

grub_cmd_cryptomount creates a directory per subtest. If a subtest is successful and debugging is not on, the directory should be empty. So it can be deleted.

---
 tests/grub_cmd_cryptomount.in | 9 +++++++++
 1 file changed, 9 insertions(+)
tests/grub_cmd_cryptomount.in +9 -0
index 8dc99127d39e..eaa187efad0a 100644
@@ -54,6 +54,15 @@ _testcase() {
     set -- "$@" $([ "${EXPECTEDRES}" -eq 1 ] && echo "--xfail")
 
     output=`"$@" 2>&1` || res=$?
+    if [ -z "$debug" ]; then
+        if ! rmdir "$TMPDIR" >/dev/null 2>&1; then
+            echo
+            echo "Note: Temporary directory cannot be removed:"
+            echo "        $TMPDIR"
+            echo "      Please inspect and remove manually."
+            echo
+        fi
+    fi
     TMPDIR=$_TMPDIR
 
     if [ "$res" -eq "$EXPECTEDRES" ]; then
Signature · 7 lines
2.34.1


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#6 lore raw

PATCH v2 6/6 tests/util/grub-shell: Remove the work directory on successful run and debug is not on

In reply to Glenn Washburn

This removes alot of empty grub-shell working directories in the TMPDIR directory.

---
 tests/util/grub-shell.in | 1 +
 1 file changed, 1 insertion(+)
tests/util/grub-shell.in +1 -0
index 15c5f45a5c30..af3d31ef4609 100644
@@ -715,6 +715,7 @@ 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"
+test -n "$debug" || rmdir "$work_directory"
 
 exit $ret
 
Signature · 7 lines
2.34.1


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Tested-by Thomas Schmitt Reviewed-by Thomas Schmitt Reviewed-by Thomas Schmitt Reviewed-by Thomas Schmitt Reviewed-by Thomas Schmitt on the v2 series
#7 lore raw
In reply to Glenn Washburn

Hi,

with remaining unrelated problems.

-----------------------------------------------------------------------
Test details:

The patch series applied by "git am" without problems to a branch cloned from freshly pulled "master".

make check TESTS=grub_cmd_cryptomount

produces

# PASS: 1

No remaining files from that run are to see in / and /tmp. During the "make check" i could see files appear and vanish in /tmp.

Then i ran the full "make check" (which lasts really long on a 4 GHz Xeon with "top" reporting the system being mostly idle).

These failures did not happen in june 2024, when i ran "make check":

FAIL: ntfs_test
FAIL: zfs_test

Other failures which i already had in 2024 are:

FAIL: hfs_test
FAIL: luks1_test
FAIL: luks2_test
FAIL: grub_func_test

Some tests which failed in 2024 but don't any more:
PASS: erofs_test
PASS: exfat_test

(My mail in june 2024 with the list of test failures was
Date: Thu, 20 Jun 2024 22:05:02 +0200
Message-Id: <[email protected]>
Regrettably http://lists.gnu.org/mailman/listinfo/grub-devel does not work for me today. So i cannot give a link into the archive.)

Files which remained in /tmp:

grub-fs-tester.20250304100244880329310.ntfs.JrW grub-fs-tester.20250304100732808627445.vfat12.AKi grub-fs-tester.20250304102111753946043.zfs_zstd.HeI grub-fs-tester.20250304102132560362937.luks1.szH grub-fs-tester.20250304102140126776818.luks2.eTV tmp.3t4AGcksU8
tmp.5ch8QxZT6p
tmp.6msLyaqLuq
tmp.CeFRqmCNlf
tmp.m60l7N0wuj

tmp.CeFRqmCNlf looks like a GRUB configuration. tmp.m60l7N0wuj looks like the result of GRUB's "ls" command, possibly with a grub-mkrescue ISO in (cd0).
The contents of the others give me no clue.

----------------------------------------------------------------------

I also reviewed the patches.
(Give me a note if i shall add the tags by single mails to the patch mails.)

Quoted 2 lines

[PATCH v2 1/6] tests/util/grub-shell-luks-tester: Add missing line
to create RET variable in cleanup

Quoted 2 lines

[PATCH v2 2/6] tests: Cleanup generated files on expected failure
in grub_cmd_cryptomount

(Deeply impressed by the "set --" gesture)

Quoted 2 lines

[PATCH v2 3/6] tests/grub_cmd_cryptomount: Cleanup the cryptsetup
script unless debug is enabled

Quoted 1 line

[PATCH v2 4/6] tests/grub_cmd_cryptomount: Default TMPDIR to /tmp

Quoted 2 lines

[PATCH v2 5/6] tests/grub_cmd_cryptomount: Remove temporary
directories if successful and debug is not on

Quoted 2 lines

[PATCH v2 6/6] tests/util/grub-shell: Remove the work directory on
successful run and debug is not on

(Already contains Signed-off-by: Thomas Schmitt <[email protected]> )

----------------------------------------------------------------------

Have a nice day :)

Thomas

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#8 lore raw
Quoted 22 lines · On Tue, 04 Mar 2025 10:56:15 +0100 "Thomas Schmitt" <[email protected]> wrote:

Hi,

with remaining unrelated problems.

-----------------------------------------------------------------------
Test details:

The patch series applied by "git am" without problems to a branch cloned from freshly pulled "master".

make check TESTS=grub_cmd_cryptomount

produces

# PASS: 1

No remaining files from that run are to see in / and /tmp. During the "make check" i could see files appear and vanish in /tmp.

Quoted 6 lines

Then i ran the full "make check" (which lasts really long on a 4 GHz Xeon with "top" reporting the system being mostly idle).

These failures did not happen in june 2024, when i ran "make check":

FAIL: ntfs_test

This was introduced by the security fixes and there's a patch on the list to fix this.

Quoted 1 line

FAIL: zfs_test

I've not looked into this, but I'm seeing it fail too.

Quoted 4 lines

Other failures which i already had in 2024 are:

FAIL: hfs_test

This should fail on anything but now ancient debian systems. This is due to the package having a custom patch that added functionality and now doesn't, IIRC.

Quoted 2 lines

FAIL: luks1_test
FAIL: luks2_test

These should not be failing.

Quoted 1 line

FAIL: grub_func_test

This is expected, and will be for the foreseeable future, unfortunately.

Glenn

Quoted 70 lines

Some tests which failed in 2024 but don't any more:
PASS: erofs_test
PASS: exfat_test

(My mail in june 2024 with the list of test failures was
Date: Thu, 20 Jun 2024 22:05:02 +0200
Message-Id: <[email protected]>
Regrettably http://lists.gnu.org/mailman/listinfo/grub-devel does not work for me today. So i cannot give a link into the archive.)

Files which remained in /tmp:

grub-fs-tester.20250304100244880329310.ntfs.JrW grub-fs-tester.20250304100732808627445.vfat12.AKi grub-fs-tester.20250304102111753946043.zfs_zstd.HeI grub-fs-tester.20250304102132560362937.luks1.szH grub-fs-tester.20250304102140126776818.luks2.eTV tmp.3t4AGcksU8
tmp.5ch8QxZT6p
tmp.6msLyaqLuq
tmp.CeFRqmCNlf
tmp.m60l7N0wuj

tmp.CeFRqmCNlf looks like a GRUB configuration. tmp.m60l7N0wuj looks like the result of GRUB's "ls" command, possibly with a grub-mkrescue ISO in (cd0).
The contents of the others give me no clue.

----------------------------------------------------------------------

I also reviewed the patches.
(Give me a note if i shall add the tags by single mails to the patch mails.)

Quoted 2 lines

[PATCH v2 1/6] tests/util/grub-shell-luks-tester: Add missing line
to create RET variable in cleanup

Quoted 2 lines

[PATCH v2 2/6] tests: Cleanup generated files on expected failure
in grub_cmd_cryptomount

(Deeply impressed by the "set --" gesture)

Quoted 2 lines

[PATCH v2 3/6] tests/grub_cmd_cryptomount: Cleanup the cryptsetup
script unless debug is enabled

Quoted 1 line

[PATCH v2 4/6] tests/grub_cmd_cryptomount: Default TMPDIR to /tmp

Quoted 2 lines

[PATCH v2 5/6] tests/grub_cmd_cryptomount: Remove temporary
directories if successful and debug is not on

Quoted 2 lines

[PATCH v2 6/6] tests/util/grub-shell: Remove the work directory on
successful run and debug is not on

Quoted 8 lines

(Already contains Signed-off-by: Thomas Schmitt <[email protected]> )

----------------------------------------------------------------------

Have a nice day :)

Thomas

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

Reviewed-by on the v2 series
#9 lore raw
In reply to Glenn Washburn
Quoted 23 lines · Glenn Washburn

Thomas Schmitt proposed variations on these fixes[1]. I've broken his patch into several patches with improvements.

Glenn

[1] https://lore.kernel.org/all/[email protected]/

v2:
* Add patch #2 to allow grub-shell-luks-tester to cleanup properly on expected failure.
* Add patch #5 to remove empty directories left by the cryptomount tests.

Glenn Washburn (5):
tests/util/grub-shell-luks-tester: Add missing line to create RET
variable in cleanup
tests: Cleanup generated files on expected failure in
grub_cmd_cryptomount
tests/grub_cmd_cryptomount: Cleanup the cryptsetup script unless debug
is enabled
tests/grub_cmd_cryptomount: Default TMPDIR to /tmp tests/util/grub-shell: Remove the work directory on successful run and
debug is not on

Quoted 3 lines

Thomas Schmitt (1):
tests/grub_cmd_cryptomount: Remove temporary directories if successful
and debug is not on

Daniel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel