refactor(tfut): move common run code to a shared file
Some existing functions used in existing TF-A tests are re-used for
unit tests. In order to avoid code duplication, these functions were
moved to a common file.
Signed-off-by: Juan Pablo Conde <juanpablo.conde@arm.com>
Signed-off-by: Edward Potapov <edward.potapov@arm.com>
Change-Id: Ic4c507fa457333b6a70824050df28420a3f1c7c5
diff --git a/script/run_common.sh b/script/run_common.sh
new file mode 100644
index 0000000..063b8c3
--- /dev/null
+++ b/script/run_common.sh
@@ -0,0 +1,34 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2024, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+# Launch a program. Have its PID saved in a file with given name with .pid
+# suffix. When the program exits, create a file with .success suffix, or one
+# with .fail if it fails. This function blocks, so the caller must '&' this if
+# they want to continue. Call must wait for $pid_dir/$name.pid to be created
+# should it want to read it.
+launch() {
+ 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
+}
+
+# Provide signal as an argument to the trap function.
+trap_with_sig() {
+ local func
+
+ func="$1" ; shift
+ for sig ; do
+ trap "$func $sig" "$sig"
+ done
+}
diff --git a/script/run_package.sh b/script/run_package.sh
index 60ebcb7..b89c4a6 100755
--- a/script/run_package.sh
+++ b/script/run_package.sh
@@ -11,7 +11,7 @@
# group. That way, we can kill a background process group in one go.
set -m
ci_root="$(readlink -f "$(dirname "$0")/..")"
-source "$ci_root/utils.sh"
+source "$ci_root/script/run_common.sh"
artefacts="${artefacts-$workspace/artefacts}"
@@ -84,34 +84,6 @@
popd
}
-# Launch a program. Have its PID saved in a file with given name with .pid
-# suffix. When the program exits, create a file with .success suffix, or one
-# with .fail if it fails. This function blocks, so the caller must '&' this if
-# they want to continue. Call must wait for $pid_dir/$name.pid to be created
-# should it want to read it.
-launch() {
- 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
-}
-
-# Provide signal as an argument to the trap function.
-trap_with_sig() {
- local func
-
- func="$1" ; shift
- for sig ; do
- trap "$func $sig" "$sig"
- done
-}
-
# Cleanup actions
trap_with_sig cleanup SIGINT SIGHUP SIGTERM EXIT