blob: fc412b3581dd800b885346ddbaa1f2b73b11c7a2 [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 Forissierdbdfe802016-01-25 17:13:46 +010045spawn ../qemu/arm-softmmu/qemu-system-arm -nographic -monitor none -machine virt -machine secure=on -cpu cortex-a15 -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 }
55 "Please press Enter to activate this console. "
56}
Jerome Forissierf080b5a2015-08-07 16:18:57 +020057send -- "\r"
58expect "root@Vexpress:/ "
59info " done, guest is booted.\nLoading OP-TEE driver and tee-supplicant..."
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"
62expect "root@Vexpress:/ "
Jerome Forissierf080b5a2015-08-07 16:18:57 +020063send -- "tee-supplicant&\r"
64expect "root@Vexpress:/ "
65sleep 1
66info " done.\nRunning: $cmd...\n"
67send -- "$cmd\r"
Jerome Forissier7950f2b2015-09-03 10:35:29 +020068set casenum "none"
Jerome Forissierf080b5a2015-08-07 16:18:57 +020069expect {
70 # Exit with error status as soon as a test fails
71 -re { XTEST_TEE_([^ ]+) FAIL} {
Jerome Forissier7950f2b2015-09-03 10:35:29 +020072 info " $expect_out(1,string) FAIL\n"
73 exit 1
74 }
75 -re {rcu_sched detected stalls} {
76 info " Kernel error: '$expect_out(0,string)'\n"
Jerome Forissierf080b5a2015-08-07 16:18:57 +020077 exit 1
78 }
79 # Crude progress indicator: print one # when each test [sub]case starts
80 -re {([\*o]) XTEST_TEE_([^ ]+) } {
81 set casenum $expect_out(2,string)
82 if {$expect_out(1,string) == "o"} {
83 if {$star == 1} {
84 # Do not count first subcase ('o') since start
85 # of test ('*') was counted already
86 set star 0
87 exp_continue
88 }
89 } else {
90 set star 1
91 }
92 info "#"
93 incr ncases
Jerome Forissier7950f2b2015-09-03 10:35:29 +020094 if {$ncases % 50 == 0} { info "\n" }
Jerome Forissierf080b5a2015-08-07 16:18:57 +020095 exp_continue
96 }
97 # Exit when result separator is seen
98 "+-----------------------------------------------------\r\r" {}
Jerome Forissierf3fa64d2016-10-17 10:50:51 +020099 # Handle errors in TEE core output
100 -i $teecore -re {(assertion.*failed at.*)\n} {
101 info "!!! TEE core assertion failed: '$expect_out(1,string)'\n"
102 exit 1
103 }
Jerome Forissierf080b5a2015-08-07 16:18:57 +0200104 timeout {
105 info "!!! Timeout\n"
Jerome Forissier7950f2b2015-09-03 10:35:29 +0200106 info "TIMEOUT - test case too long or hung? (last test started: $casenum)\n"
Jerome Forissierf080b5a2015-08-07 16:18:57 +0200107 exit 2
108 }
109}
110info "\nStatus: PASS ($ncases test cases)\n"
111