From 3d01728d2e1c9b13dcd16953d4a1518cf48da8ad Mon Sep 17 00:00:00 2001 From: Magnus Malm Date: Mon, 22 Feb 2021 23:46:40 +0100 Subject: [PATCH] test: Add testenv_enter.sh to ease debugging testenv The script testenv_enter.sh, by default, runs /bin/sh in the environment currently setup. A bit easier than copy pasting the old hint text printed before test run. Signed-off-by: Magnus Malm --- test/lib.sh | 2 ++ test/testenv_enter.sh | 23 +++++++++++++++++++++++ test/testenv_start.sh | 2 +- 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100755 test/testenv_enter.sh diff --git a/test/lib.sh b/test/lib.sh index 953525a5..c87ccd5a 100755 --- a/test/lib.sh +++ b/test/lib.sh @@ -83,6 +83,7 @@ teardown() { texec kill -SIGUSR2 1 wait + rm "$TEST_DIR"/running_test.pid } trap teardown EXIT @@ -98,6 +99,7 @@ log "$color_reset" '--' '' # Setup "$TEST_DIR/testenv_start.sh" finit & finit_ppid=$! +echo "$finit_ppid" > "$TEST_DIR"/running_test.pid finit_pid=$(retry "pgrep -P $finit_ppid") tty=/dev/$(texec cat /sys/class/tty/console/active) diff --git a/test/testenv_enter.sh b/test/testenv_enter.sh new file mode 100755 index 00000000..a2507928 --- /dev/null +++ b/test/testenv_enter.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +set -eu + +cmd="" +if [ "$#" -lt 1 ]; then + cmd="/bin/sh" +else + cmd=$1 + shift +fi + +PID_FILE=$(dirname "$0")/running_test.pid + +if [ -f "$PID_FILE" ] ; then + target=$(cat "$PID_FILE") + target=$(pgrep -P "$target") +else + echo "No test running!" + exit 1 +fi + +"$(dirname "$0")"/testenv_exec.sh "$target" "$cmd" "$@" diff --git a/test/testenv_start.sh b/test/testenv_start.sh index 5c8cee8d..db529429 100755 --- a/test/testenv_start.sh +++ b/test/testenv_start.sh @@ -5,7 +5,7 @@ set -eu TEST_DIR=$(dirname "$0") TESTS_ROOT="$(pwd)/${TEST_DIR}/test_root" ->&2 echo "Hint: Execute '${TEST_DIR}/testenv_exec.sh \$(pgrep -P $$) /bin/sh; reset' to enter the test namespace" +>&2 echo "Hint: Execute 'test/testenv_enter.sh' to enter the test namespace" unshare=$(command -v unshare) chroot=$(command -v chroot)