Skip to contentSkip to conversation

selftests: net: make busywait timeout clock portable

PATCH Applied Nirmoy Das 2 participants 2 messages Jun 30 – Jul 6

Subsystems (4)
lore
Share & tools
lore

Nirmoy Das

author
#0 lore raw

PATCH v2 1/1 selftests: net: make busywait timeout clock portable

loopy_wait() expects millisecond timestamps. However, Ubuntu Resolute can use uutils date, where date -u +%s%3N returns seconds plus full nanoseconds instead of a 3-digit millisecond field. This makes busywait expire too early and can make vlan_bridge_binding.sh read a stale operstate.

Fixes 25ae948b4478 ("selftests/net: add lib.sh")

---
Changes in v2:
- Declare variables separately from command substitutions and propagate timestamp failures, addressing ShellCheck SC2155.

 tools/testing/selftests/net/lib.sh | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)
tools/testing/selftests/net/lib.sh +23 -2
index b40694573f4c7..d030d45c0e603 100644
@@ -70,12 +70,33 @@ ksft_exit_status_merge()
 		$ksft_xfail $ksft_pass $ksft_skip $ksft_fail
 }
 
+timestamp_ms()
+{
+	local now
+	local seconds
+	local nanoseconds
+
+	now=$(date -u +%s:%N) || return
+	seconds=${now%:*}
+	nanoseconds=${now#*:}
+
+	if [[ $nanoseconds =~ ^[0-9]+$ ]]; then
+		nanoseconds=${nanoseconds:0:9}
+	else
+		nanoseconds=0
+	fi
+
+	echo $((seconds * 1000 + 10#$nanoseconds / 1000000))
+}
+
 loopy_wait()
 {
 	local sleep_cmd=$1; shift
 	local timeout_ms=$1; shift
+	local start_time
+	local current_time
 
-	local start_time="$(date -u +%s%3N)"
+	start_time=$(timestamp_ms) || return
 	while true
 	do
 		local out
@@ -84,7 +105,7 @@ loopy_wait()
 			return 0
 		fi
 
-		local current_time="$(date -u +%s%3N)"
+		current_time=$(timestamp_ms) || return
 		if ((current_time - start_time > timeout_ms)); then
 			echo -n "$out"
 			return 1

base-commit: e7cffd183c128af12683aba28ba163017ea2b192

Signature · 1 line
2.43.0
#1 lore raw
This patch was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:

Quoted 6 lines · On Tue, 30 Jun 2026 09:51:57 -0700 you wrote:

loopy_wait() expects millisecond timestamps. However, Ubuntu Resolute can use uutils date, where date -u +%s%3N returns seconds plus full nanoseconds instead of a 3-digit millisecond field. This makes busywait expire too early and can make vlan_bridge_binding.sh read a stale operstate.

Quoted 6 lines
Fixes 25ae948b4478 ("selftests/net: add lib.sh")

[...]

Here is the summary with links:
- [net,v2] selftests: net: make busywait timeout clock portable

    https://git.kernel.org/netdev/net/c/dd6a23bac306

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html