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
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