Initial commit for TF-A CI scripts
Signed-off-by: Fathi Boudra <fathi.boudra@linaro.org>
diff --git a/expect/busybox.inc b/expect/busybox.inc
new file mode 100644
index 0000000..de9acb6
--- /dev/null
+++ b/expect/busybox.inc
@@ -0,0 +1,15 @@
+#
+# Copyright (c) 2019, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+#
+# Script to interact with a Busybox filesystem
+#
+# This script is not standalone and should be sourced by a top expect script.
+#
+
+expect_string "init.sh" "Init"
+expect_re ".* # " "TEST SUCCESS"
+exit_uart 0
diff --git a/expect/cactus.exp b/expect/cactus.exp
new file mode 100644
index 0000000..4086c5d
--- /dev/null
+++ b/expect/cactus.exp
@@ -0,0 +1,15 @@
+#
+# Copyright (c) 2019, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+#
+# Expect script for the test Secure Partition Cactus
+#
+
+source [file join [file dirname [info script]] handle-arguments.inc]
+
+expect_string "Booting test Secure Partition Cactus"
+
+source [file join [file dirname [info script]] uart-hold.inc]
diff --git a/expect/el3-test-payload.exp b/expect/el3-test-payload.exp
new file mode 100644
index 0000000..d3145ab
--- /dev/null
+++ b/expect/el3-test-payload.exp
@@ -0,0 +1,22 @@
+#
+# Copyright (c) 2019, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+#
+# Expect script for Trusted Firmware + EL3 Test Payload
+#
+# Refer to handle-arguments.inc for the list of parameters.
+#
+
+source [file join [file dirname [info script]] handle-arguments.inc]
+
+# Trusted Firmware boot section
+source [file join [file dirname [info script]] trusted-firmware.inc]
+
+source [file join [file dirname [info script]] utils.inc]
+
+expect_string "Booting the EL3 test payload" "EL3 Test Payload: Started"
+expect_string "All CPUs booted!" "EL3 Test Payload: SUCCESS!"
+exit_uart 0
diff --git a/expect/handle-arguments.inc b/expect/handle-arguments.inc
new file mode 100644
index 0000000..4f06309
--- /dev/null
+++ b/expect/handle-arguments.inc
@@ -0,0 +1,19 @@
+#
+# Copyright (c) 2019, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+#
+# Script to handle the arguments and initialise the expect session.
+#
+# This script is not standalone and should be sourced by a top expect script.
+
+source [file join [file dirname [info script]] utils.inc]
+
+# Store environment variables into local variables
+set uart_port [get_param uart_port]
+set timeout [get_param timeout]
+
+# Open a telnet connection on the required UART port
+set telnet_pid [spawn telnet localhost $uart_port]
diff --git a/expect/hold_uart.exp b/expect/hold_uart.exp
new file mode 100644
index 0000000..a96fa2a
--- /dev/null
+++ b/expect/hold_uart.exp
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2019, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+#
+# Expect script
+#
+
+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
+ }
+}
diff --git a/expect/ivy.exp b/expect/ivy.exp
new file mode 100644
index 0000000..220ba19
--- /dev/null
+++ b/expect/ivy.exp
@@ -0,0 +1,15 @@
+#
+# Copyright (c) 2019, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+#
+# Expect script for the test Secure Partition Ivy
+#
+
+source [file join [file dirname [info script]] handle-arguments.inc]
+
+expect_string "Booting test Secure Partition Ivy"
+
+source [file join [file dirname [info script]] uart-hold.inc]
diff --git a/expect/linux-oe-rst-bl31.exp b/expect/linux-oe-rst-bl31.exp
new file mode 100644
index 0000000..4198295
--- /dev/null
+++ b/expect/linux-oe-rst-bl31.exp
@@ -0,0 +1,27 @@
+#
+# Copyright (c) 2019, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+#
+# Expect script for Trusted Firmware + U-Boot + Linux boot process with
+# OpenEmbedded rootfs in /dev/vda2
+# TF with reset to BL3-1
+#
+# Refer to handle-arguments.inc for the list of parameters.
+#
+
+source [file join [file dirname [info script]] handle-arguments.inc]
+
+# Trusted Firmware boot section
+source [file join [file dirname [info script]] trusted-firmware-rst-to-bl31.inc]
+
+# Linux kernel boot section
+source [file join [file dirname [info script]] linux.inc]
+
+# OpenEmbedded filesystem section
+source [file join [file dirname [info script]] openembedded.inc]
+
+exit_uart -1
+
diff --git a/expect/linux-oe.exp b/expect/linux-oe.exp
new file mode 100644
index 0000000..50cbc5f
--- /dev/null
+++ b/expect/linux-oe.exp
@@ -0,0 +1,25 @@
+#
+# Copyright (c) 2019, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+#
+# Expect script for Trusted Firmware + U-Boot + Linux boot process with
+# OpenEmbedded rootfs in /dev/vda2
+#
+# Refer to handle-arguments.inc for the list of parameters.
+#
+
+source [file join [file dirname [info script]] handle-arguments.inc]
+
+# Trusted Firmware boot section
+source [file join [file dirname [info script]] trusted-firmware.inc]
+
+# Linux kernel boot section
+source [file join [file dirname [info script]] linux.inc]
+
+# OpenEmbedded filesystem section
+source [file join [file dirname [info script]] openembedded.inc]
+
+exit_uart -1
diff --git a/expect/linux-rd-aarch32-rst-sp-min.exp b/expect/linux-rd-aarch32-rst-sp-min.exp
new file mode 100644
index 0000000..d15b1bd
--- /dev/null
+++ b/expect/linux-rd-aarch32-rst-sp-min.exp
@@ -0,0 +1,27 @@
+#
+# Copyright (c) 2019, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+#
+# Expect script for AArch32 Trusted Firmware + U-Boot + Linux boot process
+# with a AArch32 minimal initrd. The linux image must be a zImage and the
+# initrd must include the U-boot header.
+# TF with reset to SP_MIN
+#
+# Refer to handle-arguments.inc for the list of parameters.
+#
+
+source [file join [file dirname [info script]] handle-arguments.inc]
+
+# Trusted Firmware boot section
+source [file join [file dirname [info script]] trusted-firmware-aarch32-rst-to-sp-min.inc]
+
+# Linux kernel boot section
+source [file join [file dirname [info script]] linux.inc]
+
+# Busybox filesystem section
+source [file join [file dirname [info script]] busybox.inc]
+
+exit_uart -1
diff --git a/expect/linux-rd-busybox-aarch32.exp b/expect/linux-rd-busybox-aarch32.exp
new file mode 100644
index 0000000..b6aa630
--- /dev/null
+++ b/expect/linux-rd-busybox-aarch32.exp
@@ -0,0 +1,27 @@
+#
+# Copyright (c) 2019, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+#
+# Expect script for AArch32 Trusted Firmware + U-Boot + Linux boot process
+# with a AArch32 minimal initrd. The linux image must be a zImage and the
+# initrd must include the U-boot header.
+# TF with reset to BL1
+#
+# Refer to handle-arguments.inc for the list of parameters.
+#
+
+source [file join [file dirname [info script]] handle-arguments.inc]
+
+# Trusted Firmware boot section
+source [file join [file dirname [info script]] trusted-firmware-aarch32.inc]
+
+# Linux kernel boot section
+source [file join [file dirname [info script]] linux.inc]
+
+# Busybox filesystem section
+source [file join [file dirname [info script]] busybox.inc]
+
+exit_uart -1
diff --git a/expect/linux-rd-busybox.exp b/expect/linux-rd-busybox.exp
new file mode 100644
index 0000000..986c009
--- /dev/null
+++ b/expect/linux-rd-busybox.exp
@@ -0,0 +1,24 @@
+#
+# Copyright (c) 2019, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+#
+# Expect script for Trusted Firmware + UEFI + Linux boot process with RAM Disk
+#
+# Refer to handle-arguments.inc for the list of parameters.
+#
+
+source [file join [file dirname [info script]] handle-arguments.inc]
+
+# Trusted Firmware boot section
+source [file join [file dirname [info script]] trusted-firmware.inc]
+
+# Linux kernel boot section
+source [file join [file dirname [info script]] linux.inc]
+
+# Busybox filesystem section
+source [file join [file dirname [info script]] busybox.inc]
+
+exit_uart -1
diff --git a/expect/linux.inc b/expect/linux.inc
new file mode 100644
index 0000000..7c4f00d
--- /dev/null
+++ b/expect/linux.inc
@@ -0,0 +1,22 @@
+#
+# Copyright (c) 2019, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+#
+# Script to interact with a Linux kernel
+#
+# This script is not standalone and should be sourced by a top expect script.
+#
+
+# Expect 8 CPUs in total by default
+if {[info exists ::env(num_cpus)]} {
+ set num_cpus $env(num_cpus)
+} else {
+ set num_cpus 8
+}
+
+expect_string "Linux version" "Linux starting"
+expect_re "SMP: Total of $num_cpus processors activated" "Brought up secondary CPUs"
+expect_string "Freeing unused kernel memory" "End of Linux boot"
diff --git a/expect/openembedded.inc b/expect/openembedded.inc
new file mode 100644
index 0000000..801a810
--- /dev/null
+++ b/expect/openembedded.inc
@@ -0,0 +1,18 @@
+#
+# Copyright (c) 2019, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+#
+# Script to interact with an OpenEmbedded file system
+#
+# This script is not standalone and should be sourced by a top expect script.
+#
+
+expect_string "INIT:" "Init"
+expect_string "root@genericarmv8:~#" "Linux prompt"
+send "shutdown -h now\r"
+
+expect_re "(Power down|System halted)" "TEST SUCCESS"
+exit_uart 0
diff --git a/expect/spm-edk2-uart0.exp b/expect/spm-edk2-uart0.exp
new file mode 100644
index 0000000..7947fa1
--- /dev/null
+++ b/expect/spm-edk2-uart0.exp
@@ -0,0 +1,83 @@
+#
+# Copyright (c) 2019, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+#
+# Expect script for Trusted Firmware + EDK2 UART0
+#
+# Refer to handle-arguments.inc for the list of parameters.
+#
+
+source [file join [file dirname [info script]] handle-arguments.inc]
+
+# Trusted Firmware boot section
+source [file join [file dirname [info script]] trusted-firmware.inc]
+
+# EDK2 section
+expect {
+ "UEFI firmware" {
+ puts "<<EDK2 starting>>"
+ }
+ timeout {
+ exit_uart -1
+ }
+}
+
+expect {
+ "UEFI Interactive Shell" {
+ puts "<<EDK2 shell starting>>"
+ }
+ timeout {
+ exit_uart -1
+ }
+}
+
+expect {
+ "any other key to continue." {
+ send "\r"
+ }
+ timeout {
+ exit_uart -1
+ }
+}
+
+expect {
+ "Shell>" {
+ send "fs0:\r"
+ }
+ timeout {
+ exit_uart -1
+ }
+}
+
+expect {
+ "FS0:" {
+ send "UefiInfo.efi\r"
+ puts "<<Loading UEFI application>>"
+ }
+ timeout {
+ exit_uart -1
+ }
+}
+
+expect {
+ -re "Loading driver at .* UefiInfo.efi" {
+ puts "<<UEFI application is being loaded>>"
+ }
+ timeout {
+ exit_uart -1
+ }
+}
+
+expect {
+ "FS0:" {
+ puts "<<UEFI application loaded>>"
+ }
+ timeout {
+ exit_uart -1
+ }
+}
+
+exit_uart 0
diff --git a/expect/spm-edk2-uart2.exp b/expect/spm-edk2-uart2.exp
new file mode 100644
index 0000000..8462333
--- /dev/null
+++ b/expect/spm-edk2-uart2.exp
@@ -0,0 +1,51 @@
+#
+# Copyright (c) 2019, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+#
+# Expect script for Standalone MM partition UART2
+#
+# Refer to handle-arguments.inc for the list of parameters.
+#
+
+source [file join [file dirname [info script]] handle-arguments.inc]
+
+expect {
+ "SPM Version" {
+ puts "<<Secure Partition booting>>"
+ }
+ timeout {
+ exit_uart -1
+ }
+}
+
+expect {
+ "MmMain Done!" {
+ puts "<<Secure Partition booted>>"
+ }
+ timeout {
+ exit_uart -1
+ }
+}
+
+expect {
+ "Received event - 0xC4000041 on cpu" {
+ puts "<<Received event>>"
+ }
+ timeout {
+ exit_uart -1
+ }
+}
+
+expect {
+ "MmEntryPoint Done" {
+ puts "<<Secure Partition done>>"
+ }
+ timeout {
+ exit_uart -1
+ }
+}
+
+exit_uart 0
diff --git a/expect/tftf.exp b/expect/tftf.exp
new file mode 100644
index 0000000..8d5d611
--- /dev/null
+++ b/expect/tftf.exp
@@ -0,0 +1,32 @@
+#
+# Copyright (c) 2019, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+#
+# Expect script for Trusted Firmware Test Framework
+#
+
+source [file join [file dirname [info script]] handle-arguments.inc]
+
+expect_string "Booting trusted firmware test framework" "Starting TFTF"
+expect {
+ "Tests Failed : 0" {
+ puts "<<TFTF Success>>"
+ exit_uart 0
+ }
+ "Tests Passed : 0" {
+ puts "<<TFTF no tests passed>>"
+ exit_uart -1
+ }
+ -re "Tests Failed : \[^0]" {
+ puts "<<TFTF Fail>>"
+ exit_uart -1
+ }
+ timeout {
+ exit_timeout
+ }
+}
+
+exit_uart -1
diff --git a/expect/tftf_fault.exp b/expect/tftf_fault.exp
new file mode 100644
index 0000000..c8181ee
--- /dev/null
+++ b/expect/tftf_fault.exp
@@ -0,0 +1,20 @@
+#
+# Copyright (c) 2019, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+#
+# Expect script
+#
+
+source [file join [file dirname [info script]] handle-arguments.inc]
+
+# Expect the test to have set a fault message
+if {![info exists ::env(tftf_fault_msg)]} {
+ puts "Fault message not set"
+ exit_uart -1
+}
+
+expect_string "$env(tftf_fault_msg)"
+exit_uart 0
diff --git a/expect/tftf_no_ttst.exp b/expect/tftf_no_ttst.exp
new file mode 100644
index 0000000..df09a03
--- /dev/null
+++ b/expect/tftf_no_ttst.exp
@@ -0,0 +1,35 @@
+#
+# Copyright (c) 2019, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+#
+# Expect script for Trusted Firmware Test Framework
+#
+
+source [file join [file dirname [info script]] handle-arguments.inc]
+
+expect {
+ "Initial lookup level: 3" {
+ puts "<<Using TTST, but it shouldn't be using it>>"
+ exit_uart -1
+ }
+ "Tests Failed : 0" {
+ puts "<<TFTF Success>>"
+ exit_uart 0
+ }
+ "Tests Passed : 0" {
+ puts "<<TFTF no tests passed>>"
+ exit_uart -1
+ }
+ -re "Tests Failed : \[^0]" {
+ puts "<<TFTF Fail>>"
+ exit_uart -1
+ }
+ timeout {
+ exit_timeout
+ }
+}
+
+exit_uart -1
diff --git a/expect/tftf_ttst.exp b/expect/tftf_ttst.exp
new file mode 100644
index 0000000..675cc75
--- /dev/null
+++ b/expect/tftf_ttst.exp
@@ -0,0 +1,35 @@
+#
+# Copyright (c) 2019, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+#
+# Expect script for Trusted Firmware Test Framework
+#
+
+source [file join [file dirname [info script]] handle-arguments.inc]
+
+expect_string "Initial lookup level: 3"
+
+expect_string "Booting trusted firmware test framework" "Starting TFTF"
+
+expect {
+ "Tests Failed : 0" {
+ puts "<<TFTF Success>>"
+ exit_uart 0
+ }
+ "Tests Passed : 0" {
+ puts "<<TFTF no tests passed>>"
+ exit_uart -1
+ }
+ -re "Tests Failed : \[^0]" {
+ puts "<<TFTF Fail>>"
+ exit_uart -1
+ }
+ timeout {
+ exit_timeout
+ }
+}
+
+exit_uart -1
diff --git a/expect/trusted-firmware-aarch32-rst-to-sp-min.inc b/expect/trusted-firmware-aarch32-rst-to-sp-min.inc
new file mode 100644
index 0000000..af7c343
--- /dev/null
+++ b/expect/trusted-firmware-aarch32-rst-to-sp-min.inc
@@ -0,0 +1,13 @@
+#
+# Copyright (c) 2019, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+#
+# Script to interact with Trusted Firmware when resetting to SP_MIN.
+#
+# This script is not standalone and should be sourced by a top expect script.
+#
+
+expect_string "SP_MIN:" "Booting SP_MIN"
diff --git a/expect/trusted-firmware-aarch32.inc b/expect/trusted-firmware-aarch32.inc
new file mode 100644
index 0000000..378e581
--- /dev/null
+++ b/expect/trusted-firmware-aarch32.inc
@@ -0,0 +1,20 @@
+#
+# Copyright (c) 2019, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+#
+# Script to interact with Trusted Firmware when resetting to BL1.
+#
+# This script is not standalone and should be sourced by a top expect script.
+#
+
+if {![info exists ::env(skip_early_boot_msgs)]} {
+ expect_string "Booting Trusted Firmware"
+ expect_string "BL1: Booting BL2"
+ expect_string "BL1: Booting BL32"
+ expect_string "SP_MIN:" "Booting SP_MIN"
+} else {
+ puts "<<Skipping early boot messages from BL1 and BL2>>"
+}
diff --git a/expect/trusted-firmware-rst-to-bl31.inc b/expect/trusted-firmware-rst-to-bl31.inc
new file mode 100644
index 0000000..b413a3f
--- /dev/null
+++ b/expect/trusted-firmware-rst-to-bl31.inc
@@ -0,0 +1,13 @@
+#
+# Copyright (c) 2019, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+#
+# Script to interact with Trusted Firmware when resetting to BL31.
+#
+# This script is not standalone and should be sourced by a top expect script.
+#
+
+expect_re "NOTICE: BL3-?1:" "Booting BL31"
diff --git a/expect/trusted-firmware.inc b/expect/trusted-firmware.inc
new file mode 100644
index 0000000..5e98ac2
--- /dev/null
+++ b/expect/trusted-firmware.inc
@@ -0,0 +1,21 @@
+#
+# Copyright (c) 2019, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+#
+# Script to interact with Trusted Firmware when resetting to BL1.
+#
+# This script is not standalone and should be sourced by a top expect script.
+#
+
+# Initial boot message won't be present if we're starting at BL31. Skip waiting
+# for them by inspecting the environment variable 'skip_early_boot_msgs'
+if {![info exists ::env(skip_early_boot_msgs)]} {
+ expect_string "Booting Trusted Firmware"
+ expect_string "BL1: Booting BL2"
+ expect_re "BL1: Booting BL3-?1" "BL1: Booting BL31"
+} else {
+ puts "<<Skipping early boot messages from BL1 and BL2>>"
+}
diff --git a/expect/tsp.exp b/expect/tsp.exp
new file mode 100644
index 0000000..45b648f
--- /dev/null
+++ b/expect/tsp.exp
@@ -0,0 +1,51 @@
+#
+# Copyright (c) 2019, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+#
+# Expect script for TSP
+#
+
+source [file join [file dirname [info script]] handle-arguments.inc]
+
+#
+# Output from TSP:
+#
+# NOTICE: TSP: <version>(<mode>):<commit_id>
+# NOTICE: TSP: Built : <hh:mm:ss>, <date>
+#
+# With 'TSP: Built' message, we assume a successful boot. All further messages
+# are ignored.
+#
+
+# Arbitrary TSP response count during boot. Maybe adjusted as necessary
+set tsp_resp_proof [get_param tsp_resp_proof 1000]
+set tsp_resp_count 0
+
+expect_string "TSP: Built" "TSP booted"
+
+# TSPD prints more messages only when built with INFO or above.
+set tsp_debug [get_param tsp_debug]
+if {$tsp_debug != ""} {
+ while {1} {
+ expect {
+ # Following CPU power operations, TSP emits sample stats using
+ # the below prefix. After tsp_resp_proof responses during boot,
+ # we're confident TSP is functional; so quit with success.
+ "TSP: cpu" {
+ incr tsp_resp_count
+ if {$tsp_resp_count >= $tsp_resp_proof} {
+ puts "<<TSP $tsp_resp_count responses; sufficient>>"
+ break
+ }
+ }
+ timeout {
+ exit_timeout
+ }
+ }
+ }
+}
+
+source [file join [file dirname [info script]] uart-hold.inc]
diff --git a/expect/uart-hold.inc b/expect/uart-hold.inc
new file mode 100644
index 0000000..8c876ba
--- /dev/null
+++ b/expect/uart-hold.inc
@@ -0,0 +1,17 @@
+#
+# Copyright (c) 2019, 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.
+
+set timeout -1
+puts "<<holding terminal>>"
+expect {
+ "FOOBAR" {
+ exit_uart -1
+ }
+}
diff --git a/expect/utils.inc b/expect/utils.inc
new file mode 100644
index 0000000..5c13f00
--- /dev/null
+++ b/expect/utils.inc
@@ -0,0 +1,68 @@
+#
+# Copyright (c) 2019, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+
+# Retrieve script parameters from environment variables. If they don't exist,
+# return empty string
+proc get_param {name {default ""}} {
+ if {[info exists ::env($name)]} {
+ return $::env($name)
+ } else {
+ return $default
+ }
+}
+
+proc exit_uart {status} {
+ # Allow UART output to flush
+ sleep 1
+ send "\x1b"
+ send "close\r"
+ exit $status
+}
+
+proc exit_timeout {} {
+ # Allow UART output to flush
+ sleep 1
+ puts "<<TIMEOUT>>"
+ exit_uart -1
+}
+
+# Expect a given string, and an optional message to be output when it's found.
+# If not supplied, the message defaults to the string itself.
+proc expect_string {the_string {the_message ""}} {
+ if {$the_message eq ""} {
+ set the_message $the_string
+ }
+
+ expect {
+ $the_string {
+ puts "<<$the_message>>"
+ }
+ timeout {
+ puts "<<Not found: $the_string>>"
+ exit_timeout
+ }
+ }
+}
+
+# Expect a given regular expression, and an optional message to be output when
+# it's found. If not supplied, the message defaults to the regular expression
+# itself.
+proc expect_re {the_re {the_message ""}} {
+ if {$the_message eq ""} {
+ set the_message $the_re
+ }
+
+ expect {
+ -re $the_re {
+ puts "<<$the_message>>"
+ }
+ timeout {
+ puts "<<Not found: $the_re>>"
+ exit_timeout
+ }
+ }
+}