Jerome Forissier | f080b5a | 2015-08-07 16:18:57 +0200 | [diff] [blame] | 1 | #!/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 Forissier | 7a9463c | 2015-08-20 10:53:48 +0200 | [diff] [blame] | 9 | # --timeout Timeout for each test (sub)case, in seconds [480] |
Jerome Forissier | f080b5a | 2015-08-07 16:18:57 +0200 | [diff] [blame] | 10 | |
| 11 | set bios "../out/bios-qemu/bios.bin" |
| 12 | set cmd "xtest" |
| 13 | set 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 Forissier | 6d46ded | 2021-04-15 18:49:37 +0200 | [diff] [blame] | 18 | # The value here should be sufficient to run the whole optee_test suite |
| 19 | # ('xtest') with all testsuites enabled (regression+gp+pkcs11). |
| 20 | set timeout 900 |
Jerome Forissier | f080b5a | 2015-08-07 16:18:57 +0200 | [diff] [blame] | 21 | |
| 22 | # Parse command line |
| 23 | set myargs $argv |
| 24 | while {[llength $myargs]} { |
| 25 | set myargs [lassign $myargs arg] |
| 26 | switch -exact -- $arg { |
| 27 | "--bios" {set myargs [lassign $myargs ::bios]} |
Jerome Forissier | 7a9463c | 2015-08-20 10:53:48 +0200 | [diff] [blame] | 28 | "--timeout" {set myargs [lassign $myargs ::timeout]} |
Jerome Forissier | f080b5a | 2015-08-07 16:18:57 +0200 | [diff] [blame] | 29 | "-q" {set ::quiet 1} |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | proc info arg { |
| 34 | if {$::quiet==1} { return } |
| 35 | puts -nonewline $arg |
| 36 | flush stdout |
| 37 | } |
| 38 | |
| 39 | # Disable echoing of guest output |
| 40 | log_user 0 |
| 41 | # Save guest console output to a file |
| 42 | log_file -a -noappend "serial0.log" |
| 43 | info "Starting QEMU..." |
Jerome Forissier | f3fa64d | 2016-10-17 10:50:51 +0200 | [diff] [blame] | 44 | open "serial1.log" "w+" |
| 45 | spawn -open [open "|tail -f serial1.log"] |
| 46 | set teecore $spawn_id |
Jerome Forissier | 10bb03b | 2019-05-29 00:51:24 +0200 | [diff] [blame] | 47 | if {[string first "aarch64" $::env(QEMU)] != -1} { |
Ruchika Gupta | 4dc7512 | 2021-06-18 12:57:52 +0530 | [diff] [blame^] | 48 | if {$::env(XEN_BOOT) == "y"} { |
| 49 | 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 |
| 50 | } else { |
| 51 | 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" |
| 52 | } |
Jerome Forissier | 10bb03b | 2019-05-29 00:51:24 +0200 | [diff] [blame] | 53 | } else { |
Peter Griffin | 96f2ac4 | 2021-04-28 14:39:56 +0100 | [diff] [blame] | 54 | 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 Forissier | 10bb03b | 2019-05-29 00:51:24 +0200 | [diff] [blame] | 55 | } |
Jerome Forissier | 7950f2b | 2015-09-03 10:35:29 +0200 | [diff] [blame] | 56 | expect { |
| 57 | "Kernel panic" { |
| 58 | info "!!! Kernel panic\n" |
| 59 | exit 1 |
| 60 | } |
| 61 | timeout { |
| 62 | info "!!! Timeout\n" |
| 63 | exit 1 |
| 64 | } |
Jerome Forissier | 4763adc | 2018-03-14 12:06:21 +0000 | [diff] [blame] | 65 | "ogin:" |
Jerome Forissier | 7950f2b | 2015-09-03 10:35:29 +0200 | [diff] [blame] | 66 | } |
Jerome Forissier | 4763adc | 2018-03-14 12:06:21 +0000 | [diff] [blame] | 67 | send -- "root\r\r" |
| 68 | expect "# " |
Ruchika Gupta | 4dc7512 | 2021-06-18 12:57:52 +0530 | [diff] [blame^] | 69 | info " done, guest is booted" |
| 70 | if {$::env(XEN_BOOT) == "y"} { |
| 71 | info " (Xen Dom0)" |
| 72 | } |
| 73 | info ".\n" |
Jerome Forissier | 7950f2b | 2015-09-03 10:35:29 +0200 | [diff] [blame] | 74 | # Toolchain libraries might be here or there |
| 75 | send -- "export LD_LIBRARY_PATH=/lib:/lib/arm-linux-gnueabihf\r" |
Jerome Forissier | 4763adc | 2018-03-14 12:06:21 +0000 | [diff] [blame] | 76 | expect "# " |
Jerome Forissier | c8ba87c | 2017-03-03 17:24:25 +0100 | [diff] [blame] | 77 | info "Running: $cmd...\n" |
Jerome Forissier | f080b5a | 2015-08-07 16:18:57 +0200 | [diff] [blame] | 78 | send -- "$cmd\r" |
Jerome Forissier | 7950f2b | 2015-09-03 10:35:29 +0200 | [diff] [blame] | 79 | set casenum "none" |
Jerome Forissier | f080b5a | 2015-08-07 16:18:57 +0200 | [diff] [blame] | 80 | expect { |
| 81 | # Exit with error status as soon as a test fails |
Jerome Forissier | 88d93a4 | 2021-04-15 19:02:17 +0200 | [diff] [blame] | 82 | -re { ([^ ]+) FAIL} { |
Jerome Forissier | 7950f2b | 2015-09-03 10:35:29 +0200 | [diff] [blame] | 83 | info " $expect_out(1,string) FAIL\n" |
| 84 | exit 1 |
| 85 | } |
| 86 | -re {rcu_sched detected stalls} { |
| 87 | info " Kernel error: '$expect_out(0,string)'\n" |
Jerome Forissier | f080b5a | 2015-08-07 16:18:57 +0200 | [diff] [blame] | 88 | exit 1 |
| 89 | } |
| 90 | # Crude progress indicator: print one # when each test [sub]case starts |
Jerome Forissier | 88d93a4 | 2021-04-15 19:02:17 +0200 | [diff] [blame] | 91 | -re {([\*o]) ([^ ]+) } { |
Jerome Forissier | f080b5a | 2015-08-07 16:18:57 +0200 | [diff] [blame] | 92 | set casenum $expect_out(2,string) |
| 93 | if {$expect_out(1,string) == "o"} { |
| 94 | if {$star == 1} { |
| 95 | # Do not count first subcase ('o') since start |
| 96 | # of test ('*') was counted already |
| 97 | set star 0 |
| 98 | exp_continue |
| 99 | } |
| 100 | } else { |
| 101 | set star 1 |
| 102 | } |
| 103 | info "#" |
| 104 | incr ncases |
Jerome Forissier | 7950f2b | 2015-09-03 10:35:29 +0200 | [diff] [blame] | 105 | if {$ncases % 50 == 0} { info "\n" } |
Jerome Forissier | f080b5a | 2015-08-07 16:18:57 +0200 | [diff] [blame] | 106 | exp_continue |
| 107 | } |
| 108 | # Exit when result separator is seen |
| 109 | "+-----------------------------------------------------\r\r" {} |
Jerome Forissier | f3fa64d | 2016-10-17 10:50:51 +0200 | [diff] [blame] | 110 | # Handle errors in TEE core output |
| 111 | -i $teecore -re {(assertion.*failed at.*)\n} { |
Jerome Forissier | a4a259e | 2020-08-12 09:58:27 +0200 | [diff] [blame] | 112 | info "!!! $expect_out(1,string)\n" |
Jerome Forissier | f3fa64d | 2016-10-17 10:50:51 +0200 | [diff] [blame] | 113 | exit 1 |
| 114 | } |
Jerome Forissier | f080b5a | 2015-08-07 16:18:57 +0200 | [diff] [blame] | 115 | timeout { |
| 116 | info "!!! Timeout\n" |
Jerome Forissier | 7950f2b | 2015-09-03 10:35:29 +0200 | [diff] [blame] | 117 | info "TIMEOUT - test case too long or hung? (last test started: $casenum)\n" |
Jerome Forissier | f080b5a | 2015-08-07 16:18:57 +0200 | [diff] [blame] | 118 | exit 2 |
| 119 | } |
| 120 | } |
| 121 | info "\nStatus: PASS ($ncases test cases)\n" |
| 122 | |