[PATCH v4] tests: Add test for decoding of PTP_* ioctl commands
Dmitry V. Levin
ldv at altlinux.org
Sun Mar 11 01:36:19 UTC 2018
On Sat, Mar 10, 2018 at 12:00:05PM +0530, Harsha Sharma wrote:
> * tests/ioctl_ptp.c: New file.
> * tests/.gitignore: Add ioctl_ptp.
> * tests/gen_tests.in (ioctl_ptp): New entry.
> * tests/pure_executables.list: Likewise.
> ---
> Changes in v4:
> * Change 2017 to 2018 in copyright header
> * change position of ifdef
> * explicitly set value of sysoff->n_samples
>
> Changes in v3:
> * check for macro HAVE_STRUCT_PTP_SYS_OFFSET
> * print field names as per fixed decoder
> * cover all cases like when call succeeds
>
> Changes in v2:
> * Add decoding of non-zero arguments in test_no_device
> * Use TAIL_ALLOC_OBJECT_CONST_PTR
> * Change variable names and error message
> * Remove hunk from Makefile.am
> * Other minor changes
[...]
> +static void
> +test_ptp0_device(void)
> +{
> +
> + TAIL_ALLOC_OBJECT_CONST_PTR(struct ptp_clock_caps, caps);
> + fill_memory(caps, sizeof(*caps));
> + TAIL_ALLOC_OBJECT_CONST_PTR(struct ptp_sys_offset, sysoff);
> + fill_memory(sysoff, sizeof(*sysoff));
> +
> + static const char device[] = "/dev/ptp0";
> + int fd = open(device, O_RDWR);
> + if (fd < 0) {
> + perror(device);
> + return;
> + }
> +
> + /* PTP_CLOCK_GETCAPS */
> + int getcaps_ret = ioctl(fd, PTP_CLOCK_GETCAPS, caps);
> + if (getcaps_ret < 0) {
> + printf("ioctl(%d, PTP_CLOCK_GETCAPS, %p) = %s\n",
> + fd, caps, sprintrc(getcaps_ret));
> + } else {
> + printf("ioctl(%d, PTP_CLOCK_GETCAPS, {max_adj=%d, n_alarm=%d"
> + ", n_ext_ts=%d, n_per_out=%d, pps=%d}) = %s\n",
> + fd, caps->max_adj, caps->n_alarm, caps->n_ext_ts,
> + caps->n_per_out, caps->pps, sprintrc(getcaps_ret));
> + }
> +
> + /* PTP_SYS_OFFSET */
> + sysoff->n_samples = PTP_MAX_SAMPLES + 2;
Let me repeat:
According to linux/drivers/ptp/ptp_chardev.c,
PTP_SYS_OFFSET fails with EINVAL if sysoff->n_samples > PTP_MAX_SAMPLES,
so if you want to test the success path of decoder, there is no use
to specify PTP_MAX_SAMPLES + 2 there, it will fail with EINVAL.
Try specifying PTP_MAX_SAMPLES instead.
> + int sysoff_ret = ioctl(fd, PTP_SYS_OFFSET, sysoff);
> + if (sysoff_ret < 0) {
> + printf("ioctl(%d, PTP_SYS_OFFSET, {n_samples=%u}) = %s\n",
> + fd, sysoff->n_samples, sprintrc(sysoff_ret));
> + } else {
> + unsigned int n_samples, i;
> +
> + printf("ioctl(%d, PTP_SYS_OFFSET, ts=[", fd);
> + n_samples = sysoff->n_samples > PTP_MAX_SAMPLES ?
> + PTP_MAX_SAMPLES : sysoff->n_samples;
> + for (i = 0; i < 2 * n_samples + 1; ++i) {
> + if (i > 0)
> + printf(", ");
> + printf("{sec=%" PRId64 ", nsec=%" PRIu32 "}",
> + (int64_t)sysoff->ts[i].sec, sysoff->ts[i].nsec);
> + }
> + if (sysoff->n_samples > PTP_MAX_SAMPLES)
> + printf(", ...");
> + printf("]) = %s\n", sprintrc(sysoff_ret));
> + }
> +
> +}
--
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20180311/86523dee/attachment.bin>
More information about the Strace-devel
mailing list