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