Skip to content

Commit b9d5f57

Browse files
committed
selftests: net: increase the delay for relative cmsg_time.sh test
Slow machines can delay scheduling of the packets for milliseconds. Increase the delay to 8ms if KSFT_MACHINE_SLOW. Try to limit the variability by moving setsockopts earlier (before we read time). This fixes the "TXTIME rel" failures on debug kernels, like: Case ICMPv4 - TXTIME rel returned '', expected 'OK' Reviewed-by: Willem de Bruijn <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 2d3b8df commit b9d5f57

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

tools/testing/selftests/net/cmsg_sender.c

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -260,15 +260,8 @@ cs_write_cmsg(int fd, struct msghdr *msg, char *cbuf, size_t cbuf_sz)
260260
SOL_IPV6, IPV6_HOPLIMIT, &opt.v6.hlimit);
261261

262262
if (opt.txtime.ena) {
263-
struct sock_txtime so_txtime = {
264-
.clockid = CLOCK_MONOTONIC,
265-
};
266263
__u64 txtime;
267264

268-
if (setsockopt(fd, SOL_SOCKET, SO_TXTIME,
269-
&so_txtime, sizeof(so_txtime)))
270-
error(ERN_SOCKOPT, errno, "setsockopt TXTIME");
271-
272265
txtime = time_start_mono.tv_sec * (1000ULL * 1000 * 1000) +
273266
time_start_mono.tv_nsec +
274267
opt.txtime.delay * 1000;
@@ -284,13 +277,6 @@ cs_write_cmsg(int fd, struct msghdr *msg, char *cbuf, size_t cbuf_sz)
284277
memcpy(CMSG_DATA(cmsg), &txtime, sizeof(txtime));
285278
}
286279
if (opt.ts.ena) {
287-
__u32 val = SOF_TIMESTAMPING_SOFTWARE |
288-
SOF_TIMESTAMPING_OPT_TSONLY;
289-
290-
if (setsockopt(fd, SOL_SOCKET, SO_TIMESTAMPING,
291-
&val, sizeof(val)))
292-
error(ERN_SOCKOPT, errno, "setsockopt TIMESTAMPING");
293-
294280
cmsg = (struct cmsghdr *)(cbuf + cmsg_len);
295281
cmsg_len += CMSG_SPACE(sizeof(__u32));
296282
if (cbuf_sz < cmsg_len)
@@ -426,6 +412,24 @@ static void ca_set_sockopts(int fd)
426412
setsockopt(fd, SOL_SOCKET, SO_PRIORITY,
427413
&opt.sockopt.priority, sizeof(opt.sockopt.priority)))
428414
error(ERN_SOCKOPT, errno, "setsockopt SO_PRIORITY");
415+
416+
if (opt.txtime.ena) {
417+
struct sock_txtime so_txtime = {
418+
.clockid = CLOCK_MONOTONIC,
419+
};
420+
421+
if (setsockopt(fd, SOL_SOCKET, SO_TXTIME,
422+
&so_txtime, sizeof(so_txtime)))
423+
error(ERN_SOCKOPT, errno, "setsockopt TXTIME");
424+
}
425+
if (opt.ts.ena) {
426+
__u32 val = SOF_TIMESTAMPING_SOFTWARE |
427+
SOF_TIMESTAMPING_OPT_TSONLY;
428+
429+
if (setsockopt(fd, SOL_SOCKET, SO_TIMESTAMPING,
430+
&val, sizeof(val)))
431+
error(ERN_SOCKOPT, errno, "setsockopt TIMESTAMPING");
432+
}
429433
}
430434

431435
int main(int argc, char *argv[])

tools/testing/selftests/net/cmsg_time.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,13 @@ for i in "-4 $TGT4" "-6 $TGT6"; do
6666
awk '/SND/ { if ($3 > 1000) print "OK"; }')
6767
check_result $? "$ts" "OK" "$prot - TXTIME abs"
6868

69-
ts=$(ip netns exec $NS ./cmsg_sender -p $p $i 1234 -t -d 1000 |
69+
[ "$KSFT_MACHINE_SLOW" = yes ] && delay=8000 || delay=1000
70+
71+
ts=$(ip netns exec $NS ./cmsg_sender -p $p $i 1234 -t -d $delay |
7072
awk '/SND/ {snd=$3}
7173
/SCHED/ {sch=$3}
72-
END { if (snd - sch > 500) print "OK"; }')
74+
END { if (snd - sch > '$((delay/2))') print "OK";
75+
else print snd, "-", sch, "<", '$((delay/2))'; }')
7376
check_result $? "$ts" "OK" "$prot - TXTIME rel"
7477
done
7578
done

0 commit comments

Comments
 (0)