public inbox for linux-rt-users@vger.kernel.org
 help / color / mirror / Atom feed
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: Wander Lairson Costa <wander@redhat.com>
Subject: [PATCH stalld 05/36] tests/functional: Fix and refactor test_backend_selection.sh
Date: Mon, 30 Mar 2026 16:43:28 -0300	[thread overview]
Message-ID: <20260330194410.103953-6-wander@redhat.com> (raw)
In-Reply-To: <20260330194410.103953-1-wander@redhat.com>

test_backend_selection.sh fails when invoked by run_tests.sh because
it uses a relative path (../stalld) that resolves incorrectly when the
working directory is not tests/functional/. It also lacks
parse_test_options for backend passthrough from the test runner, does
not track temporary log files for cleanup, and contains four
copy-pasted 30-line blocks that implement the same
start/verify/check/stop pattern.

Extract the repeated pattern into a test_backend_flag() helper
function that starts stalld with a given -b flag, verifies the
expected backend message appears in the log, and calls stop_stalld.
The helper uses $! instead of pgrep for PID capture since stalld
runs in foreground mode. Fix the stalld path to use ${TEST_ROOT},
add parse_test_options and CLEANUP_FILES tracking, and correct the
test numbering.

Signed-off-by: Wander Lairson Costa <wander@redhat.com>
---
 tests/functional/test_backend_selection.sh | 193 +++++++--------------
 1 file changed, 61 insertions(+), 132 deletions(-)

diff --git a/tests/functional/test_backend_selection.sh b/tests/functional/test_backend_selection.sh
index 6227756..5d60072 100755
--- a/tests/functional/test_backend_selection.sh
+++ b/tests/functional/test_backend_selection.sh
@@ -10,6 +10,7 @@
 
 TEST_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
 source "${TEST_ROOT}/helpers/test_helpers.sh"
+parse_test_options "$@" || exit $?
 
 start_test "Backend Selection"
 
@@ -18,155 +19,83 @@ setup_test_environment
 
 require_root
 
-# Test 1: Start stalld with sched_debug backend
-echo "Test 1: Starting stalld with sched_debug backend"
-STALLD_LOG="/tmp/stalld_backend_sched_debug_$$.log"
-# Call stalld directly to capture its actual stderr output
-# IMPORTANT: -v must come BEFORE -b so verbose mode is enabled when backend message is logged
-../stalld -v -f -l -b sched_debug -t 60 > "${STALLD_LOG}" 2>&1 &
-sleep 1
-# Get the actual stalld PID
-STALLD_PID=$(pgrep -n -x stalld 2>/dev/null)
-if [ -z "${STALLD_PID}" ]; then
-	TEST_FAILED=$((TEST_FAILED + 1))
-	echo -e "  ${RED}FAIL${NC}: stalld failed to start with sched_debug backend"
-else
+# Helper: start stalld with a specific backend flag, verify the expected
+# backend message appears in the log. This test intentionally bypasses
+# start_stalld_with_log() because it needs to control the -b flag
+# directly rather than inheriting it from STALLD_TEST_BACKEND.
+#
+# Usage: test_backend_flag <backend_flag> <expected_message> <description>
+test_backend_flag() {
+	local backend_flag=$1
+	local expected_msg=$2
+	local description=$3
+	local log_file="/tmp/stalld_backend_${backend_flag}_$$.log"
+
+	CLEANUP_FILES+=("${log_file}")
+
+	"${TEST_ROOT}/../stalld" -v -f -l -b "${backend_flag}" -t 60 \
+		> "${log_file}" 2>&1 &
+	STALLD_PID=$!
 	CLEANUP_PIDS+=("${STALLD_PID}")
 	sleep 1
-	if kill -0 ${STALLD_PID} 2>/dev/null; then
-		# Check if log contains backend message
-		if grep -q "using sched_debug backend" "${STALLD_LOG}"; then
-			assert_equals "0" "0" "sched_debug backend selected"
-		else
-			TEST_FAILED=$((TEST_FAILED + 1))
-			echo -e "  ${RED}FAIL${NC}: Backend message not found in log"
-			echo "  Log contents:"
-			cat "${STALLD_LOG}"
-		fi
-		stop_stalld
+
+	if ! kill -0 ${STALLD_PID} 2>/dev/null; then
+		TEST_FAILED=$((TEST_FAILED + 1))
+		echo -e "  ${RED}FAIL${NC}: stalld failed to start (${description})"
+		return 1
+	fi
+
+	if grep -q "${expected_msg}" "${log_file}"; then
+		assert_equals "0" "0" "${description}"
 	else
 		TEST_FAILED=$((TEST_FAILED + 1))
-		echo -e "  ${RED}FAIL${NC}: stalld failed to start with sched_debug backend"
+		echo -e "  ${RED}FAIL${NC}: Backend message not found (${description})"
+		echo "  Expected: ${expected_msg}"
+		echo "  Log contents:"
+		cat "${log_file}"
 	fi
-fi
-rm -f "${STALLD_LOG}"
 
+	stop_stalld
+}
+
+# Test 1: sched_debug backend (full name)
+echo "Test 1: Starting stalld with sched_debug backend"
+test_backend_flag "sched_debug" "using sched_debug backend" \
+	"sched_debug backend selected"
+
+# Test 2: queue_track backend (if available)
 echo ""
-echo "=== Test 4: Check queue_track (BPF) backend availability ==="
+echo "Test 2: Check queue_track (BPF) backend"
 if is_backend_available "queue_track"; then
-	echo "Test 2a: Starting stalld with queue_track backend"
-	STALLD_LOG="/tmp/stalld_backend_queue_track_$$.log"
-	# Call stalld directly to capture its actual stderr output
-	# IMPORTANT: -v must come BEFORE -b so verbose mode is enabled when backend message is logged
-	../stalld -v -f -l -b queue_track -t 60 > "${STALLD_LOG}" 2>&1 &
-	sleep 1
-	# Get the actual stalld PID
-	STALLD_PID=$(pgrep -n -x stalld 2>/dev/null)
-	if [ -z "${STALLD_PID}" ]; then
-		TEST_FAILED=$((TEST_FAILED + 1))
-		echo -e "  ${RED}FAIL${NC}: stalld failed to start with queue_track backend"
-	else
-		CLEANUP_PIDS+=("${STALLD_PID}")
-		sleep 1
-		if kill -0 ${STALLD_PID} 2>/dev/null; then
-			# Check if log contains backend message
-			if grep -q "using queue_track backend" "${STALLD_LOG}"; then
-				assert_equals "0" "0" "queue_track backend selected"
-			else
-				TEST_FAILED=$((TEST_FAILED + 1))
-				echo -e "  ${RED}FAIL${NC}: Backend message not found in log"
-				echo "  Log contents:"
-				cat "${STALLD_LOG}"
-			fi
-			stop_stalld
-		else
-			TEST_FAILED=$((TEST_FAILED + 1))
-			echo -e "  ${RED}FAIL${NC}: stalld failed to start with queue_track backend"
-		fi
-	fi
-	rm -f "${STALLD_LOG}"
+	test_backend_flag "queue_track" "using queue_track backend" \
+		"queue_track backend selected"
 else
-	echo "ℹ queue_track (BPF) backend not available"
-	echo "  (This is expected on i686, powerpc, ppc64le, or kernels ≤3.x)"
+	echo "  queue_track (BPF) backend not available"
+	echo "  (This is expected on i686, powerpc, ppc64le, or kernels <=3.x)"
 	TEST_PASSED=$((TEST_PASSED + 1))
 fi
 
-# Test 3: Test short names (S for sched_debug)
+# Test 3: Short name 'S' for sched_debug
+echo ""
 echo "Test 3: Testing short name 'S' for sched_debug"
-STALLD_LOG="/tmp/stalld_backend_short_S_$$.log"
-# Call stalld directly to capture its actual stderr output
-# IMPORTANT: -v must come BEFORE -b so verbose mode is enabled when backend message is logged
-../stalld -v -f -l -b S -t 60 > "${STALLD_LOG}" 2>&1 &
-sleep 1
-# Get the actual stalld PID
-STALLD_PID=$(pgrep -n -x stalld 2>/dev/null)
-if [ -z "${STALLD_PID}" ]; then
-	TEST_FAILED=$((TEST_FAILED + 1))
-	echo -e "  ${RED}FAIL${NC}: stalld failed to start with short name 'S'"
-else
-	CLEANUP_PIDS+=("${STALLD_PID}")
-	sleep 1
-	if kill -0 ${STALLD_PID} 2>/dev/null; then
-		# Check if log contains backend message
-		if grep -q "using sched_debug backend" "${STALLD_LOG}"; then
-			assert_equals "0" "0" "Short name 'S' works for sched_debug"
-		else
-			TEST_FAILED=$((TEST_FAILED + 1))
-			echo -e "  ${RED}FAIL${NC}: Backend message not found for short name"
-			echo "  Log contents:"
-			cat "${STALLD_LOG}"
-		fi
-		stop_stalld
-	else
-		TEST_FAILED=$((TEST_FAILED + 1))
-		echo -e "  ${RED}FAIL${NC}: stalld failed to start with short name 'S'"
-	fi
-fi
-rm -f "${STALLD_LOG}"
+test_backend_flag "S" "using sched_debug backend" \
+	"Short name 'S' works for sched_debug"
 
-# Test 4: Test STALLD_TEST_BACKEND environment variable
+# Test 4: STALLD_TEST_BACKEND environment variable
+echo ""
 if [ -n "${STALLD_TEST_BACKEND}" ]; then
 	echo "Test 4: Testing STALLD_TEST_BACKEND=${STALLD_TEST_BACKEND}"
-	STALLD_LOG="/tmp/stalld_backend_env_$$.log"
-	# Call stalld directly to capture its actual stderr output
-	# start_stalld adds -b based on STALLD_TEST_BACKEND, so we mimic that here
-	# IMPORTANT: -v must come BEFORE -b so verbose mode is enabled when backend message is logged
-	../stalld -v -f -l -b "${STALLD_TEST_BACKEND}" -t 60 > "${STALLD_LOG}" 2>&1 &
-	sleep 1
-	# Get the actual stalld PID
-	STALLD_PID=$(pgrep -n -x stalld 2>/dev/null)
-	if [ -z "${STALLD_PID}" ]; then
-		TEST_FAILED=$((TEST_FAILED + 1))
-		echo -e "  ${RED}FAIL${NC}: stalld failed to start with STALLD_TEST_BACKEND"
-	else
-		CLEANUP_PIDS+=("${STALLD_PID}")
-		sleep 1
-		if kill -0 ${STALLD_PID} 2>/dev/null; then
-			# Normalize backend name for comparison
-			BACKEND_NORMALIZED="${STALLD_TEST_BACKEND}"
-			case "${STALLD_TEST_BACKEND}" in
-				S) BACKEND_NORMALIZED="sched_debug" ;;
-				Q) BACKEND_NORMALIZED="queue_track" ;;
-			esac
-
-			# Check if log contains backend message
-			if grep -q "using ${BACKEND_NORMALIZED} backend" "${STALLD_LOG}"; then
-				assert_equals "0" "0" "STALLD_TEST_BACKEND environment variable respected"
-			else
-				TEST_FAILED=$((TEST_FAILED + 1))
-				echo -e "  ${RED}FAIL${NC}: Backend ${BACKEND_NORMALIZED} not used from environment"
-				echo "  Log contents:"
-				cat "${STALLD_LOG}"
-			fi
-			stop_stalld
-		else
-			echo "ℹ Could not verify backend in logs (may not be logged)"
-			TEST_PASSED=$((TEST_PASSED + 1))
-		fi
-	fi
-	rm -f "${STALLD_LOG}"
+	# Normalize short names for expected message
+	BACKEND_NORMALIZED="${STALLD_TEST_BACKEND}"
+	case "${STALLD_TEST_BACKEND}" in
+		S) BACKEND_NORMALIZED="sched_debug" ;;
+		Q) BACKEND_NORMALIZED="queue_track" ;;
+	esac
+	test_backend_flag "${STALLD_TEST_BACKEND}" \
+		"using ${BACKEND_NORMALIZED} backend" \
+		"STALLD_TEST_BACKEND environment variable respected"
 else
-	echo "ℹ Skipping queue_track test - backend not available on this system"
+	echo "Test 4: Skipping (STALLD_TEST_BACKEND not set)"
 	TEST_PASSED=$((TEST_PASSED + 1))
 fi
 
-- 
2.53.0


  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 ` [PATCH stalld 01/36] tests: Add pre-test and post-test cleanup of stalld processes Wander Lairson Costa
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 ` Wander Lairson Costa [this message]
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-6-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox