blob: d9113d7f25494c98d8fac9ba962dda3f510523db [file] [log] [blame]
Fathi Boudra422bf772019-12-02 11:10:16 +02001#
Chris Kay395d49d2022-10-17 13:31:21 +01002# Copyright (c) 2019-2022, Arm Limited. All rights reserved.
Fathi Boudra422bf772019-12-02 11:10:16 +02003#
4# SPDX-License-Identifier: BSD-3-Clause
5#
Chris Kay395d49d2022-10-17 13:31:21 +01006
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).
9proc postprocessing {} {
10 if { [info exists ::env(uart_log_file)] } {
11 return 1
12 } else {
13 return 0
14 }
15}
16
Fathi Boudra422bf772019-12-02 11:10:16 +020017# Retrieve script parameters from environment variables. If they don't exist,
18# return empty string
19proc get_param {name {default ""}} {
20 if {[info exists ::env($name)]} {
21 return $::env($name)
22 } else {
23 return $default
24 }
25}
26
27proc exit_uart {status} {
Chris Kay395d49d2022-10-17 13:31:21 +010028 if { [postprocessing] != 1 } {
29 # Allow UART output to flush
30 sleep 1
31 send "\x1b"
32 send "close\r"
33 }
34
Fathi Boudra422bf772019-12-02 11:10:16 +020035 exit $status
36}
37
38proc exit_timeout {} {
Chris Kay78ea2c32022-11-15 12:24:24 +000039 message "timeout exceeded, exiting"
Fathi Boudra422bf772019-12-02 11:10:16 +020040 exit_uart -1
41}
42
Chris Kay78ea2c32022-11-15 12:24:24 +000043proc message {string} {
44 puts "<<$string>>"
45}
46
47proc found {value {message ""}} {
48 if {$message eq ""} {
49 message "found: \"$value\""
50 } else {
51 message "found: \"$value\" ($message)"
52 }
53}
54
55proc 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 Boudra422bf772019-12-02 11:10:16 +020063# 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.
65proc expect_string {the_string {the_message ""}} {
Chris Kay78ea2c32022-11-15 12:24:24 +000066 message "waiting for: \"$the_string\""
Fathi Boudra422bf772019-12-02 11:10:16 +020067
68 expect {
69 $the_string {
Chris Kay78ea2c32022-11-15 12:24:24 +000070 found "$the_string" "$the_message"
Fathi Boudra422bf772019-12-02 11:10:16 +020071 }
Chris Kay3d868ca2022-11-15 12:30:08 +000072
73 eof {
Chris Kay78ea2c32022-11-15 12:24:24 +000074 not_found "$the_string"
Chris Kay3d868ca2022-11-15 12:30:08 +000075 exit -1
76 }
77
Fathi Boudra422bf772019-12-02 11:10:16 +020078 timeout {
Chris Kay78ea2c32022-11-15 12:24:24 +000079 not_found "$the_string"
Fathi Boudra422bf772019-12-02 11:10:16 +020080 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.
88proc expect_re {the_re {the_message ""}} {
Chris Kay78ea2c32022-11-15 12:24:24 +000089 message "waiting for: \"$the_re\""
Fathi Boudra422bf772019-12-02 11:10:16 +020090
91 expect {
92 -re $the_re {
Chris Kay78ea2c32022-11-15 12:24:24 +000093 found "$the_re" "$the_message"
Fathi Boudra422bf772019-12-02 11:10:16 +020094 }
Chris Kay3d868ca2022-11-15 12:30:08 +000095
96 eof {
Chris Kay78ea2c32022-11-15 12:24:24 +000097 not_found "$the_re"
Chris Kay3d868ca2022-11-15 12:30:08 +000098 exit -1
99 }
100
Fathi Boudra422bf772019-12-02 11:10:16 +0200101 timeout {
Chris Kay78ea2c32022-11-15 12:24:24 +0000102 not_found "$the_re"
Fathi Boudra422bf772019-12-02 11:10:16 +0200103 exit_timeout
104 }
105 }
106}
Harrison Mutaifbadee42025-02-18 10:47:48 +0000107
108proc capture_log {out end_re} {
109 set event_log [open $out w]
110 expect "TCG_EfiSpecIDEvent"
111
112 expect {
113 # Parse the event log from the debug logs and store the digests
114 # so they can be matched later with what TF-A stored on the event log.
115 -re "Digest(\\s|\\w)*:\\s(\\w{2}\\s){16}|\
116 : (\\w{2}\\s){16}|\
117 (Event|EventType|EventSize)\\s*:\\s\\w+\\s" {
118 puts $event_log $expect_out(0,string)
119 exp_continue
120 }
121
122 -re "$end_re" {
123 close $event_log
124 }
125 }
126}
127
128proc capture_and_compare_log {out end_re compare} {
129 set event_log [open $out w]
130 capture_log $out $end_re
131
132 # Match the previously the given digests. The pass criteria is that both
133 # digests must match.
134 if {[catch {exec diff -s $out $compare} result options] == 0} {
135 message "tests succeeded, digests matched"
136 } else {
137 message "tests failed, digests did not match"
138 exit_uart -1
139 }
140}