[PATCH stalld 27/36] tests/functional: Use timeout for invalid argument tests
Wander Lairson Costa <[email protected]> Mon, 30 Mar 2026 16:43:50 -0300
| Newsgroups | org.kernel.vger.linux-rt-users |
|---|---|
| Message-ID | <[email protected]> |
Invalid argument tests background stalld and sleep 2-3 seconds to check whether it exited, wasting time on every run since stalld rejects bad arguments almost instantly. Run stalld synchronously under timeout instead, and treat unexpected success or timeout as test failures rather than warnings. Signed-off-by: Wander Lairson Costa <[email protected]> --- tests/functional/test_affinity.sh | 20 ++---- tests/functional/test_boost_duration.sh | 38 ++++-------- tests/functional/test_boost_period.sh | 38 ++++-------- tests/functional/test_boost_runtime.sh | 62 +++++++------------ tests/functional/test_fifo_boosting.sh | 17 ++--- tests/functional/test_pidfile.sh | 21 ++----- tests/functional/test_starvation_threshold.sh | 36 ++++------- 7 files changed, 77 insertions(+), 155 deletions(-) diff --git a/tests/functional/test_affinity.sh b/tests/functional/test_affinity.sh index c3888ba..eac61f5 100755 --- a/tests/functional/test_affinity.sh +++ b/tests/functional/test_affinity.sh @@ -264,22 +264,14 @@ if [ -n "${STALLD_TEST_BACKEND}" ]; then BACKEND_FLAG="-b ${STALLD_TEST_BACKEND}" fi -${TEST_ROOT}/../stalld -f -v ${BACKEND_FLAG} -l -t 5 -a ${invalid_cpu} > "${INVALID_LOG}" 2>&1 & -invalid_pid=$! -sleep 2 +timeout 5 ${TEST_ROOT}/../stalld -f -v ${BACKEND_FLAG} -l -t 5 -a ${invalid_cpu} > "${INVALID_LOG}" 2>&1 +ret=$? -if ! kill -0 "${invalid_pid}" 2>/dev/null; then - # Process exited - if grep -qi "error\|invalid\|failed" "${INVALID_LOG}"; then - log "✓ PASS: Invalid CPU affinity rejected with error" - else - log "ℹ INFO: Invalid CPU affinity caused exit" - fi +if [ $ret -ne 0 ] && [ $ret -ne 124 ]; then + assert_equals "1" "1" "Invalid CPU affinity rejected with error" else - # Process still running - might have been ignored - log "⚠ WARNING: stalld accepted invalid CPU affinity" - kill -TERM "${invalid_pid}" 2>/dev/null || true - wait "${invalid_pid}" 2>/dev/null || true + log "✗ FAIL: stalld did not reject invalid CPU affinity" + TEST_FAILED=$((TEST_FAILED + 1)) fi #============================================================================= diff --git a/tests/functional/test_boost_duration.sh b/tests/functional/test_boost_duration.sh index af657db..ff43df3 100755 --- a/tests/functional/test_boost_duration.sh +++ b/tests/functional/test_boost_duration.sh @@ -196,20 +196,14 @@ if [ -n "${STALLD_TEST_BACKEND}" ]; then BACKEND_FLAG="-b ${STALLD_TEST_BACKEND}" fi -${TEST_ROOT}/../stalld -f -v ${BACKEND_FLAG} -t ${threshold} -d 0 > "${INVALID_LOG}" 2>&1 & -invalid_pid=$! -sleep 2 - -if ! kill -0 "${invalid_pid}" 2>/dev/null; then - if grep -qi "error\|invalid" "${INVALID_LOG}"; then - log "✓ PASS: Zero duration rejected with error" - else - log "ℹ INFO: Zero duration caused exit (may have been rejected)" - fi +timeout 5 ${TEST_ROOT}/../stalld -f -v ${BACKEND_FLAG} -t ${threshold} -d 0 > "${INVALID_LOG}" 2>&1 +ret=$? + +if [ $ret -ne 0 ] && [ $ret -ne 124 ]; then + assert_equals "1" "1" "Zero duration rejected with error" else - log "⚠ WARNING: stalld accepted zero duration" - kill -TERM "${invalid_pid}" 2>/dev/null || true - wait "${invalid_pid}" 2>/dev/null || true + log "✗ FAIL: stalld did not reject invalid duration value 0" + TEST_FAILED=$((TEST_FAILED + 1)) fi # Test 6: Negative duration @@ -217,20 +211,14 @@ log "Testing with duration = -5" INVALID_LOG2="/tmp/stalld_test_boost_duration_invalid2_$$.log" CLEANUP_FILES+=("${INVALID_LOG2}") -${TEST_ROOT}/../stalld -f -v ${BACKEND_FLAG} -t ${threshold} -d -5 > "${INVALID_LOG2}" 2>&1 & -invalid_pid=$! -sleep 2 +timeout 5 ${TEST_ROOT}/../stalld -f -v ${BACKEND_FLAG} -t ${threshold} -d -5 > "${INVALID_LOG2}" 2>&1 +ret=$? -if ! kill -0 "${invalid_pid}" 2>/dev/null; then - if grep -qi "error\|invalid" "${INVALID_LOG2}"; then - log "✓ PASS: Negative duration rejected with error" - else - log "ℹ INFO: Negative duration caused exit" - fi +if [ $ret -ne 0 ] && [ $ret -ne 124 ]; then + assert_equals "1" "1" "Negative duration rejected with error" else - log "⚠ WARNING: stalld accepted negative duration" - kill -TERM "${invalid_pid}" 2>/dev/null || true - wait "${invalid_pid}" 2>/dev/null || true + log "✗ FAIL: stalld did not reject invalid negative duration" + TEST_FAILED=$((TEST_FAILED + 1)) fi log "" diff --git a/tests/functional/test_boost_period.sh b/tests/functional/test_boost_period.sh index 4838672..5b0ef2c 100755 --- a/tests/functional/test_boost_period.sh +++ b/tests/functional/test_boost_period.sh @@ -189,20 +189,14 @@ if [ -n "${STALLD_TEST_BACKEND}" ]; then BACKEND_FLAG="-b ${STALLD_TEST_BACKEND}" fi -${TEST_ROOT}/../stalld -f -v ${BACKEND_FLAG} -t $threshold -p 0 > "${INVALID_LOG}" 2>&1 & -invalid_pid=$! -sleep 2 - -if ! kill -0 "$invalid_pid" 2>/dev/null; then - if grep -qi "error\|invalid" "${INVALID_LOG}"; then - log "✓ PASS: Zero period rejected with error" - else - log "ℹ INFO: Zero period caused exit" - fi +timeout 5 ${TEST_ROOT}/../stalld -f -v ${BACKEND_FLAG} -t $threshold -p 0 > "${INVALID_LOG}" 2>&1 +ret=$? + +if [ $ret -ne 0 ] && [ $ret -ne 124 ]; then + assert_equals "1" "1" "Zero period rejected with error" else - log "⚠ WARNING: stalld accepted zero period" - kill -TERM "$invalid_pid" 2>/dev/null || true - wait "$invalid_pid" 2>/dev/null || true + log "✗ FAIL: stalld did not reject invalid period value 0" + TEST_FAILED=$((TEST_FAILED + 1)) fi #============================================================================= @@ -216,20 +210,14 @@ log "==========================================" INVALID_LOG2="/tmp/stalld_test_boost_period_invalid2_$$.log" CLEANUP_FILES+=("${INVALID_LOG2}") -${TEST_ROOT}/../stalld -f -v ${BACKEND_FLAG} -t $threshold -p -1000000 > "${INVALID_LOG2}" 2>&1 & -invalid_pid=$! -sleep 2 +timeout 5 ${TEST_ROOT}/../stalld -f -v ${BACKEND_FLAG} -t $threshold -p -1000000 > "${INVALID_LOG2}" 2>&1 +ret=$? -if ! kill -0 "$invalid_pid" 2>/dev/null; then - if grep -qi "error\|invalid" "${INVALID_LOG2}"; then - log "✓ PASS: Negative period rejected with error" - else - log "ℹ INFO: Negative period caused exit" - fi +if [ $ret -ne 0 ] && [ $ret -ne 124 ]; then + assert_equals "1" "1" "Negative period rejected with error" else - log "⚠ WARNING: stalld accepted negative period" - kill -TERM "$invalid_pid" 2>/dev/null || true - wait "$invalid_pid" 2>/dev/null || true + log "✗ FAIL: stalld did not reject invalid negative period" + TEST_FAILED=$((TEST_FAILED + 1)) fi #============================================================================= diff --git a/tests/functional/test_boost_runtime.sh b/tests/functional/test_boost_runtime.sh index 734a6f8..83e8fc5 100755 --- a/tests/functional/test_boost_runtime.sh +++ b/tests/functional/test_boost_runtime.sh @@ -196,22 +196,14 @@ if [ -n "${STALLD_TEST_BACKEND}" ]; then fi log "Testing with runtime ${invalid_runtime}ns > period ${period}ns" -${TEST_ROOT}/../stalld -f -v ${BACKEND_FLAG} -t ${threshold} -r ${invalid_runtime} -p ${period} > "${INVALID_LOG}" 2>&1 & -invalid_pid=$! -sleep 2 - -if ! kill -0 "${invalid_pid}" 2>/dev/null; then - # Process exited - this is expected behavior - if grep -qi "error\|invalid\|failed" "${INVALID_LOG}"; then - log "✓ PASS: Runtime > period rejected with error" - else - log "ℹ INFO: Runtime > period caused exit" - fi +timeout 5 ${TEST_ROOT}/../stalld -f -v ${BACKEND_FLAG} -t ${threshold} -r ${invalid_runtime} -p ${period} > "${INVALID_LOG}" 2>&1 +ret=$? + +if [ $ret -ne 0 ] && [ $ret -ne 124 ]; then + assert_equals "1" "1" "Runtime > period rejected with error" else - # Process still running - might be accepted or might fail later - log "⚠ WARNING: stalld accepted runtime > period" - kill -TERM "${invalid_pid}" 2>/dev/null || true - wait "${invalid_pid}" 2>/dev/null || true + log "✗ FAIL: stalld did not reject invalid runtime > period" + TEST_FAILED=$((TEST_FAILED + 1)) fi #============================================================================= @@ -226,20 +218,14 @@ INVALID_LOG2="/tmp/stalld_test_boost_runtime_invalid2_$$.log" CLEANUP_FILES+=("${INVALID_LOG2}") log "Testing with runtime = 0" -${TEST_ROOT}/../stalld -f -v ${BACKEND_FLAG} -t ${threshold} -r 0 > "${INVALID_LOG2}" 2>&1 & -invalid_pid=$! -sleep 2 - -if ! kill -0 "${invalid_pid}" 2>/dev/null; then - if grep -qi "error\|invalid" "${INVALID_LOG2}"; then - log "✓ PASS: Zero runtime rejected with error" - else - log "ℹ INFO: Zero runtime caused exit" - fi +timeout 5 ${TEST_ROOT}/../stalld -f -v ${BACKEND_FLAG} -t ${threshold} -r 0 > "${INVALID_LOG2}" 2>&1 +ret=$? + +if [ $ret -ne 0 ] && [ $ret -ne 124 ]; then + assert_equals "1" "1" "Zero runtime rejected with error" else - log "⚠ WARNING: stalld accepted zero runtime" - kill -TERM "${invalid_pid}" 2>/dev/null || true - wait "${invalid_pid}" 2>/dev/null || true + log "✗ FAIL: stalld did not reject invalid runtime value 0" + TEST_FAILED=$((TEST_FAILED + 1)) fi #============================================================================= @@ -254,20 +240,14 @@ INVALID_LOG3="/tmp/stalld_test_boost_runtime_invalid3_$$.log" CLEANUP_FILES+=("${INVALID_LOG3}") log "Testing with runtime = -5000" -${TEST_ROOT}/../stalld -f -v ${BACKEND_FLAG} -t ${threshold} -r -5000 > "${INVALID_LOG3}" 2>&1 & -invalid_pid=$! -sleep 2 - -if ! kill -0 "${invalid_pid}" 2>/dev/null; then - if grep -qi "error\|invalid" "${INVALID_LOG3}"; then - log "✓ PASS: Negative runtime rejected with error" - else - log "ℹ INFO: Negative runtime caused exit" - fi +timeout 5 ${TEST_ROOT}/../stalld -f -v ${BACKEND_FLAG} -t ${threshold} -r -5000 > "${INVALID_LOG3}" 2>&1 +ret=$? + +if [ $ret -ne 0 ] && [ $ret -ne 124 ]; then + assert_equals "1" "1" "Negative runtime rejected with error" else - log "⚠ WARNING: stalld accepted negative runtime" - kill -TERM "${invalid_pid}" 2>/dev/null || true - wait "${invalid_pid}" 2>/dev/null || true + log "✗ FAIL: stalld did not reject invalid negative runtime" + TEST_FAILED=$((TEST_FAILED + 1)) fi log "" diff --git a/tests/functional/test_fifo_boosting.sh b/tests/functional/test_fifo_boosting.sh index 3088141..dee3250 100755 --- a/tests/functional/test_fifo_boosting.sh +++ b/tests/functional/test_fifo_boosting.sh @@ -331,19 +331,14 @@ CLEANUP_FILES+=("${STALLD_LOG_FAIL}") # Try to start stalld with -F but without -A (single-threaded mode) # This should fail because single-threaded mode only works with DEADLINE -${TEST_ROOT}/../stalld -f -v -F -t 5 -c ${TEST_CPU} > "${STALLD_LOG_FAIL}" 2>&1 & -FAIL_PID=$! +timeout 5 ${TEST_ROOT}/../stalld -f -v -F -t 5 -c ${TEST_CPU} > "${STALLD_LOG_FAIL}" 2>&1 +ret=$? -# Wait a bit for it to fail -sleep 3 - -# Check if it's still running (it shouldn't be) -if ps -p ${FAIL_PID} > /dev/null 2>&1; then - log "⚠ WARNING: stalld is still running (should have exited)" - kill -TERM ${FAIL_PID} 2>/dev/null - wait ${FAIL_PID} 2>/dev/null +if [ $ret -ne 0 ] && [ $ret -ne 124 ]; then + assert_equals "1" "1" "stalld exited as expected" else - log "✓ PASS: stalld exited as expected" + log "✗ FAIL: stalld did not reject FIFO in single-threaded mode" + TEST_FAILED=$((TEST_FAILED + 1)) fi # Check for error message in log diff --git a/tests/functional/test_pidfile.sh b/tests/functional/test_pidfile.sh index 155855e..6964c0c 100755 --- a/tests/functional/test_pidfile.sh +++ b/tests/functional/test_pidfile.sh @@ -215,23 +215,14 @@ if [ -n "${STALLD_TEST_BACKEND}" ]; then fi log "Testing invalid pidfile path: ${invalid_pidfile}" -${TEST_ROOT}/../stalld -f -v ${BACKEND_FLAG} -l -t 5 --pidfile "${invalid_pidfile}" > "${INVALID_LOG}" 2>&1 & -invalid_pid=$! -sleep 2 +timeout 5 ${TEST_ROOT}/../stalld -f -v ${BACKEND_FLAG} -l -t 5 --pidfile "${invalid_pidfile}" > "${INVALID_LOG}" 2>&1 +ret=$? -# Check if stalld is still running -if ! kill -0 "${invalid_pid}" 2>/dev/null; then - # Process exited - if grep -qi "error\|permission\|denied\|failed" "${INVALID_LOG}"; then - log "✓ PASS: Invalid pidfile path rejected with error" - else - log "ℹ INFO: Invalid pidfile path caused exit" - fi +if [ $ret -ne 0 ] && [ $ret -ne 124 ]; then + assert_equals "1" "1" "Invalid pidfile path rejected with error" else - # Process still running - might have accepted it or created elsewhere - log "⚠ WARNING: stalld running despite potentially invalid pidfile path" - kill -TERM "${invalid_pid}" 2>/dev/null || true - wait "${invalid_pid}" 2>/dev/null || true + log "✗ FAIL: stalld did not reject invalid pidfile path" + TEST_FAILED=$((TEST_FAILED + 1)) fi # Cleanup diff --git a/tests/functional/test_starvation_threshold.sh b/tests/functional/test_starvation_threshold.sh index 9b14009..709f565 100755 --- a/tests/functional/test_starvation_threshold.sh +++ b/tests/functional/test_starvation_threshold.sh @@ -187,20 +187,14 @@ log "Testing with threshold = 0" INVALID_LOG="/tmp/stalld_test_threshold_invalid_$$.log" CLEANUP_FILES+=("${INVALID_LOG}") -${TEST_ROOT}/../stalld -f -v -t 0 > "${INVALID_LOG}" 2>&1 & -invalid_pid=$! -sleep 2 +timeout 5 ${TEST_ROOT}/../stalld -f -v -t 0 > "${INVALID_LOG}" 2>&1 +ret=$? -if ! kill -0 "${invalid_pid}" 2>/dev/null; then - if grep -qi "error\|invalid" "${INVALID_LOG}"; then - log "✓ PASS: Zero threshold rejected with error" - else - log "ℹ INFO: Zero threshold caused exit (may have been rejected)" - fi +if [ $ret -ne 0 ] && [ $ret -ne 124 ]; then + assert_equals "1" "1" "Zero threshold rejected with error" else - log "⚠ WARNING: stalld accepted zero threshold" - kill -TERM "${invalid_pid}" 2>/dev/null - wait "${invalid_pid}" 2>/dev/null || true + log "✗ FAIL: stalld did not reject invalid threshold value 0" + TEST_FAILED=$((TEST_FAILED + 1)) fi # Test with negative threshold @@ -208,20 +202,14 @@ log "Testing with threshold = -5" INVALID_LOG2="/tmp/stalld_test_threshold_invalid2_$$.log" CLEANUP_FILES+=("${INVALID_LOG2}") -${TEST_ROOT}/../stalld -f -v -t -5 > "${INVALID_LOG2}" 2>&1 & -invalid_pid=$! -sleep 2 +timeout 5 ${TEST_ROOT}/../stalld -f -v -t -5 > "${INVALID_LOG2}" 2>&1 +ret=$? -if ! kill -0 "${invalid_pid}" 2>/dev/null; then - if grep -qi "error\|invalid" "${INVALID_LOG2}"; then - log "✓ PASS: Negative threshold rejected with error" - else - log "ℹ INFO: Negative threshold caused exit" - fi +if [ $ret -ne 0 ] && [ $ret -ne 124 ]; then + assert_equals "1" "1" "Negative threshold rejected with error" else - log "⚠ WARNING: stalld accepted negative threshold" - kill -TERM "${invalid_pid}" 2>/dev/null - wait "${invalid_pid}" 2>/dev/null || true + log "✗ FAIL: stalld did not reject invalid negative threshold" + TEST_FAILED=$((TEST_FAILED + 1)) fi log "" -- 2.53.0