[PATCH stalld 14/36] tests/helpers: Fix fractional sleep timeout bugs

Wander Lairson Costa <[email protected]>
Newsgroups org.kernel.vger.linux-rt-users
Message-ID <[email protected]>
The cleanup() process termination loop and start_stalld() pidfile
wait both use fractional sleeps (0.1s and 0.5s) with integer
counters, causing the actual timeouts to be a fraction of the
nominal values. cleanup() with timeout=5 and sleep 0.1 gives only
0.5 seconds, and start_stalld() with timeout=15 and sleep 0.5
gives only 7.5 seconds.

Change both loops to use sleep 1, making the timeout arithmetic
correct. Restructure the cleanup loop to use the same two-phase
SIGTERM/SIGKILL pattern established in stop_stalld().

Signed-off-by: Wander Lairson Costa <[email protected]>
---
 tests/helpers/test_helpers.sh | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/tests/helpers/test_helpers.sh b/tests/helpers/test_helpers.sh
index e4e9b23..06c0471 100755
--- a/tests/helpers/test_helpers.sh
+++ b/tests/helpers/test_helpers.sh
@@ -288,7 +288,7 @@ start_stalld() {
 		local timeout=15
 		local elapsed=0
 		while [ ! -f "$pidfile" ] && [ $elapsed -lt $timeout ]; do
-			sleep 0.5
+			sleep 1
 			elapsed=$((elapsed + 1))
 		done
 
@@ -452,21 +452,23 @@ cleanup() {
 		if [ -n "${pid}" ] && [ "${pid}" -gt 0 ] 2>/dev/null; then
 			# Check if process exists
 			if kill -0 ${pid} 2>/dev/null; then
-				# Try gentle kill first
 				kill ${pid} 2>/dev/null || true
-				# Give it a moment
-				sleep 0.1
-				# Force kill if still running
-				if kill -0 ${pid} 2>/dev/null; then
-					kill -9 ${pid} 2>/dev/null || true
-				fi
-				# Poll for termination (don't use wait - might not be a child)
+
 				local timeout=5
 				local elapsed=0
 				while kill -0 ${pid} 2>/dev/null && [ ${elapsed} -lt ${timeout} ]; do
-					sleep 0.1
+					sleep 1
 					elapsed=$((elapsed + 1))
 				done
+
+				if kill -0 ${pid} 2>/dev/null; then
+					kill -9 ${pid} 2>/dev/null || true
+					elapsed=0
+					while kill -0 ${pid} 2>/dev/null && [ ${elapsed} -lt ${timeout} ]; do
+						sleep 1
+						elapsed=$((elapsed + 1))
+					done
+				fi
 			fi
 		fi
 	done
-- 
2.53.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.