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