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" |
Ruchika Gupta | f3ca6b2 | 2021-06-15 15:38:33 +0530 | [diff] [blame] | 13 | set cmd1 "cd /mnt/host/build/qemu_v8/xen" |
| 14 | set cmd2 "xl create guest.cfg" |
| 15 | set cmd3 "xl console domu" |
Jerome Forissier | f080b5a | 2015-08-07 16:18:57 +0200 | [diff] [blame] | 16 | set quiet 0 |
| 17 | |
| 18 | # The time required to run some tests (e.g., key generation tests [4007.*]) |
| 19 | # can be significant and vary widely -- typically, from about one minute to |
| 20 | # several minutes depending on the host machine. |
Jerome Forissier | 6d46ded | 2021-04-15 18:49:37 +0200 | [diff] [blame] | 21 | # The value here should be sufficient to run the whole optee_test suite |
| 22 | # ('xtest') with all testsuites enabled (regression+gp+pkcs11). |
| 23 | set timeout 900 |
Jerome Forissier | f080b5a | 2015-08-07 16:18:57 +0200 | [diff] [blame] | 24 | |
| 25 | # Parse command line |
| 26 | set myargs $argv |
| 27 | while {[llength $myargs]} { |
| 28 | set myargs [lassign $myargs arg] |
| 29 | switch -exact -- $arg { |
| 30 | "--bios" {set myargs [lassign $myargs ::bios]} |
Jerome Forissier | 7a9463c | 2015-08-20 10:53:48 +0200 | [diff] [blame] | 31 | "--timeout" {set myargs [lassign $myargs ::timeout]} |
Jerome Forissier | f080b5a | 2015-08-07 16:18:57 +0200 | [diff] [blame] | 32 | "-q" {set ::quiet 1} |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | proc info arg { |
| 37 | if {$::quiet==1} { return } |
| 38 | puts -nonewline $arg |
| 39 | flush stdout |
| 40 | } |
| 41 | |
Ruchika Gupta | f3ca6b2 | 2021-06-15 15:38:33 +0530 | [diff] [blame] | 42 | proc check_test_result arg { |
| 43 | set casenum "none" |
| 44 | expect { |
| 45 | # Exit with error status as soon as a test fails |
| 46 | -re { ([^ ]+) FAIL} { |
| 47 | info " $expect_out(1,string) FAIL\n" |
| 48 | exit 1 |
| 49 | } |
| 50 | -re {rcu_sched detected stalls} { |
| 51 | info " Kernel error: '$expect_out(0,string)'\n" |
| 52 | exit 1 |
| 53 | } |
| 54 | # Crude progress indicator: print one # when each test [sub]case starts |
| 55 | -re {([\*o]) ([^ ]+) } { |
| 56 | set casenum $expect_out(2,string) |
| 57 | if {$expect_out(1,string) == "o"} { |
| 58 | if {$star == 1} { |
| 59 | # Do not count first subcase ('o') since start |
| 60 | # of test ('*') was counted already |
| 61 | set star 0 |
| 62 | exp_continue |
| 63 | } |
| 64 | } else { |
| 65 | set star 1 |
| 66 | } |
| 67 | info "#" |
| 68 | incr ncases |
| 69 | if {$ncases % 50 == 0} { info "\n" } |
| 70 | exp_continue |
| 71 | } |
| 72 | # Exit when result separator is seen |
| 73 | "+-----------------------------------------------------\r\r" {} |
| 74 | # Handle errors in TEE core output |
| 75 | -i $arg -re {(assertion.*failed at.*)\n} { |
| 76 | info "!!! $expect_out(1,string)\n" |
| 77 | exit 1 |
| 78 | } |
| 79 | timeout { |
| 80 | info "!!! Timeout\n" |
| 81 | info "TIMEOUT - test case too long or hung? (last test started: $casenum)\n" |
| 82 | exit 2 |
| 83 | } |
| 84 | } |
| 85 | info "\nStatus: PASS ($ncases test cases)\n" |
| 86 | } |
| 87 | |
Jerome Forissier | f080b5a | 2015-08-07 16:18:57 +0200 | [diff] [blame] | 88 | # Disable echoing of guest output |
| 89 | log_user 0 |
| 90 | # Save guest console output to a file |
| 91 | log_file -a -noappend "serial0.log" |
| 92 | info "Starting QEMU..." |
Jerome Forissier | f3fa64d | 2016-10-17 10:50:51 +0200 | [diff] [blame] | 93 | open "serial1.log" "w+" |
| 94 | spawn -open [open "|tail -f serial1.log"] |
| 95 | set teecore $spawn_id |
Jerome Forissier | 10bb03b | 2019-05-29 00:51:24 +0200 | [diff] [blame] | 96 | if {[string first "aarch64" $::env(QEMU)] != -1} { |
Ruchika Gupta | 4dc7512 | 2021-06-18 12:57:52 +0530 | [diff] [blame] | 97 | if {$::env(XEN_BOOT) == "y"} { |
| 98 | 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 |
| 99 | } else { |
| 100 | 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" |
| 101 | } |
Jerome Forissier | 10bb03b | 2019-05-29 00:51:24 +0200 | [diff] [blame] | 102 | } else { |
Peter Griffin | 96f2ac4 | 2021-04-28 14:39:56 +0100 | [diff] [blame] | 103 | 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] | 104 | } |
Jerome Forissier | 7950f2b | 2015-09-03 10:35:29 +0200 | [diff] [blame] | 105 | expect { |
| 106 | "Kernel panic" { |
| 107 | info "!!! Kernel panic\n" |
| 108 | exit 1 |
| 109 | } |
| 110 | timeout { |
| 111 | info "!!! Timeout\n" |
| 112 | exit 1 |
| 113 | } |
Jerome Forissier | 4763adc | 2018-03-14 12:06:21 +0000 | [diff] [blame] | 114 | "ogin:" |
Jerome Forissier | 7950f2b | 2015-09-03 10:35:29 +0200 | [diff] [blame] | 115 | } |
Jerome Forissier | 4763adc | 2018-03-14 12:06:21 +0000 | [diff] [blame] | 116 | send -- "root\r\r" |
| 117 | expect "# " |
Ruchika Gupta | 4dc7512 | 2021-06-18 12:57:52 +0530 | [diff] [blame] | 118 | info " done, guest is booted" |
| 119 | if {$::env(XEN_BOOT) == "y"} { |
| 120 | info " (Xen Dom0)" |
| 121 | } |
| 122 | info ".\n" |
Jerome Forissier | 7950f2b | 2015-09-03 10:35:29 +0200 | [diff] [blame] | 123 | # Toolchain libraries might be here or there |
| 124 | send -- "export LD_LIBRARY_PATH=/lib:/lib/arm-linux-gnueabihf\r" |
Jerome Forissier | 4763adc | 2018-03-14 12:06:21 +0000 | [diff] [blame] | 125 | expect "# " |
Jerome Forissier | c8ba87c | 2017-03-03 17:24:25 +0100 | [diff] [blame] | 126 | info "Running: $cmd...\n" |
Jerome Forissier | f080b5a | 2015-08-07 16:18:57 +0200 | [diff] [blame] | 127 | send -- "$cmd\r" |
Ruchika Gupta | f3ca6b2 | 2021-06-15 15:38:33 +0530 | [diff] [blame] | 128 | check_test_result $teecore |
| 129 | if {$::env(XEN_BOOT) == "y"} { |
| 130 | info " Booting DomU.\n" |
| 131 | expect "# " |
| 132 | info "Running: $cmd1...\n" |
| 133 | send -- "$cmd1\r" |
| 134 | expect "# " |
| 135 | info "Running: $cmd2...\n" |
| 136 | send -- "$cmd2\r" |
| 137 | expect "# " |
| 138 | info "Running: $cmd3...\n" |
| 139 | send -- "$cmd3\r" |
| 140 | expect { |
| 141 | "Kernel panic" { |
| 142 | info "!!! Kernel panic\n" |
| 143 | exit 1 |
Jerome Forissier | f080b5a | 2015-08-07 16:18:57 +0200 | [diff] [blame] | 144 | } |
Ruchika Gupta | f3ca6b2 | 2021-06-15 15:38:33 +0530 | [diff] [blame] | 145 | timeout { |
| 146 | info "!!! Timeout\n" |
| 147 | exit 1 |
| 148 | } |
| 149 | "login:" |
Jerome Forissier | f080b5a | 2015-08-07 16:18:57 +0200 | [diff] [blame] | 150 | } |
Ruchika Gupta | f3ca6b2 | 2021-06-15 15:38:33 +0530 | [diff] [blame] | 151 | send -- "root\r\r" |
| 152 | expect "# " |
| 153 | info " done, DomU is booted.\n" |
| 154 | # Toolchain libraries might be here or there |
| 155 | send -- "export LD_LIBRARY_PATH=/lib:/lib/arm-linux-gnueabihf\r" |
| 156 | expect "# " |
| 157 | info "Running: $cmd...\n" |
| 158 | send -- "$cmd\r" |
| 159 | check_test_result $teecore |
Jerome Forissier | f080b5a | 2015-08-07 16:18:57 +0200 | [diff] [blame] | 160 | } |
Sumit Garg | 45cf44c | 2021-12-24 17:02:25 +0530 | [diff] [blame^] | 161 | # Invoke Trusted Keys tests |
| 162 | set basedir [file dirname $argv0] |
| 163 | source $basedir/trusted-keys.exp |