]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
tests: Do not occlude grub-shell return code
authorGlenn Washburn <development@efficientek.com>
Wed, 13 Oct 2021 00:39:59 +0000 (19:39 -0500)
committerDaniel Kiper <daniel.kiper@oracle.com>
Thu, 14 Oct 2021 12:48:45 +0000 (14:48 +0200)
The script grub-shell does the bulk of the testing. If it returns an error
code, that means that the test failed and the test should immediately exit
with that error code. When grub-shell is used as a non-terminating command
in a pipeline, e.g. when data needs to be extracted from its output, its
error code will be occluded by the last command in the pipeline. Refactor
tests so that the shell will error with the exit code of grub-shell by
breaking up pipelines such that grub-shell is always the last command in
the pipeline that it is used in.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
tests/ahci_test.in
tests/ehci_test.in
tests/grub_cmd_date.in
tests/grub_script_expansion.in
tests/ohci_test.in
tests/partmap_test.in
tests/uhci_test.in

index 56760326a8d7bb536d67a162302730031874f10e..7853bb8b6ed09d78f9f69d19eaee17fe1c2a4800 100644 (file)
@@ -44,8 +44,8 @@ tar cf "$imgfile" "$outfile"
 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)
+                               -device ide-hd,drive=disk,bus=ahci.0")
+v=$(echo "$v" | tail -n 1)
 if [ "$v" != "Hello World" ]; then
    rm "$imgfile"
    rm "$outfile"
index c368c59ec7758dc55353e487d9741976063e5eb8..426bfa7db8145b533ecabe539c30c1cf26be5fb1 100644 (file)
@@ -44,8 +44,8 @@ tar cf "$imgfile" "$outfile"
 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)
+                               -device usb-storage,drive=my_usb_disk")
+v=$(echo "$v" | tail -n 1)
 if [ "$v" != "Hello World" ]; then
    rm "$imgfile"
    rm "$outfile"
index f7c9ca00432fa3307a2fb53ac88ca11115d7f73f..737a278e6dc5343f0a8e3b4a14801c6218112be1 100644 (file)
@@ -9,7 +9,8 @@ if [ "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" = sparc64-ieee1275 ];
 fi
 
 pdt="$(date -u +%s)"
-dt=`echo date | @builddir@/grub-shell | sed 's, [A-Z][a-z]*$,,'`
+dt="$(echo date | @builddir@/grub-shell)"
+dt="$(echo "$dt" | sed 's, [A-Z][a-z]*$,,')"
 dtg="$(date -u -d "$dt" +%s)"
 ndt="$(date -u +%s)"
 
index 9d0dcdd29100904bfba93ccd429340d4a5afbcf3..98d5a9068a2852127e4ee0c242f11f761ac8084c 100644 (file)
@@ -17,7 +17,8 @@ set -e
 # You should have received a copy of the GNU General Public License
 # along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
 
-disks=`echo ls | @builddir@/grub-shell| grep -av '^Network protocols:$'| grep -av '^tftp http $'`
+disks=`echo ls | @builddir@/grub-shell`
+disks=`echo "$disks"| grep -av '^Network protocols:$'| grep -av '^tftp http $'`
 other=`echo insmod regexp\; echo \* | @builddir@/grub-shell`
 for d in $disks; do
     if echo "$d" |grep ',' >/dev/null; then
index 45949fb4cb740ad56458a89efdd9e76e62aafe52..2b96539b8f944ccf07a820767e4db8cd05009ce9 100644 (file)
@@ -44,8 +44,8 @@ tar cf "$imgfile" "$outfile"
 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)
+                               -device usb-storage,drive=my_usb_disk")
+v=$(echo "$v" | tail -n 1)
 if [ "$v" != "Hello World" ]; then
    rm "$imgfile"
    rm "$outfile"
index 7353dc70e1ef94e536385a24c7a77a11e84f8b21..5f18ab51c0b0363e8ccd149e8144cb0f30055e94 100644 (file)
@@ -58,8 +58,8 @@ list_parts () {
     shift
 
     echo ls | "${grubshell}" --disk="${imgfile}" \
-       --modules=$mod | tr -d "\n\r" > "${outfile}"
-    cat "${outfile}"
+       --modules=$mod > "${outfile}"
+    cat "${outfile}" | tr -d "\n\r"
     echo
 }
 
index 5a3b94c65ebcfc1dea8c7ac9671f9c369a293205..9a9492a43dc4a6c22709ab9cdd97c70798d27a5f 100644 (file)
@@ -44,8 +44,8 @@ tar cf "$imgfile" "$outfile"
 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)
+                               -device usb-storage,drive=my_usb_disk")
+v=$(echo "$v" | tail -n 1)
 if [ "$v" != "Hello World" ]; then
    rm "$imgfile"
    rm "$outfile"