blob: 03391f0a455a82bd8b6018d211427028ef0264df [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
4# xtest in the guest. The return code is 0 for success, >0 for error.
5#
6# Options:
7# --bios Path to the binary to be run [../out/bios-qemu/bios.bin]
8# -q Suppress output to stdout (quiet)
Jerome Forissier7a9463c2015-08-20 10:53:48 +02009# --timeout Timeout for each test (sub)case, in seconds [480]
Jerome Forissierf080b5a2015-08-07 16:18:57 +020010
11set bios "../out/bios-qemu/bios.bin"
12set cmd "xtest"
13set quiet 0
14
15# The time required to run some tests (e.g., key generation tests [4007.*])
16# can be significant and vary widely -- typically, from about one minute to
17# several minutes depending on the host machine.
Jerome Forissier6d46ded2021-04-15 18:49:37 +020018# The value here should be sufficient to run the whole optee_test suite
19# ('xtest') with all testsuites enabled (regression+gp+pkcs11).
20set timeout 900
Jerome Forissierf080b5a2015-08-07 16:18:57 +020021
22# Parse command line
23set myargs $argv
24while {[llength $myargs]} {
25 set myargs [lassign $myargs arg]
26 switch -exact -- $arg {
27 "--bios" {set myargs [lassign $myargs ::bios]}
Jerome Forissier7a9463c2015-08-20 10:53:48 +020028 "--timeout" {set myargs [lassign $myargs ::timeout]}
Jerome Forissierf080b5a2015-08-07 16:18:57 +020029 "-q" {set ::quiet 1}
30 }
31}
32
33proc info arg {
34 if {$::quiet==1} { return }
35 puts -nonewline $arg
36 flush stdout
37}
38
39# Disable echoing of guest output
40log_user 0
41# Save guest console output to a file
42log_file -a -noappend "serial0.log"
43info "Starting QEMU..."
Jerome Forissierf3fa64d2016-10-17 10:50:51 +020044open "serial1.log" "w+"
45spawn -open [open "|tail -f serial1.log"]
46set teecore $spawn_id
Jerome Forissier10bb03b2019-05-29 00:51:24 +020047if {[string first "aarch64" $::env(QEMU)] != -1} {
Ruchika Gupta4dc75122021-06-18 12:57:52 +053048 if {$::env(XEN_BOOT) == "y"} {
49 spawn $::env(QEMU) -nographic -serial mon:stdio -serial file:serial1.log -smp $::env(QEMU_SMP) -machine virt,secure=on,gic-version=$::env(QEMU_GIC),virtualization=true -cpu cortex-a57 -d unimp -semihosting-config enable=on,target=native -m $::env(QEMU_MEM) -bios bl1.bin -initrd rootfs.cpio.gz -kernel Image -no-acpi -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
50 } else {
51 spawn $::env(QEMU) -nographic -serial mon:stdio -serial file:serial1.log -smp $::env(QEMU_SMP) -machine virt,secure=on,gic-version=$::env(QEMU_GIC) -cpu cortex-a57 -d unimp -semihosting-config enable=on,target=native -m $::env(QEMU_MEM) -bios bl1.bin -initrd rootfs.cpio.gz -kernel Image -no-acpi -append "console=ttyAMA0,38400 keep_bootcon root=/dev/vda2"
52 }
Jerome Forissier10bb03b2019-05-29 00:51:24 +020053} else {
Peter Griffin96f2ac42021-04-28 14:39:56 +010054 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 +020055}
Jerome Forissier7950f2b2015-09-03 10:35:29 +020056expect {
57 "Kernel panic" {
58 info "!!! Kernel panic\n"
59 exit 1
60 }
61 timeout {
62 info "!!! Timeout\n"
63 exit 1
64 }
Jerome Forissier4763adc2018-03-14 12:06:21 +000065 "ogin:"
Jerome Forissier7950f2b2015-09-03 10:35:29 +020066}
Jerome Forissier4763adc2018-03-14 12:06:21 +000067send -- "root\r\r"
68expect "# "
Ruchika Gupta4dc75122021-06-18 12:57:52 +053069info " done, guest is booted"
70if {$::env(XEN_BOOT) == "y"} {
71 info " (Xen Dom0)"
72}
73info ".\n"
Jerome Forissier7950f2b2015-09-03 10:35:29 +020074# Toolchain libraries might be here or there
75send -- "export LD_LIBRARY_PATH=/lib:/lib/arm-linux-gnueabihf\r"
Jerome Forissier4763adc2018-03-14 12:06:21 +000076expect "# "
Jerome Forissierc8ba87c2017-03-03 17:24:25 +010077info "Running: $cmd...\n"
Jerome Forissierf080b5a2015-08-07 16:18:57 +020078send -- "$cmd\r"
Jerome Forissier7950f2b2015-09-03 10:35:29 +020079set casenum "none"
Jerome Forissierf080b5a2015-08-07 16:18:57 +020080expect {
81 # Exit with error status as soon as a test fails
Jerome Forissier88d93a42021-04-15 19:02:17 +020082 -re { ([^ ]+) FAIL} {
Jerome Forissier7950f2b2015-09-03 10:35:29 +020083 info " $expect_out(1,string) FAIL\n"
84 exit 1
85 }
86 -re {rcu_sched detected stalls} {
87 info " Kernel error: '$expect_out(0,string)'\n"
Jerome Forissierf080b5a2015-08-07 16:18:57 +020088 exit 1
89 }
90 # Crude progress indicator: print one # when each test [sub]case starts
Jerome Forissier88d93a42021-04-15 19:02:17 +020091 -re {([\*o]) ([^ ]+) } {
Jerome Forissierf080b5a2015-08-07 16:18:57 +020092 set casenum $expect_out(2,string)
93 if {$expect_out(1,string) == "o"} {
94 if {$star == 1} {
95 # Do not count first subcase ('o') since start
96 # of test ('*') was counted already
97 set star 0
98 exp_continue
99 }
100 } else {
101 set star 1
102 }
103 info "#"
104 incr ncases
Jerome Forissier7950f2b2015-09-03 10:35:29 +0200105 if {$ncases % 50 == 0} { info "\n" }
Jerome Forissierf080b5a2015-08-07 16:18:57 +0200106 exp_continue
107 }
108 # Exit when result separator is seen
109 "+-----------------------------------------------------\r\r" {}
Jerome Forissierf3fa64d2016-10-17 10:50:51 +0200110 # Handle errors in TEE core output
111 -i $teecore -re {(assertion.*failed at.*)\n} {
Jerome Forissiera4a259e2020-08-12 09:58:27 +0200112 info "!!! $expect_out(1,string)\n"
Jerome Forissierf3fa64d2016-10-17 10:50:51 +0200113 exit 1
114 }
Jerome Forissierf080b5a2015-08-07 16:18:57 +0200115 timeout {
116 info "!!! Timeout\n"
Jerome Forissier7950f2b2015-09-03 10:35:29 +0200117 info "TIMEOUT - test case too long or hung? (last test started: $casenum)\n"
Jerome Forissierf080b5a2015-08-07 16:18:57 +0200118 exit 2
119 }
120}
121info "\nStatus: PASS ($ncases test cases)\n"
122