feat(tfut): handle test interruption properly
When tests are run locally and the execution is interrupted by the
user, if tests keep running (e.g.: infinite loops, models not
terminating properly), the script keeps waiting for test
termination, as it receives the interruption signal (e.g. Ctrl+C)
but waits for the test to terminate, which may never happen.
This patch addresses that issue by properly addressing test
termination upon interruption or script failure.
Signed-off-by: Juan Pablo Conde <juanpablo.conde@arm.com>
Signed-off-by: Edward Potapov <edward.potapov@arm.com>
Change-Id: I1739f3a95736bb65d93e7b63d765cf345cb75250
diff --git a/script/run_common.sh b/script/run_common.sh
index 063b8c3..c87ecce 100644
--- a/script/run_common.sh
+++ b/script/run_common.sh
@@ -11,16 +11,22 @@
# they want to continue. Call must wait for $pid_dir/$name.pid to be created
# should it want to read it.
launch() {
- local pid
+ local pid
- "$@" &
- pid="$!"
- echo "$pid" > "$pid_dir/${name:?}.pid"
- if wait "$pid"; then
- touch "$pid_dir/$name.success"
- else
- touch "$pid_dir/$name.fail"
- fi
+ "$@" &
+ pid="$!"
+ echo "$pid" > "$pid_dir/${name:?}.pid"
+
+ # If the execution is halted, handle the process termination properly,
+ # so the caller does not keep looping waiting for the result file to be
+ # generated.
+ trap "{ touch \"$pid_dir/$name.fail\"; exit 1 }" SIGINT SIGHUP SIGTERM
+
+ if wait "$pid"; then
+ touch "$pid_dir/$name.success"
+ else
+ touch "$pid_dir/$name.fail"
+ fi
}
# Provide signal as an argument to the trap function.