refactor(expect): wait for SIGINT or EOF when holding UARTs
This change allows any Expect scripts that include the `uart-hold.inc`
to terminate with success upon reception of either EOF or the SIGINT
(Ctrl+C) signal. The former is necessary for the OpenCI, and the latter
for the on-premises CI.
This change also introduces the `terminable.inc` Expect script fragment,
which adds a trap handler for the SIGINT signal (Ctrl+C) which will exit
the Expect script with success. This is useful for scripts that work
around SDDKW-43675, where the model hangs if UARTs which generate a lot
of output are not flushed frequently.
The `handle-arguments.inc` fragment has been updated to ignore SIGINT so
that other terms are not terminated prematurely.
See: https://jira.arm.com/browse/SDDKW-43675
Signed-off-by: Chris Kay <chris.kay@arm.com>
Change-Id: Icb106b60409c4e3be2b025fa1d4550af3acb57be
diff --git a/expect-lava/hold_uart.exp b/expect-lava/hold_uart.exp
index 4dc417b..f64cde9 100644
--- a/expect-lava/hold_uart.exp
+++ b/expect-lava/hold_uart.exp
@@ -7,10 +7,12 @@
#
# Original TCL expect/ArmCI description:
-# If we exit from the uart, and if that had lots of prints, then the model
-# will stall. This may also occur even when the uart does not have any print.
-# See: https://jira.arm.com/browse/SDDKW-43675. So, we wait here expect for
-# something that never arrives.
+#
+# If we exit from the UART when any of the model's UARTs receive lots of prints
+# then the model will stall, so we either wait for the UART to close naturally
+# or we wait for somebody to explicitly tell us to exit.
+#
+# https://jira.arm.com/browse/SDDKW-43675
# This functionality is not required for LAVA tests, so this file is empty.
# See also ../expect-post/hold_uart.exp
diff --git a/expect/handle-arguments.inc b/expect/handle-arguments.inc
index 53ee95b..1fe03d5 100644
--- a/expect/handle-arguments.inc
+++ b/expect/handle-arguments.inc
@@ -22,6 +22,10 @@
set telnet_pid [spawn cat $uart_log_file]
}
+trap {
+ puts "<<test not yet complete, ignoring SIGINT>>"
+} SIGINT
+
expect_after {
eof {
puts "<<stream closed prematurely, exiting>>"
diff --git a/expect/hold_uart.exp b/expect/hold_uart.exp
index eca2327..ab9a8df 100644
--- a/expect/hold_uart.exp
+++ b/expect/hold_uart.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
#
@@ -7,15 +7,4 @@
#
source [file join [file dirname [info script]] handle-arguments.inc]
-
-# If we exit from the uart, and if that had lots of prints, then the model
-# will stall. This may also occur even when the uart does not have any print.
-# See: https://jira.arm.com/browse/SDDKW-43675. So, we wait here expect for
-# something that never arrives.
-set timeout -1
-puts "<<holding terminal>>"
-expect {
- "FOOBAR" {
- exit_uart -1
- }
-}
+source [file join [file dirname [info script]] uart-hold.inc]
diff --git a/expect/terminable.inc b/expect/terminable.inc
new file mode 100644
index 0000000..a96d51a
--- /dev/null
+++ b/expect/terminable.inc
@@ -0,0 +1,10 @@
+#
+# Copyright (c) 2022 Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+trap {
+ puts "<<received SIGINT, exiting>>"
+ exit_uart 0
+} SIGINT
diff --git a/expect/uart-hold.inc b/expect/uart-hold.inc
index a9e6c90..e03a83a 100644
--- a/expect/uart-hold.inc
+++ b/expect/uart-hold.inc
@@ -1,16 +1,20 @@
#
-# Copyright (c) 2019-2020 Arm Limited. All rights reserved.
+# Copyright (c) 2019-2022 Arm Limited. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
-# If we exit from a secondary uart, and if that had lots of prints, then the
-# model will stall. See: https://jira.arm.com/browse/SDDKW-43675. So, we wait
-# here expect for something that never arrives.
+
+#
+# If we exit from the UART when any of the model's UARTs receive lots of prints
+# then the model will stall, so we either wait for the UART to close naturally
+# or we wait for somebody to explicitly tell us to exit.
+#
+# https://jira.arm.com/browse/SDDKW-43675
+#
set timeout -1
-puts "<<holding terminal>>"
-expect {
- "FOOBAR" {
- exit_uart -1
- }
-}
+
+source [file join [file dirname [info script]] terminable.inc]
+
+puts "<<test complete, waiting for EOF or SIGINT>>"
+expect eof