]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
tests: Do not occlude subshell error codes when used as input to the test command
authorGlenn Washburn <development@efficientek.com>
Wed, 13 Oct 2021 00:39:58 +0000 (19:39 -0500)
committerDaniel Kiper <daniel.kiper@oracle.com>
Thu, 14 Oct 2021 12:45:10 +0000 (14:45 +0200)
When using the output of a subshell as input, its error code is ignored in
the context of "set -e". Many test scripts use grub-shell in a subshell with
output used as an argument to the test command to test for expected output.
Refactor these tests so that the subshell output goes to a shell variable,
so that if the subshell errors the script will immediately exit with an
error code.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
13 files changed:
tests/ahci_test.in
tests/cdboot_test.in
tests/core_compress_test.in
tests/ehci_test.in
tests/fddboot_test.in
tests/gzcompress_test.in
tests/hddboot_test.in
tests/lzocompress_test.in
tests/netboot_test.in
tests/ohci_test.in
tests/pata_test.in
tests/uhci_test.in
tests/xzcompress_test.in

index d844fe680fd340ccd80340d3923f934811e60af7..56760326a8d7bb536d67a162302730031874f10e 100644 (file)
@@ -41,7 +41,12 @@ echo "hello" > "$outfile"
 
 tar cf "$imgfile" "$outfile"
 
-if [ "$(echo "nativedisk; source '(ahci0)/$outfile';" | "${grubshell}" --qemu-opts="-drive id=disk,file=$imgfile,if=none -device ahci,id=ahci -device ide-hd,drive=disk,bus=ahci.0 " | tail -n 1)" != "Hello World" ]; then
+v=$(echo "nativedisk; source '(ahci0)/$outfile';" |
+    "${grubshell}" --qemu-opts="-drive id=disk,file=$imgfile,if=none
+                               -device ahci,id=ahci
+                               -device ide-hd,drive=disk,bus=ahci.0" |
+    tail -n 1)
+if [ "$v" != "Hello World" ]; then
    rm "$imgfile"
    rm "$outfile"
    exit 1
index 75acdfedb7fe4a634d4122e44b3cd01778ed6f35..bf9549a6be49e93c11dc57a1c725c7f7666e7ba0 100644 (file)
@@ -34,6 +34,7 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
        exit 0;;
 esac
 
-if [ "$(echo hello | "${grubshell}" --boot=cd)" != "Hello World" ]; then
+v=$(echo hello | "${grubshell}" --boot=cd)
+if [ "$v" != "Hello World" ]; then
    exit 1
 fi
index 9d216ebcff60bfce04e3be4dbd1f8834800a6948..52708fd831206678d3285f2b1597b31d15cf73c2 100644 (file)
@@ -27,10 +27,12 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
 esac
 
 
-if [ "$(echo hello | "${grubshell}" --grub-mkimage-extra=--compress=xz)" != "Hello World" ]; then
+v=$(echo hello | "${grubshell}" --grub-mkimage-extra=--compress=xz)
+if [ "$v" != "Hello World" ]; then
    exit 1
 fi
 
-if [ "$(echo hello | "${grubshell}" --grub-mkimage-extra=--compress=none)" != "Hello World" ]; then
+v=$(echo hello | "${grubshell}" --grub-mkimage-extra=--compress=none)
+if [ "$v" != "Hello World" ]; then
    exit 1
 fi
index b197f8cdc922628ed35863dfa384eeef4cc4cc09..c368c59ec7758dc55353e487d9741976063e5eb8 100644 (file)
@@ -41,7 +41,12 @@ echo "hello" > "$outfile"
 
 tar cf "$imgfile" "$outfile"
 
-if [ "$(echo "nativedisk; source '(usb0)/$outfile';" | "${grubshell}" --qemu-opts="-device ich9-usb-ehci1 -drive id=my_usb_disk,file=$imgfile,if=none -device usb-storage,drive=my_usb_disk" | tail -n 1)" != "Hello World" ]; then
+v=$(echo "nativedisk; source '(usb0)/$outfile';" |
+    "${grubshell}" --qemu-opts="-device ich9-usb-ehci1
+                               -drive id=my_usb_disk,file=$imgfile,if=none
+                               -device usb-storage,drive=my_usb_disk" |
+    tail -n 1)
+if [ "$v" != "Hello World" ]; then
    rm "$imgfile"
    rm "$outfile"
    exit 1
index 2d7dfc8891f6d7fdf42f88dea1213428e23b6f2e..32281c75f112cbc3adff970079a2b876a04ce284 100644 (file)
@@ -46,6 +46,7 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
        exit 0;;
 esac
 
-if [ "$(echo hello | "${grubshell}" --boot=fd --mkrescue-arg="--compress=xz --fonts= --locales= --themes= -no-pad")" != "Hello World" ]; then
+v=$(echo hello | "${grubshell}" --boot=fd --mkrescue-arg="--compress=xz --fonts= --locales= --themes= -no-pad")
+if [ "$v" != "Hello World" ]; then
    exit 1
 fi
index 42c8fe7c4e8fc83022f656c0be7963aab3166a75..d7a594bb2c3b8c3608a4502cb54300c051e5a89c 100644 (file)
@@ -24,6 +24,7 @@ if ! which gzip >/dev/null 2>&1; then
    exit 77
 fi
 
-if [ "$(echo hello | "${grubshell}" --mkrescue-arg=--compress=gz)" != "Hello World" ]; then
+v=$(echo hello | "${grubshell}" --mkrescue-arg=--compress=gz)
+if [ "$v" != "Hello World" ]; then
    exit 1
 fi
index 6d70847a5dec394fec13e6b21a9dd0d890cf2a4d..ded2cde7ba14395806ec162da0f65747939225f5 100644 (file)
@@ -31,7 +31,8 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
        exit 0;;
 esac
 
-if [ "$(echo hello | "${grubshell}" --boot=hd)" != "Hello World" ]; then
+v=$(echo hello | "${grubshell}" --boot=hd)
+if [ "$v" != "Hello World" ]; then
    exit 1
 fi
 
index 4e5f7e078d5116f0794b035cabe1002420fb1d2c..42e270df02643c8ecc2e0217ed621c4203a6185b 100644 (file)
@@ -24,6 +24,7 @@ if ! which lzop >/dev/null 2>&1; then
    exit 77
 fi
 
-if [ "$(echo hello | "${grubshell}" --mkrescue-arg=--compress=lzo)" != "Hello World" ]; then
+v=$(echo hello | "${grubshell}" --mkrescue-arg=--compress=lzo)
+if [ "$v" != "Hello World" ]; then
    exit 1
 fi
index 9f71e3d88542ae9b87e9218c1c1197aeef29989a..b274f3e2de3b072a624a6ab174599b228ddcf45b 100644 (file)
@@ -40,6 +40,7 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
        exit 0;;
 esac
 
-if [ "$(echo hello | "${grubshell}" --boot=net)" != "Hello World" ]; then
+v=$(echo hello | "${grubshell}" --boot=net)
+if [ "$v" != "Hello World" ]; then
    exit 1
 fi
index 8693f8c472879fcbd43f52d4e61973d19b52ddc1..45949fb4cb740ad56458a89efdd9e76e62aafe52 100644 (file)
@@ -41,7 +41,12 @@ echo "hello" > "$outfile"
 
 tar cf "$imgfile" "$outfile"
 
-if [ "$(echo "nativedisk; source '(usb0)/$outfile';" | "${grubshell}" --qemu-opts="-device pci-ohci -drive id=my_usb_disk,file=$imgfile,if=none -device usb-storage,drive=my_usb_disk" | tail -n 1)" != "Hello World" ]; then
+v=$(echo "nativedisk; source '(usb0)/$outfile';" |
+    "${grubshell}" --qemu-opts="-device pci-ohci
+                               -drive id=my_usb_disk,file=$imgfile,if=none
+                               -device usb-storage,drive=my_usb_disk" |
+    tail -n 1)
+if [ "$v" != "Hello World" ]; then
    rm "$imgfile"
    rm "$outfile"
    exit 1
index 4b18fdef3d3594ccb105dd0d265e8517890d9853..38dff74a873b743e7b3eba5d536e4b367909043a 100644 (file)
@@ -45,7 +45,8 @@ echo "hello" > "$outfile"
 
 tar cf "$imgfile" "$outfile"
 
-if [ "$(echo "nativedisk; source '($indisk)/$outfile';" | "${grubshell}" --qemu-opts="-$disk $imgfile")" != "Hello World" ]; then
+v=$(echo "nativedisk; source '($indisk)/$outfile';" | "${grubshell}" --qemu-opts="-$disk $imgfile")
+if [ "$v" != "Hello World" ]; then
    rm "$imgfile"
    rm "$outfile"
    exit 1
index f0eec50328840881f6b1b50bf376584a083ca770..5a3b94c65ebcfc1dea8c7ac9671f9c369a293205 100644 (file)
@@ -41,7 +41,12 @@ echo "hello" > "$outfile"
 
 tar cf "$imgfile" "$outfile"
 
-if [ "$(echo "nativedisk; source '(usb0)/$outfile';" | "${grubshell}" --qemu-opts="-device ich9-usb-uhci1 -drive id=my_usb_disk,file=$imgfile,if=none -device usb-storage,drive=my_usb_disk" | tail -n 1)" != "Hello World" ]; then
+v=$(echo "nativedisk; source '(usb0)/$outfile';" |
+    "${grubshell}" --qemu-opts="-device ich9-usb-uhci1
+                               -drive id=my_usb_disk,file=$imgfile,if=none
+                               -device usb-storage,drive=my_usb_disk" |
+    tail -n 1)
+if [ "$v" != "Hello World" ]; then
    rm "$imgfile"
    rm "$outfile"
    exit 1
index 03bfb5e951dd8dfb7ccb15fb6a31dd4aea639df9..cfc6ccba66352c5c37d026f0f354b7902a14db17 100644 (file)
@@ -24,6 +24,7 @@ if ! which xz >/dev/null 2>&1; then
    exit 77
 fi
 
-if [ "$(echo hello | "${grubshell}" --mkrescue-arg=--compress=xz)" != "Hello World" ]; then
+v=$(echo hello | "${grubshell}" --mkrescue-arg=--compress=xz)
+if [ "$v" != "Hello World" ]; then
    exit 1
 fi