handle xlat styles ioprio

Dmitry V. Levin ldv at altlinux.org
Tue Feb 19 18:14:14 UTC 2019


On Mon, Feb 18, 2019 at 07:08:12AM -0800, shankarapailoor wrote:
> Subject: [PATCH v2] handle xlat_styles when decoding ioprio_get and set
> 
> * ioprio.c (ioprio_get, SYS_FUNC(ioprio_set)): Only print auxstring in abbrev. Handle xlat_styles.
> * tests/ioprio.c: Add xlat macros.
> * tests/ioprio-Xabbrev.c: New test.
> * tests/ioprio-Xraw.c: Likewise.
> * tests/ioprio-Xverbose.c: Likewise.
> * tests/pure_executables.list: Add new tests ioprio-Xabbrev, ioprio-Xraw, ioprio-Xverbose.
> * tests/gen_tests.in: Likewise.
> * tests/.gitignore: Likewise.
> ---
>  ioprio.c                    | 15 +++++++++---
>  tests/.gitignore            |  3 +++
>  tests/gen_tests.in          |  3 +++
>  tests/ioprio-Xabbrev.c      |  1 +
>  tests/ioprio-Xraw.c         |  2 ++
>  tests/ioprio-Xverbose.c     |  2 ++
>  tests/ioprio.c              | 48 +++++++++++++++++++++++++++++++++----
>  tests/pure_executables.list |  3 +++
>  8 files changed, 69 insertions(+), 8 deletions(-)
>  create mode 100644 tests/ioprio-Xabbrev.c
>  create mode 100644 tests/ioprio-Xraw.c
>  create mode 100644 tests/ioprio-Xverbose.c

Thanks.

> diff --git a/ioprio.c b/ioprio.c
> index 2d7c4f6a..5a5c469a 100644
> --- a/ioprio.c
> +++ b/ioprio.c
> @@ -45,8 +45,10 @@ SYS_FUNC(ioprio_get)
>  	} else {
>  		if (syserror(tcp))
>  			return 0;
> -
> -		tcp->auxstr = sprint_ioprio(tcp->u_rval);
> +		if (xlat_verbose(xlat_verbosity) == XLAT_STYLE_RAW)
> +			tcp->auxstr = NULL;
> +		else
> +			tcp->auxstr = sprint_ioprio(tcp->u_rval);
>  		return RVAL_STR;
>  	}
>  }
> @@ -58,7 +60,14 @@ SYS_FUNC(ioprio_set)
>  	/* int who */
>  	tprintf(", %d, ", (int) tcp->u_arg[1]);
>  	/* int ioprio */
> -	tprints(sprint_ioprio(tcp->u_arg[2]));
> +	if (xlat_verbose(xlat_verbosity) != XLAT_STYLE_ABBREV)
> +		tprintf("%d", (int) tcp->u_arg[2]);
> +
> +	if (xlat_verbose(xlat_verbosity) == XLAT_STYLE_RAW)
> +		return RVAL_DECODED;
> +
> +	(xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE
> +		? tprints_comment : tprints)(sprint_ioprio(tcp->u_arg[2]));
>  
>  	return RVAL_DECODED;
>  }
> diff --git a/tests/.gitignore b/tests/.gitignore
> index 24b17017..4e960c88 100644
> --- a/tests/.gitignore
> +++ b/tests/.gitignore
> @@ -176,6 +176,9 @@ ioctl_v4l2
>  ioperm
>  iopl
>  ioprio
> +ioprio-Xabbrev
> +ioprio-Xraw
> +ioprio-Xverbose
>  ip_mreq
>  ipc
>  ipc_msg
> diff --git a/tests/gen_tests.in b/tests/gen_tests.in
> index e2e70a12..ef579f3f 100644
> --- a/tests/gen_tests.in
> +++ b/tests/gen_tests.in
> @@ -147,6 +147,9 @@ ioctl_v4l2	+ioctl.test
>  ioperm	-a27
>  iopl	-a8
>  ioprio	-a18 -e trace=ioprio_get,ioprio_set
> +ioprio-Xabbrev	-a18 -e trace=ioprio_get,ioprio_set -Xabbrev
> +ioprio-Xraw	-a18 -e trace=ioprio_get,ioprio_set -Xraw
> +ioprio-Xverbose	-a18 -e trace=ioprio_get,ioprio_set -Xverbose
>  ip_mreq	-e trace=setsockopt
>  ipc	-a19
>  ipc_msg	+ipc.sh -a26
> diff --git a/tests/ioprio-Xabbrev.c b/tests/ioprio-Xabbrev.c
> new file mode 100644
> index 00000000..01a07f48
> --- /dev/null
> +++ b/tests/ioprio-Xabbrev.c
> @@ -0,0 +1 @@
> +#include "ioprio.c"
> diff --git a/tests/ioprio-Xraw.c b/tests/ioprio-Xraw.c
> new file mode 100644
> index 00000000..6a815069
> --- /dev/null
> +++ b/tests/ioprio-Xraw.c
> @@ -0,0 +1,2 @@
> +#define XLAT_RAW 1
> +#include "ioprio.c"
> diff --git a/tests/ioprio-Xverbose.c b/tests/ioprio-Xverbose.c
> new file mode 100644
> index 00000000..3c12bb6c
> --- /dev/null
> +++ b/tests/ioprio-Xverbose.c
> @@ -0,0 +1,2 @@
> +#define XLAT_VERBOSE 1
> +#include "ioprio.c"
> diff --git a/tests/ioprio.c b/tests/ioprio.c
> index 5c52b3db..1bb01161 100644
> --- a/tests/ioprio.c
> +++ b/tests/ioprio.c
> @@ -44,32 +44,70 @@ main(void)
>  		(kernel_ulong_t) 0xbadc0dedda7a1057ULL;
>  	static const kernel_ulong_t bogus_ioprio =
>  		(kernel_ulong_t) 0xdec0ded1facefeedULL;
> +#if !XLAT_RAW
>  	static const char * const bogus_ioprio_str =
>  		"IOPRIO_PRIO_VALUE(0x7d677 /* IOPRIO_CLASS_??? */, 7917)";
> +#endif
>  
>  	long rc;
> +	const char *errstr;
>  
>  	rc = syscall(__NR_ioprio_get, bogus_which, bogus_who);
> +	errstr = sprintrc(rc);
> +#if XLAT_RAW
> +	printf("ioprio_get(%#x, %d) = %s\n",
> +	       (int) bogus_which, (int) bogus_who, errstr);
> +#else /* XLAT_ABBREV || XLAT_VERBOSE */
>  	printf("ioprio_get(%#x /* IOPRIO_WHO_??? */, %d) = %s\n",
> -	       (int) bogus_which, (int) bogus_who, sprintrc(rc));
> +	       (int) bogus_which, (int) bogus_who, errstr);
> +#endif
>  
>  	rc = syscall(__NR_ioprio_get, 1, 0);
> -	printf("ioprio_get(IOPRIO_WHO_PROCESS, 0) = %s", sprintrc(rc));
> +	errstr = sprintrc(rc);
> +#if XLAT_RAW
> +	printf("ioprio_get(0x1, 0) = %s\n", errstr);
> +#elif XLAT_VERBOSE
> +	printf("ioprio_get(0x1 /* IOPRIO_WHO_PROCESS */, 0) = %s"
> +		" (IOPRIO_PRIO_VALUE(0 /* IOPRIO_CLASS_NONE */, 4))\n", errstr);
> +#else /* XLAT_ABBREV */
> +	printf("ioprio_get(IOPRIO_WHO_PROCESS, 0) = %s", errstr);
> +#endif
>  
> +#if !XLAT_RAW && !XLAT_VERBOSE
>  	if (rc >= -1)
>  		print_ioprio(rc);
> -
>  	puts("");
> +#endif

I don't think we can assume that ioprio_get returns any particular value.

I changed this part of the test before merging.


-- 
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/20190219/ecfaedfa/attachment.bin>


More information about the Strace-devel mailing list