blob: a077fad3620a3e01af1b14af5c81b19b87c23e9f [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
Sumit Garg92d86ba2021-12-29 11:51:11 +05304# tests in the guest. The return code is 0 for success, >0 for error.
Jerome Forissierf080b5a2015-08-07 16:18:57 +02005#
6# Options:
7# --bios Path to the binary to be run [../out/bios-qemu/bios.bin]
8# -q Suppress output to stdout (quiet)
Sumit Garg92d86ba2021-12-29 11:51:11 +05309# --tests Type of tests to run, values: all, xtest and trusted-keys
Jerome Forissier7a9463c2015-08-20 10:53:48 +020010# --timeout Timeout for each test (sub)case, in seconds [480]
Jerome Forissierf080b5a2015-08-07 16:18:57 +020011
12set bios "../out/bios-qemu/bios.bin"
13set cmd "xtest"
Ruchika Guptaf3ca6b22021-06-15 15:38:33 +053014set cmd1 "cd /mnt/host/build/qemu_v8/xen"
15set cmd2 "xl create guest.cfg"
16set cmd3 "xl console domu"
Jerome Forissierf080b5a2015-08-07 16:18:57 +020017set quiet 0
18
19# The time required to run some tests (e.g., key generation tests [4007.*])
20# can be significant and vary widely -- typically, from about one minute to
21# several minutes depending on the host machine.
Jerome Forissier6d46ded2021-04-15 18:49:37 +020022# The value here should be sufficient to run the whole optee_test suite
23# ('xtest') with all testsuites enabled (regression+gp+pkcs11).
24set timeout 900
Sumit Garg92d86ba2021-12-29 11:51:11 +053025set tests "all"
Jerome Forissierf080b5a2015-08-07 16:18:57 +020026
27# Parse command line
28set myargs $argv
29while {[llength $myargs]} {
30 set myargs [lassign $myargs arg]
31 switch -exact -- $arg {
32 "--bios" {set myargs [lassign $myargs ::bios]}
Sumit Garg92d86ba2021-12-29 11:51:11 +053033 "--tests" {set myargs [lassign $myargs ::tests]}
Jerome Forissier7a9463c2015-08-20 10:53:48 +020034 "--timeout" {set myargs [lassign $myargs ::timeout]}
Jerome Forissierf080b5a2015-08-07 16:18:57 +020035 "-q" {set ::quiet 1}
36 }
37}
38
39proc info arg {
40 if {$::quiet==1} { return }
41 puts -nonewline $arg
42 flush stdout
43}
44
Ruchika Guptaf3ca6b22021-06-15 15:38:33 +053045proc check_test_result arg {
46 set casenum "none"
47 expect {
48 # Exit with error status as soon as a test fails
49 -re { ([^ ]+) FAIL} {
50 info " $expect_out(1,string) FAIL\n"
51 exit 1
52 }
53 -re {rcu_sched detected stalls} {
54 info " Kernel error: '$expect_out(0,string)'\n"
55 exit 1
56 }
57 # Crude progress indicator: print one # when each test [sub]case starts
58 -re {([\*o]) ([^ ]+) } {
59 set casenum $expect_out(2,string)
60 if {$expect_out(1,string) == "o"} {
61 if {$star == 1} {
62 # Do not count first subcase ('o') since start
63 # of test ('*') was counted already
64 set star 0
65 exp_continue
66 }
67 } else {
68 set star 1
69 }
70 info "#"
71 incr ncases
72 if {$ncases % 50 == 0} { info "\n" }
73 exp_continue
74 }
75 # Exit when result separator is seen
76 "+-----------------------------------------------------\r\r" {}
77 # Handle errors in TEE core output
Jerome Forissiera16b1592022-06-28 09:37:44 +020078 -i $arg -re {(..TC:[^\n]*assertion[^\n]*failed at[^\n]*)} {
Jens Wiklander09900ef2022-04-21 19:34:55 +020079 info "!!! $expect_out(1,string)\n"
80 exit 1
81 }
Jerome Forissiera16b1592022-06-28 09:37:44 +020082 -i $arg -re {(..TC:[^\n]*Panic at[^\n]*)} {
Ruchika Guptaf3ca6b22021-06-15 15:38:33 +053083 info "!!! $expect_out(1,string)\n"
84 exit 1
85 }
86 timeout {
87 info "!!! Timeout\n"
88 info "TIMEOUT - test case too long or hung? (last test started: $casenum)\n"
89 exit 2
90 }
91 }
92 info "\nStatus: PASS ($ncases test cases)\n"
93}
94
Jerome Forissierf080b5a2015-08-07 16:18:57 +020095# Disable echoing of guest output
96log_user 0
97# Save guest console output to a file
98log_file -a -noappend "serial0.log"
99info "Starting QEMU..."
Jerome Forissierf3fa64d2016-10-17 10:50:51 +0200100open "serial1.log" "w+"
101spawn -open [open "|tail -f serial1.log"]
102set teecore $spawn_id
Jerome Forissier10bb03b2019-05-29 00:51:24 +0200103if {[string first "aarch64" $::env(QEMU)] != -1} {
Ruchika Gupta4dc75122021-06-18 12:57:52 +0530104 if {$::env(XEN_BOOT) == "y"} {
Jens Wiklander4384ece2022-04-14 08:09:08 +0200105 spawn $::env(QEMU) -nographic -serial mon:stdio -serial file:serial1.log -smp $::env(QEMU_SMP) -machine virt,secure=on,mte=$::env(QEMU_MTE),gic-version=$::env(QEMU_GIC),virtualization=true -cpu $::env(QEMU_CPU) -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
Ruchika Gupta4dc75122021-06-18 12:57:52 +0530106 } else {
Jens Wiklander4384ece2022-04-14 08:09:08 +0200107 spawn $::env(QEMU) -nographic -serial mon:stdio -serial file:serial1.log -smp $::env(QEMU_SMP) -machine virt,secure=on,mte=$::env(QEMU_MTE),gic-version=$::env(QEMU_GIC) -cpu $::env(QEMU_CPU) -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"
Ruchika Gupta4dc75122021-06-18 12:57:52 +0530108 }
Jerome Forissier10bb03b2019-05-29 00:51:24 +0200109} else {
Peter Griffin96f2ac42021-04-28 14:39:56 +0100110 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 +0200111}
Jerome Forissier7950f2b2015-09-03 10:35:29 +0200112expect {
113 "Kernel panic" {
114 info "!!! Kernel panic\n"
115 exit 1
116 }
117 timeout {
118 info "!!! Timeout\n"
119 exit 1
120 }
Jerome Forissier4763adc2018-03-14 12:06:21 +0000121 "ogin:"
Jerome Forissier7950f2b2015-09-03 10:35:29 +0200122}
Jerome Forissier4763adc2018-03-14 12:06:21 +0000123send -- "root\r\r"
124expect "# "
Ruchika Gupta4dc75122021-06-18 12:57:52 +0530125info " done, guest is booted"
126if {$::env(XEN_BOOT) == "y"} {
127 info " (Xen Dom0)"
128}
129info ".\n"
Jerome Forissier7950f2b2015-09-03 10:35:29 +0200130# Toolchain libraries might be here or there
131send -- "export LD_LIBRARY_PATH=/lib:/lib/arm-linux-gnueabihf\r"
Sumit Garg92d86ba2021-12-29 11:51:11 +0530132if {$tests == "all" || $tests == "xtest"} {
133 info "Running: $cmd...\n"
Jerome Forissier3c36a552022-01-05 08:59:42 +0100134 expect "# "
Sumit Garg92d86ba2021-12-29 11:51:11 +0530135 send -- "$cmd\r"
136 check_test_result $teecore
137}
Ruchika Guptaf3ca6b22021-06-15 15:38:33 +0530138if {$::env(XEN_BOOT) == "y"} {
139 info " Booting DomU.\n"
140 expect "# "
141 info "Running: $cmd1...\n"
142 send -- "$cmd1\r"
143 expect "# "
144 info "Running: $cmd2...\n"
145 send -- "$cmd2\r"
146 expect "# "
147 info "Running: $cmd3...\n"
148 send -- "$cmd3\r"
149 expect {
150 "Kernel panic" {
151 info "!!! Kernel panic\n"
152 exit 1
Jerome Forissierf080b5a2015-08-07 16:18:57 +0200153 }
Ruchika Guptaf3ca6b22021-06-15 15:38:33 +0530154 timeout {
155 info "!!! Timeout\n"
156 exit 1
157 }
158 "login:"
Jerome Forissierf080b5a2015-08-07 16:18:57 +0200159 }
Ruchika Guptaf3ca6b22021-06-15 15:38:33 +0530160 send -- "root\r\r"
161 expect "# "
162 info " done, DomU is booted.\n"
163 # Toolchain libraries might be here or there
164 send -- "export LD_LIBRARY_PATH=/lib:/lib/arm-linux-gnueabihf\r"
165 expect "# "
Sumit Garg92d86ba2021-12-29 11:51:11 +0530166 if {$tests == "all" || $tests == "xtest"} {
167 info "Running: $cmd...\n"
168 send -- "$cmd\r"
169 check_test_result $teecore
170 }
Jerome Forissierf080b5a2015-08-07 16:18:57 +0200171}
Sumit Garg92d86ba2021-12-29 11:51:11 +0530172if {$tests == "all" || $tests == "trusted-keys"} {
173 # Invoke Trusted Keys tests
174 set basedir [file dirname $argv0]
175 source $basedir/trusted-keys.exp
176}