diff options
author | Daniel Wagner <wagi@monom.org> | 2019-07-31 16:26:40 +0200 |
---|---|---|
committer | Daniel Wagner <dwagner@suse.de> | 2020-08-27 21:12:23 +0200 |
commit | 3da70643414b3debfed10a6cf0cbc093c262a463 (patch) | |
tree | 195d15329288b0dac49f49103ba604ecfc6fc1a9 /automated | |
parent | 4a22baaf9de0b48f55612330dfd6e3b25036048b (diff) |
sh-test-lib: Add background process control functions
Allow test to start and stop background processes.
Instead just using lava's version of the background process script we
use our own version in order to avoid dependencies on lava.
Signed-off-by: Daniel Wagner <wagi@monom.org>
Diffstat (limited to 'automated')
-rwxr-xr-x | automated/lib/sh-test-lib | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/automated/lib/sh-test-lib b/automated/lib/sh-test-lib index b611381..161611f 100755 --- a/automated/lib/sh-test-lib +++ b/automated/lib/sh-test-lib @@ -565,3 +565,64 @@ format_partitions() { sleep 5 done } + +background_process_start() { + NAME="$1" + shift + if [ -z "$NAME" ]; then + err_msg "Usage: background-process-start NAME --cmd PROCESS" + fi + + while [ $# -gt 0 ]; do + case $1 in + --cmd) + shift + PROCESS="$*" + shift + ;; + *) + err_msg "Unhandled argument" + ;; + esac + done + + if [ -z "${PROCESS}" ]; then + return + fi + + result_dir="${OUTPUT}/results/$NAME" + mkdir -p "${result_dir}" + + cat <<EOF > "${result_dir}/bg_run.sh" +set -e +trap "exit" SIGHUP SIGINT SIGTERM +while true; do + $PROCESS > /dev/null + sleep 1 +done +EOF + + /bin/bash "${result_dir}/bg_run.sh" & + echo $! > "${result_dir}/pid" +} + +background_process_stop() { + NAME="$1" + shift + if [ -z "${NAME}" ]; then + err_msg "Usage: background-process-stop NAME" + fi + + result_dir="${OUTPUT}/results/${NAME}" + + if [ ! -d "${result_dir}" ] ; then + return + fi + + PID=$(cat "${result_dir}/pid") + + if ps -p "${PID}" > /dev/null; + then + kill "${PID}" > /dev/null 2>&1 + fi +} |