blob: 0100534b24183fc2ec47f834a73f0b3093c854ae [file] [log] [blame]
Fathi Boudra422bf772019-12-02 11:10:16 +02001#
Leonardo Sandoval579c7372020-10-23 15:23:32 -05002# Copyright (c) 2019-2020 Arm Limited. All rights reserved.
Fathi Boudra422bf772019-12-02 11:10:16 +02003#
4# SPDX-License-Identifier: BSD-3-Clause
5#
Fathi Boudra422bf772019-12-02 11:10:16 +02006# Retrieve script parameters from environment variables. If they don't exist,
7# return empty string
8proc get_param {name {default ""}} {
9 if {[info exists ::env($name)]} {
10 return $::env($name)
11 } else {
12 return $default
13 }
14}
15
16proc exit_uart {status} {
17 # Allow UART output to flush
18 sleep 1
19 send "\x1b"
20 send "close\r"
21 exit $status
22}
23
24proc exit_timeout {} {
25 # Allow UART output to flush
26 sleep 1
27 puts "<<TIMEOUT>>"
28 exit_uart -1
29}
30
31# Expect a given string, and an optional message to be output when it's found.
32# If not supplied, the message defaults to the string itself.
33proc expect_string {the_string {the_message ""}} {
34 if {$the_message eq ""} {
35 set the_message $the_string
36 }
37
38 expect {
39 $the_string {
40 puts "<<$the_message>>"
41 }
42 timeout {
43 puts "<<Not found: $the_string>>"
44 exit_timeout
45 }
46 }
47}
48
49# Expect a given regular expression, and an optional message to be output when
50# it's found. If not supplied, the message defaults to the regular expression
51# itself.
52proc expect_re {the_re {the_message ""}} {
53 if {$the_message eq ""} {
54 set the_message $the_re
55 }
56
57 expect {
58 -re $the_re {
59 puts "<<$the_message>>"
60 }
61 timeout {
62 puts "<<Not found: $the_re>>"
63 exit_timeout
64 }
65 }
66}