Skip to content

Commit

Permalink
selftests: net: increase the delay for relative cmsg_time.sh test
Browse files Browse the repository at this point in the history
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 <willemb@google.com>
Link: https://lore.kernel.org/r/20240510005705.43069-2-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Jakub Kicinski committed May 11, 2024
1 parent 2d3b8df commit b9d5f57
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
32 changes: 18 additions & 14 deletions tools/testing/selftests/net/cmsg_sender.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,15 +260,8 @@ cs_write_cmsg(int fd, struct msghdr *msg, char *cbuf, size_t cbuf_sz)
SOL_IPV6, IPV6_HOPLIMIT, &opt.v6.hlimit);

if (opt.txtime.ena) {
struct sock_txtime so_txtime = {
.clockid = CLOCK_MONOTONIC,
};
__u64 txtime;

if (setsockopt(fd, SOL_SOCKET, SO_TXTIME,
&so_txtime, sizeof(so_txtime)))
error(ERN_SOCKOPT, errno, "setsockopt TXTIME");

txtime = time_start_mono.tv_sec * (1000ULL * 1000 * 1000) +
time_start_mono.tv_nsec +
opt.txtime.delay * 1000;
Expand All @@ -284,13 +277,6 @@ cs_write_cmsg(int fd, struct msghdr *msg, char *cbuf, size_t cbuf_sz)
memcpy(CMSG_DATA(cmsg), &txtime, sizeof(txtime));
}
if (opt.ts.ena) {
__u32 val = SOF_TIMESTAMPING_SOFTWARE |
SOF_TIMESTAMPING_OPT_TSONLY;

if (setsockopt(fd, SOL_SOCKET, SO_TIMESTAMPING,
&val, sizeof(val)))
error(ERN_SOCKOPT, errno, "setsockopt TIMESTAMPING");

cmsg = (struct cmsghdr *)(cbuf + cmsg_len);
cmsg_len += CMSG_SPACE(sizeof(__u32));
if (cbuf_sz < cmsg_len)
Expand Down Expand Up @@ -426,6 +412,24 @@ static void ca_set_sockopts(int fd)
setsockopt(fd, SOL_SOCKET, SO_PRIORITY,
&opt.sockopt.priority, sizeof(opt.sockopt.priority)))
error(ERN_SOCKOPT, errno, "setsockopt SO_PRIORITY");

if (opt.txtime.ena) {
struct sock_txtime so_txtime = {
.clockid = CLOCK_MONOTONIC,
};

if (setsockopt(fd, SOL_SOCKET, SO_TXTIME,
&so_txtime, sizeof(so_txtime)))
error(ERN_SOCKOPT, errno, "setsockopt TXTIME");
}
if (opt.ts.ena) {
__u32 val = SOF_TIMESTAMPING_SOFTWARE |
SOF_TIMESTAMPING_OPT_TSONLY;

if (setsockopt(fd, SOL_SOCKET, SO_TIMESTAMPING,
&val, sizeof(val)))
error(ERN_SOCKOPT, errno, "setsockopt TIMESTAMPING");
}
}

int main(int argc, char *argv[])
Expand Down
7 changes: 5 additions & 2 deletions tools/testing/selftests/net/cmsg_time.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,13 @@ for i in "-4 $TGT4" "-6 $TGT6"; do
awk '/SND/ { if ($3 > 1000) print "OK"; }')
check_result $? "$ts" "OK" "$prot - TXTIME abs"

ts=$(ip netns exec $NS ./cmsg_sender -p $p $i 1234 -t -d 1000 |
[ "$KSFT_MACHINE_SLOW" = yes ] && delay=8000 || delay=1000

ts=$(ip netns exec $NS ./cmsg_sender -p $p $i 1234 -t -d $delay |
awk '/SND/ {snd=$3}
/SCHED/ {sch=$3}
END { if (snd - sch > 500) print "OK"; }')
END { if (snd - sch > '$((delay/2))') print "OK";
else print snd, "-", sch, "<", '$((delay/2))'; }')
check_result $? "$ts" "OK" "$prot - TXTIME rel"
done
done
Expand Down

0 comments on commit b9d5f57

Please sign in to comment.