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 | 7a9463c | 2015-08-20 10:53:48 +0200 | [diff] [blame] | 18 | set timeout 480 |
Jerome Forissier | f080b5a | 2015-08-07 16:18:57 +0200 | [diff] [blame] | 19 | |
| 20 | # Parse command line |
| 21 | set myargs $argv |
| 22 | while {[llength $myargs]} { |
| 23 | set myargs [lassign $myargs arg] |
| 24 | switch -exact -- $arg { |
| 25 | "--bios" {set myargs [lassign $myargs ::bios]} |
Jerome Forissier | 7a9463c | 2015-08-20 10:53:48 +0200 | [diff] [blame] | 26 | "--timeout" {set myargs [lassign $myargs ::timeout]} |
Jerome Forissier | f080b5a | 2015-08-07 16:18:57 +0200 | [diff] [blame] | 27 | "-q" {set ::quiet 1} |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | proc info arg { |
| 32 | if {$::quiet==1} { return } |
| 33 | puts -nonewline $arg |
| 34 | flush stdout |
| 35 | } |
| 36 | |
| 37 | # Disable echoing of guest output |
| 38 | log_user 0 |
| 39 | # Save guest console output to a file |
| 40 | log_file -a -noappend "serial0.log" |
| 41 | info "Starting QEMU..." |
Jerome Forissier | f3fa64d | 2016-10-17 10:50:51 +0200 | [diff] [blame^] | 42 | open "serial1.log" "w+" |
| 43 | spawn -open [open "|tail -f serial1.log"] |
| 44 | set teecore $spawn_id |
Jerome Forissier | dbdfe80 | 2016-01-25 17:13:46 +0100 | [diff] [blame] | 45 | spawn ../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 Forissier | 7950f2b | 2015-09-03 10:35:29 +0200 | [diff] [blame] | 46 | expect { |
| 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 Forissier | f080b5a | 2015-08-07 16:18:57 +0200 | [diff] [blame] | 57 | send -- "\r" |
| 58 | expect "root@Vexpress:/ " |
| 59 | info " done, guest is booted.\nLoading OP-TEE driver and tee-supplicant..." |
Jerome Forissier | 7950f2b | 2015-09-03 10:35:29 +0200 | [diff] [blame] | 60 | # Toolchain libraries might be here or there |
| 61 | send -- "export LD_LIBRARY_PATH=/lib:/lib/arm-linux-gnueabihf\r" |
| 62 | expect "root@Vexpress:/ " |
Jerome Forissier | f080b5a | 2015-08-07 16:18:57 +0200 | [diff] [blame] | 63 | send -- "tee-supplicant&\r" |
| 64 | expect "root@Vexpress:/ " |
| 65 | sleep 1 |
| 66 | info " done.\nRunning: $cmd...\n" |
| 67 | send -- "$cmd\r" |
Jerome Forissier | 7950f2b | 2015-09-03 10:35:29 +0200 | [diff] [blame] | 68 | set casenum "none" |
Jerome Forissier | f080b5a | 2015-08-07 16:18:57 +0200 | [diff] [blame] | 69 | expect { |
| 70 | # Exit with error status as soon as a test fails |
| 71 | -re { XTEST_TEE_([^ ]+) FAIL} { |
Jerome Forissier | 7950f2b | 2015-09-03 10:35:29 +0200 | [diff] [blame] | 72 | 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 Forissier | f080b5a | 2015-08-07 16:18:57 +0200 | [diff] [blame] | 77 | 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 Forissier | 7950f2b | 2015-09-03 10:35:29 +0200 | [diff] [blame] | 94 | if {$ncases % 50 == 0} { info "\n" } |
Jerome Forissier | f080b5a | 2015-08-07 16:18:57 +0200 | [diff] [blame] | 95 | exp_continue |
| 96 | } |
| 97 | # Exit when result separator is seen |
| 98 | "+-----------------------------------------------------\r\r" {} |
Jerome Forissier | f3fa64d | 2016-10-17 10:50:51 +0200 | [diff] [blame^] | 99 | # 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 Forissier | f080b5a | 2015-08-07 16:18:57 +0200 | [diff] [blame] | 104 | timeout { |
| 105 | info "!!! Timeout\n" |
Jerome Forissier | 7950f2b | 2015-09-03 10:35:29 +0200 | [diff] [blame] | 106 | 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] | 107 | exit 2 |
| 108 | } |
| 109 | } |
| 110 | info "\nStatus: PASS ($ncases test cases)\n" |
| 111 | |