summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/ptp/testptp.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/testing/selftests/ptp/testptp.c')
-rw-r--r--tools/testing/selftests/ptp/testptp.c73
1 files changed, 71 insertions, 2 deletions
diff --git a/tools/testing/selftests/ptp/testptp.c b/tools/testing/selftests/ptp/testptp.c
index e9438a1862ad..c9f6cca4feb4 100644
--- a/tools/testing/selftests/ptp/testptp.c
+++ b/tools/testing/selftests/ptp/testptp.c
@@ -143,8 +143,10 @@ static void usage(char *progname)
" -S set the system time from the ptp clock time\n"
" -t val shift the ptp clock time by 'val' seconds\n"
" -T val set the ptp clock time to 'val' seconds\n"
+ " -x val get an extended ptp clock time with the desired number of samples (up to %d)\n"
+ " -X get a ptp clock cross timestamp\n"
" -z test combinations of rising/falling external time stamp flags\n",
- progname);
+ progname, PTP_MAX_SAMPLES);
}
int main(int argc, char *argv[])
@@ -158,6 +160,8 @@ int main(int argc, char *argv[])
struct timex tx;
struct ptp_clock_time *pct;
struct ptp_sys_offset *sysoff;
+ struct ptp_sys_offset_extended *soe;
+ struct ptp_sys_offset_precise *xts;
char *progname;
unsigned int i;
@@ -176,6 +180,8 @@ int main(int argc, char *argv[])
int index = 0;
int list_pins = 0;
int pct_offset = 0;
+ int getextended = 0;
+ int getcross = 0;
int n_samples = 0;
int pin_index = -1, pin_func;
int pps = -1;
@@ -190,7 +196,7 @@ int main(int argc, char *argv[])
progname = strrchr(argv[0], '/');
progname = progname ? 1+progname : argv[0];
- while (EOF != (c = getopt(argc, argv, "cd:e:f:ghH:i:k:lL:n:o:p:P:sSt:T:w:z"))) {
+ while (EOF != (c = getopt(argc, argv, "cd:e:f:ghH:i:k:lL:n:o:p:P:sSt:T:w:x:Xz"))) {
switch (c) {
case 'c':
capabilities = 1;
@@ -255,6 +261,18 @@ int main(int argc, char *argv[])
case 'w':
pulsewidth = atoi(optarg);
break;
+ case 'x':
+ getextended = atoi(optarg);
+ if (getextended < 1 || getextended > PTP_MAX_SAMPLES) {
+ fprintf(stderr,
+ "number of extended timestamp samples must be between 1 and %d; was asked for %d\n",
+ PTP_MAX_SAMPLES, getextended);
+ return -1;
+ }
+ break;
+ case 'X':
+ getcross = 1;
+ break;
case 'z':
flagtest = 1;
break;
@@ -535,6 +553,57 @@ int main(int argc, char *argv[])
free(sysoff);
}
+ if (getextended) {
+ soe = calloc(1, sizeof(*soe));
+ if (!soe) {
+ perror("calloc");
+ return -1;
+ }
+
+ soe->n_samples = getextended;
+
+ if (ioctl(fd, PTP_SYS_OFFSET_EXTENDED, soe)) {
+ perror("PTP_SYS_OFFSET_EXTENDED");
+ } else {
+ printf("extended timestamp request returned %d samples\n",
+ getextended);
+
+ for (i = 0; i < getextended; i++) {
+ printf("sample #%2d: system time before: %lld.%09u\n",
+ i, soe->ts[i][0].sec, soe->ts[i][0].nsec);
+ printf(" phc time: %lld.%09u\n",
+ soe->ts[i][1].sec, soe->ts[i][1].nsec);
+ printf(" system time after: %lld.%09u\n",
+ soe->ts[i][2].sec, soe->ts[i][2].nsec);
+ }
+ }
+
+ free(soe);
+ }
+
+ if (getcross) {
+ xts = calloc(1, sizeof(*xts));
+ if (!xts) {
+ perror("calloc");
+ return -1;
+ }
+
+ if (ioctl(fd, PTP_SYS_OFFSET_PRECISE, xts)) {
+ perror("PTP_SYS_OFFSET_PRECISE");
+ } else {
+ puts("system and phc crosstimestamping request okay");
+
+ printf("device time: %lld.%09u\n",
+ xts->device.sec, xts->device.nsec);
+ printf("system time: %lld.%09u\n",
+ xts->sys_realtime.sec, xts->sys_realtime.nsec);
+ printf("monoraw time: %lld.%09u\n",
+ xts->sys_monoraw.sec, xts->sys_monoraw.nsec);
+ }
+
+ free(xts);
+ }
+
close(fd);
return 0;
}