From: Wander Lairson Costa <wander@redhat.com>
To: williams@redhat.com, jkacur@redhat.com, juri.lelli@redhat.com,
luffyluo@tencent.com, davidlt@rivosinc.com,
linux-rt-users@vger.kernel.org
Cc: Claude <noreply@anthropic.com>, Wander Lairson Costa <wander@redhat.com>
Subject: [PATCH stalld 01/36] tests: Add pre-test and post-test cleanup of stalld processes
Date: Mon, 30 Mar 2026 16:43:24 -0300 [thread overview]
Message-ID: <20260330194410.103953-2-wander@redhat.com> (raw)
In-Reply-To: <20260330194410.103953-1-wander@redhat.com>
From: Clark Williams <williams@redhat.com>
Add kill_existing_stalld() function to test_helpers.sh and
kill_existing_stalld_processes() function to run_tests.sh to ensure
no stale stalld processes from previous test runs interfere with new
tests. This prevents orphaned processes from interrupted test runs
from causing false negatives or unexpected behavior.
Changes:
- test_helpers.sh: Add kill_existing_stalld() with graceful then
forced shutdown, export the function, and call from
setup_test_environment()
- run_tests.sh: Add kill_existing_stalld_processes() with logging,
call from init_tests() before tests start, and call from
cleanup_runner() on exit
This ensures clean test environment initialization and proper cleanup
even when test runs are interrupted.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
Assisted-By: git-scm-master (claude-sonnet-4 / 36f1d1f06f2e)
Signed-off-by: Clark Williams <williams@redhat.com>
Signed-off-by: Wander Lairson Costa <wander@redhat.com>
---
tests/helpers/test_helpers.sh | 35 ++++++++++++++++++++++++++++-
tests/run_tests.sh | 42 +++++++++++++++++++++++++++++++++++
2 files changed, 76 insertions(+), 1 deletion(-)
diff --git a/tests/helpers/test_helpers.sh b/tests/helpers/test_helpers.sh
index 630601a..c42dab3 100755
--- a/tests/helpers/test_helpers.sh
+++ b/tests/helpers/test_helpers.sh
@@ -407,6 +407,36 @@ stop_stalld() {
fi
}
+# Kill any existing stalld processes (cleanup from previous runs)
+# This ensures a clean slate before starting tests
+kill_existing_stalld() {
+ local pids=$(pgrep -x stalld 2>/dev/null)
+ if [ -n "${pids}" ]; then
+ echo "Killing existing stalld processes: ${pids}"
+ for pid in ${pids}; do
+ # Try graceful shutdown first
+ kill ${pid} 2>/dev/null || true
+ done
+ sleep 0.5
+ # Force kill any remaining
+ pids=$(pgrep -x stalld 2>/dev/null)
+ if [ -n "${pids}" ]; then
+ for pid in ${pids}; do
+ kill -9 ${pid} 2>/dev/null || true
+ done
+ sleep 0.2
+ fi
+ # Verify all killed
+ pids=$(pgrep -x stalld 2>/dev/null)
+ if [ -n "${pids}" ]; then
+ echo -e "${YELLOW}WARNING: Could not kill all stalld processes: ${pids}${NC}"
+ return 1
+ fi
+ echo "All existing stalld processes killed"
+ fi
+ return 0
+}
+
# Cleanup function (call in trap)
cleanup() {
local exit_code=$?
@@ -712,6 +742,9 @@ disable_dl_server() {
setup_test_environment() {
echo "Setting up test environment..."
+ # Kill any existing stalld processes from previous runs
+ kill_existing_stalld
+
# Save and disable RT throttling
save_rt_throttling
disable_rt_throttling
@@ -1022,7 +1055,7 @@ export -f start_test end_test
export -f assert_equals assert_contains assert_not_contains
export -f assert_file_exists assert_file_not_exists
export -f assert_process_running assert_process_not_running
-export -f start_stalld stop_stalld cleanup
+export -f start_stalld stop_stalld kill_existing_stalld cleanup
export -f wait_for_log_message
export -f get_thread_policy get_thread_priority
export -f create_cpu_load
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
index c6adc49..16b6750 100755
--- a/tests/run_tests.sh
+++ b/tests/run_tests.sh
@@ -220,6 +220,15 @@ cleanup_runner() {
fi
if [ $EUID -eq 0 ]; then
+ # Kill any remaining stalld processes
+ local pids=$(pgrep -x stalld 2>/dev/null)
+ if [ -n "${pids}" ]; then
+ echo -e "${BLUE}Cleaning up remaining stalld processes: ${pids}${NC}"
+ for pid in ${pids}; do
+ kill -9 ${pid} 2>/dev/null || true
+ done
+ fi
+
restore_dl_server_state
restore_rt_throttling_state
fi
@@ -236,6 +245,34 @@ handle_interrupt() {
trap cleanup_runner EXIT
trap handle_interrupt INT TERM
+# Kill any existing stalld processes before tests
+kill_existing_stalld_processes() {
+ local pids=$(pgrep -x stalld 2>/dev/null)
+ if [ -n "${pids}" ]; then
+ echo -e "${BLUE}Killing existing stalld processes: ${pids}${NC}" | tee -a "${LOG_FILE}"
+ for pid in ${pids}; do
+ kill ${pid} 2>/dev/null || true
+ done
+ sleep 0.5
+ # Force kill any remaining
+ pids=$(pgrep -x stalld 2>/dev/null)
+ if [ -n "${pids}" ]; then
+ for pid in ${pids}; do
+ kill -9 ${pid} 2>/dev/null || true
+ done
+ sleep 0.2
+ fi
+ # Verify
+ pids=$(pgrep -x stalld 2>/dev/null)
+ if [ -n "${pids}" ]; then
+ echo -e "${YELLOW}WARNING: Could not kill all stalld processes: ${pids}${NC}" | tee -a "${LOG_FILE}"
+ else
+ echo -e "${GREEN}All existing stalld processes killed${NC}" | tee -a "${LOG_FILE}"
+ fi
+ echo "" | tee -a "${LOG_FILE}"
+ fi
+}
+
# Initialize
init_tests() {
mkdir -p "${RESULTS_DIR}"
@@ -243,6 +280,11 @@ init_tests() {
print_banner | tee "${LOG_FILE}"
echo "" | tee -a "${LOG_FILE}"
+ # Kill any existing stalld processes from previous runs
+ if [ $EUID -eq 0 ]; then
+ kill_existing_stalld_processes
+ fi
+
# Save and disable RT throttling if running as root
if [ $EUID -eq 0 ]; then
save_and_disable_rt_throttling
--
2.53.0
next prev parent reply other threads:[~2026-03-30 19:44 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-30 19:43 [PATCH stalld 00/36] tests: Replace timing-dependent synchronization with event-driven helpers Wander Lairson Costa
2026-03-30 19:43 ` Wander Lairson Costa [this message]
2026-03-30 19:43 ` [PATCH stalld 02/36] tests/helpers: Fix stalld daemon detection in start_stalld() Wander Lairson Costa
2026-03-30 19:43 ` [PATCH stalld 03/36] tests/helpers: Remove duplicate log() function Wander Lairson Costa
2026-03-30 19:43 ` [PATCH stalld 04/36] tests: Add per-test runtime measurement to run_tests.sh Wander Lairson Costa
2026-03-30 19:43 ` [PATCH stalld 05/36] tests/functional: Fix and refactor test_backend_selection.sh Wander Lairson Costa
2026-03-30 19:43 ` [PATCH stalld 06/36] tests/functional: Fix test_logging_destinations.sh path and backend Wander Lairson Costa
2026-03-30 19:43 ` [PATCH stalld 07/36] tests/helpers: Replace sleep with poll in start_stalld_with_log() Wander Lairson Costa
2026-03-30 19:43 ` [PATCH stalld 08/36] tests/helpers: Fix stop_stalld() timeout and shutdown logic Wander Lairson Costa
2026-03-30 19:43 ` [PATCH stalld 09/36] tests/helpers: Fix relative path in backend detection functions Wander Lairson Costa
2026-03-30 19:43 ` [PATCH stalld 10/36] tests/functional: Remove redundant post-stop_stalld sleeps Wander Lairson Costa
2026-03-30 19:43 ` [PATCH stalld 11/36] tests/functional: Fix false positive log matching in test_logging_destinations Wander Lairson Costa
2026-03-30 19:43 ` [PATCH stalld 12/36] tests/helpers: Rewrite wait_for_log_message() with process substitution Wander Lairson Costa
2026-03-30 19:43 ` [PATCH stalld 13/36] tests/helpers: Add wait_for_stalld_ready() and use in start_stalld_with_log() Wander Lairson Costa
2026-03-30 19:43 ` [PATCH stalld 14/36] tests/helpers: Fix fractional sleep timeout bugs Wander Lairson Costa
2026-03-30 19:43 ` [PATCH stalld 15/36] tests/helpers: Flush stdout after starvation_gen startup messages Wander Lairson Costa
2026-03-30 19:43 ` [PATCH stalld 16/36] tests/helpers: Add start_starvation_gen() helper function Wander Lairson Costa
2026-03-30 19:43 ` [PATCH stalld 17/36] tests/helpers: Add wait_for_starvation_detected() and wait_for_boost_detected() Wander Lairson Costa
2026-03-30 19:43 ` [PATCH stalld 18/36] tests/functional: Use start_starvation_gen() helper Wander Lairson Costa
2026-03-30 19:43 ` [PATCH stalld 19/36] tests/functional: Replace detection sleeps with event-driven helpers Wander Lairson Costa
2026-03-30 19:43 ` [PATCH stalld 20/36] tests/functional: Remove duplicated -a flag in test_fifo_priority_starvation Wander Lairson Costa
2026-03-30 19:43 ` [PATCH stalld 21/36] tests/functional: Add missing -a flag in test_starvation_detection Wander Lairson Costa
2026-03-30 19:43 ` [PATCH stalld 22/36] tests/functional: Use start_stalld_with_log() in test_log_only Wander Lairson Costa
2026-03-30 19:43 ` [PATCH stalld 23/36] tests/functional: Use start_stalld_with_log() in test_logging_destinations Wander Lairson Costa
2026-03-30 19:43 ` [PATCH stalld 24/36] tests/functional: Use start_stalld_with_log() in test_cpu_selection Wander Lairson Costa
2026-03-30 19:43 ` [PATCH stalld 25/36] tests/functional: Use wait_for_stalld_ready() in test_backend_selection Wander Lairson Costa
2026-03-30 19:43 ` [PATCH stalld 26/36] tests/functional: Use timeout for error path in test_force_fifo Wander Lairson Costa
2026-03-30 19:43 ` [PATCH stalld 27/36] tests/functional: Use timeout for invalid argument tests Wander Lairson Costa
2026-03-30 19:43 ` [PATCH stalld 28/36] tests: Add pass() helper and replace assert_equals hack Wander Lairson Costa
2026-03-30 19:43 ` [PATCH stalld 29/36] tests/functional: Use pass() for all test pass reporting Wander Lairson Costa
2026-03-30 19:43 ` [PATCH stalld 30/36] tests: Add fail() helper and use for all test failures Wander Lairson Costa
2026-03-30 19:43 ` [PATCH stalld 31/36] tests/helpers: Use pass()/fail() in assert functions Wander Lairson Costa
2026-03-30 19:43 ` [PATCH stalld 32/36] tests/functional: Fix multi-CPU detection in test_starvation_detection Wander Lairson Costa
2026-03-30 19:43 ` [PATCH stalld 33/36] tests/functional: Accept FIFO fallback in test_fifo_boosting Wander Lairson Costa
2026-03-30 19:43 ` [PATCH stalld 34/36] tests/functional: Fix readiness detection and FIFO fallback in test_force_fifo Wander Lairson Costa
2026-03-30 19:43 ` [PATCH stalld 35/36] tests/functional: Fix invalid pidfile test in test_pidfile Wander Lairson Costa
2026-03-30 19:43 ` [PATCH stalld 36/36] stalld: die on invalid CPU affinity Wander Lairson Costa
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=20260330194410.103953-2-wander@redhat.com \
--to=wander@redhat.com \
--cc=davidlt@rivosinc.com \
--cc=jkacur@redhat.com \
--cc=juri.lelli@redhat.com \
--cc=linux-rt-users@vger.kernel.org \
--cc=luffyluo@tencent.com \
--cc=noreply@anthropic.com \
--cc=williams@redhat.com \
/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