Skip to content

Commit 2d3b8df

Browse files
committed
selftests: net: fix timestamp not arriving in cmsg_time.sh
On slow machines the SND timestamp sometimes doesn't arrive before we quit. The test only waits as long as the packet delay, so it's easy for a race condition to happen. Double the wait but do a bit of polling, once the SND timestamp arrives there's no point to wait any longer. This fixes the "TXTIME abs" failures on debug kernels, like: Case ICMPv4 - TXTIME abs 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 b49bd37 commit 2d3b8df

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

tools/testing/selftests/net/cmsg_sender.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -333,16 +333,17 @@ static const char *cs_ts_info2str(unsigned int info)
333333
return "unknown";
334334
}
335335

336-
static void
336+
static unsigned long
337337
cs_read_cmsg(int fd, struct msghdr *msg, char *cbuf, size_t cbuf_sz)
338338
{
339339
struct sock_extended_err *see;
340340
struct scm_timestamping *ts;
341+
unsigned long ts_seen = 0;
341342
struct cmsghdr *cmsg;
342343
int i, err;
343344

344345
if (!opt.ts.ena)
345-
return;
346+
return 0;
346347
msg->msg_control = cbuf;
347348
msg->msg_controllen = cbuf_sz;
348349

@@ -396,8 +397,11 @@ cs_read_cmsg(int fd, struct msghdr *msg, char *cbuf, size_t cbuf_sz)
396397
printf(" %5s ts%d %lluus\n",
397398
cs_ts_info2str(see->ee_info),
398399
i, rel_time);
400+
ts_seen |= 1 << see->ee_info;
399401
}
400402
}
403+
404+
return ts_seen;
401405
}
402406

403407
static void ca_set_sockopts(int fd)
@@ -509,10 +513,16 @@ int main(int argc, char *argv[])
509513
err = ERN_SUCCESS;
510514

511515
if (opt.ts.ena) {
512-
/* Make sure all timestamps have time to loop back */
513-
usleep(opt.txtime.delay);
516+
unsigned long seen;
517+
int i;
514518

515-
cs_read_cmsg(fd, &msg, cbuf, sizeof(cbuf));
519+
/* Make sure all timestamps have time to loop back */
520+
for (i = 0; i < 40; i++) {
521+
seen = cs_read_cmsg(fd, &msg, cbuf, sizeof(cbuf));
522+
if (seen & (1 << SCM_TSTAMP_SND))
523+
break;
524+
usleep(opt.txtime.delay / 20);
525+
}
516526
}
517527

518528
err_out:

0 commit comments

Comments
 (0)