blob: 645ee1b0259ae3e8cef7cfe2d3fc958051f3969f [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 Forissier10bb03b2019-05-29 00:51:24 +020045if {[string first "aarch64" $::env(QEMU)] != -1} {
46 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"
47} else {
48 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
49}
Jerome Forissier7950f2b2015-09-03 10:35:29 +020050expect {
51 "Kernel panic" {
52 info "!!! Kernel panic\n"
53 exit 1
54 }
55 timeout {
56 info "!!! Timeout\n"
57 exit 1
58 }
Jerome Forissier4763adc2018-03-14 12:06:21 +000059 "ogin:"
Jerome Forissier7950f2b2015-09-03 10:35:29 +020060}
Jerome Forissier4763adc2018-03-14 12:06:21 +000061send -- "root\r\r"
62expect "# "
Jerome Forissierc8ba87c2017-03-03 17:24:25 +010063info " done, guest is booted.\n"
Jerome Forissier7950f2b2015-09-03 10:35:29 +020064# Toolchain libraries might be here or there
65send -- "export LD_LIBRARY_PATH=/lib:/lib/arm-linux-gnueabihf\r"
Jerome Forissier4763adc2018-03-14 12:06:21 +000066expect "# "
Jerome Forissierc8ba87c2017-03-03 17:24:25 +010067info "Running: $cmd...\n"
Jerome Forissierf080b5a2015-08-07 16:18:57 +020068send -- "$cmd\r"
Jerome Forissier7950f2b2015-09-03 10:35:29 +020069set casenum "none"
Jerome Forissierf080b5a2015-08-07 16:18:57 +020070expect {
71 # Exit with error status as soon as a test fails
Jens Wiklander06bb4422017-01-20 10:04:09 +010072 -re { regression_([^ ]+) FAIL} {
Jerome Forissier7950f2b2015-09-03 10:35:29 +020073 info " $expect_out(1,string) FAIL\n"
74 exit 1
75 }
76 -re {rcu_sched detected stalls} {
77 info " Kernel error: '$expect_out(0,string)'\n"
Jerome Forissierf080b5a2015-08-07 16:18:57 +020078 exit 1
79 }
80 # Crude progress indicator: print one # when each test [sub]case starts
Jens Wiklander06bb4422017-01-20 10:04:09 +010081 -re {([\*o]) regression_([^ ]+) } {
Jerome Forissierf080b5a2015-08-07 16:18:57 +020082 set casenum $expect_out(2,string)
83 if {$expect_out(1,string) == "o"} {
84 if {$star == 1} {
85 # Do not count first subcase ('o') since start
86 # of test ('*') was counted already
87 set star 0
88 exp_continue
89 }
90 } else {
91 set star 1
92 }
93 info "#"
94 incr ncases
Jerome Forissier7950f2b2015-09-03 10:35:29 +020095 if {$ncases % 50 == 0} { info "\n" }
Jerome Forissierf080b5a2015-08-07 16:18:57 +020096 exp_continue
97 }
98 # Exit when result separator is seen
99 "+-----------------------------------------------------\r\r" {}
Jerome Forissierf3fa64d2016-10-17 10:50:51 +0200100 # Handle errors in TEE core output
101 -i $teecore -re {(assertion.*failed at.*)\n} {
102 info "!!! TEE core assertion failed: '$expect_out(1,string)'\n"
103 exit 1
104 }
Jerome Forissierf080b5a2015-08-07 16:18:57 +0200105 timeout {
106 info "!!! Timeout\n"
Jerome Forissier7950f2b2015-09-03 10:35:29 +0200107 info "TIMEOUT - test case too long or hung? (last test started: $casenum)\n"
Jerome Forissierf080b5a2015-08-07 16:18:57 +0200108 exit 2
109 }
110}
111info "\nStatus: PASS ($ncases test cases)\n"
112