blob: 3d5a7f555065bbacb14f18d1c5ef003fa218baa5 [file] [log] [blame]
Fathi Boudra422bf772019-12-02 11:10:16 +02001#
Chris Kay395d49d2022-10-17 13:31:21 +01002# Copyright (c) 2019-2022, Arm Limited. All rights reserved.
Fathi Boudra422bf772019-12-02 11:10:16 +02003#
4# SPDX-License-Identifier: BSD-3-Clause
5#
Chris Kay395d49d2022-10-17 13:31:21 +01006
7# Determine whether the script is being run on a live FVP UART terminal or
8# postprocessing a UART log file (probably dumped by LAVA).
9proc postprocessing {} {
10 if { [info exists ::env(uart_log_file)] } {
11 return 1
12 } else {
13 return 0
14 }
15}
16
Fathi Boudra422bf772019-12-02 11:10:16 +020017# Retrieve script parameters from environment variables. If they don't exist,
18# return empty string
19proc get_param {name {default ""}} {
20 if {[info exists ::env($name)]} {
21 return $::env($name)
22 } else {
23 return $default
24 }
25}
26
27proc exit_uart {status} {
Chris Kay395d49d2022-10-17 13:31:21 +010028 if { [postprocessing] != 1 } {
29 # Allow UART output to flush
30 sleep 1
31 send "\x1b"
32 send "close\r"
33 }
34
Fathi Boudra422bf772019-12-02 11:10:16 +020035 exit $status
36}
37
38proc exit_timeout {} {
39 # Allow UART output to flush
40 sleep 1
41 puts "<<TIMEOUT>>"
42 exit_uart -1
43}
44
45# Expect a given string, and an optional message to be output when it's found.
46# If not supplied, the message defaults to the string itself.
47proc expect_string {the_string {the_message ""}} {
48 if {$the_message eq ""} {
49 set the_message $the_string
50 }
51
52 expect {
53 $the_string {
54 puts "<<$the_message>>"
55 }
56 timeout {
57 puts "<<Not found: $the_string>>"
58 exit_timeout
59 }
60 }
61}
62
63# Expect a given regular expression, and an optional message to be output when
64# it's found. If not supplied, the message defaults to the regular expression
65# itself.
66proc expect_re {the_re {the_message ""}} {
67 if {$the_message eq ""} {
68 set the_message $the_re
69 }
70
71 expect {
72 -re $the_re {
73 puts "<<$the_message>>"
74 }
75 timeout {
76 puts "<<Not found: $the_re>>"
77 exit_timeout
78 }
79 }
80}