Skip to content

Commit c8ba75c

Browse files
amaftei-xilinxdavem330
authored andcommitted
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>
1 parent 8ad228b commit c8ba75c

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

tools/testing/selftests/ptp/testptp.c

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,9 @@ 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"
146147
" -z test combinations of rising/falling external time stamp flags\n",
147-
progname);
148+
progname, PTP_MAX_SAMPLES);
148149
}
149150

150151
int main(int argc, char *argv[])
@@ -158,6 +159,7 @@ int main(int argc, char *argv[])
158159
struct timex tx;
159160
struct ptp_clock_time *pct;
160161
struct ptp_sys_offset *sysoff;
162+
struct ptp_sys_offset_extended *soe;
161163

162164
char *progname;
163165
unsigned int i;
@@ -176,6 +178,7 @@ int main(int argc, char *argv[])
176178
int index = 0;
177179
int list_pins = 0;
178180
int pct_offset = 0;
181+
int getextended = 0;
179182
int n_samples = 0;
180183
int pin_index = -1, pin_func;
181184
int pps = -1;
@@ -190,7 +193,7 @@ int main(int argc, char *argv[])
190193

191194
progname = strrchr(argv[0], '/');
192195
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"))) {
196+
while (EOF != (c = getopt(argc, argv, "cd:e:f:ghH:i:k:lL:n:o:p:P:sSt:T:w:x:z"))) {
194197
switch (c) {
195198
case 'c':
196199
capabilities = 1;
@@ -255,6 +258,15 @@ int main(int argc, char *argv[])
255258
case 'w':
256259
pulsewidth = atoi(optarg);
257260
break;
261+
case 'x':
262+
getextended = atoi(optarg);
263+
if (getextended < 1 || getextended > PTP_MAX_SAMPLES) {
264+
fprintf(stderr,
265+
"number of extended timestamp samples must be between 1 and %d; was asked for %d\n",
266+
PTP_MAX_SAMPLES, getextended);
267+
return -1;
268+
}
269+
break;
258270
case 'z':
259271
flagtest = 1;
260272
break;
@@ -535,6 +547,34 @@ int main(int argc, char *argv[])
535547
free(sysoff);
536548
}
537549

550+
if (getextended) {
551+
soe = calloc(1, sizeof(*soe));
552+
if (!soe) {
553+
perror("calloc");
554+
return -1;
555+
}
556+
557+
soe->n_samples = getextended;
558+
559+
if (ioctl(fd, PTP_SYS_OFFSET_EXTENDED, soe)) {
560+
perror("PTP_SYS_OFFSET_EXTENDED");
561+
} else {
562+
printf("extended timestamp request returned %d samples\n",
563+
getextended);
564+
565+
for (i = 0; i < getextended; i++) {
566+
printf("sample #%2d: system time before: %lld.%09u\n",
567+
i, soe->ts[i][0].sec, soe->ts[i][0].nsec);
568+
printf(" phc time: %lld.%09u\n",
569+
soe->ts[i][1].sec, soe->ts[i][1].nsec);
570+
printf(" system time after: %lld.%09u\n",
571+
soe->ts[i][2].sec, soe->ts[i][2].nsec);
572+
}
573+
}
574+
575+
free(soe);
576+
}
577+
538578
close(fd);
539579
return 0;
540580
}

0 commit comments

Comments
 (0)