Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/ptp: Add -X option for testing PTP_SYS_OFFSET_PRECISE

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>

authored by

Alex Maftei and committed by
David S. Miller
3cf119ad c8ba75c4

+30 -1
+30 -1
tools/testing/selftests/ptp/testptp.c
··· 144 144 " -t val shift the ptp clock time by 'val' seconds\n" 145 145 " -T val set the ptp clock time to 'val' seconds\n" 146 146 " -x val get an extended ptp clock time with the desired number of samples (up to %d)\n" 147 + " -X get a ptp clock cross timestamp\n" 147 148 " -z test combinations of rising/falling external time stamp flags\n", 148 149 progname, PTP_MAX_SAMPLES); 149 150 } ··· 161 160 struct ptp_clock_time *pct; 162 161 struct ptp_sys_offset *sysoff; 163 162 struct ptp_sys_offset_extended *soe; 163 + struct ptp_sys_offset_precise *xts; 164 164 165 165 char *progname; 166 166 unsigned int i; ··· 181 179 int list_pins = 0; 182 180 int pct_offset = 0; 183 181 int getextended = 0; 182 + int getcross = 0; 184 183 int n_samples = 0; 185 184 int pin_index = -1, pin_func; 186 185 int pps = -1; ··· 196 193 197 194 progname = strrchr(argv[0], '/'); 198 195 progname = progname ? 1+progname : argv[0]; 199 - while (EOF != (c = getopt(argc, argv, "cd:e:f:ghH:i:k:lL:n:o:p:P:sSt:T:w:x:z"))) { 196 + while (EOF != (c = getopt(argc, argv, "cd:e:f:ghH:i:k:lL:n:o:p:P:sSt:T:w:x:Xz"))) { 200 197 switch (c) { 201 198 case 'c': 202 199 capabilities = 1; ··· 269 266 PTP_MAX_SAMPLES, getextended); 270 267 return -1; 271 268 } 269 + break; 270 + case 'X': 271 + getcross = 1; 272 272 break; 273 273 case 'z': 274 274 flagtest = 1; ··· 579 573 } 580 574 581 575 free(soe); 576 + } 577 + 578 + if (getcross) { 579 + xts = calloc(1, sizeof(*xts)); 580 + if (!xts) { 581 + perror("calloc"); 582 + return -1; 583 + } 584 + 585 + if (ioctl(fd, PTP_SYS_OFFSET_PRECISE, xts)) { 586 + perror("PTP_SYS_OFFSET_PRECISE"); 587 + } else { 588 + puts("system and phc crosstimestamping request okay"); 589 + 590 + printf("device time: %lld.%09u\n", 591 + xts->device.sec, xts->device.nsec); 592 + printf("system time: %lld.%09u\n", 593 + xts->sys_realtime.sec, xts->sys_realtime.nsec); 594 + printf("monoraw time: %lld.%09u\n", 595 + xts->sys_monoraw.sec, xts->sys_monoraw.nsec); 596 + } 597 + 598 + free(xts); 582 599 } 583 600 584 601 close(fd);