Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1 | # |
Leonardo Sandoval | 579c737 | 2020-10-23 15:23:32 -0500 | [diff] [blame] | 2 | # Copyright (c) 2019-2020 Arm Limited. All rights reserved. |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
| 5 | # |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 6 | # Retrieve script parameters from environment variables. If they don't exist, |
| 7 | # return empty string |
| 8 | proc get_param {name {default ""}} { |
| 9 | if {[info exists ::env($name)]} { |
| 10 | return $::env($name) |
| 11 | } else { |
| 12 | return $default |
| 13 | } |
| 14 | } |
| 15 | |
| 16 | proc exit_uart {status} { |
| 17 | # Allow UART output to flush |
| 18 | sleep 1 |
| 19 | send "\x1b" |
| 20 | send "close\r" |
| 21 | exit $status |
| 22 | } |
| 23 | |
| 24 | proc 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. |
| 33 | proc 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. |
| 52 | proc 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 | } |