refactor(expect): introduce timeout Expect script fragment
This change introduces an Expect script fragment for handling timeouts
sanely on both the on-premises CI and the OpenCI.
The two CI systems need a different mechanism for dealing with timeouts
because they both read from the UARTs in different ways. In the OpenCI,
an Expect script cannot "time out" in the conventional sense because
UART logs are generated by LAVA and merely read from the log file by
Expect. This differs from the on-premises CI, which spawns a telnet
terminal to read UART output live.
Timeouts must therefore look for both a real timeout and the stream EOF.
If either of these are encountered then the script exits with success,
otherwise it exits with failure.
Additionally, the fragment looks for common failure cases - "hung" UARTs
should neither include a crash dump nor reach the end of TFTF.
Signed-off-by: Chris Kay <chris.kay@arm.com>
Change-Id: Ic15df36fc563458734a64e61420f29bcf09ea566
(cherry picked from commit 38c68965ceafedb36cdf3eb0b64a5160db1486c0)
diff --git a/expect/timeout.exp b/expect/timeout.exp
index 276244c..4a57fd9 100644
--- a/expect/timeout.exp
+++ b/expect/timeout.exp
@@ -1,5 +1,5 @@
#
-# Copyright (c) 2020, Arm Limited. All rights reserved.
+# Copyright (c) 2020-2022, Arm Limited. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
@@ -7,12 +7,4 @@
#
source [file join [file dirname [info script]] handle-arguments.inc]
-
-expect {
- timeout {
- puts "<<Timeout expected - Success>>"
- exit_uart 0
- }
-}
-
-exit_uart -1
+source [file join [file dirname [info script]] timeout.inc]
diff --git a/expect/timeout.inc b/expect/timeout.inc
new file mode 100644
index 0000000..7e07ff6
--- /dev/null
+++ b/expect/timeout.inc
@@ -0,0 +1,37 @@
+#
+# Copyright (c) 2022, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+puts "<<test completed, waiting for EOF or timeout>>"
+
+expect {
+ "Exiting tests." {
+ puts "<<expected hang, found TFTF completion>>"
+ }
+
+ "PANIC in EL3." {
+ puts "<<expected hang, found crash dump>>"
+ }
+
+ "Unhandled Exception in EL3." {
+ puts "<<expected hang, found crash dump>>"
+ }
+
+ "Unhandled Exception from EL" {
+ puts "<<expected hang, found crash dump>>"
+ }
+
+ eof {
+ puts "<<stream closed as expected, exiting>>"
+ exit 0
+ }
+
+ timeout {
+ puts "<<timeout triggered as expected, exiting>>"
+ exit_uart 0
+ }
+}
+
+exit_uart -1
diff --git a/expect/timeout_spmin_roxlattables.exp b/expect/timeout_spmin_roxlattables.exp
index 64a54ef..656b7bf 100644
--- a/expect/timeout_spmin_roxlattables.exp
+++ b/expect/timeout_spmin_roxlattables.exp
@@ -1,5 +1,5 @@
#
-# Copyright (c) 2020, Arm Limited. All rights reserved.
+# Copyright (c) 2020-2022, Arm Limited. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
@@ -9,11 +9,5 @@
source [file join [file dirname [info script]] handle-arguments.inc]
expect_string "Translation tables are now read-only at EL3."
-expect {
- timeout {
- puts "<<Timeout expected - Success>>"
- exit_uart 0
- }
-}
-exit_uart -1
+source [file join [file dirname [info script]] timeout.inc]
diff --git a/expect/timeout_test.exp b/expect/timeout_test.exp
index 7e2b758..11fb0c5 100644
--- a/expect/timeout_test.exp
+++ b/expect/timeout_test.exp
@@ -1,5 +1,5 @@
#
-# Copyright (c) 2019-2020 Arm Limited. All rights reserved.
+# Copyright (c) 2019-2022 Arm Limited. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
@@ -9,11 +9,5 @@
source [file join [file dirname [info script]] handle-arguments.inc]
expect_string "Booting trusted firmware test framework" "Starting TFTF"
-expect {
- timeout {
- puts "<<Timeout expected - Success>>"
- exit_uart 0
- }
-}
-exit_uart -1
+source [file join [file dirname [info script]] timeout.inc]