Leonardo Sandoval | 9dfdd1b | 2020-08-06 17:08:11 -0500 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 2 | # |
Boyan Karatotev | 55a18e9 | 2025-07-28 09:17:42 +0100 | [diff] [blame] | 3 | # Copyright (c) 2019-2025, Arm Limited. All rights reserved. |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 4 | # |
| 5 | # SPDX-License-Identifier: BSD-3-Clause |
| 6 | # |
| 7 | |
| 8 | set -e |
| 9 | |
| 10 | # Enable job control to have background processes run in their own process |
| 11 | # group. That way, we can kill a background process group in one go. |
| 12 | set -m |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 13 | ci_root="$(readlink -f "$(dirname "$0")/..")" |
| 14 | source "$ci_root/utils.sh" |
| 15 | |
| 16 | artefacts="${artefacts-$workspace/artefacts}" |
| 17 | |
| 18 | run_root="$workspace/run" |
| 19 | pid_dir="$workspace/pids" |
| 20 | |
Manish V Badarkhe | 359b3ff | 2020-12-25 18:54:03 +0000 | [diff] [blame] | 21 | # Model exit parameter string |
| 22 | model_exit_param_string="bp.pl011_uart0.shutdown_on_eot=1" |
| 23 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 24 | mkdir -p "$pid_dir" |
| 25 | mkdir -p "$run_root" |
| 26 | |
| 27 | kill_and_reap() { |
| 28 | local gid |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 29 | # Kill an active process. Ignore errors |
| 30 | [ "$1" ] || return 0 |
| 31 | kill -0 "$1" &>/dev/null || return 0 |
| 32 | |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 33 | # Kill the children |
| 34 | kill -- "-$1" &>/dev/null || true |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 35 | # Kill the group |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 36 | { gid="$(awk '{print $5}' < /proc/$1/stat)";} 2>/dev/null || return |
| 37 | # For Code Coverage plugin it is needed to propagate |
| 38 | # the kill signal to the plugin in order to save |
| 39 | # the trace statistics. |
| 40 | if [ "${COVERAGE_ON}" == "1" ] || [ -n "$cc_enable" ]; then |
| 41 | kill -SIGTERM -- "-$gid" &>/dev/null || true |
| 42 | else |
| 43 | kill -SIGKILL -- "-$gid" &>/dev/null || true |
| 44 | fi |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 45 | wait "$gid" &>/dev/null || true |
| 46 | } |
| 47 | |
| 48 | # Perform clean up and ignore errors |
| 49 | cleanup() { |
| 50 | local pid |
Manish V Badarkhe | 359b3ff | 2020-12-25 18:54:03 +0000 | [diff] [blame] | 51 | local sig |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 52 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 53 | pushd "$pid_dir" |
| 54 | set +e |
Manish V Badarkhe | 359b3ff | 2020-12-25 18:54:03 +0000 | [diff] [blame] | 55 | |
| 56 | sig=${1:-SIGINT} |
| 57 | echo "signal received: $sig" |
| 58 | |
Boyan Karatotev | 40fa01a | 2025-07-29 14:18:02 +0100 | [diff] [blame^] | 59 | while read pid; do |
| 60 | pid="$(cat $pid)" |
| 61 | echo $pid |
| 62 | # Forcefully killing model process does not show statistical |
| 63 | # data (Host CPU time spent running in User and System). Safely |
| 64 | # kill the model by using SIGINT(^C) that helps in printing |
| 65 | # statistical data. |
| 66 | if [ "$pid" == "$model_pid" ] && [ "${COVERAGE_ON}" != "1" ]; then |
| 67 | model_cid=$(pgrep -P "$model_pid" | xargs || true) |
| 68 | if [ -z "$model_cid" ]; then |
| 69 | echo "Model quit by itself. Not killing!" |
| 70 | continue |
Manish V Badarkhe | 359b3ff | 2020-12-25 18:54:03 +0000 | [diff] [blame] | 71 | fi |
Harrison Mutai | 5d66de3 | 2022-10-19 11:36:30 +0100 | [diff] [blame] | 72 | |
Boyan Karatotev | 40fa01a | 2025-07-29 14:18:02 +0100 | [diff] [blame^] | 73 | # ignore errors |
| 74 | kill -SIGINT "$model_cid" &>/dev/null || true |
| 75 | # Allow some time to print data, we can't use wait since the process is |
| 76 | # a child of the daemonized launch process. |
| 77 | sleep 5 |
| 78 | fi |
Harrison Mutai | 5d66de3 | 2022-10-19 11:36:30 +0100 | [diff] [blame] | 79 | |
Boyan Karatotev | 40fa01a | 2025-07-29 14:18:02 +0100 | [diff] [blame^] | 80 | kill_and_reap "$pid" |
| 81 | |
| 82 | done < <(find -name '*.pid') |
Manish V Badarkhe | 359b3ff | 2020-12-25 18:54:03 +0000 | [diff] [blame] | 83 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 84 | popd |
| 85 | } |
| 86 | |
| 87 | # Launch a program. Have its PID saved in a file with given name with .pid |
| 88 | # suffix. When the program exits, create a file with .success suffix, or one |
| 89 | # with .fail if it fails. This function blocks, so the caller must '&' this if |
| 90 | # they want to continue. Call must wait for $pid_dir/$name.pid to be created |
| 91 | # should it want to read it. |
| 92 | launch() { |
| 93 | local pid |
| 94 | |
| 95 | "$@" & |
| 96 | pid="$!" |
| 97 | echo "$pid" > "$pid_dir/${name:?}.pid" |
| 98 | if wait "$pid"; then |
| 99 | touch "$pid_dir/$name.success" |
| 100 | else |
| 101 | touch "$pid_dir/$name.fail" |
| 102 | fi |
| 103 | } |
| 104 | |
Manish V Badarkhe | 359b3ff | 2020-12-25 18:54:03 +0000 | [diff] [blame] | 105 | # Provide signal as an argument to the trap function. |
| 106 | trap_with_sig() { |
| 107 | local func |
| 108 | |
| 109 | func="$1" ; shift |
| 110 | for sig ; do |
| 111 | trap "$func $sig" "$sig" |
| 112 | done |
| 113 | } |
| 114 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 115 | # Cleanup actions |
Manish V Badarkhe | 359b3ff | 2020-12-25 18:54:03 +0000 | [diff] [blame] | 116 | trap_with_sig cleanup SIGINT SIGHUP SIGTERM EXIT |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 117 | |
| 118 | # Prevent xterm windows from untracked terminals from popping up, especially |
| 119 | # when running locally |
| 120 | not_upon "$test_run" && export DISPLAY= |
| 121 | |
| 122 | # Source variables required for run |
| 123 | source "$artefacts/env" |
| 124 | |
| 125 | echo |
| 126 | echo "RUNNING: $TEST_CONFIG" |
| 127 | echo |
| 128 | |
| 129 | # Accept BIN_MODE from environment, or default to release. If bin_mode is set |
| 130 | # and non-empty (intended to be set from command line), that takes precedence. |
| 131 | pkg_bin_mode="${BIN_MODE:-release}" |
| 132 | bin_mode="${bin_mode:-$pkg_bin_mode}" |
| 133 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 134 | # Whether to display primary UART progress live on the console |
| 135 | primary_live="${primary_live-$PRIMARY_LIVE}" |
| 136 | |
| 137 | # Change directory so that all binaries can be accessed realtive to where they |
| 138 | # lie |
| 139 | run_cwd="$artefacts/$bin_mode" |
| 140 | cd "$run_cwd" |
| 141 | |
| 142 | # Source environment for run |
| 143 | if [ -f "run/env" ]; then |
| 144 | source "run/env" |
| 145 | fi |
| 146 | |
Zelalem | 1af7a7b | 2020-08-04 17:34:32 -0500 | [diff] [blame] | 147 | # Source model environment for run |
| 148 | if [ -f "run/model_env" ]; then |
| 149 | source "run/model_env" |
| 150 | fi |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 151 | # Fail if there was no model path set |
| 152 | if [ -z "$model_path" ]; then |
| 153 | die "No model path set by package!" |
| 154 | fi |
| 155 | |
| 156 | # Launch model with parameters |
| 157 | model_out="$run_root/model_log.txt" |
| 158 | run_sh="$run_root/run.sh" |
| 159 | |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 160 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 161 | # Generate run.sh |
| 162 | echo "$model_path \\" > "$run_sh" |
| 163 | sed '/^\s*$/d' < model_params | sort | sed 's/^/\t/;s/$/ \\/' >> "$run_sh" |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 164 | |
| 165 | if [ "${COVERAGE_ON}" == "1" ]; then |
| 166 | # Adding code coverage plugin |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 167 | echo -e "\t--plugin $coverage_trace_plugin \\" >> "$run_sh" |
| 168 | fi |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 169 | echo -e "\t\"\$@\"" >> "$run_sh" |
| 170 | |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 171 | # Running Reboot/Shutdown tests requires storing the state in non-volatile |
| 172 | # memory(NVM) across reboot. On FVP, NVM is not persistent across reboot, hence |
| 173 | # NVM was saved to a file($NVM_file) when running the model using the run.sh |
| 174 | # shell script. |
| 175 | # If TFTF Reboot/Shutdown tests are enabled, run the fvp model 10 times by |
| 176 | # feeding the file containing NVM state generated from the previous run. Note |
| 177 | # that this file also includes FIP image. |
| 178 | |
| 179 | if upon "$run_tftf_reboot_tests" = "1"; then |
| 180 | tftf_reboot_tests="$run_root/tftf_reboot_tests.sh" |
| 181 | |
| 182 | # Generate tftf_reboot_tests command. It is similar to run_sh. |
| 183 | # The model would run the reboot and shutdown tests 10 times |
| 184 | # The uart log file generated by FVP model gets overwritten |
| 185 | # across reboots. Copy its contents at the end of the test |
| 186 | echo "cat $uart0_file >> UART0.log" >>"$tftf_reboot_tests" |
| 187 | echo "cat $uart1_file >> UART1.log" >>"$tftf_reboot_tests" |
| 188 | cat <<EOF >>"$tftf_reboot_tests" |
| 189 | |
| 190 | for i in {1..10} |
| 191 | do |
| 192 | EOF |
| 193 | cat "$run_sh" >> "$tftf_reboot_tests" |
| 194 | echo "cat $uart0_file >> UART0.log" >>"$tftf_reboot_tests" |
| 195 | echo "cat $uart1_file >> UART1.log" >>"$tftf_reboot_tests" |
| 196 | cat <<EOF >>"$tftf_reboot_tests" |
| 197 | done |
| 198 | EOF |
| 199 | #Replace fip.bin with file $NVM_file |
| 200 | sed -i 's/fip.bin/'"$NVM_file"'/' "$tftf_reboot_tests" |
| 201 | |
| 202 | echo "TFTF Reboot/Shutdown Tests Enabled" |
| 203 | cat "$tftf_reboot_tests" >> "$run_sh" |
| 204 | rm "$tftf_reboot_tests" |
| 205 | fi |
| 206 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 207 | echo "Model command line:" |
| 208 | echo |
| 209 | cat "$run_sh" |
| 210 | chmod +x "$run_sh" |
| 211 | echo |
| 212 | |
| 213 | # If it's a test run, skip all the hoops and launch model directly. |
| 214 | if upon "$test_run"; then |
| 215 | "$run_sh" "$@" |
| 216 | exit 0 |
| 217 | fi |
| 218 | |
| 219 | # For an automated run, export a known variable so that we can identify stale |
| 220 | # processes spawned by Trusted Firmware CI by inspecting its environment. |
| 221 | export TRUSTED_FIRMWARE_CI="1" |
| 222 | |
| 223 | # Change directory to workspace, as all artifacts paths are relative to |
| 224 | # that, and launch the model. Have model use no buffering on stdout |
| 225 | : >"$model_out" |
| 226 | name="model" launch stdbuf -o0 -e0 "$run_sh" &>"$model_out" & |
| 227 | wait_count=0 |
| 228 | while :; do |
| 229 | if [ -f "$pid_dir/model.pid" ]; then |
| 230 | break |
| 231 | fi |
| 232 | sleep 0.1 |
| 233 | |
| 234 | let "wait_count += 1" |
| 235 | if [ "$wait_count" -gt 100 ]; then |
| 236 | die "Failed to launch model!" |
| 237 | fi |
| 238 | done |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 239 | |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 240 | model_pid="$(cat $pid_dir/model.pid)" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 241 | |
| 242 | # Start a watchdog to kill ourselves if we wait too long for the model |
| 243 | # response. Note that this is not the timeout for the whole test, but only for |
| 244 | # the Model to output port numbers. |
| 245 | ( |
| 246 | if upon "$jenkins_run"; then |
| 247 | # Increase this timeout for a cluster run, as it could take longer if |
| 248 | # the load on the Jenkins server is high. |
| 249 | model_wait_timeout=120 |
| 250 | else |
| 251 | model_wait_timeout=30 |
| 252 | fi |
| 253 | sleep $model_wait_timeout |
| 254 | echo "Model wait timeout!" |
| 255 | kill "$$" |
| 256 | ) & |
| 257 | watchdog="$!" |
| 258 | |
Chris Kay | 03ffbe7 | 2022-11-17 18:53:50 +0000 | [diff] [blame] | 259 | ports_output="$(mktempfile)" |
| 260 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 261 | # Parse UARTs ports from early model output. Send a SIGSTOP to the model |
| 262 | # as soon as it outputs all UART ports. This is to prevent the model |
| 263 | # executing before the expect scripts get a chance to connect to the |
| 264 | # UART thereby losing messages. |
| 265 | model_fail=1 |
| 266 | while :; do |
Chris Kay | 03ffbe7 | 2022-11-17 18:53:50 +0000 | [diff] [blame] | 267 | awk -v "num_uarts=$(get_num_uarts "${run_cwd}")" \ |
| 268 | -f "$(get_ports_script "${run_cwd}")" "$model_out" > "$ports_output" |
| 269 | if [ $(wc -l < "$ports_output") -eq "$(get_num_uarts "${run_cwd}")" ]; then |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 270 | kill -SIGSTOP "$model_pid" |
| 271 | model_fail=0 |
| 272 | break |
| 273 | fi |
| 274 | |
| 275 | # Bail out if model exited meanwhile |
| 276 | if ! kill -0 "$model_pid" &>/dev/null; then |
| 277 | echo "Model terminated unexpectedly!" |
| 278 | break |
| 279 | fi |
| 280 | done |
| 281 | |
| 282 | # Kill the watch dog |
| 283 | kill_and_reap "$watchdog" || true |
| 284 | |
| 285 | # Check the model had failed meanwhile, for some reason |
| 286 | if [ "$model_fail" -ne 0 ]; then |
| 287 | exit 1 |
| 288 | fi |
| 289 | |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 290 | if ! [ -x "$(command -v expect)" ]; then |
| 291 | echo "Error: Expect is not installed." |
| 292 | exit 1 |
| 293 | fi |
| 294 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 295 | # The wait loop above exited after model port numbers have been parsed. The |
| 296 | # script's output is ready to be sourced now. |
| 297 | declare -a ports |
| 298 | source "$ports_output" |
| 299 | rm -f "$ports_output" |
Chris Kay | 03ffbe7 | 2022-11-17 18:53:50 +0000 | [diff] [blame] | 300 | if [ "${#ports[@]}" -ne "$(get_num_uarts "${run_cwd}")" ]; then |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 301 | echo "Failed to get UART port numbers" |
| 302 | kill_and_reap "$model_pid" |
| 303 | unset model_pid |
| 304 | fi |
| 305 | |
| 306 | # Launch expect scripts for all UARTs |
| 307 | uarts=0 |
Chris Kay | 03ffbe7 | 2022-11-17 18:53:50 +0000 | [diff] [blame] | 308 | for u in $(seq 0 $(( "$(get_num_uarts "${run_cwd}")" - 1 )) | tac); do |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 309 | script="run/uart$u/expect" |
| 310 | if [ -f "$script" ]; then |
| 311 | script="$(cat "$script")" |
| 312 | else |
| 313 | script= |
| 314 | fi |
| 315 | |
| 316 | # Primary UART must have a script |
| 317 | if [ -z "$script" ]; then |
Chris Kay | 03ffbe7 | 2022-11-17 18:53:50 +0000 | [diff] [blame] | 318 | if [ "$u" = "$(get_primary_uart "${run_cwd}")" ]; then |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 319 | die "No primary UART script!" |
| 320 | else |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 321 | echo "Ignoring UART$u (no expect script provided)." |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 322 | continue |
| 323 | fi |
| 324 | fi |
| 325 | |
| 326 | timeout="run/uart$u/timeout" |
| 327 | if [ -f "$timeout" ]; then |
| 328 | timeout="$(cat "$timeout")" |
| 329 | else |
| 330 | timeout= |
| 331 | fi |
Saul Romero | d54b6eb | 2020-10-20 09:03:08 +0100 | [diff] [blame] | 332 | timeout="${timeout-1200}" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 333 | |
| 334 | full_log="$run_root/uart${u}_full.txt" |
| 335 | |
Chris Kay | 03ffbe7 | 2022-11-17 18:53:50 +0000 | [diff] [blame] | 336 | if [ "$u" = "$(get_primary_uart "${run_cwd}")" ]; then |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 337 | star="*" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 338 | else |
| 339 | star=" " |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 340 | fi |
| 341 | |
Madhukar Pappireddy | 1e95372 | 2021-11-08 15:23:02 -0600 | [diff] [blame] | 342 | uart_name="uart$u" |
| 343 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 344 | # Launch expect after exporting required variables |
| 345 | ( |
| 346 | if [ -f "run/uart$u/env" ]; then |
| 347 | set -a |
| 348 | source "run/uart$u/env" |
| 349 | set +a |
| 350 | fi |
| 351 | |
Chris Kay | 03ffbe7 | 2022-11-17 18:53:50 +0000 | [diff] [blame] | 352 | if [ "$u" = "$(get_primary_uart "${run_cwd}")" ] && upon "$primary_live"; then |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 353 | uart_port="${ports[$u]}" timeout="$timeout" \ |
| 354 | name="$uart_name" launch expect -f "$ci_root/expect/$script" | \ |
| 355 | tee "$full_log" |
| 356 | echo |
| 357 | else |
| 358 | uart_port="${ports[$u]}" timeout="$timeout" \ |
| 359 | name="$uart_name" launch expect -f "$ci_root/expect/$script" \ |
| 360 | &>"$full_log" |
| 361 | fi |
| 362 | |
| 363 | ) & |
| 364 | |
| 365 | let "uarts += 1" |
| 366 | echo "Tracking UART$u$star with $script; timeout $timeout." |
| 367 | done |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 368 | # Wait here long 'enough' for expect scripts to connect to ports; then |
| 369 | # let the model proceed |
| 370 | sleep 2 |
| 371 | kill -SIGCONT "$model_pid" |
| 372 | |
| 373 | # Wait for all children. Note that the wait below is *not* a timed wait. |
| 374 | result=0 |
| 375 | |
| 376 | set +e |
| 377 | pushd "$pid_dir" |
Chris Kay | 23f5869 | 2022-11-03 14:01:43 +0000 | [diff] [blame] | 378 | |
| 379 | timeout=3600 |
| 380 | |
| 381 | echo |
| 382 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 383 | while :; do |
Chris Kay | 23f5869 | 2022-11-03 14:01:43 +0000 | [diff] [blame] | 384 | readarray -d '' all < <(find "${pid_dir}" -name 'uart*.pid' -print0) |
| 385 | readarray -d '' succeeded < <(find "${pid_dir}" -name 'uart*.success' -print0) |
| 386 | readarray -d '' failed < <(find "${pid_dir}" -name 'uart*.fail' -print0) |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 387 | |
Chris Kay | 23f5869 | 2022-11-03 14:01:43 +0000 | [diff] [blame] | 388 | all=("${all[@]##${pid_dir}/uart}") |
| 389 | all=("${all[@]%%.pid}") |
| 390 | |
| 391 | succeeded=("${succeeded[@]##${pid_dir}/uart}") |
| 392 | succeeded=("${succeeded[@]%%.success}") |
| 393 | |
| 394 | failed=("${failed[@]##${pid_dir}/uart}") |
| 395 | failed=("${failed[@]%%.fail}") |
| 396 | |
| 397 | completed=("${succeeded[@]}" "${failed[@]}") |
| 398 | |
| 399 | readarray -t remaining < <( \ |
| 400 | comm -23 \ |
| 401 | <(printf '%s\n' "${all[@]}" | sort) \ |
| 402 | <(printf '%s\n' "${completed[@]}" | sort) \ |
| 403 | ) |
| 404 | |
| 405 | if [ ${#remaining[@]} = 0 ]; then |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 406 | break |
| 407 | fi |
| 408 | |
Chris Kay | 23f5869 | 2022-11-03 14:01:43 +0000 | [diff] [blame] | 409 | echo "Waiting ${timeout}s for ${#remaining[@]} UART(s): ${remaining[@]}" |
| 410 | |
Chris Kay | 03ffbe7 | 2022-11-17 18:53:50 +0000 | [diff] [blame] | 411 | if [[ " ${completed[@]} " =~ " $(get_payload_uart "${run_cwd}") " ]]; then |
| 412 | echo "- Payload (UART $(get_payload_uart "${run_cwd}")) completed!" |
Chris Kay | 23f5869 | 2022-11-03 14:01:43 +0000 | [diff] [blame] | 413 | |
| 414 | for uart in "${remaining[@]}"; do |
| 415 | pid=$(cat "${pid_dir}/uart${uart}.pid") |
| 416 | |
| 417 | echo "- Terminating UART ${uart} script (PID ${pid})..." |
| 418 | |
| 419 | kill -SIGINT ${pid} || true # Send Ctrl+C - don't force-kill it! |
| 420 | done |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 421 | fi |
Chris Kay | 23f5869 | 2022-11-03 14:01:43 +0000 | [diff] [blame] | 422 | |
| 423 | if [ ${timeout} = 0 ]; then |
| 424 | echo "- Timeout exceeded! Killing model (PID ${model_pid})..." |
| 425 | |
| 426 | kill_and_reap "${model_pid}" |
| 427 | fi |
| 428 | |
| 429 | timeout=$((${timeout} - 5)) && sleep 5 |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 430 | done |
Chris Kay | 23f5869 | 2022-11-03 14:01:43 +0000 | [diff] [blame] | 431 | |
| 432 | echo |
| 433 | |
| 434 | if [ ${#failed[@]} != 0 ]; then |
| 435 | echo "${#failed[@]} UART(s) did not match expectations:" |
| 436 | echo |
| 437 | |
| 438 | for uart in "${failed[@]}"; do |
| 439 | echo " - UART ${uart}: uart${uart}_full.txt" |
| 440 | done |
| 441 | |
| 442 | echo |
| 443 | |
| 444 | result=1 |
| 445 | fi |
| 446 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 447 | popd |
| 448 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 449 | if [ "$result" -eq 0 ]; then |
| 450 | echo "Test success!" |
| 451 | else |
| 452 | echo "Test failed!" |
| 453 | fi |
| 454 | |
| 455 | if upon "$jenkins_run"; then |
| 456 | echo |
| 457 | echo "Artefacts location: $BUILD_URL." |
| 458 | echo |
| 459 | fi |
| 460 | |
| 461 | if upon "$jenkins_run" && upon "$artefacts_receiver" && [ -d "$workspace/run" ]; then |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 462 | source "$CI_ROOT/script/send_artefacts.sh" "run" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 463 | fi |
| 464 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 465 | |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 466 | exit "$result" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 467 | # vim: set tw=80 sw=8 noet: |