Skip to content

Commit 3cf119a

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

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

tools/testing/selftests/ptp/testptp.c

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ static void usage(char *progname)
144144
" -t val shift the ptp clock time by 'val' seconds\n"
145145
" -T val set the ptp clock time to 'val' seconds\n"
146146
" -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"
147148
" -z test combinations of rising/falling external time stamp flags\n",
148149
progname, PTP_MAX_SAMPLES);
149150
}
@@ -160,6 +161,7 @@ int main(int argc, char *argv[])
160161
struct ptp_clock_time *pct;
161162
struct ptp_sys_offset *sysoff;
162163
struct ptp_sys_offset_extended *soe;
164+
struct ptp_sys_offset_precise *xts;
163165

164166
char *progname;
165167
unsigned int i;
@@ -179,6 +181,7 @@ int main(int argc, char *argv[])
179181
int list_pins = 0;
180182
int pct_offset = 0;
181183
int getextended = 0;
184+
int getcross = 0;
182185
int n_samples = 0;
183186
int pin_index = -1, pin_func;
184187
int pps = -1;
@@ -193,7 +196,7 @@ int main(int argc, char *argv[])
193196

194197
progname = strrchr(argv[0], '/');
195198
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:x:z"))) {
199+
while (EOF != (c = getopt(argc, argv, "cd:e:f:ghH:i:k:lL:n:o:p:P:sSt:T:w:x:Xz"))) {
197200
switch (c) {
198201
case 'c':
199202
capabilities = 1;
@@ -267,6 +270,9 @@ int main(int argc, char *argv[])
267270
return -1;
268271
}
269272
break;
273+
case 'X':
274+
getcross = 1;
275+
break;
270276
case 'z':
271277
flagtest = 1;
272278
break;
@@ -575,6 +581,29 @@ int main(int argc, char *argv[])
575581
free(soe);
576582
}
577583

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+
578607
close(fd);
579608
return 0;
580609
}

0 commit comments

Comments
 (0)