mirror of
https://github.com/torvalds/linux.git
synced 2026-09-22 04:34:03 +02:00
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. Link: https://github.com/uutils/coreutils/issues/11658 Signed-off-by: Nirmoy Das <nirmoyd@nvidia.com> Link: https://patch.msgid.link/20260626144902.3214350-1-nirmoyd@nvidia.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
parent
ba7ad852e1
commit
895bad9cc4
|
|
@ -70,12 +70,27 @@ ksft_exit_status_merge()
|
||||||
$ksft_xfail $ksft_pass $ksft_skip $ksft_fail
|
$ksft_xfail $ksft_pass $ksft_skip $ksft_fail
|
||||||
}
|
}
|
||||||
|
|
||||||
|
timestamp_ms()
|
||||||
|
{
|
||||||
|
local now=$(date -u +%s:%N)
|
||||||
|
local seconds=${now%:*}
|
||||||
|
local nanoseconds=${now#*:}
|
||||||
|
|
||||||
|
if [[ $nanoseconds =~ ^[0-9]+$ ]]; then
|
||||||
|
nanoseconds=${nanoseconds:0:9}
|
||||||
|
else
|
||||||
|
nanoseconds=0
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo $((seconds * 1000 + 10#$nanoseconds / 1000000))
|
||||||
|
}
|
||||||
|
|
||||||
loopy_wait()
|
loopy_wait()
|
||||||
{
|
{
|
||||||
local sleep_cmd=$1; shift
|
local sleep_cmd=$1; shift
|
||||||
local timeout_ms=$1; shift
|
local timeout_ms=$1; shift
|
||||||
|
|
||||||
local start_time="$(date -u +%s%3N)"
|
local start_time=$(timestamp_ms)
|
||||||
while true
|
while true
|
||||||
do
|
do
|
||||||
local out
|
local out
|
||||||
|
|
@ -84,7 +99,7 @@ loopy_wait()
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local current_time="$(date -u +%s%3N)"
|
local current_time=$(timestamp_ms)
|
||||||
if ((current_time - start_time > timeout_ms)); then
|
if ((current_time - start_time > timeout_ms)); then
|
||||||
echo -n "$out"
|
echo -n "$out"
|
||||||
return 1
|
return 1
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user