blob: 48f72def4a66ae72eee0db96fa9d53f82e6c96a7 [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 {} {
Chris Kay78ea2c32022-11-15 12:24:24 +000039 message "timeout exceeded, exiting"
Fathi Boudra422bf772019-12-02 11:10:16 +020040 exit_uart -1
41}
42
Chris Kay78ea2c32022-11-15 12:24:24 +000043proc message {string} {
44 puts "<<$string>>"
45}
46
47proc found {value {message ""}} {
48 if {$message eq ""} {
49 message "found: \"$value\""
50 } else {
51 message "found: \"$value\" ($message)"
52 }
53}
54
55proc not_found {value {message ""}} {
56 if {$message eq ""} {
57 message "not found: \"$value\""
58 } else {
59 message "not found: \"$value\" ($message)"
60 }
61}
62
Fathi Boudra422bf772019-12-02 11:10:16 +020063# Expect a given string, and an optional message to be output when it's found.
64# If not supplied, the message defaults to the string itself.
65proc expect_string {the_string {the_message ""}} {
Chris Kay78ea2c32022-11-15 12:24:24 +000066 message "waiting for: \"$the_string\""
Fathi Boudra422bf772019-12-02 11:10:16 +020067
68 expect {
69 $the_string {
Chris Kay78ea2c32022-11-15 12:24:24 +000070 found "$the_string" "$the_message"
Fathi Boudra422bf772019-12-02 11:10:16 +020071 }
Chris Kay3d868ca2022-11-15 12:30:08 +000072
73 eof {
Chris Kay78ea2c32022-11-15 12:24:24 +000074 not_found "$the_string"
Chris Kay3d868ca2022-11-15 12:30:08 +000075 exit -1
76 }
77
Fathi Boudra422bf772019-12-02 11:10:16 +020078 timeout {
Chris Kay78ea2c32022-11-15 12:24:24 +000079 not_found "$the_string"
Fathi Boudra422bf772019-12-02 11:10:16 +020080 exit_timeout
81 }
82 }
83}
84
85# Expect a given regular expression, and an optional message to be output when
86# it's found. If not supplied, the message defaults to the regular expression
87# itself.
88proc expect_re {the_re {the_message ""}} {
Chris Kay78ea2c32022-11-15 12:24:24 +000089 message "waiting for: \"$the_re\""
Fathi Boudra422bf772019-12-02 11:10:16 +020090
91 expect {
92 -re $the_re {
Chris Kay78ea2c32022-11-15 12:24:24 +000093 found "$the_re" "$the_message"
Fathi Boudra422bf772019-12-02 11:10:16 +020094 }
Chris Kay3d868ca2022-11-15 12:30:08 +000095
96 eof {
Chris Kay78ea2c32022-11-15 12:24:24 +000097 not_found "$the_re"
Chris Kay3d868ca2022-11-15 12:30:08 +000098 exit -1
99 }
100
Fathi Boudra422bf772019-12-02 11:10:16 +0200101 timeout {
Chris Kay78ea2c32022-11-15 12:24:24 +0000102 not_found "$the_re"
Fathi Boudra422bf772019-12-02 11:10:16 +0200103 exit_timeout
104 }
105 }
106}