blob: a5c96e5ae1fc1f94a4fba620cb30a819ee39e29b [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} {
Harrison Mutaicfe90f32025-05-06 15:26:04 +0000109 set event_log [open $out w]
Harrison Mutaifbadee42025-02-18 10:47:48 +0000110
Harrison Mutaicfe90f32025-05-06 15:26:04 +0000111 expect -re {(?:\w+: )?(TCG_EfiSpecIDEvent:)\r\n} {
112 puts $event_log $expect_out(1,string)
113 }
Harrison Mutaifbadee42025-02-18 10:47:48 +0000114
Harrison Mutaicfe90f32025-05-06 15:26:04 +0000115 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 Mutaifbadee42025-02-18 10:47:48 +0000130}
131
Harrison Mutai47751e02025-02-28 12:08:09 +0000132proc compare_log {out compare} {
Harrison Mutaifbadee42025-02-18 10:47:48 +0000133 # Match the previously the given digests. The pass criteria is that both
134 # digests must match.
Harrison Mutaicfe90f32025-05-06 15:26:04 +0000135 if {[catch {exec diff -ws $out $compare} result options] == 0} {
Harrison Mutaifbadee42025-02-18 10:47:48 +0000136 message "tests succeeded, digests matched"
137 } else {
138 message "tests failed, digests did not match"
139 exit_uart -1
140 }
141}
Harrison Mutai47751e02025-02-28 12:08:09 +0000142
143proc 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}