From: Wander Lairson Costa <wander@redhat.com>
To: Clark Williams <williams@redhat.com>,
John Kacur <jkacur@redhat.com>,
linux-rt-users@vger.kernel.org
Cc: Juri Lelli <juri.lelli@redhat.com>,
luffyluo@tencent.com, davidlt@rivosinc.com,
Wander Lairson Costa <wander@redhat.com>
Subject: [[PATCH stalld] 21/33] tests: Remove if-wrappers around assert calls
Date: Wed, 20 May 2026 11:00:48 -0300 [thread overview]
Message-ID: <20260520140104.112142-22-wander@redhat.com> (raw)
In-Reply-To: <20260520140104.112142-1-wander@redhat.com>
This is the second commit in a series introducing fail-fast semantics
to the test suite. Currently, several test scripts wrap assertion calls
in conditional blocks to guard subsequent execution steps.
Since the guarded test logic only makes sense when the initial assertion
passes, these conditional wrappers create unnecessary nesting. Once the
failure mechanism is updated to be immediately fatal in the next commit,
these protective conditional structures will become completely
redundant.
Removing the conditional structures and flattening the code flow across
the foreground, logging, pidfile, and starvation test scripts improves
overall readability and maintainability. Branches handling non-fatal
conditions such as skips or informational warnings have been preserved
in their original form.
Signed-off-by: Wander Lairson Costa <wander@redhat.com>
Assisted-by: Claude Code:claude-opus-4-6[1m] [PAL]
---
tests/functional/test_foreground.sh | 36 +++++++----------
tests/functional/test_logging_destinations.sh | 20 +++-------
tests/functional/test_pidfile.sh | 39 +++++--------------
tests/functional/test_starvation_detection.sh | 7 +---
4 files changed, 29 insertions(+), 73 deletions(-)
diff --git a/tests/functional/test_foreground.sh b/tests/functional/test_foreground.sh
index f5de736..792aee0 100755
--- a/tests/functional/test_foreground.sh
+++ b/tests/functional/test_foreground.sh
@@ -26,17 +26,13 @@ test_section "Test 1: stalld daemonizes by default"
start_stalld -l -t 5
sleep 2
-# Check if stalld is running
-if assert_process_running "${STALLD_PID}" "stalld should be running"; then
- # Check parent process - should be init (PID 1) or systemd
- PARENT_PID=$(ps -o ppid= -p ${STALLD_PID} 2>/dev/null | tr -d ' ')
- if [ "${PARENT_PID}" == "1" ] || [ "${PARENT_PID}" == "2" ]; then
- pass "stalld daemonized (parent is init/kthreadd)"
- else
- # On modern systems with session leaders, ppid might not be 1
- # Just verify it's not our shell's PID
- assert_success "stalld daemonized (parent is not test shell)" test "${PARENT_PID}" != "$$"
- fi
+assert_process_running "${STALLD_PID}" "stalld should be running"
+
+PARENT_PID=$(ps -o ppid= -p ${STALLD_PID} 2>/dev/null | tr -d ' ')
+if [ "${PARENT_PID}" == "1" ] || [ "${PARENT_PID}" == "2" ]; then
+ pass "stalld daemonized (parent is init/kthreadd)"
+else
+ assert_success "stalld daemonized (parent is not test shell)" test "${PARENT_PID}" != "$$"
fi
stop_stalld
@@ -48,15 +44,10 @@ test_section "Test 2: stalld stays in foreground with -f"
start_stalld -f -l -t 5
sleep 2
-# Check if stalld is running
-if assert_process_running "${STALLD_PID}" "stalld should be running with -f"; then
- # With -f, it should NOT daemonize, parent should be our shell
- PARENT_PID=$(ps -o ppid= -p ${STALLD_PID} 2>/dev/null | tr -d ' ')
+assert_process_running "${STALLD_PID}" "stalld should be running with -f"
- # The parent might be the subshell from start_stalld, not directly our shell
- # So we just verify it's not PID 1
- assert_success "stalld did not daemonize with -f (parent is not init)" test "${PARENT_PID}" != "1"
-fi
+PARENT_PID=$(ps -o ppid= -p ${STALLD_PID} 2>/dev/null | tr -d ' ')
+assert_success "stalld did not daemonize with -f (parent is not init)" test "${PARENT_PID}" != "1"
stop_stalld
@@ -66,11 +57,10 @@ test_section "Test 3: -v implies foreground mode"
start_stalld -v -l -t 5
sleep 2
-if assert_process_running "${STALLD_PID}" "stalld should be running with -v"; then
- PARENT_PID=$(ps -o ppid= -p ${STALLD_PID} 2>/dev/null | tr -d ' ')
+assert_process_running "${STALLD_PID}" "stalld should be running with -v"
- assert_success "-v implies foreground mode" test "${PARENT_PID}" != "1"
-fi
+PARENT_PID=$(ps -o ppid= -p ${STALLD_PID} 2>/dev/null | tr -d ' ')
+assert_success "-v implies foreground mode" test "${PARENT_PID}" != "1"
stop_stalld
diff --git a/tests/functional/test_logging_destinations.sh b/tests/functional/test_logging_destinations.sh
index 5a8cc5b..a25e571 100755
--- a/tests/functional/test_logging_destinations.sh
+++ b/tests/functional/test_logging_destinations.sh
@@ -35,17 +35,9 @@ CLEANUP_FILES+=("${LOG_FILE}")
start_stalld_with_log "${LOG_FILE}" -f -v -l -t 5
-if assert_process_running "${STALLD_PID}" "stalld should be running"; then
- # Check that output was written to our log file
- if [ -s "${LOG_FILE}" ]; then
- pass "verbose mode produces output"
-
- # Should contain initialization messages
- assert_log_contains "${LOG_FILE}" "stalld\|version\|monitoring" "output contains expected messages"
- else
- fail "no output in verbose mode"
- fi
-fi
+assert_process_running "${STALLD_PID}" "stalld should be running"
+assert_success "verbose mode produces output" test -s "${LOG_FILE}"
+assert_log_contains "${LOG_FILE}" "stalld\|version\|monitoring" "output contains expected messages"
stop_stalld
@@ -147,10 +139,8 @@ CLEANUP_FILES+=("${LOG_FILE}")
start_stalld_with_log "${LOG_FILE}" -f -v -k -s -l -t 5
-if assert_process_running "${STALLD_PID}" "stalld with combined logging should be running"; then
- # Verify verbose output
- assert_success "combined logging produces output" test -s "${LOG_FILE}"
-fi
+assert_process_running "${STALLD_PID}" "stalld with combined logging should be running"
+assert_success "combined logging produces output" test -s "${LOG_FILE}"
stop_stalld
diff --git a/tests/functional/test_pidfile.sh b/tests/functional/test_pidfile.sh
index 23c60e5..75b5359 100755
--- a/tests/functional/test_pidfile.sh
+++ b/tests/functional/test_pidfile.sh
@@ -60,16 +60,10 @@ log "Starting stalld with custom pidfile: ${custom_pidfile}"
start_stalld -l -t 5 --pidfile "${custom_pidfile}"
sleep 2
-# Verify pidfile was created
-if [ -f "${custom_pidfile}" ]; then
- pass "Custom pidfile created at ${custom_pidfile}"
+assert_file_exists "${custom_pidfile}" "Custom pidfile created at ${custom_pidfile}"
- # Verify content
- pid_from_file=$(cat "${custom_pidfile}")
- assert_success "Custom pidfile contains correct PID" test "$pid_from_file" = "${STALLD_PID}"
-else
- fail "Custom pidfile not created at ${custom_pidfile}"
-fi
+pid_from_file=$(cat "${custom_pidfile}")
+assert_success "Custom pidfile contains correct PID" test "$pid_from_file" = "${STALLD_PID}"
# Test 3: Verify pidfile removed on clean shutdown
test_section "Test 3: Verify pidfile removed on clean shutdown"
@@ -95,14 +89,10 @@ log "Starting stalld with /tmp pidfile: ${tmp_pidfile}"
start_stalld -l -t 5 --pidfile "${tmp_pidfile}"
sleep 2
-if [ -f "${tmp_pidfile}" ]; then
- pass "Pidfile created in /tmp directory"
+assert_file_exists "${tmp_pidfile}" "Pidfile created in /tmp directory"
- pid_from_file=$(cat "${tmp_pidfile}")
- assert_success "/tmp pidfile contains correct PID" test "$pid_from_file" = "${STALLD_PID}"
-else
- fail "Pidfile not created in /tmp"
-fi
+pid_from_file=$(cat "${tmp_pidfile}")
+assert_success "/tmp pidfile contains correct PID" test "$pid_from_file" = "${STALLD_PID}"
stop_stalld
@@ -151,20 +141,11 @@ log "Starting stalld with readable pidfile: ${readable_pidfile}"
start_stalld -l -t 5 --pidfile "${readable_pidfile}"
sleep 2
-if [ -f "${readable_pidfile}" ]; then
- # Try to read the pidfile as a regular user would
- if cat "${readable_pidfile}" > /dev/null 2>&1; then
- pass "Pidfile is readable"
+assert_file_exists "${readable_pidfile}" "Pidfile created"
+assert_success "Pidfile is readable" cat "${readable_pidfile}"
- # Check permissions
- perms=$(stat -c "%a" "${readable_pidfile}" 2>/dev/null || stat -f "%Lp" "${readable_pidfile}" 2>/dev/null)
- log "ℹ INFO: Pidfile permissions: $perms"
- else
- fail "Pidfile not readable"
- fi
-else
- fail "Pidfile not created"
-fi
+perms=$(stat -c "%a" "${readable_pidfile}" 2>/dev/null || stat -f "%Lp" "${readable_pidfile}" 2>/dev/null)
+log "ℹ INFO: Pidfile permissions: $perms"
stop_stalld
diff --git a/tests/functional/test_starvation_detection.sh b/tests/functional/test_starvation_detection.sh
index 1df6bb0..1d43516 100755
--- a/tests/functional/test_starvation_detection.sh
+++ b/tests/functional/test_starvation_detection.sh
@@ -186,12 +186,7 @@ start_starvation_gen -c ${TEST_CPU} -p 80 -n 1 -d 3
# Wait for task to exit
sleep 5
-# Verify stalld is still running (didn't crash)
-if assert_process_running "${STALLD_PID}" "stalld still running after task exit"; then
- pass "stalld handled task exit gracefully"
-else
- fail "stalld crashed or exited unexpectedly"
-fi
+assert_process_running "${STALLD_PID}" "stalld still running after task exit"
# Check for error messages
assert_log_contains --negate --ignore-case "${STALLD_LOG}" "error\|segfault\|crash" "No error messages in log"
--
2.54.0
next prev parent reply other threads:[~2026-05-20 14:02 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-20 14:00 [[PATCH stalld] 00/33] Test suite hardening, correctness fixes, and BPF optimization Wander Lairson Costa
2026-05-20 14:00 ` [[PATCH stalld] 01/33] stalld: Reject --force_fifo in single-threaded mode Wander Lairson Costa
2026-05-20 14:00 ` [[PATCH stalld] 02/33] tests: Introduce test_section() helper Wander Lairson Costa
2026-05-20 14:00 ` [[PATCH stalld] 03/33] tests: Introduce cleanup_scenario() helper Wander Lairson Costa
2026-05-20 14:00 ` [[PATCH stalld] 04/33] tests: Introduce starvation and boost asserts Wander Lairson Costa
2026-05-20 14:00 ` [[PATCH stalld] 05/33] tests: Introduce find_starved_child() helper Wander Lairson Costa
2026-05-20 14:00 ` [[PATCH stalld] 06/33] tests: Fix task exit timing in test_boost_restoration Wander Lairson Costa
2026-05-20 14:00 ` [[PATCH stalld] 07/33] tests: Consolidate and adopt init_functional_test() Wander Lairson Costa
2026-05-20 14:00 ` [[PATCH stalld] 08/33] tests: Introduce assert_stalld_rejects() helper Wander Lairson Costa
2026-05-20 14:00 ` [[PATCH stalld] 09/33] tests: Fix boost verification in runtime and duration tests Wander Lairson Costa
2026-05-20 14:00 ` [[PATCH stalld] 10/33] tests: Fix subshell swallowing test results Wander Lairson Costa
2026-05-20 14:00 ` [[PATCH stalld] 11/33] tests: Fix repeated log match finding same line Wander Lairson Costa
2026-05-20 14:00 ` [[PATCH stalld] 12/33] chore: Remove legacy test infrastructure and stale docs Wander Lairson Costa
2026-05-20 14:00 ` [[PATCH stalld] 13/33] tests: Add assertions to SCHED_OTHER restoration test Wander Lairson Costa
2026-05-20 14:00 ` [[PATCH stalld] 14/33] tests: Fix CPU selection grep substring matches Wander Lairson Costa
2026-05-20 14:00 ` [[PATCH stalld] 15/33] tests: Add idle CPU skipping assertion Wander Lairson Costa
2026-05-20 14:00 ` [[PATCH stalld] 16/33] tests: Remove redundant pkill from cleanup Wander Lairson Costa
2026-05-20 14:00 ` [[PATCH stalld] 17/33] tests: Introduce and adopt assert_log_contains() helper Wander Lairson Costa
2026-05-20 14:00 ` [[PATCH stalld] 18/33] tests: Remove weak, redundant, and assertion-free test blocks Wander Lairson Costa
2026-05-20 14:00 ` [[PATCH stalld] 19/33] tests: Introduce and adopt assert_success() helper Wander Lairson Costa
2026-05-20 14:00 ` [[PATCH stalld] 20/33] tests: Replace wait conditionals with asserts Wander Lairson Costa
2026-05-20 14:00 ` Wander Lairson Costa [this message]
2026-05-20 14:00 ` [[PATCH stalld] 22/33] tests: Abort immediately on test failure Wander Lairson Costa
2026-05-20 14:00 ` [[PATCH stalld] 23/33] tests: Remove dead code after making fail() fatal Wander Lairson Costa
2026-05-20 14:00 ` [[PATCH stalld] 24/33] tests: Introduce and adopt process helpers Wander Lairson Costa
2026-05-20 14:00 ` [[PATCH stalld] 25/33] tests: Extract wait_for_process_exit helper Wander Lairson Costa
2026-05-20 14:00 ` [[PATCH stalld] 26/33] tests: Reduce default wait timeouts Wander Lairson Costa
2026-05-20 14:00 ` [[PATCH stalld] 27/33] tests: Reduce starvation_gen durations Wander Lairson Costa
2026-05-20 14:00 ` [[PATCH stalld] 28/33] tests: Replace init sleeps in test_affinity Wander Lairson Costa
2026-05-20 14:00 ` [[PATCH stalld] 29/33] tests: Drop redundant sleeps in test_pidfile Wander Lairson Costa
2026-05-20 14:00 ` [[PATCH stalld] 30/33] tests: Remove redundant sleeps after start_stalld Wander Lairson Costa
2026-05-20 14:00 ` [[PATCH stalld] 31/33] tests: Reduce timing and replace sleeps with event waits Wander Lairson Costa
2026-05-20 14:00 ` [[PATCH stalld] 32/33] tests: Fix async-signal-unsafe handler Wander Lairson Costa
2026-05-20 14:01 ` [[PATCH stalld] 33/33] bpf: Replace linear task scan with hash map 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=20260520140104.112142-22-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=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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.