blob: b16cf4de81df64c568f09f29442ecbeeb3424237 [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} {
48 spawn $::env(QEMU) -nographic -serial mon:stdio -serial file:serial1.log -smp $::env(QEMU_SMP) -machine virt,secure=on -cpu cortex-a57 -d unimp -semihosting-config enable,target=native -m 1057 -bios bl1.bin -initrd rootfs.cpio.gz -kernel Image -no-acpi -append "console=ttyAMA0,38400 keep_bootcon root=/dev/vda2"
49} else {
50 spawn $::env(QEMU) -nographic -monitor none -machine virt -machine secure=on -cpu cortex-a15 -smp $::env(QEMU_SMP) -d unimp -semihosting-config enable,target=native -m 1057 -serial stdio -serial file:serial1.log -bios $bios
51}
Jerome Forissier7950f2b2015-09-03 10:35:29 +020052expect {
53 "Kernel panic" {
54 info "!!! Kernel panic\n"
55 exit 1
56 }
57 timeout {
58 info "!!! Timeout\n"
59 exit 1
60 }
Jerome Forissier4763adc2018-03-14 12:06:21 +000061 "ogin:"
Jerome Forissier7950f2b2015-09-03 10:35:29 +020062}
Jerome Forissier4763adc2018-03-14 12:06:21 +000063send -- "root\r\r"
64expect "# "
Jerome Forissierc8ba87c2017-03-03 17:24:25 +010065info " done, guest is booted.\n"
Jerome Forissier7950f2b2015-09-03 10:35:29 +020066# Toolchain libraries might be here or there
67send -- "export LD_LIBRARY_PATH=/lib:/lib/arm-linux-gnueabihf\r"
Jerome Forissier4763adc2018-03-14 12:06:21 +000068expect "# "
Jerome Forissierc8ba87c2017-03-03 17:24:25 +010069info "Running: $cmd...\n"
Jerome Forissierf080b5a2015-08-07 16:18:57 +020070send -- "$cmd\r"
Jerome Forissier7950f2b2015-09-03 10:35:29 +020071set casenum "none"
Jerome Forissierf080b5a2015-08-07 16:18:57 +020072expect {
73 # Exit with error status as soon as a test fails
Jens Wiklander06bb4422017-01-20 10:04:09 +010074 -re { regression_([^ ]+) FAIL} {
Jerome Forissier7950f2b2015-09-03 10:35:29 +020075 info " $expect_out(1,string) FAIL\n"
76 exit 1
77 }
78 -re {rcu_sched detected stalls} {
79 info " Kernel error: '$expect_out(0,string)'\n"
Jerome Forissierf080b5a2015-08-07 16:18:57 +020080 exit 1
81 }
82 # Crude progress indicator: print one # when each test [sub]case starts
Jens Wiklander06bb4422017-01-20 10:04:09 +010083 -re {([\*o]) regression_([^ ]+) } {
Jerome Forissierf080b5a2015-08-07 16:18:57 +020084 set casenum $expect_out(2,string)
85 if {$expect_out(1,string) == "o"} {
86 if {$star == 1} {
87 # Do not count first subcase ('o') since start
88 # of test ('*') was counted already
89 set star 0
90 exp_continue
91 }
92 } else {
93 set star 1
94 }
95 info "#"
96 incr ncases
Jerome Forissier7950f2b2015-09-03 10:35:29 +020097 if {$ncases % 50 == 0} { info "\n" }
Jerome Forissierf080b5a2015-08-07 16:18:57 +020098 exp_continue
99 }
100 # Exit when result separator is seen
101 "+-----------------------------------------------------\r\r" {}
Jerome Forissierf3fa64d2016-10-17 10:50:51 +0200102 # Handle errors in TEE core output
103 -i $teecore -re {(assertion.*failed at.*)\n} {
Jerome Forissiera4a259e2020-08-12 09:58:27 +0200104 info "!!! $expect_out(1,string)\n"
Jerome Forissierf3fa64d2016-10-17 10:50:51 +0200105 exit 1
106 }
Jerome Forissierf080b5a2015-08-07 16:18:57 +0200107 timeout {
108 info "!!! Timeout\n"
Jerome Forissier7950f2b2015-09-03 10:35:29 +0200109 info "TIMEOUT - test case too long or hung? (last test started: $casenum)\n"
Jerome Forissierf080b5a2015-08-07 16:18:57 +0200110 exit 2
111 }
112}
113info "\nStatus: PASS ($ncases test cases)\n"
114