zephyr/tests/bsim/sh_common.source
Jonathan Rico 098b5bd05b tests: bsim: send SIGKILL if app doesn't respond to SIGTERM
I have seen the CI hang (both downstream and upstream) as the executable
doesn't always respond to the SIGTERM sent by `timeout`.

This will prevent that behavior. 5 whole seconds ought to be enough to
clean-up a small program.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2023-10-20 15:07:58 +02:00

48 lines
1 KiB
Plaintext

# Copyright 2023 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0
_process_ids="";
#All user scripts require these variable, let's check for them here already
: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}"
#Give a default value to BOARD if it does not have one yet:
BOARD="${BOARD:-nrf52_bsim}"
function run_in_background(){
$@ & _process_ids="$_process_ids $!"
}
function wait_for_background_jobs(){
exit_code=0
for process_id in $_process_ids; do
wait $process_id || let "exit_code=$?"
done
[ $exit_code -eq 0 ] || exit $exit_code
}
trap ctrl_c INT
function ctrl_c() {
echo "Aborted by CTRL-C"
for process_id in $_process_ids; do
kill -15 $process_id
done
}
function check_program_exists() {
if [ ! -f $1 ]; then
echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\
compile it?)\e[39m"
exit 1
fi
}
function Execute() {
EXECUTE_TIMEOUT="${EXECUTE_TIMEOUT:-30}"
check_program_exists $1
run_in_background timeout --kill-after=5 -v ${EXECUTE_TIMEOUT} $@
}