Skip to content

Commit 92af463

Browse files
committed
Merge branch 'selftest-ptp'
Alex Maftei says: ==================== selftests/ptp: Add support for new timestamp IOCTLs PTP_SYS_OFFSET_EXTENDED was added in November 2018 in 3618008 (" ptp: add PTP_SYS_OFFSET_EXTENDED ioctl") and PTP_SYS_OFFSET_PRECISE was added in February 2016 in 719f1aa ("ptp: Add PTP_SYS_OFFSET_PRECISE for driver crosstimestamping") The PTP selftest code is lacking support for these two IOCTLS. This short series of patches adds support for them. Changes in v2: - Fixed rebase issues (v1 somehow ended up with patch 1 being from the first manual split of my changes and patch 2 being from rebase 2 out of 3) - Rebased on top of net-next ==================== Acked-by: Richard Cochran <richardcochran@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 8ad228b + 3cf119a commit 92af463

File tree

1 file changed

+71
-2
lines changed

1 file changed

+71
-2
lines changed

tools/testing/selftests/ptp/testptp.c

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,10 @@ static void usage(char *progname)
143143
" -S set the system time from the ptp clock time\n"
144144
" -t val shift the ptp clock time by 'val' seconds\n"
145145
" -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"
147+
" -X get a ptp clock cross timestamp\n"
146148
" -z test combinations of rising/falling external time stamp flags\n",
147-
progname);
149+
progname, PTP_MAX_SAMPLES);
148150
}
149151

150152
int main(int argc, char *argv[])
@@ -158,6 +160,8 @@ int main(int argc, char *argv[])
158160
struct timex tx;
159161
struct ptp_clock_time *pct;
160162
struct ptp_sys_offset *sysoff;
163+
struct ptp_sys_offset_extended *soe;
164+
struct ptp_sys_offset_precise *xts;
161165

162166
char *progname;
163167
unsigned int i;
@@ -176,6 +180,8 @@ int main(int argc, char *argv[])
176180
int index = 0;
177181
int list_pins = 0;
178182
int pct_offset = 0;
183+
int getextended = 0;
184+
int getcross = 0;
179185
int n_samples = 0;
180186
int pin_index = -1, pin_func;
181187
int pps = -1;
@@ -190,7 +196,7 @@ int main(int argc, char *argv[])
190196

191197
progname = strrchr(argv[0], '/');
192198
progname = progname ? 1+progname : argv[0];
193-
while (EOF != (c = getopt(argc, argv, "cd:e:f:ghH:i:k:lL:n:o:p:P:sSt:T:w:z"))) {
199+
while (EOF != (c = getopt(argc, argv, "cd:e:f:ghH:i:k:lL:n:o:p:P:sSt:T:w:x:Xz"))) {
194200
switch (c) {
195201
case 'c':
196202
capabilities = 1;
@@ -255,6 +261,18 @@ int main(int argc, char *argv[])
255261
case 'w':
256262
pulsewidth = atoi(optarg);
257263
break;
264+
case 'x':
265+
getextended = atoi(optarg);
266+
if (getextended < 1 || getextended > PTP_MAX_SAMPLES) {
267+
fprintf(stderr,
268+
"number of extended timestamp samples must be between 1 and %d; was asked for %d\n",
269+
PTP_MAX_SAMPLES, getextended);
270+
return -1;
271+
}
272+
break;
273+
case 'X':
274+
getcross = 1;
275+
break;
258276
case 'z':
259277
flagtest = 1;
260278
break;
@@ -535,6 +553,57 @@ int main(int argc, char *argv[])
535553
free(sysoff);
536554
}
537555

556+
if (getextended) {
557+
soe = calloc(1, sizeof(*soe));
558+
if (!soe) {
559+
perror("calloc");
560+
return -1;
561+
}
562+
563+
soe->n_samples = getextended;
564+
565+
if (ioctl(fd, PTP_SYS_OFFSET_EXTENDED, soe)) {
566+
perror("PTP_SYS_OFFSET_EXTENDED");
567+
} else {
568+
printf("extended timestamp request returned %d samples\n",
569+
getextended);
570+
571+
for (i = 0; i < getextended; i++) {
572+
printf("sample #%2d: system time before: %lld.%09u\n",
573+
i, soe->ts[i][0].sec, soe->ts[i][0].nsec);
574+
printf(" phc time: %lld.%09u\n",
575+
soe->ts[i][1].sec, soe->ts[i][1].nsec);
576+
printf(" system time after: %lld.%09u\n",
577+
soe->ts[i][2].sec, soe->ts[i][2].nsec);
578+
}
579+
}
580+
581+
free(soe);
582+
}
583+
584+
if (getcross) {
585+
xts = calloc(1, sizeof(*xts));
586+
if (!xts) {
587+
perror("calloc");
588+
return -1;
589+
}
590+
591+
if (ioctl(fd, PTP_SYS_OFFSET_PRECISE, xts)) {
592+
perror("PTP_SYS_OFFSET_PRECISE");
593+
} else {
594+
puts("system and phc crosstimestamping request okay");
595+
596+
printf("device time: %lld.%09u\n",
597+
xts->device.sec, xts->device.nsec);
598+
printf("system time: %lld.%09u\n",
599+
xts->sys_realtime.sec, xts->sys_realtime.nsec);
600+
printf("monoraw time: %lld.%09u\n",
601+
xts->sys_monoraw.sec, xts->sys_monoraw.nsec);
602+
}
603+
604+
free(xts);
605+
}
606+
538607
close(fd);
539608
return 0;
540609
}

0 commit comments

Comments
 (0)