diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 17:20:00 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 17:20:00 +0000 |
commit | 8daa83a594a2e98f39d764422bfbdbc62c9efd44 (patch) | |
tree | 4099e8021376c7d8c05bdf8503093d80e9c7bad0 /ctdb/tests/UNIT/cunit/run_proc_001.sh | |
parent | Initial commit. (diff) | |
download | samba-8daa83a594a2e98f39d764422bfbdbc62c9efd44.tar.xz samba-8daa83a594a2e98f39d764422bfbdbc62c9efd44.zip |
Adding upstream version 2:4.20.0+dfsg.upstream/2%4.20.0+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rwxr-xr-x | ctdb/tests/UNIT/cunit/run_proc_001.sh | 159 |
1 files changed, 159 insertions, 0 deletions
diff --git a/ctdb/tests/UNIT/cunit/run_proc_001.sh b/ctdb/tests/UNIT/cunit/run_proc_001.sh new file mode 100755 index 0000000..3f48885 --- /dev/null +++ b/ctdb/tests/UNIT/cunit/run_proc_001.sh @@ -0,0 +1,159 @@ +#!/bin/sh + +. "${TEST_SCRIPTS_DIR}/unit.sh" + +# Invalid path +ok <<EOF +Process exited with error $(errcode ENOENT) +EOF +unit_test run_proc_test 0 -1 /a/b/c + +# Non-executable path +prog=$(TMPDIR="$CTDB_TEST_TMP_DIR" mktemp) +cat > "$prog" <<EOF +echo hello +EOF + +ok <<EOF +Process exited with error $(errcode EACCES) +EOF +unit_test run_proc_test 0 -1 "$prog" + +# Executable path +chmod +x "$prog" + +ok <<EOF +Process exited with error $(errcode ENOEXEC) +EOF +unit_test run_proc_test 0 -1 "$prog" + +# Capture output +cat > "$prog" <<EOF +#!/bin/sh +echo hello +EOF + +ok <<EOF +Process exited with status 0 +Output = (hello +) +EOF +unit_test run_proc_test 0 -1 "$prog" + +# Specify timeout +ok <<EOF +Process exited with status 0 +Output = (hello +) +EOF +unit_test run_proc_test 5 -1 "$prog" + +# Redirected output +output=$(TMPDIR="$CTDB_TEST_TMP_DIR" mktemp) +cat > "$prog" <<EOF +#!/bin/sh +exec >"$output" 2>&1 +echo hello +EOF + +ok <<EOF +Process exited with status 0 +EOF +unit_test run_proc_test 0 -1 "$prog" + +ok <<EOF +hello +EOF +unit_test cat "$output" + +# Exit with error +cat > "$prog" <<EOF +#!/bin/sh +exit 1 +EOF + +ok <<EOF +Process exited with status 1 +EOF +unit_test run_proc_test 0 -1 "$prog" + +# Exit with signal +cat > "$prog" <<EOF +#!/bin/sh +kill \$$ +EOF + +ok <<EOF +Process exited with signal 15 +EOF +unit_test run_proc_test 0 -1 "$prog" + +# Exit with timeout +cat > "$prog" <<EOF +#!/bin/sh +echo "Sleeping for 5 seconds" +sleep 5 +EOF + +result_filter () +{ + _pid="[0-9][0-9]*" + sed -e "s|= ${_pid}|= PID|" +} + +ok <<EOF +Process exited with error $(errcode ETIMEDOUT) +Child = PID +Output = (Sleeping for 5 seconds +) +EOF +unit_test run_proc_test 1 -1 "$prog" + +# No zombie processes +pidfile=$(TMPDIR="$CTDB_TEST_TMP_DIR" mktemp) + +cat > "$prog" <<EOF +#!/bin/sh +echo \$$ > "$pidfile" +sleep 10 +EOF + +ok <<EOF +Process exited with error $(errcode ETIMEDOUT) +Child = PID +EOF +unit_test run_proc_test 1 -1 "$prog" + +result_filter () +{ + _header=" *PID *TTY *TIME *CMD" + _header2=" *PID *TT *STAT *TIME *COMMAND" + sed -e "s|^${_header}|HEADER|" -e "s|^${_header2}|HEADER|" +} + +pid=$(cat "$pidfile") +required_result 1 <<EOF +HEADER +EOF +unit_test ps -p "$pid" + +# Redirect stdin +cat > "$prog" <<EOF +#!/bin/sh +cat - +EOF + +cat > "$output" <<EOF +this is sample input +EOF + +ok <<EOF +Process exited with status 0 +Output = (this is sample input +) +EOF +(unit_test run_proc_test 0 4 "$prog") 4<"$output" + +rm -f "$pidfile" +rm -f "$output" +rm -f "$prog" |