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