Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ptp: Extend the test program to check the external time stamp flags.

Because each driver and hardware has different capabilities, the test
cannot provide a simple pass/fail result, but it can at least show what
combinations of flags are supported.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Richard Cochran and committed by
David S. Miller
6eb54cbb ca12cf5a

+51 -2
+51 -2
tools/testing/selftests/ptp/testptp.c
··· 44 44 } 45 45 #endif 46 46 47 + static void show_flag_test(int rq_index, unsigned int flags, int err) 48 + { 49 + printf("PTP_EXTTS_REQUEST%c flags 0x%08x : (%d) %s\n", 50 + rq_index ? '1' + rq_index : ' ', 51 + flags, err, strerror(errno)); 52 + /* sigh, uClibc ... */ 53 + errno = 0; 54 + } 55 + 56 + static void do_flag_test(int fd, unsigned int index) 57 + { 58 + struct ptp_extts_request extts_request; 59 + unsigned long request[2] = { 60 + PTP_EXTTS_REQUEST, 61 + PTP_EXTTS_REQUEST2, 62 + }; 63 + unsigned int enable_flags[5] = { 64 + PTP_ENABLE_FEATURE, 65 + PTP_ENABLE_FEATURE | PTP_RISING_EDGE, 66 + PTP_ENABLE_FEATURE | PTP_FALLING_EDGE, 67 + PTP_ENABLE_FEATURE | PTP_RISING_EDGE | PTP_FALLING_EDGE, 68 + PTP_ENABLE_FEATURE | (PTP_EXTTS_VALID_FLAGS + 1), 69 + }; 70 + int err, i, j; 71 + 72 + memset(&extts_request, 0, sizeof(extts_request)); 73 + extts_request.index = index; 74 + 75 + for (i = 0; i < 2; i++) { 76 + for (j = 0; j < 5; j++) { 77 + extts_request.flags = enable_flags[j]; 78 + err = ioctl(fd, request[i], &extts_request); 79 + show_flag_test(i, extts_request.flags, err); 80 + 81 + extts_request.flags = 0; 82 + err = ioctl(fd, request[i], &extts_request); 83 + } 84 + } 85 + } 86 + 47 87 static clockid_t get_clockid(int fd) 48 88 { 49 89 #define CLOCKFD 3 ··· 136 96 " -s set the ptp clock time from the system time\n" 137 97 " -S set the system time from the ptp clock time\n" 138 98 " -t val shift the ptp clock time by 'val' seconds\n" 139 - " -T val set the ptp clock time to 'val' seconds\n", 99 + " -T val set the ptp clock time to 'val' seconds\n" 100 + " -z test combinations of rising/falling external time stamp flags\n", 140 101 progname); 141 102 } 142 103 ··· 163 122 int adjtime = 0; 164 123 int capabilities = 0; 165 124 int extts = 0; 125 + int flagtest = 0; 166 126 int gettime = 0; 167 127 int index = 0; 168 128 int list_pins = 0; ··· 180 138 181 139 progname = strrchr(argv[0], '/'); 182 140 progname = progname ? 1+progname : argv[0]; 183 - while (EOF != (c = getopt(argc, argv, "cd:e:f:ghi:k:lL:p:P:sSt:T:v"))) { 141 + while (EOF != (c = getopt(argc, argv, "cd:e:f:ghi:k:lL:p:P:sSt:T:z"))) { 184 142 switch (c) { 185 143 case 'c': 186 144 capabilities = 1; ··· 232 190 case 'T': 233 191 settime = 3; 234 192 seconds = atoi(optarg); 193 + break; 194 + case 'z': 195 + flagtest = 1; 235 196 break; 236 197 case 'h': 237 198 usage(progname); ··· 365 320 if (ioctl(fd, PTP_EXTTS_REQUEST, &extts_request)) { 366 321 perror("PTP_EXTTS_REQUEST"); 367 322 } 323 + } 324 + 325 + if (flagtest) { 326 + do_flag_test(fd, index); 368 327 } 369 328 370 329 if (list_pins) {