Skip to content

Commit 3d07b69

Browse files
Mahesh Bandewarkuba-moo
authored andcommitted
selftest/ptp: update ptp selftest to exercise the gettimex options
With the inclusion of commit c259aca ("ptp/ioctl: support MONOTONIC{,_RAW} timestamps for PTP_SYS_OFFSET_EXTENDED") clock_gettime() now allows retrieval of pre/post timestamps for CLOCK_MONOTONIC and CLOCK_MONOTONIC_RAW timebases along with the previously supported CLOCK_REALTIME. This patch adds a command line option 'y' to the testptp program to choose one of the allowed timebases [realtime aka system, monotonic, and monotonic-raw). Signed-off-by: Mahesh Bandewar <maheshb@google.com> Cc: Shuah Khan <shuah@kernel.org> Acked-by: Richard Cochran <richardcochran@gmail.com> Link: https://patch.msgid.link/20241003101506.769418-1-maheshb@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 2f65168 commit 3d07b69

File tree

1 file changed

+57
-5
lines changed

1 file changed

+57
-5
lines changed

tools/testing/selftests/ptp/testptp.c

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ static void usage(char *progname)
146146
" -T val set the ptp clock time to 'val' seconds\n"
147147
" -x val get an extended ptp clock time with the desired number of samples (up to %d)\n"
148148
" -X get a ptp clock cross timestamp\n"
149+
" -y val pre/post tstamp timebase to use {realtime|monotonic|monotonic-raw}\n"
149150
" -z test combinations of rising/falling external time stamp flags\n",
150151
progname, PTP_MAX_SAMPLES);
151152
}
@@ -189,6 +190,7 @@ int main(int argc, char *argv[])
189190
int seconds = 0;
190191
int settime = 0;
191192
int channel = -1;
193+
clockid_t ext_clockid = CLOCK_REALTIME;
192194

193195
int64_t t1, t2, tp;
194196
int64_t interval, offset;
@@ -198,7 +200,7 @@ int main(int argc, char *argv[])
198200

199201
progname = strrchr(argv[0], '/');
200202
progname = progname ? 1+progname : argv[0];
201-
while (EOF != (c = getopt(argc, argv, "cd:e:f:F:ghH:i:k:lL:n:o:p:P:sSt:T:w:x:Xz"))) {
203+
while (EOF != (c = getopt(argc, argv, "cd:e:f:F:ghH:i:k:lL:n:o:p:P:sSt:T:w:x:Xy:z"))) {
202204
switch (c) {
203205
case 'c':
204206
capabilities = 1;
@@ -278,6 +280,21 @@ int main(int argc, char *argv[])
278280
case 'X':
279281
getcross = 1;
280282
break;
283+
case 'y':
284+
if (!strcasecmp(optarg, "realtime"))
285+
ext_clockid = CLOCK_REALTIME;
286+
else if (!strcasecmp(optarg, "monotonic"))
287+
ext_clockid = CLOCK_MONOTONIC;
288+
else if (!strcasecmp(optarg, "monotonic-raw"))
289+
ext_clockid = CLOCK_MONOTONIC_RAW;
290+
else {
291+
fprintf(stderr,
292+
"type needs to be realtime, monotonic or monotonic-raw; was given %s\n",
293+
optarg);
294+
return -1;
295+
}
296+
break;
297+
281298
case 'z':
282299
flagtest = 1;
283300
break;
@@ -566,6 +583,7 @@ int main(int argc, char *argv[])
566583
}
567584

568585
soe->n_samples = getextended;
586+
soe->clockid = ext_clockid;
569587

570588
if (ioctl(fd, PTP_SYS_OFFSET_EXTENDED, soe)) {
571589
perror("PTP_SYS_OFFSET_EXTENDED");
@@ -574,12 +592,46 @@ int main(int argc, char *argv[])
574592
getextended);
575593

576594
for (i = 0; i < getextended; i++) {
577-
printf("sample #%2d: system time before: %lld.%09u\n",
578-
i, soe->ts[i][0].sec, soe->ts[i][0].nsec);
595+
switch (ext_clockid) {
596+
case CLOCK_REALTIME:
597+
printf("sample #%2d: real time before: %lld.%09u\n",
598+
i, soe->ts[i][0].sec,
599+
soe->ts[i][0].nsec);
600+
break;
601+
case CLOCK_MONOTONIC:
602+
printf("sample #%2d: monotonic time before: %lld.%09u\n",
603+
i, soe->ts[i][0].sec,
604+
soe->ts[i][0].nsec);
605+
break;
606+
case CLOCK_MONOTONIC_RAW:
607+
printf("sample #%2d: monotonic-raw time before: %lld.%09u\n",
608+
i, soe->ts[i][0].sec,
609+
soe->ts[i][0].nsec);
610+
break;
611+
default:
612+
break;
613+
}
579614
printf(" phc time: %lld.%09u\n",
580615
soe->ts[i][1].sec, soe->ts[i][1].nsec);
581-
printf(" system time after: %lld.%09u\n",
582-
soe->ts[i][2].sec, soe->ts[i][2].nsec);
616+
switch (ext_clockid) {
617+
case CLOCK_REALTIME:
618+
printf(" real time after: %lld.%09u\n",
619+
soe->ts[i][2].sec,
620+
soe->ts[i][2].nsec);
621+
break;
622+
case CLOCK_MONOTONIC:
623+
printf(" monotonic time after: %lld.%09u\n",
624+
soe->ts[i][2].sec,
625+
soe->ts[i][2].nsec);
626+
break;
627+
case CLOCK_MONOTONIC_RAW:
628+
printf(" monotonic-raw time after: %lld.%09u\n",
629+
soe->ts[i][2].sec,
630+
soe->ts[i][2].nsec);
631+
break;
632+
default:
633+
break;
634+
}
583635
}
584636
}
585637

0 commit comments

Comments
 (0)