Skip to content

Commit

Permalink
selftests/ptp: Add -X option for testing PTP_SYS_OFFSET_PRECISE
Browse files Browse the repository at this point in the history
The -X option was chosen because X looks like a cross, and the underlying
callback is 'get cross timestamp'.

Signed-off-by: Alex Maftei <alex.maftei@amd.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Alex Maftei authored and David S. Miller committed Jul 28, 2023
1 parent c8ba75c commit 3cf119a
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion tools/testing/selftests/ptp/testptp.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ static void usage(char *progname)
" -t val shift the ptp clock time by 'val' seconds\n"
" -T val set the ptp clock time to 'val' seconds\n"
" -x val get an extended ptp clock time with the desired number of samples (up to %d)\n"
" -X get a ptp clock cross timestamp\n"
" -z test combinations of rising/falling external time stamp flags\n",
progname, PTP_MAX_SAMPLES);
}
Expand All @@ -160,6 +161,7 @@ int main(int argc, char *argv[])
struct ptp_clock_time *pct;
struct ptp_sys_offset *sysoff;
struct ptp_sys_offset_extended *soe;
struct ptp_sys_offset_precise *xts;

char *progname;
unsigned int i;
Expand All @@ -179,6 +181,7 @@ int main(int argc, char *argv[])
int list_pins = 0;
int pct_offset = 0;
int getextended = 0;
int getcross = 0;
int n_samples = 0;
int pin_index = -1, pin_func;
int pps = -1;
Expand All @@ -193,7 +196,7 @@ int main(int argc, char *argv[])

progname = strrchr(argv[0], '/');
progname = progname ? 1+progname : argv[0];
while (EOF != (c = getopt(argc, argv, "cd:e:f:ghH:i:k:lL:n:o:p:P:sSt:T:w:x:z"))) {
while (EOF != (c = getopt(argc, argv, "cd:e:f:ghH:i:k:lL:n:o:p:P:sSt:T:w:x:Xz"))) {
switch (c) {
case 'c':
capabilities = 1;
Expand Down Expand Up @@ -267,6 +270,9 @@ int main(int argc, char *argv[])
return -1;
}
break;
case 'X':
getcross = 1;
break;
case 'z':
flagtest = 1;
break;
Expand Down Expand Up @@ -575,6 +581,29 @@ int main(int argc, char *argv[])
free(soe);
}

if (getcross) {
xts = calloc(1, sizeof(*xts));
if (!xts) {
perror("calloc");
return -1;
}

if (ioctl(fd, PTP_SYS_OFFSET_PRECISE, xts)) {
perror("PTP_SYS_OFFSET_PRECISE");
} else {
puts("system and phc crosstimestamping request okay");

printf("device time: %lld.%09u\n",
xts->device.sec, xts->device.nsec);
printf("system time: %lld.%09u\n",
xts->sys_realtime.sec, xts->sys_realtime.nsec);
printf("monoraw time: %lld.%09u\n",
xts->sys_monoraw.sec, xts->sys_monoraw.nsec);
}

free(xts);
}

close(fd);
return 0;
}

0 comments on commit 3cf119a

Please sign in to comment.