diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 11:36:04 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 11:36:04 +0000 |
commit | 040eee1aa49b49df4698d83a05af57c220127fd1 (patch) | |
tree | f635435954e6ccde5eee9893889e24f30ca68346 /src/lib/asiolink/tests/process_spawn_app.sh.in | |
parent | Initial commit. (diff) | |
download | isc-kea-upstream.tar.xz isc-kea-upstream.zip |
Adding upstream version 2.2.0.upstream/2.2.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/lib/asiolink/tests/process_spawn_app.sh.in')
-rw-r--r-- | src/lib/asiolink/tests/process_spawn_app.sh.in | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/src/lib/asiolink/tests/process_spawn_app.sh.in b/src/lib/asiolink/tests/process_spawn_app.sh.in new file mode 100644 index 0000000..eab7310 --- /dev/null +++ b/src/lib/asiolink/tests/process_spawn_app.sh.in @@ -0,0 +1,75 @@ +#!/bin/sh + +# Copyright (C) 2015-2021 Internet Systems Consortium, Inc. ("ISC") +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + + +# This script is used for testing the ProcessSpawn utility class. This +# class is used to fork and execute a new process. It also allows for +# checking the exit code returned when the process terminates. +# The unit tests execute this script via ProcessSpawn class with +# different command line parameters to test the class functionality. +# +# In particular, they check if the class correctly records the exit code +# returned. The exit code returned is controlled by the caller. It is +# possible to explicitly specify the exit code to be returned using +# the command line options. It is also possible to specify that the +# exit code is "unique" for the process, so as the test can check +# that two distinct processes spawned by the same ProcessSpawn +# object may return different status code. The command line of this +# script also allows for forcing the process to sleep so as the +# test has much enough time to verify that the convenience methods +# checking the state of the process, i.e. process running or not. + +# Exit with error if commands exit with non-zero and if undefined variables are +# used. +set -eu + +exit_code= + +while test "${#}" -gt 0 +do + option=${1} + case ${option} in + -p) + exit_code=${$} + ;; + -e) + shift + exit_code=${1-} + ;; + -s) + shift + sleep "${1}" + ;; + -v) + shift + VAR_NAME=${1} + shift + VAR_VALUE=${1} + EXPECTED=$(env | grep -E "^${VAR_NAME}=") + if ! test "${VAR_NAME}=${VAR_VALUE}" = "${EXPECTED}"; then + exit 123 + fi + ;; + *) + exit 123 + ;; + esac + # We've shifted in the loop so we may have run out of parameters in the + # meantime. Check again. + if test "${#}" -gt 0; then + shift + fi +done + +# The exit code of 32 is returned when no args specified or +# when only the -s arg has been specified. +if [ -z "${exit_code}" ]; then + exit 32 +fi + +exit "${exit_code}" |