blob: 22e9b53087f959a1138c5ee59b8a709dccc85365 [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 ""
Jerome Forissierf080b5a2015-08-07 16:18:57 +020023
24# The time required to run some tests (e.g., key generation tests [4007.*])
25# can be significant and vary widely -- typically, from about one minute to
26# several minutes depending on the host machine.
Jerome Forissier6d46ded2021-04-15 18:49:37 +020027# The value here should be sufficient to run the whole optee_test suite
28# ('xtest') with all testsuites enabled (regression+gp+pkcs11).
29set timeout 900
Sumit Garg92d86ba2021-12-29 11:51:11 +053030set tests "all"
Jerome Forissierf080b5a2015-08-07 16:18:57 +020031
32# Parse command line
33set myargs $argv
34while {[llength $myargs]} {
35 set myargs [lassign $myargs arg]
36 switch -exact -- $arg {
37 "--bios" {set myargs [lassign $myargs ::bios]}
Sumit Garg92d86ba2021-12-29 11:51:11 +053038 "--tests" {set myargs [lassign $myargs ::tests]}
Jerome Forissier7a9463c2015-08-20 10:53:48 +020039 "--timeout" {set myargs [lassign $myargs ::timeout]}
Jerome Forissierf080b5a2015-08-07 16:18:57 +020040 "-q" {set ::quiet 1}
Jerome Forissier923226b2023-01-30 10:56:44 +010041 "--xtest-args" {set myargs [lassign $myargs ::xtest_args]}
Jerome Forissierf080b5a2015-08-07 16:18:57 +020042 }
43}
44
Jerome Forissier923226b2023-01-30 10:56:44 +010045set cmd "xtest $xtest_args"
46
Jerome Forissierf080b5a2015-08-07 16:18:57 +020047proc info arg {
48 if {$::quiet==1} { return }
49 puts -nonewline $arg
50 flush stdout
51}
52
Ruchika Guptaf3ca6b22021-06-15 15:38:33 +053053proc check_test_result arg {
54 set casenum "none"
55 expect {
56 # Exit with error status as soon as a test fails
57 -re { ([^ ]+) FAIL} {
58 info " $expect_out(1,string) FAIL\n"
59 exit 1
60 }
61 -re {rcu_sched detected stalls} {
62 info " Kernel error: '$expect_out(0,string)'\n"
63 exit 1
64 }
65 # Crude progress indicator: print one # when each test [sub]case starts
66 -re {([\*o]) ([^ ]+) } {
67 set casenum $expect_out(2,string)
68 if {$expect_out(1,string) == "o"} {
69 if {$star == 1} {
70 # Do not count first subcase ('o') since start
71 # of test ('*') was counted already
72 set star 0
73 exp_continue
74 }
75 } else {
76 set star 1
77 }
78 info "#"
79 incr ncases
80 if {$ncases % 50 == 0} { info "\n" }
81 exp_continue
82 }
83 # Exit when result separator is seen
84 "+-----------------------------------------------------\r\r" {}
85 # Handle errors in TEE core output
Jerome Forissiera16b1592022-06-28 09:37:44 +020086 -i $arg -re {(..TC:[^\n]*assertion[^\n]*failed at[^\n]*)} {
Jens Wiklander09900ef2022-04-21 19:34:55 +020087 info "!!! $expect_out(1,string)\n"
88 exit 1
89 }
Jerome Forissiera16b1592022-06-28 09:37:44 +020090 -i $arg -re {(..TC:[^\n]*Panic at[^\n]*)} {
Ruchika Guptaf3ca6b22021-06-15 15:38:33 +053091 info "!!! $expect_out(1,string)\n"
92 exit 1
93 }
94 timeout {
95 info "!!! Timeout\n"
96 info "TIMEOUT - test case too long or hung? (last test started: $casenum)\n"
97 exit 2
98 }
99 }
100 info "\nStatus: PASS ($ncases test cases)\n"
101}
102
Jerome Forissierf080b5a2015-08-07 16:18:57 +0200103# Disable echoing of guest output
104log_user 0
105# Save guest console output to a file
106log_file -a -noappend "serial0.log"
107info "Starting QEMU..."
Jerome Forissierf3fa64d2016-10-17 10:50:51 +0200108open "serial1.log" "w+"
109spawn -open [open "|tail -f serial1.log"]
110set teecore $spawn_id
Jerome Forissier10bb03b2019-05-29 00:51:24 +0200111if {[string first "aarch64" $::env(QEMU)] != -1} {
Ruchika Gupta4dc75122021-06-18 12:57:52 +0530112 if {$::env(XEN_BOOT) == "y"} {
Jerome Forissierc77ea2c2023-08-02 11:57:17 +0200113 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 +0530114 } else {
Jens Wiklanderc750a232023-08-02 12:55:41 +0200115 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 +0530116 }
Jerome Forissier10bb03b2019-05-29 00:51:24 +0200117} else {
Peter Griffin96f2ac42021-04-28 14:39:56 +0100118 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 +0200119}
Jerome Forissier7950f2b2015-09-03 10:35:29 +0200120expect {
121 "Kernel panic" {
122 info "!!! Kernel panic\n"
123 exit 1
124 }
125 timeout {
126 info "!!! Timeout\n"
127 exit 1
128 }
Jerome Forissier4763adc2018-03-14 12:06:21 +0000129 "ogin:"
Jerome Forissier7950f2b2015-09-03 10:35:29 +0200130}
Jerome Forissier4763adc2018-03-14 12:06:21 +0000131send -- "root\r\r"
132expect "# "
Ruchika Gupta4dc75122021-06-18 12:57:52 +0530133info " done, guest is booted"
134if {$::env(XEN_BOOT) == "y"} {
135 info " (Xen Dom0)"
136}
137info ".\n"
Jerome Forissier7950f2b2015-09-03 10:35:29 +0200138# Toolchain libraries might be here or there
139send -- "export LD_LIBRARY_PATH=/lib:/lib/arm-linux-gnueabihf\r"
Sumit Garg92d86ba2021-12-29 11:51:11 +0530140if {$tests == "all" || $tests == "xtest"} {
141 info "Running: $cmd...\n"
Jerome Forissier3c36a552022-01-05 08:59:42 +0100142 expect "# "
Sumit Garg92d86ba2021-12-29 11:51:11 +0530143 send -- "$cmd\r"
144 check_test_result $teecore
145}
Ruchika Guptaf3ca6b22021-06-15 15:38:33 +0530146if {$::env(XEN_BOOT) == "y"} {
147 info " Booting DomU.\n"
148 expect "# "
149 info "Running: $cmd1...\n"
150 send -- "$cmd1\r"
151 expect "# "
152 info "Running: $cmd2...\n"
153 send -- "$cmd2\r"
154 expect "# "
155 info "Running: $cmd3...\n"
156 send -- "$cmd3\r"
157 expect {
158 "Kernel panic" {
159 info "!!! Kernel panic\n"
160 exit 1
Jerome Forissierf080b5a2015-08-07 16:18:57 +0200161 }
Ruchika Guptaf3ca6b22021-06-15 15:38:33 +0530162 timeout {
163 info "!!! Timeout\n"
164 exit 1
165 }
166 "login:"
Jerome Forissierf080b5a2015-08-07 16:18:57 +0200167 }
Ruchika Guptaf3ca6b22021-06-15 15:38:33 +0530168 send -- "root\r\r"
169 expect "# "
170 info " done, DomU is booted.\n"
171 # Toolchain libraries might be here or there
172 send -- "export LD_LIBRARY_PATH=/lib:/lib/arm-linux-gnueabihf\r"
173 expect "# "
Sumit Garg92d86ba2021-12-29 11:51:11 +0530174 if {$tests == "all" || $tests == "xtest"} {
175 info "Running: $cmd...\n"
176 send -- "$cmd\r"
177 check_test_result $teecore
178 }
Jerome Forissierf080b5a2015-08-07 16:18:57 +0200179}
Sumit Garg92d86ba2021-12-29 11:51:11 +0530180if {$tests == "all" || $tests == "trusted-keys"} {
181 # Invoke Trusted Keys tests
182 set basedir [file dirname $argv0]
183 source $basedir/trusted-keys.exp
184}