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] 04/33] tests: Introduce starvation and boost asserts
Date: Wed, 20 May 2026 11:00:31 -0300 [thread overview]
Message-ID: <20260520140104.112142-5-wander@redhat.com> (raw)
In-Reply-To: <20260520140104.112142-1-wander@redhat.com>
Add assert_starvation_detected() and assert_boost_detected() wrappers
to tests/helpers/test_helpers.sh. These functions wrap the common
pattern of evaluating wait_for_* conditions, logging passes, and
dumping logs on failure into a single function call. Both helpers
return 0 or 1 to match the existing assert_* convention used
throughout the test suite.
Update 6 test files to replace 16 simple if/else evaluation blocks
with the new helpers, reducing boilerplate and yielding a net
reduction of 33 lines. Complex evaluation blocks containing nested
logic are intentionally left intact to preserve their specific
behaviors.
Signed-off-by: Wander Lairson Costa <wander@redhat.com>
Assisted-by: Claude Code:claude-opus-4-6[1m] [PAL]
---
tests/functional/test_boost_duration.sh | 24 ++----------
tests/functional/test_boost_period.sh | 18 ++-------
tests/functional/test_boost_runtime.sh | 24 ++----------
tests/functional/test_log_only.sh | 8 +---
tests/functional/test_starvation_detection.sh | 12 +-----
tests/functional/test_starvation_threshold.sh | 17 +-------
tests/helpers/test_helpers.sh | 39 ++++++++++++++++++-
7 files changed, 54 insertions(+), 88 deletions(-)
diff --git a/tests/functional/test_boost_duration.sh b/tests/functional/test_boost_duration.sh
index 9a4c11c..d1cdd1e 100755
--- a/tests/functional/test_boost_duration.sh
+++ b/tests/functional/test_boost_duration.sh
@@ -63,11 +63,7 @@ log "Creating starvation on CPU ${TEST_CPU} for ${starvation_duration}s"
start_starvation_gen -c "${TEST_CPU}" -p 80 -n 2 -d ${starvation_duration}
# Wait for starvation detection
-if wait_for_starvation_detected "${STALLD_LOG}"; then
- pass "Starvation detection occurred with default duration"
-else
- fail "No starvation detection"
-fi
+assert_starvation_detected "${STALLD_LOG}" "Starvation detection occurred with default duration"
# Cleanup
cleanup_scenario "${STARVE_PID}"
@@ -89,11 +85,7 @@ log "Creating starvation on CPU ${TEST_CPU} for ${starvation_duration}s"
start_starvation_gen -c "${TEST_CPU}" -p 80 -n 2 -d ${starvation_duration}
# Wait for starvation detection
-if wait_for_starvation_detected "${STALLD_LOG2}"; then
- pass "Starvation detection with ${short_duration}s duration"
-else
- fail "No starvation detection with short duration"
-fi
+assert_starvation_detected "${STALLD_LOG2}" "Starvation detection with ${short_duration}s duration"
# Cleanup
cleanup_scenario "${STARVE_PID}"
@@ -117,11 +109,7 @@ log "Creating starvation on CPU ${TEST_CPU} for ${long_starvation}s"
start_starvation_gen -c "${TEST_CPU}" -p 80 -n 2 -d ${long_starvation}
# Wait for starvation detection
-if wait_for_starvation_detected "${STALLD_LOG3}"; then
- pass "Starvation detection with ${long_duration}s duration"
-else
- fail "No starvation detection with long duration"
-fi
+assert_starvation_detected "${STALLD_LOG3}" "Starvation detection with ${long_duration}s duration"
# Cleanup
cleanup_scenario "${STARVE_PID}"
@@ -144,11 +132,7 @@ log "Creating starvation on CPU ${TEST_CPU} for 15s"
start_starvation_gen -c "${TEST_CPU}" -p 80 -n 1 -d 15
# Wait for starvation detection
-if wait_for_starvation_detected "${STALLD_LOG4}"; then
- pass "Starvation detection with ${duration}s boost duration"
-else
- fail "No starvation detection"
-fi
+assert_starvation_detected "${STALLD_LOG4}" "Starvation detection with ${duration}s boost duration"
# Cleanup
cleanup_scenario "${STARVE_PID}"
diff --git a/tests/functional/test_boost_period.sh b/tests/functional/test_boost_period.sh
index d7cb75f..d7112bb 100755
--- a/tests/functional/test_boost_period.sh
+++ b/tests/functional/test_boost_period.sh
@@ -91,11 +91,7 @@ log "Creating starvation on CPU ${TEST_CPU}"
start_starvation_gen -c "${TEST_CPU}" -p 80 -n 2 -d ${starvation_duration}
# Wait for starvation detection and boosting
-if wait_for_boost_detected "${STALLD_LOG}"; then
- pass "Boosting occurred with custom period ${custom_period} ns"
-else
- fail "No boosting with custom period"
-fi
+assert_boost_detected "${STALLD_LOG}" "Boosting occurred with custom period ${custom_period} ns"
# Cleanup
cleanup_scenario "${STARVE_PID}"
@@ -115,11 +111,7 @@ log "Creating starvation on CPU ${TEST_CPU}"
start_starvation_gen -c "${TEST_CPU}" -p 80 -n 2 -d ${starvation_duration}
# Wait for starvation detection and boosting
-if wait_for_boost_detected "${STALLD_LOG}"; then
- pass "Boosting occurred with short period ${short_period} ns"
-else
- fail "No boosting with short period"
-fi
+assert_boost_detected "${STALLD_LOG}" "Boosting occurred with short period ${short_period} ns"
# Cleanup
cleanup_scenario "${STARVE_PID}"
@@ -139,11 +131,7 @@ log "Creating starvation on CPU ${TEST_CPU}"
start_starvation_gen -c "${TEST_CPU}" -p 80 -n 2 -d ${starvation_duration}
# Wait for starvation detection and boosting
-if wait_for_boost_detected "${STALLD_LOG}"; then
- pass "Boosting occurred with long period ${long_period} ns"
-else
- fail "No boosting with long period"
-fi
+assert_boost_detected "${STALLD_LOG}" "Boosting occurred with long period ${long_period} ns"
# Cleanup
cleanup_scenario "${STARVE_PID}"
diff --git a/tests/functional/test_boost_runtime.sh b/tests/functional/test_boost_runtime.sh
index d8dba70..c17ac27 100755
--- a/tests/functional/test_boost_runtime.sh
+++ b/tests/functional/test_boost_runtime.sh
@@ -63,11 +63,7 @@ log "Creating starvation on CPU ${TEST_CPU} for ${starvation_duration}s"
start_starvation_gen -c "${TEST_CPU}" -p 80 -n 2 -d ${starvation_duration}
# Wait for detection and boosting
-if wait_for_starvation_detected "${STALLD_LOG}"; then
- pass "Starvation detection with default runtime"
-else
- fail "No starvation detection"
-fi
+assert_starvation_detected "${STALLD_LOG}" "Starvation detection with default runtime"
# Cleanup
cleanup_scenario "${STARVE_PID}"
@@ -89,11 +85,7 @@ log "Creating starvation on CPU ${TEST_CPU} for ${starvation_duration}s"
start_starvation_gen -c "${TEST_CPU}" -p 80 -n 2 -d ${starvation_duration}
# Wait for detection and boosting
-if wait_for_starvation_detected "${STALLD_LOG2}"; then
- pass "Starvation detection with custom runtime ${custom_runtime}ns"
-else
- fail "No starvation detection with custom runtime"
-fi
+assert_starvation_detected "${STALLD_LOG2}" "Starvation detection with custom runtime ${custom_runtime}ns"
# Cleanup
cleanup_scenario "${STARVE_PID}"
@@ -115,11 +107,7 @@ log "Creating starvation on CPU ${TEST_CPU} for ${starvation_duration}s"
start_starvation_gen -c "${TEST_CPU}" -p 80 -n 2 -d ${starvation_duration}
# Wait for detection and boosting
-if wait_for_starvation_detected "${STALLD_LOG3}"; then
- pass "Starvation detection with large runtime ${large_runtime}ns"
-else
- fail "No starvation detection with large runtime"
-fi
+assert_starvation_detected "${STALLD_LOG3}" "Starvation detection with large runtime ${large_runtime}ns"
# Cleanup
cleanup_scenario "${STARVE_PID}"
@@ -143,11 +131,7 @@ log "Creating starvation on CPU ${TEST_CPU} for ${starvation_duration}s"
start_starvation_gen -c "${TEST_CPU}" -p 80 -n 2 -d ${starvation_duration}
# Wait for detection and boosting
-if wait_for_starvation_detected "${STALLD_LOG4}"; then
- pass "Starvation detection with runtime < period"
-else
- fail "No starvation detection when runtime < period"
-fi
+assert_starvation_detected "${STALLD_LOG4}" "Starvation detection with runtime < period"
# Cleanup
cleanup_scenario "${STARVE_PID}"
diff --git a/tests/functional/test_log_only.sh b/tests/functional/test_log_only.sh
index 0e6d41b..b10b4d9 100755
--- a/tests/functional/test_log_only.sh
+++ b/tests/functional/test_log_only.sh
@@ -58,13 +58,7 @@ echo "Starvation generator started (PID ${STARVGEN_PID})"
echo "Waiting for starvation detection..."
# Check if stalld detected the starvation (should log it)
-if wait_for_starvation_detected "${LOG_FILE}"; then
- pass "stalld detected and logged starvation"
-else
- fail "stalld did not detect starvation"
- echo "Log contents:"
- cat "${LOG_FILE}"
-fi
+assert_starvation_detected "${LOG_FILE}" "stalld detected and logged starvation"
# Check that stalld did NOT boost (should not see "boosted" message with -l)
if ! grep -q "boosted" "${LOG_FILE}"; then
diff --git a/tests/functional/test_starvation_detection.sh b/tests/functional/test_starvation_detection.sh
index 919148b..3307edb 100755
--- a/tests/functional/test_starvation_detection.sh
+++ b/tests/functional/test_starvation_detection.sh
@@ -256,18 +256,10 @@ else
# Wait for starvation detection on both CPUs
log "Waiting for starvation detection on CPU ${CPU0}..."
- if wait_for_starvation_detected "${STALLD_LOG}" 30 "${CPU0}"; then
- pass "Starvation detected on CPU ${CPU0}"
- else
- fail "Starvation not detected on CPU ${CPU0}"
- fi
+ assert_starvation_detected "${STALLD_LOG}" "Starvation detected on CPU ${CPU0}" "30" "${CPU0}"
log "Waiting for starvation detection on CPU ${CPU1}..."
- if wait_for_starvation_detected "${STALLD_LOG}" 30 "${CPU1}"; then
- pass "Starvation detected on CPU ${CPU1}"
- else
- fail "Starvation not detected on CPU ${CPU1}"
- fi
+ assert_starvation_detected "${STALLD_LOG}" "Starvation detected on CPU ${CPU1}" "30" "${CPU1}"
# Cleanup
cleanup_scenario "${STARVE_PID0}" "${STARVE_PID1}"
diff --git a/tests/functional/test_starvation_threshold.sh b/tests/functional/test_starvation_threshold.sh
index 8b54b95..62f7420 100755
--- a/tests/functional/test_starvation_threshold.sh
+++ b/tests/functional/test_starvation_threshold.sh
@@ -71,14 +71,7 @@ start_stalld_with_log "${STALLD_LOG}" -f -v -N -M -g 1 -i "ksoftirqd,kworker" -c
# Wait for starvation detection
log "Waiting for detection (threshold: ${threshold}s)"
-# Check if starvation was detected - specifically look for starvation_gen tasks
-if wait_for_starvation_detected "${STALLD_LOG}"; then
- pass "Starvation detected after ${threshold}s threshold"
-else
- fail "Starvation not detected after ${threshold}s threshold"
- log "Log contents:"
- cat "${STALLD_LOG}"
-fi
+assert_starvation_detected "${STALLD_LOG}" "Starvation detected after ${threshold}s threshold"
# Cleanup
cleanup_scenario "${STARVE_PID}"
@@ -145,13 +138,7 @@ start_stalld_with_log "${STALLD_LOG3}" -f -v -N -M -g 1 -i "ksoftirqd,kworker" -
log "Waiting for detection (threshold: ${threshold}s)"
# Check if starvation_gen was detected
-if wait_for_starvation_detected "${STALLD_LOG3}"; then
- pass "Starvation detected with ${threshold}s threshold"
-else
- fail "Starvation not detected with ${threshold}s threshold"
- log "Log contents:"
- cat "${STALLD_LOG3}"
-fi
+assert_starvation_detected "${STALLD_LOG3}" "Starvation detected with ${threshold}s threshold"
# Cleanup
cleanup_scenario "${STARVE_PID}"
diff --git a/tests/helpers/test_helpers.sh b/tests/helpers/test_helpers.sh
index d4e98f7..fb6c9d1 100755
--- a/tests/helpers/test_helpers.sh
+++ b/tests/helpers/test_helpers.sh
@@ -126,6 +126,43 @@ cleanup_scenario() {
stop_stalld
}
+# Assert that stalld detects a starving task within the timeout.
+# Usage: assert_starvation_detected <log_file> <message> [timeout] [cpu]
+assert_starvation_detected() {
+ local log_file=$1
+ local message=${2:-"Starvation detected"}
+ local timeout=${3:-30}
+ local cpu=${4:-}
+
+ if wait_for_starvation_detected "${log_file}" "${timeout}" "${cpu}"; then
+ pass "${message}"
+ return 0
+ else
+ fail "${message}"
+ log "Log contents:"
+ cat "${log_file}"
+ return 1
+ fi
+}
+
+# Assert that stalld boosts a starving task within the timeout.
+# Usage: assert_boost_detected <log_file> <message> [timeout]
+assert_boost_detected() {
+ local log_file=$1
+ local message=${2:-"Boost detected"}
+ local timeout=${3:-30}
+
+ if wait_for_boost_detected "${log_file}" "${timeout}"; then
+ pass "${message}"
+ return 0
+ else
+ fail "${message}"
+ log "Log contents:"
+ cat "${log_file}"
+ return 1
+ fi
+}
+
# Record a test pass with a description message.
#
# Usage: pass "description"
@@ -1150,7 +1187,7 @@ start_starvation_gen() {
}
# Export functions for use in tests
-export -f start_test end_test test_section cleanup_scenario
+export -f start_test end_test test_section cleanup_scenario assert_starvation_detected assert_boost_detected
export -f pass fail 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
--
2.54.0
next prev parent reply other threads:[~2026-05-20 14:01 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 ` Wander Lairson Costa [this message]
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 ` [[PATCH stalld] 21/33] tests: Remove if-wrappers around assert calls Wander Lairson Costa
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-5-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.