[PATCH v2] tests: Add test for decoding of PTP_* ioctl commands

Dmitry V. Levin ldv at altlinux.org
Mon Feb 26 14:17:47 UTC 2018


On Mon, Feb 26, 2018 at 06:20:22PM +0530, Harsha Sharma wrote:
[...]
> +#include "tests.h"
> +#include "xlat.h"
> +#include <fcntl.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <sys/ioctl.h>
> +#include <inttypes.h>
> +#include <unistd.h>
> +
> +#ifdef HAVE_STRUCT_PTP_SYS_OFFSET

I don't think this is going to build if the macro is not defined.
See many examples e.g. tests/ioctl_mtd.c how to do it properly.

[...]
> +	/* PTP_PEROUT_REQUEST */
> +	ioctl(-1, PTP_PEROUT_REQUEST, NULL);
> +	printf("ioctl(-1, PTP_PEROUT_REQUEST, NULL) = -1 EBADF (%m)\n");
> +	ioctl(-1, PTP_PEROUT_REQUEST, perout);
> +	printf("ioctl(-1, PTP_PEROUT_REQUEST, {start={%" PRId64 ""
> +	       ", %" PRIu32 "}, period={%" PRId64 ", %" PRIu32 "}"
> +	       ", index=%d, flags=", (int64_t)perout->start.sec,
> +	       perout->start.nsec, (int64_t)perout->period.sec,
> +	       perout->period.nsec, perout->index);

From this expected output I can tell that the decoder itself
should be fixed to print field names along with their values.

[...]
> +	/* PTP_CLOCK_GETCAPS */
> +	int getcaps_ret = ioctl(fd, PTP_CLOCK_GETCAPS, caps);
> +	printf("ioctl(%d, PTP_CLOCK_GETCAPS, %p) = %s\n",
> +	       fd, caps,  sprintrc(getcaps_ret));

What if PTP_CLOCK_GETCAPS actually succeeds?

> +	/* PTP_SYS_OFFSET */
> +	int sysoff_ret = ioctl(fd, PTP_SYS_OFFSET, sysoff);
> +	printf("ioctl(%d, PTP_SYS_OFFSET, {n_samples=%u}) = %s\n",
> +	       fd, sysoff->n_samples, sprintrc(sysoff_ret));

Likewise, what if you specified sysoff->n_samples <= PTP_MAX_SAMPLES
and the call actually succeeded?


-- 
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/20180226/afef42e6/attachment.bin>


More information about the Strace-devel mailing list