blob: bc306e8e277f76aa1ce84f55fe5077496bda5d9c [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
78 -i $arg -re {(assertion.*failed at.*)\n} {
79 info "!!! $expect_out(1,string)\n"
80 exit 1
81 }
82 timeout {
83 info "!!! Timeout\n"
84 info "TIMEOUT - test case too long or hung? (last test started: $casenum)\n"
85 exit 2
86 }
87 }
88 info "\nStatus: PASS ($ncases test cases)\n"
89}
90
Jerome Forissierf080b5a2015-08-07 16:18:57 +020091# Disable echoing of guest output
92log_user 0
93# Save guest console output to a file
94log_file -a -noappend "serial0.log"
95info "Starting QEMU..."
Jerome Forissierf3fa64d2016-10-17 10:50:51 +020096open "serial1.log" "w+"
97spawn -open [open "|tail -f serial1.log"]
98set teecore $spawn_id
Jerome Forissier10bb03b2019-05-29 00:51:24 +020099if {[string first "aarch64" $::env(QEMU)] != -1} {
Ruchika Gupta4dc75122021-06-18 12:57:52 +0530100 if {$::env(XEN_BOOT) == "y"} {
101 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
102 } else {
103 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"
104 }
Jerome Forissier10bb03b2019-05-29 00:51:24 +0200105} else {
Peter Griffin96f2ac42021-04-28 14:39:56 +0100106 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 +0200107}
Jerome Forissier7950f2b2015-09-03 10:35:29 +0200108expect {
109 "Kernel panic" {
110 info "!!! Kernel panic\n"
111 exit 1
112 }
113 timeout {
114 info "!!! Timeout\n"
115 exit 1
116 }
Jerome Forissier4763adc2018-03-14 12:06:21 +0000117 "ogin:"
Jerome Forissier7950f2b2015-09-03 10:35:29 +0200118}
Jerome Forissier4763adc2018-03-14 12:06:21 +0000119send -- "root\r\r"
120expect "# "
Ruchika Gupta4dc75122021-06-18 12:57:52 +0530121info " done, guest is booted"
122if {$::env(XEN_BOOT) == "y"} {
123 info " (Xen Dom0)"
124}
125info ".\n"
Jerome Forissier7950f2b2015-09-03 10:35:29 +0200126# Toolchain libraries might be here or there
127send -- "export LD_LIBRARY_PATH=/lib:/lib/arm-linux-gnueabihf\r"
Sumit Garg92d86ba2021-12-29 11:51:11 +0530128if {$tests == "all" || $tests == "xtest"} {
129 info "Running: $cmd...\n"
Jerome Forissier3c36a552022-01-05 08:59:42 +0100130 expect "# "
Sumit Garg92d86ba2021-12-29 11:51:11 +0530131 send -- "$cmd\r"
132 check_test_result $teecore
133}
Ruchika Guptaf3ca6b22021-06-15 15:38:33 +0530134if {$::env(XEN_BOOT) == "y"} {
135 info " Booting DomU.\n"
136 expect "# "
137 info "Running: $cmd1...\n"
138 send -- "$cmd1\r"
139 expect "# "
140 info "Running: $cmd2...\n"
141 send -- "$cmd2\r"
142 expect "# "
143 info "Running: $cmd3...\n"
144 send -- "$cmd3\r"
145 expect {
146 "Kernel panic" {
147 info "!!! Kernel panic\n"
148 exit 1
Jerome Forissierf080b5a2015-08-07 16:18:57 +0200149 }
Ruchika Guptaf3ca6b22021-06-15 15:38:33 +0530150 timeout {
151 info "!!! Timeout\n"
152 exit 1
153 }
154 "login:"
Jerome Forissierf080b5a2015-08-07 16:18:57 +0200155 }
Ruchika Guptaf3ca6b22021-06-15 15:38:33 +0530156 send -- "root\r\r"
157 expect "# "
158 info " done, DomU is booted.\n"
159 # Toolchain libraries might be here or there
160 send -- "export LD_LIBRARY_PATH=/lib:/lib/arm-linux-gnueabihf\r"
161 expect "# "
Sumit Garg92d86ba2021-12-29 11:51:11 +0530162 if {$tests == "all" || $tests == "xtest"} {
163 info "Running: $cmd...\n"
164 send -- "$cmd\r"
165 check_test_result $teecore
166 }
Jerome Forissierf080b5a2015-08-07 16:18:57 +0200167}
Sumit Garg92d86ba2021-12-29 11:51:11 +0530168if {$tests == "all" || $tests == "trusted-keys"} {
169 # Invoke Trusted Keys tests
170 set basedir [file dirname $argv0]
171 source $basedir/trusted-keys.exp
172}