blob: 0a2e14f023be01d80e266907f08331daec9bc30e [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 Forissier7a9463c2015-08-20 10:53:48 +020018set timeout 480
Jerome Forissierf080b5a2015-08-07 16:18:57 +020019
20# Parse command line
21set myargs $argv
22while {[llength $myargs]} {
23 set myargs [lassign $myargs arg]
24 switch -exact -- $arg {
25 "--bios" {set myargs [lassign $myargs ::bios]}
Jerome Forissier7a9463c2015-08-20 10:53:48 +020026 "--timeout" {set myargs [lassign $myargs ::timeout]}
Jerome Forissierf080b5a2015-08-07 16:18:57 +020027 "-q" {set ::quiet 1}
28 }
29}
30
31proc info arg {
32 if {$::quiet==1} { return }
33 puts -nonewline $arg
34 flush stdout
35}
36
37# Disable echoing of guest output
38log_user 0
39# Save guest console output to a file
40log_file -a -noappend "serial0.log"
41info "Starting QEMU..."
Jerome Forissierf3fa64d2016-10-17 10:50:51 +020042open "serial1.log" "w+"
43spawn -open [open "|tail -f serial1.log"]
44set teecore $spawn_id
Jerome Forissier2a90dde2017-10-13 13:32:45 +020045spawn $::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
Jerome Forissier7950f2b2015-09-03 10:35:29 +020046expect {
47 "Kernel panic" {
48 info "!!! Kernel panic\n"
49 exit 1
50 }
51 timeout {
52 info "!!! Timeout\n"
53 exit 1
54 }
Jerome Forissier4763adc2018-03-14 12:06:21 +000055 "ogin:"
Jerome Forissier7950f2b2015-09-03 10:35:29 +020056}
Jerome Forissier4763adc2018-03-14 12:06:21 +000057send -- "root\r\r"
58expect "# "
Jerome Forissierc8ba87c2017-03-03 17:24:25 +010059info " done, guest is booted.\n"
Jerome Forissier7950f2b2015-09-03 10:35:29 +020060# Toolchain libraries might be here or there
61send -- "export LD_LIBRARY_PATH=/lib:/lib/arm-linux-gnueabihf\r"
Jerome Forissier4763adc2018-03-14 12:06:21 +000062expect "# "
Jerome Forissierc8ba87c2017-03-03 17:24:25 +010063info "Running: $cmd...\n"
Jerome Forissierf080b5a2015-08-07 16:18:57 +020064send -- "$cmd\r"
Jerome Forissier7950f2b2015-09-03 10:35:29 +020065set casenum "none"
Jerome Forissierf080b5a2015-08-07 16:18:57 +020066expect {
67 # Exit with error status as soon as a test fails
Jens Wiklander06bb4422017-01-20 10:04:09 +010068 -re { regression_([^ ]+) FAIL} {
Jerome Forissier7950f2b2015-09-03 10:35:29 +020069 info " $expect_out(1,string) FAIL\n"
70 exit 1
71 }
72 -re {rcu_sched detected stalls} {
73 info " Kernel error: '$expect_out(0,string)'\n"
Jerome Forissierf080b5a2015-08-07 16:18:57 +020074 exit 1
75 }
76 # Crude progress indicator: print one # when each test [sub]case starts
Jens Wiklander06bb4422017-01-20 10:04:09 +010077 -re {([\*o]) regression_([^ ]+) } {
Jerome Forissierf080b5a2015-08-07 16:18:57 +020078 set casenum $expect_out(2,string)
79 if {$expect_out(1,string) == "o"} {
80 if {$star == 1} {
81 # Do not count first subcase ('o') since start
82 # of test ('*') was counted already
83 set star 0
84 exp_continue
85 }
86 } else {
87 set star 1
88 }
89 info "#"
90 incr ncases
Jerome Forissier7950f2b2015-09-03 10:35:29 +020091 if {$ncases % 50 == 0} { info "\n" }
Jerome Forissierf080b5a2015-08-07 16:18:57 +020092 exp_continue
93 }
94 # Exit when result separator is seen
95 "+-----------------------------------------------------\r\r" {}
Jerome Forissierf3fa64d2016-10-17 10:50:51 +020096 # Handle errors in TEE core output
97 -i $teecore -re {(assertion.*failed at.*)\n} {
98 info "!!! TEE core assertion failed: '$expect_out(1,string)'\n"
99 exit 1
100 }
Jerome Forissierf080b5a2015-08-07 16:18:57 +0200101 timeout {
102 info "!!! Timeout\n"
Jerome Forissier7950f2b2015-09-03 10:35:29 +0200103 info "TIMEOUT - test case too long or hung? (last test started: $casenum)\n"
Jerome Forissierf080b5a2015-08-07 16:18:57 +0200104 exit 2
105 }
106}
107info "\nStatus: PASS ($ncases test cases)\n"
108