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 {} { |
Chris Kay | 78ea2c3 | 2022-11-15 12:24:24 +0000 | [diff] [blame] | 39 | message "timeout exceeded, exiting" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 40 | exit_uart -1 |
| 41 | } |
| 42 | |
Chris Kay | 78ea2c3 | 2022-11-15 12:24:24 +0000 | [diff] [blame] | 43 | proc message {string} { |
| 44 | puts "<<$string>>" |
| 45 | } |
| 46 | |
| 47 | proc found {value {message ""}} { |
| 48 | if {$message eq ""} { |
| 49 | message "found: \"$value\"" |
| 50 | } else { |
| 51 | message "found: \"$value\" ($message)" |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | proc 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 Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 63 | # 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. |
| 65 | proc expect_string {the_string {the_message ""}} { |
Chris Kay | 78ea2c3 | 2022-11-15 12:24:24 +0000 | [diff] [blame] | 66 | message "waiting for: \"$the_string\"" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 67 | |
| 68 | expect { |
| 69 | $the_string { |
Chris Kay | 78ea2c3 | 2022-11-15 12:24:24 +0000 | [diff] [blame] | 70 | found "$the_string" "$the_message" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 71 | } |
Chris Kay | 3d868ca | 2022-11-15 12:30:08 +0000 | [diff] [blame] | 72 | |
| 73 | eof { |
Chris Kay | 78ea2c3 | 2022-11-15 12:24:24 +0000 | [diff] [blame] | 74 | not_found "$the_string" |
Chris Kay | 3d868ca | 2022-11-15 12:30:08 +0000 | [diff] [blame] | 75 | exit -1 |
| 76 | } |
| 77 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 78 | timeout { |
Chris Kay | 78ea2c3 | 2022-11-15 12:24:24 +0000 | [diff] [blame] | 79 | not_found "$the_string" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 80 | 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. |
| 88 | proc expect_re {the_re {the_message ""}} { |
Chris Kay | 78ea2c3 | 2022-11-15 12:24:24 +0000 | [diff] [blame] | 89 | message "waiting for: \"$the_re\"" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 90 | |
| 91 | expect { |
| 92 | -re $the_re { |
Chris Kay | 78ea2c3 | 2022-11-15 12:24:24 +0000 | [diff] [blame] | 93 | found "$the_re" "$the_message" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 94 | } |
Chris Kay | 3d868ca | 2022-11-15 12:30:08 +0000 | [diff] [blame] | 95 | |
| 96 | eof { |
Chris Kay | 78ea2c3 | 2022-11-15 12:24:24 +0000 | [diff] [blame] | 97 | not_found "$the_re" |
Chris Kay | 3d868ca | 2022-11-15 12:30:08 +0000 | [diff] [blame] | 98 | exit -1 |
| 99 | } |
| 100 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 101 | timeout { |
Chris Kay | 78ea2c3 | 2022-11-15 12:24:24 +0000 | [diff] [blame] | 102 | not_found "$the_re" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 103 | exit_timeout |
| 104 | } |
| 105 | } |
| 106 | } |
Harrison Mutai | fbadee4 | 2025-02-18 10:47:48 +0000 | [diff] [blame] | 107 | |
| 108 | proc capture_log {out end_re} { |
Harrison Mutai | cfe90f3 | 2025-05-06 15:26:04 +0000 | [diff] [blame] | 109 | set event_log [open $out w] |
Harrison Mutai | fbadee4 | 2025-02-18 10:47:48 +0000 | [diff] [blame] | 110 | |
Harrison Mutai | cfe90f3 | 2025-05-06 15:26:04 +0000 | [diff] [blame] | 111 | expect -re {(?:\w+: )?(TCG_EfiSpecIDEvent:)\r\n} { |
| 112 | puts $event_log $expect_out(1,string) |
| 113 | } |
Harrison Mutai | fbadee4 | 2025-02-18 10:47:48 +0000 | [diff] [blame] | 114 | |
Harrison Mutai | cfe90f3 | 2025-05-06 15:26:04 +0000 | [diff] [blame] | 115 | while {1} { |
| 116 | # Skip the known logging headers in the first non-capture group to |
| 117 | # ensure we only capture the contents of the log. |
| 118 | expect -re {(?:\w+: |\S+: )?([^\n]*)\r\n} { |
| 119 | set line $expect_out(1,string) |
| 120 | |
| 121 | if {[regexp -- $end_re $line]} { |
| 122 | break |
| 123 | } |
| 124 | |
| 125 | puts $event_log $line |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | close $event_log |
Harrison Mutai | fbadee4 | 2025-02-18 10:47:48 +0000 | [diff] [blame] | 130 | } |
| 131 | |
Harrison Mutai | 47751e0 | 2025-02-28 12:08:09 +0000 | [diff] [blame] | 132 | proc compare_log {out compare} { |
Harrison Mutai | fbadee4 | 2025-02-18 10:47:48 +0000 | [diff] [blame] | 133 | # Match the previously the given digests. The pass criteria is that both |
| 134 | # digests must match. |
Harrison Mutai | cfe90f3 | 2025-05-06 15:26:04 +0000 | [diff] [blame] | 135 | if {[catch {exec diff -ws $out $compare} result options] == 0} { |
Harrison Mutai | fbadee4 | 2025-02-18 10:47:48 +0000 | [diff] [blame] | 136 | message "tests succeeded, digests matched" |
| 137 | } else { |
| 138 | message "tests failed, digests did not match" |
| 139 | exit_uart -1 |
| 140 | } |
| 141 | } |
Harrison Mutai | 47751e0 | 2025-02-28 12:08:09 +0000 | [diff] [blame] | 142 | |
| 143 | proc capture_and_compare_log {out end_re compare} { |
| 144 | set event_log [open $out w] |
| 145 | capture_log $out $end_re |
| 146 | |
| 147 | compare_log $out $compare |
| 148 | } |