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_EXTENDED

The -x option (where 'x' stands for eXtended) takes an argument which
represents the number of samples to request from the PTP device.
The help message will display the maximum number of samples allowed.
Providing an invalid argument will also display the maximum number of
samples allowed.

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
c8ba75c4 8ad228b1

+42 -2
+42 -2
tools/testing/selftests/ptp/testptp.c
··· 143 143 " -S set the system time from the ptp clock time\n" 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 + " -x val get an extended ptp clock time with the desired number of samples (up to %d)\n" 146 147 " -z test combinations of rising/falling external time stamp flags\n", 147 - progname); 148 + progname, PTP_MAX_SAMPLES); 148 149 } 149 150 150 151 int main(int argc, char *argv[]) ··· 159 158 struct timex tx; 160 159 struct ptp_clock_time *pct; 161 160 struct ptp_sys_offset *sysoff; 161 + struct ptp_sys_offset_extended *soe; 162 162 163 163 char *progname; 164 164 unsigned int i; ··· 178 176 int index = 0; 179 177 int list_pins = 0; 180 178 int pct_offset = 0; 179 + int getextended = 0; 181 180 int n_samples = 0; 182 181 int pin_index = -1, pin_func; 183 182 int pps = -1; ··· 193 190 194 191 progname = strrchr(argv[0], '/'); 195 192 progname = progname ? 1+progname : argv[0]; 196 - while (EOF != (c = getopt(argc, argv, "cd:e:f:ghH:i:k:lL:n:o:p:P:sSt:T:w:z"))) { 193 + while (EOF != (c = getopt(argc, argv, "cd:e:f:ghH:i:k:lL:n:o:p:P:sSt:T:w:x:z"))) { 197 194 switch (c) { 198 195 case 'c': 199 196 capabilities = 1; ··· 257 254 break; 258 255 case 'w': 259 256 pulsewidth = atoi(optarg); 257 + break; 258 + case 'x': 259 + getextended = atoi(optarg); 260 + if (getextended < 1 || getextended > PTP_MAX_SAMPLES) { 261 + fprintf(stderr, 262 + "number of extended timestamp samples must be between 1 and %d; was asked for %d\n", 263 + PTP_MAX_SAMPLES, getextended); 264 + return -1; 265 + } 260 266 break; 261 267 case 'z': 262 268 flagtest = 1; ··· 545 533 } 546 534 547 535 free(sysoff); 536 + } 537 + 538 + if (getextended) { 539 + soe = calloc(1, sizeof(*soe)); 540 + if (!soe) { 541 + perror("calloc"); 542 + return -1; 543 + } 544 + 545 + soe->n_samples = getextended; 546 + 547 + if (ioctl(fd, PTP_SYS_OFFSET_EXTENDED, soe)) { 548 + perror("PTP_SYS_OFFSET_EXTENDED"); 549 + } else { 550 + printf("extended timestamp request returned %d samples\n", 551 + getextended); 552 + 553 + for (i = 0; i < getextended; i++) { 554 + printf("sample #%2d: system time before: %lld.%09u\n", 555 + i, soe->ts[i][0].sec, soe->ts[i][0].nsec); 556 + printf(" phc time: %lld.%09u\n", 557 + soe->ts[i][1].sec, soe->ts[i][1].nsec); 558 + printf(" system time after: %lld.%09u\n", 559 + soe->ts[i][2].sec, soe->ts[i][2].nsec); 560 + } 561 + } 562 + 563 + free(soe); 548 564 } 549 565 550 566 close(fd);