blob: fdba942d5bb042db4cf8bd91e154c8088b965fc2 [file] [log] [blame]
Jerome Forissierf080b5a2015-08-07 16:18:57 +02001#!/usr/bin/expect -f
2#
3# This scripts starts QEMU, loads and boots Linux/OP-TEE, then runs
Sumit Garg92d86ba2021-12-29 11:51:11 +05304# tests in the guest. The return code is 0 for success, >0 for error.
Jerome Forissierf080b5a2015-08-07 16:18:57 +02005#
6# Options:
Jerome Forissierf080b5a2015-08-07 16:18:57 +02007# -q Suppress output to stdout (quiet)
Sumit Garg92d86ba2021-12-29 11:51:11 +05308# --tests Type of tests to run, values: all, xtest and trusted-keys
Jerome Forissier7a9463c2015-08-20 10:53:48 +02009# --timeout Timeout for each test (sub)case, in seconds [480]
Jerome Forissier923226b2023-01-30 10:56:44 +010010# --xtest-args Optional arguments to xtest
Jerome Forissierf080b5a2015-08-07 16:18:57 +020011
12set bios "../out/bios-qemu/bios.bin"
Ruchika Guptaf3ca6b22021-06-15 15:38:33 +053013set cmd1 "cd /mnt/host/build/qemu_v8/xen"
Jerome Forissier45f56192024-01-03 15:39:08 +010014if {[info exists ::env(XEN_FFA)] && $::env(XEN_FFA) == "y"} {
Jens Wiklander4809b4f2023-11-10 14:09:22 +010015 set cmd2 "xl create guest_ffa.cfg"
16} else {
17 set cmd2 "xl create guest.cfg"
18}
Ruchika Guptaf3ca6b22021-06-15 15:38:33 +053019set cmd3 "xl console domu"
Jerome Forissierf080b5a2015-08-07 16:18:57 +020020set quiet 0
Jerome Forissier923226b2023-01-30 10:56:44 +010021set xtest_args ""
Sumit Garge742dc82024-01-11 18:53:06 +053022if {[info exists ::env(RUST_ENABLE)] && $::env(RUST_ENABLE) == "y"} {
23 set rust_enable 1
24} else {
25 set rust_enable 0
26}
Jerome Forissierf080b5a2015-08-07 16:18:57 +020027
28# The time required to run some tests (e.g., key generation tests [4007.*])
29# can be significant and vary widely -- typically, from about one minute to
30# several minutes depending on the host machine.
Jerome Forissier6d46ded2021-04-15 18:49:37 +020031# The value here should be sufficient to run the whole optee_test suite
32# ('xtest') with all testsuites enabled (regression+gp+pkcs11).
33set timeout 900
Sumit Garg92d86ba2021-12-29 11:51:11 +053034set tests "all"
Sumit Garge742dc82024-01-11 18:53:06 +053035set basedir [file dirname $argv0]
Jerome Forissierf080b5a2015-08-07 16:18:57 +020036
37# Parse command line
38set myargs $argv
39while {[llength $myargs]} {
40 set myargs [lassign $myargs arg]
41 switch -exact -- $arg {
Sumit Garg92d86ba2021-12-29 11:51:11 +053042 "--tests" {set myargs [lassign $myargs ::tests]}
Jerome Forissier7a9463c2015-08-20 10:53:48 +020043 "--timeout" {set myargs [lassign $myargs ::timeout]}
Jerome Forissierf080b5a2015-08-07 16:18:57 +020044 "-q" {set ::quiet 1}
Jerome Forissier923226b2023-01-30 10:56:44 +010045 "--xtest-args" {set myargs [lassign $myargs ::xtest_args]}
Jerome Forissierf080b5a2015-08-07 16:18:57 +020046 }
47}
48
Jerome Forissier923226b2023-01-30 10:56:44 +010049set cmd "xtest $xtest_args"
50
Jerome Forissierf080b5a2015-08-07 16:18:57 +020051proc info arg {
52 if {$::quiet==1} { return }
53 puts -nonewline $arg
54 flush stdout
55}
56
Ruchika Guptaf3ca6b22021-06-15 15:38:33 +053057proc check_test_result arg {
58 set casenum "none"
Raymond Maobe802522025-05-07 08:11:36 -070059 set star 0
60 set ncases 0
Ruchika Guptaf3ca6b22021-06-15 15:38:33 +053061 expect {
62 # Exit with error status as soon as a test fails
63 -re { ([^ ]+) FAIL} {
64 info " $expect_out(1,string) FAIL\n"
65 exit 1
66 }
Jerome Forissier89ab87c2024-12-18 11:42:28 +010067 -re {rcu.*detected stalls} {
Ruchika Guptaf3ca6b22021-06-15 15:38:33 +053068 info " Kernel error: '$expect_out(0,string)'\n"
69 exit 1
70 }
71 # Crude progress indicator: print one # when each test [sub]case starts
72 -re {([\*o]) ([^ ]+) } {
73 set casenum $expect_out(2,string)
74 if {$expect_out(1,string) == "o"} {
75 if {$star == 1} {
76 # Do not count first subcase ('o') since start
77 # of test ('*') was counted already
78 set star 0
79 exp_continue
80 }
81 } else {
82 set star 1
83 }
84 info "#"
85 incr ncases
86 if {$ncases % 50 == 0} { info "\n" }
87 exp_continue
88 }
89 # Exit when result separator is seen
90 "+-----------------------------------------------------\r\r" {}
91 # Handle errors in TEE core output
Jerome Forissiera16b1592022-06-28 09:37:44 +020092 -i $arg -re {(..TC:[^\n]*assertion[^\n]*failed at[^\n]*)} {
Jens Wiklander09900ef2022-04-21 19:34:55 +020093 info "!!! $expect_out(1,string)\n"
94 exit 1
95 }
Jerome Forissiera16b1592022-06-28 09:37:44 +020096 -i $arg -re {(..TC:[^\n]*Panic at[^\n]*)} {
Ruchika Guptaf3ca6b22021-06-15 15:38:33 +053097 info "!!! $expect_out(1,string)\n"
98 exit 1
99 }
100 timeout {
101 info "!!! Timeout\n"
102 info "TIMEOUT - test case too long or hung? (last test started: $casenum)\n"
103 exit 2
104 }
105 }
106 info "\nStatus: PASS ($ncases test cases)\n"
107}
108
Jerome Forissierf080b5a2015-08-07 16:18:57 +0200109# Disable echoing of guest output
110log_user 0
111# Save guest console output to a file
112log_file -a -noappend "serial0.log"
113info "Starting QEMU..."
Jerome Forissierf3fa64d2016-10-17 10:50:51 +0200114open "serial1.log" "w+"
115spawn -open [open "|tail -f serial1.log"]
116set teecore $spawn_id
Jerome Forissier355a74e2024-05-29 10:38:32 +0200117spawn sh -c "$::env(QEMU) $::env(QEMU_CHECK_ARGS)"
Jerome Forissier7950f2b2015-09-03 10:35:29 +0200118expect {
119 "Kernel panic" {
120 info "!!! Kernel panic\n"
121 exit 1
122 }
123 timeout {
124 info "!!! Timeout\n"
125 exit 1
126 }
Jerome Forissier4763adc2018-03-14 12:06:21 +0000127 "ogin:"
Jerome Forissier7950f2b2015-09-03 10:35:29 +0200128}
Jerome Forissier4763adc2018-03-14 12:06:21 +0000129send -- "root\r\r"
130expect "# "
Ruchika Gupta4dc75122021-06-18 12:57:52 +0530131info " done, guest is booted"
132if {$::env(XEN_BOOT) == "y"} {
133 info " (Xen Dom0)"
134}
135info ".\n"
Jerome Forissier7950f2b2015-09-03 10:35:29 +0200136# Toolchain libraries might be here or there
137send -- "export LD_LIBRARY_PATH=/lib:/lib/arm-linux-gnueabihf\r"
Sumit Garg92d86ba2021-12-29 11:51:11 +0530138if {$tests == "all" || $tests == "xtest"} {
139 info "Running: $cmd...\n"
Jerome Forissier3c36a552022-01-05 08:59:42 +0100140 expect "# "
Sumit Garg92d86ba2021-12-29 11:51:11 +0530141 send -- "$cmd\r"
142 check_test_result $teecore
143}
Ruchika Guptaf3ca6b22021-06-15 15:38:33 +0530144if {$::env(XEN_BOOT) == "y"} {
145 info " Booting DomU.\n"
146 expect "# "
147 info "Running: $cmd1...\n"
148 send -- "$cmd1\r"
149 expect "# "
150 info "Running: $cmd2...\n"
151 send -- "$cmd2\r"
152 expect "# "
153 info "Running: $cmd3...\n"
154 send -- "$cmd3\r"
155 expect {
156 "Kernel panic" {
157 info "!!! Kernel panic\n"
158 exit 1
Jerome Forissierf080b5a2015-08-07 16:18:57 +0200159 }
Ruchika Guptaf3ca6b22021-06-15 15:38:33 +0530160 timeout {
161 info "!!! Timeout\n"
162 exit 1
163 }
164 "login:"
Jerome Forissierf080b5a2015-08-07 16:18:57 +0200165 }
Ruchika Guptaf3ca6b22021-06-15 15:38:33 +0530166 send -- "root\r\r"
167 expect "# "
168 info " done, DomU is booted.\n"
169 # Toolchain libraries might be here or there
170 send -- "export LD_LIBRARY_PATH=/lib:/lib/arm-linux-gnueabihf\r"
171 expect "# "
Sumit Garg92d86ba2021-12-29 11:51:11 +0530172 if {$tests == "all" || $tests == "xtest"} {
173 info "Running: $cmd...\n"
174 send -- "$cmd\r"
175 check_test_result $teecore
176 }
Jerome Forissierf080b5a2015-08-07 16:18:57 +0200177}
Sumit Garg92d86ba2021-12-29 11:51:11 +0530178if {$tests == "all" || $tests == "trusted-keys"} {
179 # Invoke Trusted Keys tests
Sumit Garg92d86ba2021-12-29 11:51:11 +0530180 source $basedir/trusted-keys.exp
181}
Sumit Garge742dc82024-01-11 18:53:06 +0530182if {($tests == "all" || $tests == "rust") && $::rust_enable == 1} {
183 # Invoke Rust tests
184 source $basedir/rust.exp
185}