Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1lLcqZ-0004TL-CL for mharc-grub-devel@gnu.org; Sun, 14 Mar 2021 22:20:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40402) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLcqY-0004RU-36 for grub-devel@gnu.org; Sun, 14 Mar 2021 22:20:42 -0400 Received: from mail-ot1-x32a.google.com ([2607:f8b0:4864:20::32a]:34579) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLcqV-00045M-Gn for grub-devel@gnu.org; Sun, 14 Mar 2021 22:20:41 -0400 Received: by mail-ot1-x32a.google.com with SMTP id k14-20020a9d7dce0000b02901b866632f29so4394276otn.1 for ; Sun, 14 Mar 2021 19:20:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficientek-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vfnocKUCdSle4ltPO+jGvhjBFhjeitw3x7D8k8BOK5E=; b=Wsx/IXS4q7yucuj2h5oe0yJYhGeiIkGHiX+ghYV4ClyfujQbeYJn/rD8oFYuAGimAw bFoyFmHpdB69mCeE2buG7GXHdxcTUhaIFhpqNF/2RlCujWw4j2Id0hPz6b504d6Hl8mS S+Iku+MujTkjEjBglziLXQVvxXYSdpUZIuyummpG8eKjZpYadm9fFsoZ6fN+LofmrQJV OHez8i6QH/Fow4scxt91zTvr4ZzxMpUmUPwetFjKDOr/Kt9w0kjRzFrrtLUy9wrl9ylb hf0/f+lMk8fDdRaYqOWaGkW4NyTprUKP42NnwEW33JQjF8CfnsewIOpXtxJQNra7gEDt E/xQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vfnocKUCdSle4ltPO+jGvhjBFhjeitw3x7D8k8BOK5E=; b=O9SdfnjJoWW3pmpUrmlrdMN8RNX3aop3MxDG8Garq1x8fvbY7YeLiKzLiXgK1yT69L xFxy4PsThymXjbMaCpL9qkeYrCbw5pciI36AXkcpGqpi++3Gotj+xdf3tTfisSiZTgAw LrUmhm1CbFAnD70v93hlzu74jLVO39cyPWgoqm7qTTX28oGHfAnwHgsc4mrx6LsBhy+d m4goamMpOhUYYpLVNcib3twhzAIMW/KeMtDNJEGsmPaJJJYnVvghe/6McA43bq9kLIgZ UOTaaT5+LoUO1zD6p4h0RycMvtBxAUVUSJ9wijxYJM14QUtNKHUezKo7Dh0GrX6Hl8nk H72Q== X-Gm-Message-State: AOAM531UxDnixgFEc1sK1Ke2IJIzVuL3vPH46J70Rzu2LeKLmoSTG2c4 hasKNV5E1jyjqo6zjhY723kGAXOUI2hgIQ== X-Google-Smtp-Source: ABdhPJwATJVN/7IEJmHxX3MJzSVuT3L64viAB9UDSO8UQ6yiQW2q+DVoJU0s/tOIIqWXFF4kVGkrdw== X-Received: by 2002:a9d:6215:: with SMTP id g21mr12013684otj.80.1615774837570; Sun, 14 Mar 2021 19:20:37 -0700 (PDT) Received: from localhost.localdomain ([2605:a601:aac5:3700:b5e5:83e3:99ae:e6e8]) by smtp.gmail.com with ESMTPSA id t22sm6733206otl.49.2021.03.14.19.20.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 19:20:37 -0700 (PDT) From: Glenn Washburn To: grub-devel@gnu.org, Daniel Kiper Cc: Glenn Washburn Subject: [PATCH 4/8] tests: Fail immediately when grub-shell fails and do not occlude the error code Date: Sun, 14 Mar 2021 21:20:19 -0500 Message-Id: <1499f58f4bfaa6510b9cac2a4e55a18dabe85fe6.1615773047.git.development@efficientek.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::32a; envelope-from=development@efficientek.com; helo=mail-ot1-x32a.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 15 Mar 2021 02:20:42 -0000 If grub-shell fails, that means that whatever was being tested was not actually tested. So fail immediately. Sometimes grub-shell is not the last command in a pipeline of several commands, and in this case the failed error code can be hidden by a later failing command or hidden when 'set -e' is not set and there are subsequent successful commands. When the test script fails because of a failure in grub-shell, then test script should exit with the failed exit code of grub-shell. Signed-off-by: Glenn Washburn --- tests/ahci_test.in | 6 +++++- tests/cdboot_test.in | 3 ++- tests/core_compress_test.in | 6 ++++-- tests/ehci_test.in | 6 +++++- tests/fddboot_test.in | 3 ++- tests/grub_cmd_date.in | 3 ++- tests/grub_cmd_test.in | 1 + tests/grub_script_blockarg.in | 2 +- tests/grub_script_expansion.in | 3 ++- tests/gzcompress_test.in | 3 ++- tests/hddboot_test.in | 3 ++- tests/lzocompress_test.in | 3 ++- tests/netboot_test.in | 3 ++- tests/ohci_test.in | 6 +++++- tests/partmap_test.in | 4 ++-- tests/pata_test.in | 3 ++- tests/test_sha512sum.in | 1 + tests/uhci_test.in | 6 +++++- tests/xzcompress_test.in | 3 ++- 19 files changed, 49 insertions(+), 19 deletions(-) diff --git a/tests/ahci_test.in b/tests/ahci_test.in index 7df560462..3fb7f54a2 100644 --- a/tests/ahci_test.in +++ b/tests/ahci_test.in @@ -41,7 +41,11 @@ 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-drive,drive=disk,bus=ahci.0 " | tail -n 1)" != "Hello World" ]; then +echo "nativedisk; source '(ahci0)/$outfile';" | + "${grubshell}" --qemu-opts="-drive id=disk,file=$imgfile,if=none + -device ahci,id=ahci + -device ide-drive,drive=disk,bus=ahci.0" >$outfile +if [ "$(cat "$outfile" | tail -n 1)" != "Hello World" ]; then rm "$imgfile" rm "$outfile" exit 1 diff --git a/tests/cdboot_test.in b/tests/cdboot_test.in index 75acdfedb..7229f79fb 100644 --- a/tests/cdboot_test.in +++ b/tests/cdboot_test.in @@ -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 diff --git a/tests/core_compress_test.in b/tests/core_compress_test.in index 9d216ebcf..90dd00607 100644 --- a/tests/core_compress_test.in +++ b/tests/core_compress_test.in @@ -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 diff --git a/tests/ehci_test.in b/tests/ehci_test.in index b197f8cdc..64bd80070 100644 --- a/tests/ehci_test.in +++ b/tests/ehci_test.in @@ -41,7 +41,11 @@ 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 +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" >$outfile +if [ "$(cat "$outfile" | tail -n 1)" != "Hello World" ]; then rm "$imgfile" rm "$outfile" exit 1 diff --git a/tests/fddboot_test.in b/tests/fddboot_test.in index 2d7dfc889..1bbe60ee5 100644 --- a/tests/fddboot_test.in +++ b/tests/fddboot_test.in @@ -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 diff --git a/tests/grub_cmd_date.in b/tests/grub_cmd_date.in index f7c9ca004..f9156691e 100644 --- a/tests/grub_cmd_date.in +++ b/tests/grub_cmd_date.in @@ -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)" diff --git a/tests/grub_cmd_test.in b/tests/grub_cmd_test.in index 3399eb292..dac6f7d6a 100644 --- a/tests/grub_cmd_test.in +++ b/tests/grub_cmd_test.in @@ -1,4 +1,5 @@ #! @BUILD_SHEBANG@ +set -e # create a randome file empty="`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"`" || exit 1 diff --git a/tests/grub_script_blockarg.in b/tests/grub_script_blockarg.in index 6ea9b8c3d..6152cc141 100644 --- a/tests/grub_script_blockarg.in +++ b/tests/grub_script_blockarg.in @@ -1,4 +1,4 @@ -#! @BUILD_SHEBANG@ +#! @BUILD_SHEBANG@ -e # Run GRUB script in a Qemu instance # Copyright (C) 2010 Free Software Foundation, Inc. diff --git a/tests/grub_script_expansion.in b/tests/grub_script_expansion.in index 9d0dcdd29..98d5a9068 100644 --- a/tests/grub_script_expansion.in +++ b/tests/grub_script_expansion.in @@ -17,7 +17,8 @@ set -e # You should have received a copy of the GNU General Public License # along with GRUB. If not, see . -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 diff --git a/tests/gzcompress_test.in b/tests/gzcompress_test.in index 42c8fe7c4..572b2a1a5 100644 --- a/tests/gzcompress_test.in +++ b/tests/gzcompress_test.in @@ -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 diff --git a/tests/hddboot_test.in b/tests/hddboot_test.in index 6d70847a5..abe3e0ae1 100644 --- a/tests/hddboot_test.in +++ b/tests/hddboot_test.in @@ -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 diff --git a/tests/lzocompress_test.in b/tests/lzocompress_test.in index 4e5f7e078..8f08a8046 100644 --- a/tests/lzocompress_test.in +++ b/tests/lzocompress_test.in @@ -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 diff --git a/tests/netboot_test.in b/tests/netboot_test.in index 9f71e3d88..6a1d95a22 100644 --- a/tests/netboot_test.in +++ b/tests/netboot_test.in @@ -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 diff --git a/tests/ohci_test.in b/tests/ohci_test.in index 8693f8c47..cc35f67a9 100644 --- a/tests/ohci_test.in +++ b/tests/ohci_test.in @@ -41,7 +41,11 @@ 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 +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" >$outfile +if [ "$(cat "$outfile" | tail -n 1)" != "Hello World" ]; then rm "$imgfile" rm "$outfile" exit 1 diff --git a/tests/partmap_test.in b/tests/partmap_test.in index 7353dc70e..5f18ab51c 100644 --- a/tests/partmap_test.in +++ b/tests/partmap_test.in @@ -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 } diff --git a/tests/pata_test.in b/tests/pata_test.in index 4b18fdef3..3d19cecde 100644 --- a/tests/pata_test.in +++ b/tests/pata_test.in @@ -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 diff --git a/tests/test_sha512sum.in b/tests/test_sha512sum.in index 027092a8b..d97b7ae2c 100644 --- a/tests/test_sha512sum.in +++ b/tests/test_sha512sum.in @@ -1,4 +1,5 @@ #! @BUILD_SHEBANG@ +set -e # create a randome file file="`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"`" || exit 1 diff --git a/tests/uhci_test.in b/tests/uhci_test.in index f0eec5032..6aab10ba6 100644 --- a/tests/uhci_test.in +++ b/tests/uhci_test.in @@ -41,7 +41,11 @@ 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 +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" >$outfile +if [ "$(cat "$outfile" | tail -n 1)" != "Hello World" ]; then rm "$imgfile" rm "$outfile" exit 1 diff --git a/tests/xzcompress_test.in b/tests/xzcompress_test.in index 03bfb5e95..61acba33b 100644 --- a/tests/xzcompress_test.in +++ b/tests/xzcompress_test.in @@ -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 -- 2.27.0