Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1 | # |
Chris Kay | 395d49d | 2022-10-17 13:31:21 +0100 | [diff] [blame^] | 2 | # Copyright (c) 2019-2022, 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 | # |
Chris Kay | 395d49d | 2022-10-17 13:31:21 +0100 | [diff] [blame^] | 6 | |
| 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). |
| 9 | proc postprocessing {} { |
| 10 | if { [info exists ::env(uart_log_file)] } { |
| 11 | return 1 |
| 12 | } else { |
| 13 | return 0 |
| 14 | } |
| 15 | } |
| 16 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 17 | # Retrieve script parameters from environment variables. If they don't exist, |
| 18 | # return empty string |
| 19 | proc get_param {name {default ""}} { |
| 20 | if {[info exists ::env($name)]} { |
| 21 | return $::env($name) |
| 22 | } else { |
| 23 | return $default |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | proc exit_uart {status} { |
Chris Kay | 395d49d | 2022-10-17 13:31:21 +0100 | [diff] [blame^] | 28 | if { [postprocessing] != 1 } { |
| 29 | # Allow UART output to flush |
| 30 | sleep 1 |
| 31 | send "\x1b" |
| 32 | send "close\r" |
| 33 | } |
| 34 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 35 | exit $status |
| 36 | } |
| 37 | |
| 38 | proc 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. |
| 47 | proc 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 | } |
| 56 | timeout { |
| 57 | puts "<<Not found: $the_string>>" |
| 58 | exit_timeout |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | # Expect a given regular expression, and an optional message to be output when |
| 64 | # it's found. If not supplied, the message defaults to the regular expression |
| 65 | # itself. |
| 66 | proc expect_re {the_re {the_message ""}} { |
| 67 | if {$the_message eq ""} { |
| 68 | set the_message $the_re |
| 69 | } |
| 70 | |
| 71 | expect { |
| 72 | -re $the_re { |
| 73 | puts "<<$the_message>>" |
| 74 | } |
| 75 | timeout { |
| 76 | puts "<<Not found: $the_re>>" |
| 77 | exit_timeout |
| 78 | } |
| 79 | } |
| 80 | } |