public inbox for util-linux@vger.kernel.org
 help / color / mirror / Atom feed
From: Kiran Rangoon <kiranrangoon0@gmail.com>
To: util-linux@vger.kernel.org
Cc: kzak@redhat.com, Kiran Rangoon <kiranrangoon0@gmail.com>
Subject: [Patch V3 4/4] tests: add tests for unshare --forward-signals
Date: Fri, 16 Jan 2026 12:06:48 -0500	[thread overview]
Message-ID: <20260116170648.26439-5-kiranrangoon0@gmail.com> (raw)
In-Reply-To: <20260116170648.26439-1-kiranrangoon0@gmail.com>

Add two test cases for the new --forward-signals option:
- forward-signals: verifies SIGTERM is forwarded to child
- forward-signals-kill-child: verifies compatibility with --kill-child

Both tests use test_sigreceive which exits with the signal number
received, confirming proper signal forwarding.

Signed-off-by: Kiran Rangoon <kiranrangoon0@gmail.com>
---
 tests/expected/unshare/forward-signals        |  1 +
 .../unshare/forward-signals-kill-child        |  1 +
 tests/ts/unshare/forward-signals              | 73 ++++++++++++++++++
 tests/ts/unshare/forward-signals-kill-child   | 74 +++++++++++++++++++
 4 files changed, 149 insertions(+)
 create mode 100644 tests/expected/unshare/forward-signals
 create mode 100644 tests/expected/unshare/forward-signals-kill-child
 create mode 100755 tests/ts/unshare/forward-signals
 create mode 100755 tests/ts/unshare/forward-signals-kill-child

diff --git a/tests/expected/unshare/forward-signals b/tests/expected/unshare/forward-signals
new file mode 100644
index 000000000..868dab6e1
--- /dev/null
+++ b/tests/expected/unshare/forward-signals
@@ -0,0 +1 @@
+SIGTERM forwarded successfully
diff --git a/tests/expected/unshare/forward-signals-kill-child b/tests/expected/unshare/forward-signals-kill-child
new file mode 100644
index 000000000..d4e1224da
--- /dev/null
+++ b/tests/expected/unshare/forward-signals-kill-child
@@ -0,0 +1 @@
+SIGTERM forwarded successfully with kill-child
diff --git a/tests/ts/unshare/forward-signals b/tests/ts/unshare/forward-signals
new file mode 100755
index 000000000..042ee0a58
--- /dev/null
+++ b/tests/ts/unshare/forward-signals
@@ -0,0 +1,73 @@
+#!/bin/bash
+
+#
+# Copyright (C) 2026 util-linux contributors
+#
+# This file is part of util-linux.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This file is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+TS_TOPDIR="${0%/*}/../.."
+TS_DESC="forward signals to child"
+
+. "$TS_TOPDIR/functions.sh"
+ts_init "$*"
+
+ts_check_test_command "$TS_CMD_UNSHARE"
+ts_check_test_command "$TS_HELPER_SIGRECEIVE"
+
+ts_skip_nonroot
+
+# Verify that user namespaces work
+"$TS_CMD_UNSHARE" --user --map-root-user /bin/true &> /dev/null || \
+	ts_skip "user namespaces not supported"
+
+# Start unshare with --forward-signals and a child process that exits
+# with the signal number it receives
+"$TS_CMD_UNSHARE" --user --map-root-user \
+	--pid --mount-proc \
+	--fork --forward-signals \
+	"$TS_HELPER_SIGRECEIVE" < /dev/null >> $TS_OUTPUT 2>> $TS_ERRLOG &
+
+UNSHARE_PID=$!
+
+# Wait for child to be ready - poll for up to 10 seconds
+# The child process tree should exist
+TIMEOUT=10
+ELAPSED=0
+while [ $ELAPSED -lt $TIMEOUT ]; do
+	# Check if the process still exists
+	if ! kill -0 $UNSHARE_PID 2>/dev/null; then
+		ts_skip "unshare process died prematurely"
+	fi
+	# Give it a bit more time to set up namespaces and signal handlers
+	if [ $ELAPSED -ge 2 ]; then
+		break
+	fi
+	sleep 0.5
+	ELAPSED=$((ELAPSED + 1))
+done
+
+# Send SIGTERM to parent unshare process
+kill -TERM $UNSHARE_PID 2>/dev/null
+
+# Wait for completion with timeout
+wait $UNSHARE_PID
+EXIT_CODE=$?
+
+# test_sigreceive exits with the signal number it receives (15 = SIGTERM)
+if [ $EXIT_CODE -eq 15 ]; then
+	echo "SIGTERM forwarded successfully" >> $TS_OUTPUT
+else
+	echo "UNEXPECTED EXIT CODE: $EXIT_CODE" >> $TS_OUTPUT
+fi
+
+ts_finalize
diff --git a/tests/ts/unshare/forward-signals-kill-child b/tests/ts/unshare/forward-signals-kill-child
new file mode 100755
index 000000000..766f9fe56
--- /dev/null
+++ b/tests/ts/unshare/forward-signals-kill-child
@@ -0,0 +1,74 @@
+#!/bin/bash
+
+#
+# Copyright (C) 2026 util-linux contributors
+#
+# This file is part of util-linux.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This file is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+TS_TOPDIR="${0%/*}/../.."
+TS_DESC="forward signals with kill-child"
+
+. "$TS_TOPDIR/functions.sh"
+ts_init "$*"
+
+ts_check_test_command "$TS_CMD_UNSHARE"
+ts_check_test_command "$TS_HELPER_SIGRECEIVE"
+
+ts_skip_nonroot
+
+# Verify that user namespaces work
+"$TS_CMD_UNSHARE" --user --map-root-user /bin/true &> /dev/null || \
+	ts_skip "user namespaces not supported"
+
+# Start unshare with both --forward-signals and --kill-child
+# The child should receive SIGTERM from forwarding first
+"$TS_CMD_UNSHARE" --user --map-root-user \
+	--pid --mount-proc \
+	--fork --forward-signals --kill-child \
+	"$TS_HELPER_SIGRECEIVE" < /dev/null >> $TS_OUTPUT 2>> $TS_ERRLOG &
+
+UNSHARE_PID=$!
+
+# Wait for child to be ready - poll for up to 10 seconds
+# The child process tree should exist
+TIMEOUT=10
+ELAPSED=0
+while [ $ELAPSED -lt $TIMEOUT ]; do
+	# Check if the process still exists
+	if ! kill -0 $UNSHARE_PID 2>/dev/null; then
+		ts_skip "unshare process died prematurely"
+	fi
+	# Give it a bit more time to set up namespaces and signal handlers
+	if [ $ELAPSED -ge 2 ]; then
+		break
+	fi
+	sleep 0.5
+	ELAPSED=$((ELAPSED + 1))
+done
+
+# Send SIGTERM to parent unshare process
+kill -TERM $UNSHARE_PID 2>/dev/null
+
+# Wait for completion with timeout
+wait $UNSHARE_PID
+EXIT_CODE=$?
+
+# test_sigreceive exits with the signal number it receives (15 = SIGTERM)
+# With --kill-child, it should still receive SIGTERM first via forwarding
+if [ $EXIT_CODE -eq 15 ]; then
+	echo "SIGTERM forwarded successfully with kill-child" >> $TS_OUTPUT
+else
+	echo "UNEXPECTED EXIT CODE: $EXIT_CODE" >> $TS_OUTPUT
+fi
+
+ts_finalize
-- 
2.47.3


  parent reply	other threads:[~2026-01-16 17:07 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-08 18:31 [PATCH 0/5] unshare: fix signal forwarding to child processes Kiran Rangoon
2026-01-08 18:31 ` [PATCH 1/5] unshare: add global child_pid variable for signal forwarding Kiran Rangoon
2026-01-08 18:31 ` [PATCH 2/5] unshare: add signal forwarding handler Kiran Rangoon
2026-01-08 18:31 ` [PATCH 3/5] unshare: replace signal blocking with signal handlers Kiran Rangoon
2026-01-08 18:31 ` [PATCH 4/5] unshare: store child PID in global variable Kiran Rangoon
2026-01-08 18:31 ` [PATCH 5/5] unshare: handle EINTR in waitpid loop Kiran Rangoon
2026-01-12 14:05 ` [PATCH 0/5] unshare: fix signal forwarding to child processes Karel Zak
2026-01-13 17:29   ` [Patch V2 0/4] " Kiran Rangoon
2026-01-13 17:29     ` [V2 1/4] unshare: add --forward-signals option to argument parser Kiran Rangoon
2026-01-13 17:29     ` [V2 2/4] unshare: implement signal forwarding when --forward-signals is used Kiran Rangoon
2026-01-13 17:29     ` [V2 3/4] unshare: document --forward-signals in man page Kiran Rangoon
2026-01-13 17:29     ` [V2 4/4] tests: add tests for unshare --forward-signals Kiran Rangoon
2026-01-16 17:06       ` [PATCH V3 0/4] unshare: add --forward-signals option Kiran Rangoon
2026-01-16 17:06         ` [Patch V3 1/4] unshare: add --forward-signals option to argument parser Kiran Rangoon
2026-01-16 17:06         ` [Patch V3 2/4] unshare: implement signal forwarding when --forward-signals is used Kiran Rangoon
2026-01-16 17:06         ` [Patch V3 3/4] unshare: document --forward-signals in man page Kiran Rangoon
2026-01-16 17:06         ` Kiran Rangoon [this message]
2026-01-21  8:37         ` [PATCH V3 0/4] unshare: add --forward-signals option Karel Zak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260116170648.26439-5-kiranrangoon0@gmail.com \
    --to=kiranrangoon0@gmail.com \
    --cc=kzak@redhat.com \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox