blob: 751b2701e0450244f3c7ca0396e1aab48c60b835 [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:
7# --bios Path to the binary to be run [../out/bios-qemu/bios.bin]
8# -q Suppress output to stdout (quiet)
Sumit Garg92d86ba2021-12-29 11:51:11 +05309# --tests Type of tests to run, values: all, xtest and trusted-keys
Jerome Forissier7a9463c2015-08-20 10:53:48 +020010# --timeout Timeout for each test (sub)case, in seconds [480]
Jerome Forissier923226b2023-01-30 10:56:44 +010011# --xtest-args Optional arguments to xtest
Jerome Forissierf080b5a2015-08-07 16:18:57 +020012
13set bios "../out/bios-qemu/bios.bin"
Ruchika Guptaf3ca6b22021-06-15 15:38:33 +053014set cmd1 "cd /mnt/host/build/qemu_v8/xen"
Jerome Forissier45f56192024-01-03 15:39:08 +010015if {[info exists ::env(XEN_FFA)] && $::env(XEN_FFA) == "y"} {
Jens Wiklander4809b4f2023-11-10 14:09:22 +010016 set cmd2 "xl create guest_ffa.cfg"
17} else {
18 set cmd2 "xl create guest.cfg"
19}
Ruchika Guptaf3ca6b22021-06-15 15:38:33 +053020set cmd3 "xl console domu"
Jerome Forissierf080b5a2015-08-07 16:18:57 +020021set quiet 0
Jerome Forissier923226b2023-01-30 10:56:44 +010022set xtest_args ""
Sumit Garge742dc82024-01-11 18:53:06 +053023if {[info exists ::env(RUST_ENABLE)] && $::env(RUST_ENABLE) == "y"} {
24 set rust_enable 1
25} else {
26 set rust_enable 0
27}
Jerome Forissierf080b5a2015-08-07 16:18:57 +020028
29# The time required to run some tests (e.g., key generation tests [4007.*])
30# can be significant and vary widely -- typically, from about one minute to
31# several minutes depending on the host machine.
Jerome Forissier6d46ded2021-04-15 18:49:37 +020032# The value here should be sufficient to run the whole optee_test suite
33# ('xtest') with all testsuites enabled (regression+gp+pkcs11).
34set timeout 900
Sumit Garg92d86ba2021-12-29 11:51:11 +053035set tests "all"
Sumit Garge742dc82024-01-11 18:53:06 +053036set basedir [file dirname $argv0]
Jerome Forissierf080b5a2015-08-07 16:18:57 +020037
38# Parse command line
39set myargs $argv
40while {[llength $myargs]} {
41 set myargs [lassign $myargs arg]
42 switch -exact -- $arg {
43 "--bios" {set myargs [lassign $myargs ::bios]}
Sumit Garg92d86ba2021-12-29 11:51:11 +053044 "--tests" {set myargs [lassign $myargs ::tests]}
Jerome Forissier7a9463c2015-08-20 10:53:48 +020045 "--timeout" {set myargs [lassign $myargs ::timeout]}
Jerome Forissierf080b5a2015-08-07 16:18:57 +020046 "-q" {set ::quiet 1}
Jerome Forissier923226b2023-01-30 10:56:44 +010047 "--xtest-args" {set myargs [lassign $myargs ::xtest_args]}
Jerome Forissierf080b5a2015-08-07 16:18:57 +020048 }
49}
50
Jerome Forissier923226b2023-01-30 10:56:44 +010051set cmd "xtest $xtest_args"
52
Jerome Forissierf080b5a2015-08-07 16:18:57 +020053proc info arg {
54 if {$::quiet==1} { return }
55 puts -nonewline $arg
56 flush stdout
57}
58
Ruchika Guptaf3ca6b22021-06-15 15:38:33 +053059proc check_test_result arg {
60 set casenum "none"
61 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 }
67 -re {rcu_sched detected stalls} {
68 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 Forissier10bb03b2019-05-29 00:51:24 +0200117if {[string first "aarch64" $::env(QEMU)] != -1} {
Ruchika Gupta4dc75122021-06-18 12:57:52 +0530118 if {$::env(XEN_BOOT) == "y"} {
Jerome Forissierc77ea2c2023-08-02 11:57:17 +0200119 spawn $::env(QEMU) -nographic -serial mon:stdio -serial file:serial1.log -smp $::env(QEMU_SMP) -machine virt,acpi=off,secure=on,mte=$::env(QEMU_MTE),gic-version=$::env(QEMU_GIC),virtualization=true -cpu $::env(QEMU_CPU) -d unimp -semihosting-config enable=on,target=native -m $::env(QEMU_MEM) -bios bl1.bin -initrd rootfs.cpio.gz -kernel Image -append "console=ttyAMA0,38400 keep_bootcon root=/dev/vda2" -drive if=none,file=xen.ext4,format=raw,id=hd1 -device virtio-blk-device,drive=hd1 -fsdev local,id=fsdev0,path=../..,security_model=none -device virtio-9p-device,fsdev=fsdev0,mount_tag=host
Ruchika Gupta4dc75122021-06-18 12:57:52 +0530120 } else {
Jens Wiklanderc750a232023-08-02 12:55:41 +0200121 spawn $::env(QEMU) -nographic -serial mon:stdio -serial file:serial1.log -smp $::env(QEMU_SMP) -machine virt,acpi=off,secure=on,mte=$::env(QEMU_MTE),gic-version=$::env(QEMU_GIC),virtualization=$::env(QEMU_VIRT) -cpu $::env(QEMU_CPU) -d unimp -semihosting-config enable=on,target=native -m $::env(QEMU_MEM) -bios bl1.bin -initrd rootfs.cpio.gz -kernel Image -append "console=ttyAMA0,38400 keep_bootcon root=/dev/vda2"
Ruchika Gupta4dc75122021-06-18 12:57:52 +0530122 }
Jerome Forissier10bb03b2019-05-29 00:51:24 +0200123} else {
Peter Griffin96f2ac42021-04-28 14:39:56 +0100124 spawn $::env(QEMU) -nographic -monitor none -machine virt -machine secure=on -cpu cortex-a15 -smp $::env(QEMU_SMP) -d unimp -semihosting-config enable=on,target=native -m 1057 -serial stdio -serial file:serial1.log -bios $bios
Jerome Forissier10bb03b2019-05-29 00:51:24 +0200125}
Jerome Forissier7950f2b2015-09-03 10:35:29 +0200126expect {
127 "Kernel panic" {
128 info "!!! Kernel panic\n"
129 exit 1
130 }
131 timeout {
132 info "!!! Timeout\n"
133 exit 1
134 }
Jerome Forissier4763adc2018-03-14 12:06:21 +0000135 "ogin:"
Jerome Forissier7950f2b2015-09-03 10:35:29 +0200136}
Jerome Forissier4763adc2018-03-14 12:06:21 +0000137send -- "root\r\r"
138expect "# "
Ruchika Gupta4dc75122021-06-18 12:57:52 +0530139info " done, guest is booted"
140if {$::env(XEN_BOOT) == "y"} {
141 info " (Xen Dom0)"
142}
143info ".\n"
Jerome Forissier7950f2b2015-09-03 10:35:29 +0200144# Toolchain libraries might be here or there
145send -- "export LD_LIBRARY_PATH=/lib:/lib/arm-linux-gnueabihf\r"
Sumit Garg92d86ba2021-12-29 11:51:11 +0530146if {$tests == "all" || $tests == "xtest"} {
147 info "Running: $cmd...\n"
Jerome Forissier3c36a552022-01-05 08:59:42 +0100148 expect "# "
Sumit Garg92d86ba2021-12-29 11:51:11 +0530149 send -- "$cmd\r"
150 check_test_result $teecore
151}
Ruchika Guptaf3ca6b22021-06-15 15:38:33 +0530152if {$::env(XEN_BOOT) == "y"} {
153 info " Booting DomU.\n"
154 expect "# "
155 info "Running: $cmd1...\n"
156 send -- "$cmd1\r"
157 expect "# "
158 info "Running: $cmd2...\n"
159 send -- "$cmd2\r"
160 expect "# "
161 info "Running: $cmd3...\n"
162 send -- "$cmd3\r"
163 expect {
164 "Kernel panic" {
165 info "!!! Kernel panic\n"
166 exit 1
Jerome Forissierf080b5a2015-08-07 16:18:57 +0200167 }
Ruchika Guptaf3ca6b22021-06-15 15:38:33 +0530168 timeout {
169 info "!!! Timeout\n"
170 exit 1
171 }
172 "login:"
Jerome Forissierf080b5a2015-08-07 16:18:57 +0200173 }
Ruchika Guptaf3ca6b22021-06-15 15:38:33 +0530174 send -- "root\r\r"
175 expect "# "
176 info " done, DomU is booted.\n"
177 # Toolchain libraries might be here or there
178 send -- "export LD_LIBRARY_PATH=/lib:/lib/arm-linux-gnueabihf\r"
179 expect "# "
Sumit Garg92d86ba2021-12-29 11:51:11 +0530180 if {$tests == "all" || $tests == "xtest"} {
181 info "Running: $cmd...\n"
182 send -- "$cmd\r"
183 check_test_result $teecore
184 }
Jerome Forissierf080b5a2015-08-07 16:18:57 +0200185}
Sumit Garg92d86ba2021-12-29 11:51:11 +0530186if {$tests == "all" || $tests == "trusted-keys"} {
187 # Invoke Trusted Keys tests
Sumit Garg92d86ba2021-12-29 11:51:11 +0530188 source $basedir/trusted-keys.exp
189}
Sumit Garge742dc82024-01-11 18:53:06 +0530190if {($tests == "all" || $tests == "rust") && $::rust_enable == 1} {
191 # Invoke Rust tests
192 source $basedir/rust.exp
193}