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) |
| 9 | |
| 10 | set bios "../out/bios-qemu/bios.bin" |
| 11 | set cmd "xtest" |
| 12 | set quiet 0 |
| 13 | |
| 14 | # The time required to run some tests (e.g., key generation tests [4007.*]) |
| 15 | # can be significant and vary widely -- typically, from about one minute to |
| 16 | # several minutes depending on the host machine. |
| 17 | # So, set an infinite timeout. |
| 18 | set timeout -1 |
| 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]} |
| 26 | "-q" {set ::quiet 1} |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | proc info arg { |
| 31 | if {$::quiet==1} { return } |
| 32 | puts -nonewline $arg |
| 33 | flush stdout |
| 34 | } |
| 35 | |
| 36 | # Disable echoing of guest output |
| 37 | log_user 0 |
| 38 | # Save guest console output to a file |
| 39 | log_file -a -noappend "serial0.log" |
| 40 | info "Starting QEMU..." |
| 41 | spawn ../qemu/arm-softmmu/qemu-system-arm -machine virt -cpu cortex-a15 -m 1057 -serial stdio -serial file:serial1.log -bios $bios |
| 42 | expect "*Please press Enter to activate this console. " |
| 43 | send -- "\r" |
| 44 | expect "root@Vexpress:/ " |
| 45 | info " done, guest is booted.\nLoading OP-TEE driver and tee-supplicant..." |
| 46 | send -- "modprobe optee_armtz\r" |
| 47 | expect "root@Vexpress:/ " |
| 48 | sleep 1 |
| 49 | send -- "tee-supplicant&\r" |
| 50 | expect "root@Vexpress:/ " |
| 51 | sleep 1 |
| 52 | info " done.\nRunning: $cmd...\n" |
| 53 | send -- "$cmd\r" |
| 54 | expect { |
| 55 | # Exit with error status as soon as a test fails |
| 56 | -re { XTEST_TEE_([^ ]+) FAIL} { |
| 57 | info "$expect_out(1,string) FAIL" |
| 58 | exit 1 |
| 59 | } |
| 60 | # Crude progress indicator: print one # when each test [sub]case starts |
| 61 | -re {([\*o]) XTEST_TEE_([^ ]+) } { |
| 62 | set casenum $expect_out(2,string) |
| 63 | if {$expect_out(1,string) == "o"} { |
| 64 | if {$star == 1} { |
| 65 | # Do not count first subcase ('o') since start |
| 66 | # of test ('*') was counted already |
| 67 | set star 0 |
| 68 | exp_continue |
| 69 | } |
| 70 | } else { |
| 71 | set star 1 |
| 72 | } |
| 73 | info "#" |
| 74 | incr ncases |
| 75 | exp_continue |
| 76 | } |
| 77 | # Exit when result separator is seen |
| 78 | "+-----------------------------------------------------\r\r" {} |
| 79 | timeout { |
| 80 | info "!!! Timeout\n" |
| 81 | info "TIMEOUT - test case too long or hung? ($casenum)\n" |
| 82 | exit 2 |
| 83 | } |
| 84 | } |
| 85 | info "\nStatus: PASS ($ncases test cases)\n" |
| 86 | |