blob: 2ce3ecb01082e3d4e0599effbe56d310c8539cc9 [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"
Ruchika Guptaf3ca6b22021-06-15 15:38:33 +053013set cmd1 "cd /mnt/host/build/qemu_v8/xen"
14set cmd2 "xl create guest.cfg"
15set cmd3 "xl console domu"
Jerome Forissierf080b5a2015-08-07 16:18:57 +020016set quiet 0
17
18# The time required to run some tests (e.g., key generation tests [4007.*])
19# can be significant and vary widely -- typically, from about one minute to
20# several minutes depending on the host machine.
Jerome Forissier6d46ded2021-04-15 18:49:37 +020021# The value here should be sufficient to run the whole optee_test suite
22# ('xtest') with all testsuites enabled (regression+gp+pkcs11).
23set timeout 900
Jerome Forissierf080b5a2015-08-07 16:18:57 +020024
25# Parse command line
26set myargs $argv
27while {[llength $myargs]} {
28 set myargs [lassign $myargs arg]
29 switch -exact -- $arg {
30 "--bios" {set myargs [lassign $myargs ::bios]}
Jerome Forissier7a9463c2015-08-20 10:53:48 +020031 "--timeout" {set myargs [lassign $myargs ::timeout]}
Jerome Forissierf080b5a2015-08-07 16:18:57 +020032 "-q" {set ::quiet 1}
33 }
34}
35
36proc info arg {
37 if {$::quiet==1} { return }
38 puts -nonewline $arg
39 flush stdout
40}
41
Ruchika Guptaf3ca6b22021-06-15 15:38:33 +053042proc check_test_result arg {
43 set casenum "none"
44 expect {
45 # Exit with error status as soon as a test fails
46 -re { ([^ ]+) FAIL} {
47 info " $expect_out(1,string) FAIL\n"
48 exit 1
49 }
50 -re {rcu_sched detected stalls} {
51 info " Kernel error: '$expect_out(0,string)'\n"
52 exit 1
53 }
54 # Crude progress indicator: print one # when each test [sub]case starts
55 -re {([\*o]) ([^ ]+) } {
56 set casenum $expect_out(2,string)
57 if {$expect_out(1,string) == "o"} {
58 if {$star == 1} {
59 # Do not count first subcase ('o') since start
60 # of test ('*') was counted already
61 set star 0
62 exp_continue
63 }
64 } else {
65 set star 1
66 }
67 info "#"
68 incr ncases
69 if {$ncases % 50 == 0} { info "\n" }
70 exp_continue
71 }
72 # Exit when result separator is seen
73 "+-----------------------------------------------------\r\r" {}
74 # Handle errors in TEE core output
75 -i $arg -re {(assertion.*failed at.*)\n} {
76 info "!!! $expect_out(1,string)\n"
77 exit 1
78 }
79 timeout {
80 info "!!! Timeout\n"
81 info "TIMEOUT - test case too long or hung? (last test started: $casenum)\n"
82 exit 2
83 }
84 }
85 info "\nStatus: PASS ($ncases test cases)\n"
86}
87
Jerome Forissierf080b5a2015-08-07 16:18:57 +020088# Disable echoing of guest output
89log_user 0
90# Save guest console output to a file
91log_file -a -noappend "serial0.log"
92info "Starting QEMU..."
Jerome Forissierf3fa64d2016-10-17 10:50:51 +020093open "serial1.log" "w+"
94spawn -open [open "|tail -f serial1.log"]
95set teecore $spawn_id
Jerome Forissier10bb03b2019-05-29 00:51:24 +020096if {[string first "aarch64" $::env(QEMU)] != -1} {
Ruchika Gupta4dc75122021-06-18 12:57:52 +053097 if {$::env(XEN_BOOT) == "y"} {
98 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
99 } else {
100 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"
101 }
Jerome Forissier10bb03b2019-05-29 00:51:24 +0200102} else {
Peter Griffin96f2ac42021-04-28 14:39:56 +0100103 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 +0200104}
Jerome Forissier7950f2b2015-09-03 10:35:29 +0200105expect {
106 "Kernel panic" {
107 info "!!! Kernel panic\n"
108 exit 1
109 }
110 timeout {
111 info "!!! Timeout\n"
112 exit 1
113 }
Jerome Forissier4763adc2018-03-14 12:06:21 +0000114 "ogin:"
Jerome Forissier7950f2b2015-09-03 10:35:29 +0200115}
Jerome Forissier4763adc2018-03-14 12:06:21 +0000116send -- "root\r\r"
117expect "# "
Ruchika Gupta4dc75122021-06-18 12:57:52 +0530118info " done, guest is booted"
119if {$::env(XEN_BOOT) == "y"} {
120 info " (Xen Dom0)"
121}
122info ".\n"
Jerome Forissier7950f2b2015-09-03 10:35:29 +0200123# Toolchain libraries might be here or there
124send -- "export LD_LIBRARY_PATH=/lib:/lib/arm-linux-gnueabihf\r"
Jerome Forissier4763adc2018-03-14 12:06:21 +0000125expect "# "
Jerome Forissierc8ba87c2017-03-03 17:24:25 +0100126info "Running: $cmd...\n"
Jerome Forissierf080b5a2015-08-07 16:18:57 +0200127send -- "$cmd\r"
Ruchika Guptaf3ca6b22021-06-15 15:38:33 +0530128check_test_result $teecore
129if {$::env(XEN_BOOT) == "y"} {
130 info " Booting DomU.\n"
131 expect "# "
132 info "Running: $cmd1...\n"
133 send -- "$cmd1\r"
134 expect "# "
135 info "Running: $cmd2...\n"
136 send -- "$cmd2\r"
137 expect "# "
138 info "Running: $cmd3...\n"
139 send -- "$cmd3\r"
140 expect {
141 "Kernel panic" {
142 info "!!! Kernel panic\n"
143 exit 1
Jerome Forissierf080b5a2015-08-07 16:18:57 +0200144 }
Ruchika Guptaf3ca6b22021-06-15 15:38:33 +0530145 timeout {
146 info "!!! Timeout\n"
147 exit 1
148 }
149 "login:"
Jerome Forissierf080b5a2015-08-07 16:18:57 +0200150 }
Ruchika Guptaf3ca6b22021-06-15 15:38:33 +0530151 send -- "root\r\r"
152 expect "# "
153 info " done, DomU is booted.\n"
154 # Toolchain libraries might be here or there
155 send -- "export LD_LIBRARY_PATH=/lib:/lib/arm-linux-gnueabihf\r"
156 expect "# "
157 info "Running: $cmd...\n"
158 send -- "$cmd\r"
159 check_test_result $teecore
Jerome Forissierf080b5a2015-08-07 16:18:57 +0200160}