]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftests: net: make busywait timeout clock portable
authorNirmoy Das <nirmoyd@nvidia.com>
Tue, 30 Jun 2026 16:51:57 +0000 (09:51 -0700)
committerPaolo Abeni <pabeni@redhat.com>
Mon, 6 Jul 2026 10:13:37 +0000 (12:13 +0200)
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")
Cc: stable@vger.kernel.org # 6.8+
Link: https://github.com/uutils/coreutils/issues/11658
Signed-off-by: Nirmoy Das <nirmoyd@nvidia.com>
Link: https://patch.msgid.link/20260630165157.3814871-1-nirmoyd@nvidia.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
tools/testing/selftests/net/lib.sh

index b3827b43782b0441f296186f54520e5a70f9a696..d46d2cec89e450355e2b56c6130b182e29db2a34 100644 (file)
@@ -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