blob: c15a4f93cfcd984f4b8bbc9c7eec35180ee53285 [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"
15set cmd2 "xl create guest.cfg"
16set cmd3 "xl console domu"
Jerome Forissierf080b5a2015-08-07 16:18:57 +020017set quiet 0
Jerome Forissier923226b2023-01-30 10:56:44 +010018set xtest_args ""
Jerome Forissierf080b5a2015-08-07 16:18:57 +020019
20# The time required to run some tests (e.g., key generation tests [4007.*])
21# can be significant and vary widely -- typically, from about one minute to
22# several minutes depending on the host machine.
Jerome Forissier6d46ded2021-04-15 18:49:37 +020023# The value here should be sufficient to run the whole optee_test suite
24# ('xtest') with all testsuites enabled (regression+gp+pkcs11).
25set timeout 900
Sumit Garg92d86ba2021-12-29 11:51:11 +053026set tests "all"
Jerome Forissierf080b5a2015-08-07 16:18:57 +020027
28# Parse command line
29set myargs $argv
30while {[llength $myargs]} {
31 set myargs [lassign $myargs arg]
32 switch -exact -- $arg {
33 "--bios" {set myargs [lassign $myargs ::bios]}
Sumit Garg92d86ba2021-12-29 11:51:11 +053034 "--tests" {set myargs [lassign $myargs ::tests]}
Jerome Forissier7a9463c2015-08-20 10:53:48 +020035 "--timeout" {set myargs [lassign $myargs ::timeout]}
Jerome Forissierf080b5a2015-08-07 16:18:57 +020036 "-q" {set ::quiet 1}
Jerome Forissier923226b2023-01-30 10:56:44 +010037 "--xtest-args" {set myargs [lassign $myargs ::xtest_args]}
Jerome Forissierf080b5a2015-08-07 16:18:57 +020038 }
39}
40
Jerome Forissier923226b2023-01-30 10:56:44 +010041set cmd "xtest $xtest_args"
42
Jerome Forissierf080b5a2015-08-07 16:18:57 +020043proc info arg {
44 if {$::quiet==1} { return }
45 puts -nonewline $arg
46 flush stdout
47}
48
Ruchika Guptaf3ca6b22021-06-15 15:38:33 +053049proc check_test_result arg {
50 set casenum "none"
51 expect {
52 # Exit with error status as soon as a test fails
53 -re { ([^ ]+) FAIL} {
54 info " $expect_out(1,string) FAIL\n"
55 exit 1
56 }
57 -re {rcu_sched detected stalls} {
58 info " Kernel error: '$expect_out(0,string)'\n"
59 exit 1
60 }
61 # Crude progress indicator: print one # when each test [sub]case starts
62 -re {([\*o]) ([^ ]+) } {
63 set casenum $expect_out(2,string)
64 if {$expect_out(1,string) == "o"} {
65 if {$star == 1} {
66 # Do not count first subcase ('o') since start
67 # of test ('*') was counted already
68 set star 0
69 exp_continue
70 }
71 } else {
72 set star 1
73 }
74 info "#"
75 incr ncases
76 if {$ncases % 50 == 0} { info "\n" }
77 exp_continue
78 }
79 # Exit when result separator is seen
80 "+-----------------------------------------------------\r\r" {}
81 # Handle errors in TEE core output
Jerome Forissiera16b1592022-06-28 09:37:44 +020082 -i $arg -re {(..TC:[^\n]*assertion[^\n]*failed at[^\n]*)} {
Jens Wiklander09900ef2022-04-21 19:34:55 +020083 info "!!! $expect_out(1,string)\n"
84 exit 1
85 }
Jerome Forissiera16b1592022-06-28 09:37:44 +020086 -i $arg -re {(..TC:[^\n]*Panic at[^\n]*)} {
Ruchika Guptaf3ca6b22021-06-15 15:38:33 +053087 info "!!! $expect_out(1,string)\n"
88 exit 1
89 }
90 timeout {
91 info "!!! Timeout\n"
92 info "TIMEOUT - test case too long or hung? (last test started: $casenum)\n"
93 exit 2
94 }
95 }
96 info "\nStatus: PASS ($ncases test cases)\n"
97}
98
Jerome Forissierf080b5a2015-08-07 16:18:57 +020099# Disable echoing of guest output
100log_user 0
101# Save guest console output to a file
102log_file -a -noappend "serial0.log"
103info "Starting QEMU..."
Jerome Forissierf3fa64d2016-10-17 10:50:51 +0200104open "serial1.log" "w+"
105spawn -open [open "|tail -f serial1.log"]
106set teecore $spawn_id
Jerome Forissier10bb03b2019-05-29 00:51:24 +0200107if {[string first "aarch64" $::env(QEMU)] != -1} {
Ruchika Gupta4dc75122021-06-18 12:57:52 +0530108 if {$::env(XEN_BOOT) == "y"} {
Jerome Forissierc77ea2c2023-08-02 11:57:17 +0200109 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 +0530110 } else {
Jens Wiklanderc750a232023-08-02 12:55:41 +0200111 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 +0530112 }
Jerome Forissier10bb03b2019-05-29 00:51:24 +0200113} else {
Peter Griffin96f2ac42021-04-28 14:39:56 +0100114 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 +0200115}
Jerome Forissier7950f2b2015-09-03 10:35:29 +0200116expect {
117 "Kernel panic" {
118 info "!!! Kernel panic\n"
119 exit 1
120 }
121 timeout {
122 info "!!! Timeout\n"
123 exit 1
124 }
Jerome Forissier4763adc2018-03-14 12:06:21 +0000125 "ogin:"
Jerome Forissier7950f2b2015-09-03 10:35:29 +0200126}
Jerome Forissier4763adc2018-03-14 12:06:21 +0000127send -- "root\r\r"
128expect "# "
Ruchika Gupta4dc75122021-06-18 12:57:52 +0530129info " done, guest is booted"
130if {$::env(XEN_BOOT) == "y"} {
131 info " (Xen Dom0)"
132}
133info ".\n"
Jerome Forissier7950f2b2015-09-03 10:35:29 +0200134# Toolchain libraries might be here or there
135send -- "export LD_LIBRARY_PATH=/lib:/lib/arm-linux-gnueabihf\r"
Sumit Garg92d86ba2021-12-29 11:51:11 +0530136if {$tests == "all" || $tests == "xtest"} {
137 info "Running: $cmd...\n"
Jerome Forissier3c36a552022-01-05 08:59:42 +0100138 expect "# "
Sumit Garg92d86ba2021-12-29 11:51:11 +0530139 send -- "$cmd\r"
140 check_test_result $teecore
141}
Ruchika Guptaf3ca6b22021-06-15 15:38:33 +0530142if {$::env(XEN_BOOT) == "y"} {
143 info " Booting DomU.\n"
144 expect "# "
145 info "Running: $cmd1...\n"
146 send -- "$cmd1\r"
147 expect "# "
148 info "Running: $cmd2...\n"
149 send -- "$cmd2\r"
150 expect "# "
151 info "Running: $cmd3...\n"
152 send -- "$cmd3\r"
153 expect {
154 "Kernel panic" {
155 info "!!! Kernel panic\n"
156 exit 1
Jerome Forissierf080b5a2015-08-07 16:18:57 +0200157 }
Ruchika Guptaf3ca6b22021-06-15 15:38:33 +0530158 timeout {
159 info "!!! Timeout\n"
160 exit 1
161 }
162 "login:"
Jerome Forissierf080b5a2015-08-07 16:18:57 +0200163 }
Ruchika Guptaf3ca6b22021-06-15 15:38:33 +0530164 send -- "root\r\r"
165 expect "# "
166 info " done, DomU is booted.\n"
167 # Toolchain libraries might be here or there
168 send -- "export LD_LIBRARY_PATH=/lib:/lib/arm-linux-gnueabihf\r"
169 expect "# "
Sumit Garg92d86ba2021-12-29 11:51:11 +0530170 if {$tests == "all" || $tests == "xtest"} {
171 info "Running: $cmd...\n"
172 send -- "$cmd\r"
173 check_test_result $teecore
174 }
Jerome Forissierf080b5a2015-08-07 16:18:57 +0200175}
Sumit Garg92d86ba2021-12-29 11:51:11 +0530176if {$tests == "all" || $tests == "trusted-keys"} {
177 # Invoke Trusted Keys tests
178 set basedir [file dirname $argv0]
179 source $basedir/trusted-keys.exp
180}