| # |
| # Copyright (c) 2019-2022, Arm Limited. All rights reserved. |
| # |
| # SPDX-License-Identifier: BSD-3-Clause |
| # |
| |
| # Determine whether the script is being run on a live FVP UART terminal or |
| # postprocessing a UART log file (probably dumped by LAVA). |
| proc postprocessing {} { |
| if { [info exists ::env(uart_log_file)] } { |
| return 1 |
| } else { |
| return 0 |
| } |
| } |
| |
| # Retrieve script parameters from environment variables. If they don't exist, |
| # return empty string |
| proc get_param {name {default ""}} { |
| if {[info exists ::env($name)]} { |
| return $::env($name) |
| } else { |
| return $default |
| } |
| } |
| |
| proc exit_uart {status} { |
| if { [postprocessing] != 1 } { |
| # Allow UART output to flush |
| sleep 1 |
| send "\x1b" |
| send "close\r" |
| } |
| |
| exit $status |
| } |
| |
| proc exit_timeout {} { |
| message "timeout exceeded, exiting" |
| exit_uart -1 |
| } |
| |
| proc message {string} { |
| puts "<<$string>>" |
| } |
| |
| proc found {value {message ""}} { |
| if {$message eq ""} { |
| message "found: \"$value\"" |
| } else { |
| message "found: \"$value\" ($message)" |
| } |
| } |
| |
| proc not_found {value {message ""}} { |
| if {$message eq ""} { |
| message "not found: \"$value\"" |
| } else { |
| message "not found: \"$value\" ($message)" |
| } |
| } |
| |
| # Expect a given string, and an optional message to be output when it's found. |
| # If not supplied, the message defaults to the string itself. |
| proc expect_string {the_string {the_message ""}} { |
| message "waiting for: \"$the_string\"" |
| |
| expect { |
| $the_string { |
| found "$the_string" "$the_message" |
| } |
| |
| eof { |
| not_found "$the_string" |
| exit -1 |
| } |
| |
| timeout { |
| not_found "$the_string" |
| exit_timeout |
| } |
| } |
| } |
| |
| # Expect a given regular expression, and an optional message to be output when |
| # it's found. If not supplied, the message defaults to the regular expression |
| # itself. |
| proc expect_re {the_re {the_message ""}} { |
| message "waiting for: \"$the_re\"" |
| |
| expect { |
| -re $the_re { |
| found "$the_re" "$the_message" |
| } |
| |
| eof { |
| not_found "$the_re" |
| exit -1 |
| } |
| |
| timeout { |
| not_found "$the_re" |
| exit_timeout |
| } |
| } |
| } |
| |
| proc capture_log {out end_re} { |
| set event_log [open $out w] |
| expect "TCG_EfiSpecIDEvent" |
| |
| expect { |
| # Parse the event log from the debug logs and store the digests |
| # so they can be matched later with what TF-A stored on the event log. |
| -re "Digest(\\s|\\w)*:\\s(\\w{2}\\s){16}|\ |
| : (\\w{2}\\s){16}|\ |
| (Event|EventType|EventSize)\\s*:\\s\\w+\\s" { |
| puts $event_log $expect_out(0,string) |
| exp_continue |
| } |
| |
| -re "$end_re" { |
| close $event_log |
| } |
| } |
| } |
| |
| proc capture_and_compare_log {out end_re compare} { |
| set event_log [open $out w] |
| capture_log $out $end_re |
| |
| # Match the previously the given digests. The pass criteria is that both |
| # digests must match. |
| if {[catch {exec diff -s $out $compare} result options] == 0} { |
| message "tests succeeded, digests matched" |
| } else { |
| message "tests failed, digests did not match" |
| exit_uart -1 |
| } |
| } |