blob: fc635297f39f1ac2251bd9885a0106bc0eec7be7 [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 }
Chris Kay3d868ca2022-11-15 12:30:08 +000056
57 eof {
58 puts "<<not found: \"$the_string\">>"
59 exit -1
60 }
61
Fathi Boudra422bf772019-12-02 11:10:16 +020062 timeout {
63 puts "<<Not found: $the_string>>"
64 exit_timeout
65 }
66 }
67}
68
69# Expect a given regular expression, and an optional message to be output when
70# it's found. If not supplied, the message defaults to the regular expression
71# itself.
72proc expect_re {the_re {the_message ""}} {
73 if {$the_message eq ""} {
74 set the_message $the_re
75 }
76
77 expect {
78 -re $the_re {
79 puts "<<$the_message>>"
80 }
Chris Kay3d868ca2022-11-15 12:30:08 +000081
82 eof {
83 puts "<<not found: \"$the_re\">>"
84 exit -1
85 }
86
Fathi Boudra422bf772019-12-02 11:10:16 +020087 timeout {
88 puts "<<Not found: $the_re>>"
89 exit_timeout
90 }
91 }
92}