Blame SOURCES/0033-tests-test-evdev-bitset-decoding-more-thoroughly.patch

3bb695
From cdd8206af74fcb961f0179e21eacf5d55d23f0ac Mon Sep 17 00:00:00 2001
3bb695
From: Eugene Syromyatnikov <evgsyr@gmail.com>
3bb695
Date: Fri, 12 Jul 2019 14:31:44 +0200
3bb695
Subject: [PATCH 3/3] tests: test evdev bitset decoding more thoroughly
3bb695
3bb695
* tests/ioctl_evdev-success-v.test: Inject various values.
3bb695
* tests/ioctl_evdev-success.test: Likewise.
3bb695
* tests/ioctl_evdev-success.c (NUM_WORDS): New macro.
3bb695
(struct evdev_check): Constify arg_ptr and print_arg args.
3bb695
(invoke_test_syscall, test_evdev, print_input_absinfo, print_input_id,
3bb695
print_mtslots): Add const qualifiers.
3bb695
(print_getbit): Add const qualifiers, rewrite to expect trailing NULL
3bb695
in the string array instead of leading string count.
3bb695
(main): Set size for ev_more, ev_less, ev_zero arrays; replace leading
3bb695
count element in ev_more_str, ev_less_str, ev_zero_str with trailing
3bb695
NULL; replace ev_more_str and ev_less_str with ev_more_str_2/ev_less_str_2
3bb695
and ev_more_str_3/ev_less_str_3 that differ by presence of flags that reside
3bb695
beyond first two bytes; add static and const qualifiers where possible;
3bb695
add key/key_sts_8/key_str_16 values; update a to provide either ev_more_str_2
3bb695
or ev_more_str_3 and either key_str_8 or key_str_16 depending on inject_retval
3bb695
value.
3bb695
---
3bb695
 tests/ioctl_evdev-success-v.test |  15 +++---
3bb695
 tests/ioctl_evdev-success.c      | 100 ++++++++++++++++++++++++++-------------
3bb695
 tests/ioctl_evdev-success.test   |  15 +++---
3bb695
 3 files changed, 84 insertions(+), 46 deletions(-)
3bb695
3bb695
Index: strace-4.24/tests/ioctl_evdev-success-v.test
3bb695
===================================================================
3bb695
--- strace-4.24.orig/tests/ioctl_evdev-success-v.test	2019-08-01 18:40:58.009521546 +0200
3bb695
+++ strace-4.24/tests/ioctl_evdev-success-v.test	2019-08-01 19:21:32.297062218 +0200
3bb695
@@ -3,11 +3,14 @@
3bb695
 . "${srcdir=.}/scno_tampering.sh"
3bb695
 
3bb695
 : ${IOCTL_INJECT_START=256}
3bb695
-: ${IOCTL_INJECT_RETVAL=8}
3bb695
 
3bb695
 run_prog
3bb695
-run_strace -a16 -v -e trace=ioctl \
3bb695
-	-e inject=ioctl:retval="${IOCTL_INJECT_RETVAL}":when="${IOCTL_INJECT_START}+" \
3bb695
-	../ioctl_evdev-success-v "${IOCTL_INJECT_START}" "${IOCTL_INJECT_RETVAL}"> "$EXP"
3bb695
-grep -v '^ioctl([012][,<]' < "$LOG" > "$OUT"
3bb695
-match_diff "$OUT" "$EXP"
3bb695
+
3bb695
+for ret in 0 2 8 15 16; do
3bb695
+	run_strace -a16 -v -e trace=ioctl \
3bb695
+		-e inject=ioctl:retval="${ret}":when="${IOCTL_INJECT_START}+" \
3bb695
+		../ioctl_evdev-success-v \
3bb695
+		"${IOCTL_INJECT_START}" "${ret}"> "$EXP.$ret"
3bb695
+	grep -v '^ioctl([012][,<]' < "$LOG" > "$OUT.$ret"
3bb695
+	match_diff "$OUT.$ret" "$EXP.$ret"
3bb695
+done
3bb695
Index: strace-4.24/tests/ioctl_evdev-success.c
3bb695
===================================================================
3bb695
--- strace-4.24.orig/tests/ioctl_evdev-success.c	2019-08-01 18:40:58.009521546 +0200
3bb695
+++ strace-4.24/tests/ioctl_evdev-success.c	2019-08-01 19:21:32.297062218 +0200
3bb695
@@ -2,6 +2,7 @@
3bb695
 
3bb695
 #ifdef HAVE_LINUX_INPUT_H
3bb695
 
3bb695
+# include <assert.h>
3bb695
 # include <inttypes.h>
3bb695
 # include <stdio.h>
3bb695
 # include <stdlib.h>
3bb695
@@ -9,17 +10,19 @@
3bb695
 # include <linux/input.h>
3bb695
 # include "print_fields.h"
3bb695
 
3bb695
+# define NUM_WORDS 4
3bb695
+
3bb695
 static const char *errstr;
3bb695
 
3bb695
 struct evdev_check {
3bb695
 	unsigned long cmd;
3bb695
 	const char *cmd_str;
3bb695
-	void *arg_ptr;
3bb695
-	void (*print_arg)(long rc, void *ptr, void *arg);
3bb695
+	const void *arg_ptr;
3bb695
+	void (*print_arg)(long rc, const void *ptr, const void *arg);
3bb695
 };
3bb695
 
3bb695
 static long
3bb695
-invoke_test_syscall(unsigned long cmd, void *p)
3bb695
+invoke_test_syscall(unsigned long cmd, const void *p)
3bb695
 {
3bb695
 	long rc = ioctl(-1, cmd, p);
3bb695
 	errstr = sprintrc(rc);
3bb695
@@ -31,7 +34,7 @@
3bb695
 }
3bb695
 
3bb695
 static void
3bb695
-test_evdev(struct evdev_check *check, void *arg)
3bb695
+test_evdev(struct evdev_check *check, const void *arg)
3bb695
 {
3bb695
 	long rc = invoke_test_syscall(check->cmd, check->arg_ptr);
3bb695
 	printf("ioctl(-1, %s, ", check->cmd_str);
3bb695
@@ -43,9 +46,9 @@
3bb695
 }
3bb695
 
3bb695
 static void
3bb695
-print_input_absinfo(long rc, void *ptr, void *arg)
3bb695
+print_input_absinfo(long rc, const void *ptr, const void *arg)
3bb695
 {
3bb695
-	struct input_absinfo *absinfo = ptr;
3bb695
+	const struct input_absinfo *absinfo = ptr;
3bb695
 
3bb695
 	if (rc < 0) {
3bb695
 		printf("%p", absinfo);
3bb695
@@ -67,9 +70,9 @@
3bb695
 }
3bb695
 
3bb695
 static void
3bb695
-print_input_id(long rc, void *ptr, void *arg)
3bb695
+print_input_id(long rc, const void *ptr, const void *arg)
3bb695
 {
3bb695
-	struct input_id *id = ptr;
3bb695
+	const struct input_id *id = ptr;
3bb695
 
3bb695
 	if (rc < 0) {
3bb695
 		printf("%p", id);
3bb695
@@ -84,10 +87,10 @@
3bb695
 
3bb695
 # ifdef EVIOCGMTSLOTS
3bb695
 static void
3bb695
-print_mtslots(long rc, void *ptr, void *arg)
3bb695
+print_mtslots(long rc, const void *ptr, const void *arg)
3bb695
 {
3bb695
-	int *buffer = ptr;
3bb695
-	const char **str = arg;
3bb695
+	const int *buffer = ptr;
3bb695
+	const char * const * str = arg;
3bb695
 	int num = atoi(*(str + 1));
3bb695
 
3bb695
 	if (rc < 0) {
3bb695
@@ -104,27 +107,26 @@
3bb695
 # endif
3bb695
 
3bb695
 static void
3bb695
-print_getbit(long rc, void *ptr, void *arg)
3bb695
+print_getbit(long rc, const void *ptr, const void *arg)
3bb695
 {
3bb695
-	const char **str = arg;
3bb695
-	int num = atoi(*str);
3bb695
+	const char * const *str = arg;
3bb695
 
3bb695
-	if (rc < 0) {
3bb695
+	if (rc <= 0) {
3bb695
 		printf("%p", ptr);
3bb695
 		return;
3bb695
 	}
3bb695
 
3bb695
 	printf("[");
3bb695
-	printf("%s", *(str + 1));
3bb695
-	for (unsigned int i = 2; i <= (unsigned) num; i++) {
3bb695
+	for (unsigned long i = 0; str[i]; i++) {
3bb695
 # if ! VERBOSE
3bb695
-		if (i > 4) {
3bb695
+		if (i >= 4) {
3bb695
 			printf(", ...");
3bb695
 			break;
3bb695
 		}
3bb695
 # endif
3bb695
-		printf(", ");
3bb695
-		printf("%s", *(str + i));
3bb695
+		if (i)
3bb695
+			printf(", ");
3bb695
+		printf("%s", str[i]);
3bb695
 	}
3bb695
 	printf("]");
3bb695
 }
3bb695
@@ -170,6 +172,7 @@
3bb695
 	TAIL_ALLOC_OBJECT_CONST_PTR(struct input_id, id);
3bb695
 	TAIL_ALLOC_OBJECT_CONST_PTR(struct input_absinfo, absinfo);
3bb695
 	TAIL_ALLOC_OBJECT_CONST_PTR(int, bad_addr_slot);
3bb695
+
3bb695
 # ifdef EVIOCGMTSLOTS
3bb695
 	int mtslots[] = { ABS_MT_SLOT, 1, 3 };
3bb695
 	/* we use the second element to indicate the number of values */
3bb695
@@ -183,36 +186,65 @@
3bb695
 	const char *invalid_mtslot_str[] = { invalid_str, "1", "1" };
3bb695
 # endif
3bb695
 
3bb695
+	enum { ULONG_BIT = sizeof(unsigned long) * 8 };
3bb695
+
3bb695
 	/* set more than 4 bits */
3bb695
-	unsigned long ev_more[] = { 1 << EV_ABS | 1 << EV_MSC | 1 << EV_LED | 1 << EV_SND | 1 << EV_PWR };
3bb695
-	/* we use the first element to indicate the number of set bits */
3bb695
-	/* ev_more_str[0] is "5" so the number of set bits is 5 */
3bb695
-	const char *ev_more_str[] = { "5", "EV_ABS", "EV_MSC", "EV_LED", "EV_SND", "EV_PWR" };
3bb695
+	static const unsigned long ev_more[NUM_WORDS] = {
3bb695
+		1 << EV_ABS | 1 << EV_MSC | 1 << EV_LED | 1 << EV_SND
3bb695
+		| 1 << EV_PWR };
3bb695
+	static const char * const ev_more_str_2[] = {
3bb695
+		"EV_ABS", "EV_MSC", NULL };
3bb695
+	static const char * const ev_more_str_3[] = {
3bb695
+		"EV_ABS", "EV_MSC", "EV_LED", "EV_SND", "EV_PWR", NULL };
3bb695
 
3bb695
 	/* set less than 4 bits */
3bb695
-	unsigned long ev_less[] = { 1 << EV_ABS | 1 << EV_MSC | 1 << EV_LED };
3bb695
-	const char *ev_less_str[] = { "3", "EV_ABS", "EV_MSC", "EV_LED" };
3bb695
+	static const unsigned long ev_less[NUM_WORDS] = {
3bb695
+		1 << EV_ABS | 1 << EV_MSC | 1 << EV_LED };
3bb695
+	static const char * const ev_less_str_2[] = {
3bb695
+		"EV_ABS", "EV_MSC", NULL };
3bb695
+	static const char * const ev_less_str_3[] = {
3bb695
+		"EV_ABS", "EV_MSC", "EV_LED", NULL };
3bb695
 
3bb695
 	/* set zero bit */
3bb695
-	unsigned long ev_zero[] = { 0x0 };
3bb695
-	const char *ev_zero_str[] = { "0", " 0 " };
3bb695
+	static const unsigned long ev_zero[NUM_WORDS] = { 0x0 };
3bb695
+	static const char * const ev_zero_str[] = { " 0 ", NULL };
3bb695
 
3bb695
 	/* KEY_MAX is 0x2ff which is greater than retval * 8 */
3bb695
-	unsigned long key[] = { 1 << KEY_1 | 1 << KEY_2, 0 };
3bb695
-	const char *key_str[] = { "2", "KEY_1", "KEY_2" };
3bb695
+	static const unsigned long key[NUM_WORDS] = {
3bb695
+		1 << KEY_1 | 1 << KEY_2,
3bb695
+		[ KEY_F12 / ULONG_BIT ] = 1 << (KEY_F12 % ULONG_BIT) };
3bb695
+
3bb695
+	static const char * const key_str_8[] = {
3bb695
+		"KEY_1", "KEY_2", NULL };
3bb695
+	static const char * const key_str_16[] = {
3bb695
+		"KEY_1", "KEY_2", "KEY_F12", NULL };
3bb695
+
3bb695
+	assert(sizeof(ev_more) >= (unsigned long) inject_retval);
3bb695
+	assert(sizeof(ev_less) >= (unsigned long) inject_retval);
3bb695
+	assert(sizeof(ev_zero) >= (unsigned long) inject_retval);
3bb695
+	assert(sizeof(key) >= (unsigned long) inject_retval);
3bb695
 
3bb695
 	struct {
3bb695
 		struct evdev_check check;
3bb695
-		void *ptr;
3bb695
+		const void *ptr;
3bb695
 	} a[] = {
3bb695
 		{ { ARG_STR(EVIOCGID), id, print_input_id }, NULL },
3bb695
 		{ { ARG_STR(EVIOCGABS(ABS_X)), absinfo, print_input_absinfo }, NULL },
3bb695
 		{ { ARG_STR(EVIOCGABS(ABS_Y)), absinfo, print_input_absinfo }, NULL },
3bb695
 		{ { ARG_STR(EVIOCGABS(ABS_Y)), absinfo, print_input_absinfo }, NULL },
3bb695
-		{ { ARG_STR(EVIOCGBIT(0, 0)), ev_more, print_getbit }, &ev_more_str },
3bb695
-		{ { ARG_STR(EVIOCGBIT(0, 0)), ev_less, print_getbit }, &ev_less_str },
3bb695
+		{ { ARG_STR(EVIOCGBIT(0, 0)), ev_more, print_getbit },
3bb695
+			inject_retval * 8 <= EV_LED
3bb695
+				? (const void *) &ev_more_str_2
3bb695
+				: (const void *) &ev_more_str_3 },
3bb695
+		{ { ARG_STR(EVIOCGBIT(0, 0)), ev_less, print_getbit },
3bb695
+			inject_retval * 8 <= EV_LED
3bb695
+				? (const void *) &ev_less_str_2
3bb695
+				: (const void *) &ev_less_str_3 },
3bb695
 		{ { ARG_STR(EVIOCGBIT(0, 0)), ev_zero, print_getbit }, &ev_zero_str },
3bb695
-		{ { ARG_STR(EVIOCGBIT(EV_KEY, 0)), key, print_getbit }, &key_str},
3bb695
+		{ { ARG_STR(EVIOCGBIT(EV_KEY, 0)), key, print_getbit },
3bb695
+			inject_retval * 8 <= KEY_F12
3bb695
+				? (const void *) &key_str_8
3bb695
+				: (const void *) &key_str_16 },
3bb695
 # ifdef EVIOCGMTSLOTS
3bb695
 		{ { ARG_STR(EVIOCGMTSLOTS(12)), mtslots, print_mtslots }, &mtslots_str },
3bb695
 		{ { ARG_STR(EVIOCGMTSLOTS(8)), invalid_mtslot, print_mtslots }, &invalid_mtslot_str }
3bb695
Index: strace-4.24/tests/ioctl_evdev-success.test
3bb695
===================================================================
3bb695
--- strace-4.24.orig/tests/ioctl_evdev-success.test	2019-08-01 18:40:58.009521546 +0200
3bb695
+++ strace-4.24/tests/ioctl_evdev-success.test	2019-08-01 19:21:32.298062205 +0200
3bb695
@@ -3,11 +3,14 @@
3bb695
 . "${srcdir=.}/scno_tampering.sh"
3bb695
 
3bb695
 : ${IOCTL_INJECT_START=256}
3bb695
-: ${IOCTL_INJECT_RETVAL=8}
3bb695
 
3bb695
 run_prog
3bb695
-run_strace -a16 -e trace=ioctl \
3bb695
-	-e inject=ioctl:retval="${IOCTL_INJECT_RETVAL}":when="${IOCTL_INJECT_START}+" \
3bb695
-	../ioctl_evdev-success "${IOCTL_INJECT_START}" "${IOCTL_INJECT_RETVAL}"> "$EXP"
3bb695
-grep -v '^ioctl([012][,<]' < "$LOG" > "$OUT"
3bb695
-match_diff "$OUT" "$EXP"
3bb695
+
3bb695
+for ret in 0 2 8 15 16; do
3bb695
+	run_strace -a16 -e trace=ioctl \
3bb695
+		-e inject=ioctl:retval="${ret}":when="${IOCTL_INJECT_START}+" \
3bb695
+		../ioctl_evdev-success \
3bb695
+		"${IOCTL_INJECT_START}" "${ret}"> "$EXP.${ret}"
3bb695
+	grep -v '^ioctl([012][,<]' < "$LOG" > "$OUT.$ret"
3bb695
+	match_diff "$OUT.$ret" "$EXP.$ret"
3bb695
+done
3bb695
Index: strace-4.24/tests-m32/ioctl_evdev-success-v.test
3bb695
===================================================================
3bb695
--- strace-4.24.orig/tests-m32/ioctl_evdev-success-v.test	2019-08-01 18:40:58.009521546 +0200
3bb695
+++ strace-4.24/tests-m32/ioctl_evdev-success-v.test	2019-08-01 19:21:32.298062205 +0200
3bb695
@@ -3,11 +3,14 @@
3bb695
 . "${srcdir=.}/scno_tampering.sh"
3bb695
 
3bb695
 : ${IOCTL_INJECT_START=256}
3bb695
-: ${IOCTL_INJECT_RETVAL=8}
3bb695
 
3bb695
 run_prog
3bb695
-run_strace -a16 -v -e trace=ioctl \
3bb695
-	-e inject=ioctl:retval="${IOCTL_INJECT_RETVAL}":when="${IOCTL_INJECT_START}+" \
3bb695
-	../ioctl_evdev-success-v "${IOCTL_INJECT_START}" "${IOCTL_INJECT_RETVAL}"> "$EXP"
3bb695
-grep -v '^ioctl([012][,<]' < "$LOG" > "$OUT"
3bb695
-match_diff "$OUT" "$EXP"
3bb695
+
3bb695
+for ret in 0 2 8 15 16; do
3bb695
+	run_strace -a16 -v -e trace=ioctl \
3bb695
+		-e inject=ioctl:retval="${ret}":when="${IOCTL_INJECT_START}+" \
3bb695
+		../ioctl_evdev-success-v \
3bb695
+		"${IOCTL_INJECT_START}" "${ret}"> "$EXP.$ret"
3bb695
+	grep -v '^ioctl([012][,<]' < "$LOG" > "$OUT.$ret"
3bb695
+	match_diff "$OUT.$ret" "$EXP.$ret"
3bb695
+done
3bb695
Index: strace-4.24/tests-m32/ioctl_evdev-success.test
3bb695
===================================================================
3bb695
--- strace-4.24.orig/tests-m32/ioctl_evdev-success.test	2019-08-01 18:40:58.009521546 +0200
3bb695
+++ strace-4.24/tests-m32/ioctl_evdev-success.test	2019-08-01 19:21:32.298062205 +0200
3bb695
@@ -3,11 +3,14 @@
3bb695
 . "${srcdir=.}/scno_tampering.sh"
3bb695
 
3bb695
 : ${IOCTL_INJECT_START=256}
3bb695
-: ${IOCTL_INJECT_RETVAL=8}
3bb695
 
3bb695
 run_prog
3bb695
-run_strace -a16 -e trace=ioctl \
3bb695
-	-e inject=ioctl:retval="${IOCTL_INJECT_RETVAL}":when="${IOCTL_INJECT_START}+" \
3bb695
-	../ioctl_evdev-success "${IOCTL_INJECT_START}" "${IOCTL_INJECT_RETVAL}"> "$EXP"
3bb695
-grep -v '^ioctl([012][,<]' < "$LOG" > "$OUT"
3bb695
-match_diff "$OUT" "$EXP"
3bb695
+
3bb695
+for ret in 0 2 8 15 16; do
3bb695
+	run_strace -a16 -e trace=ioctl \
3bb695
+		-e inject=ioctl:retval="${ret}":when="${IOCTL_INJECT_START}+" \
3bb695
+		../ioctl_evdev-success \
3bb695
+		"${IOCTL_INJECT_START}" "${ret}"> "$EXP.${ret}"
3bb695
+	grep -v '^ioctl([012][,<]' < "$LOG" > "$OUT.$ret"
3bb695
+	match_diff "$OUT.$ret" "$EXP.$ret"
3bb695
+done
3bb695
Index: strace-4.24/tests-mx32/ioctl_evdev-success-v.test
3bb695
===================================================================
3bb695
--- strace-4.24.orig/tests-mx32/ioctl_evdev-success-v.test	2019-08-01 18:40:58.009521546 +0200
3bb695
+++ strace-4.24/tests-mx32/ioctl_evdev-success-v.test	2019-08-01 19:21:32.298062205 +0200
3bb695
@@ -3,11 +3,14 @@
3bb695
 . "${srcdir=.}/scno_tampering.sh"
3bb695
 
3bb695
 : ${IOCTL_INJECT_START=256}
3bb695
-: ${IOCTL_INJECT_RETVAL=8}
3bb695
 
3bb695
 run_prog
3bb695
-run_strace -a16 -v -e trace=ioctl \
3bb695
-	-e inject=ioctl:retval="${IOCTL_INJECT_RETVAL}":when="${IOCTL_INJECT_START}+" \
3bb695
-	../ioctl_evdev-success-v "${IOCTL_INJECT_START}" "${IOCTL_INJECT_RETVAL}"> "$EXP"
3bb695
-grep -v '^ioctl([012][,<]' < "$LOG" > "$OUT"
3bb695
-match_diff "$OUT" "$EXP"
3bb695
+
3bb695
+for ret in 0 2 8 15 16; do
3bb695
+	run_strace -a16 -v -e trace=ioctl \
3bb695
+		-e inject=ioctl:retval="${ret}":when="${IOCTL_INJECT_START}+" \
3bb695
+		../ioctl_evdev-success-v \
3bb695
+		"${IOCTL_INJECT_START}" "${ret}"> "$EXP.$ret"
3bb695
+	grep -v '^ioctl([012][,<]' < "$LOG" > "$OUT.$ret"
3bb695
+	match_diff "$OUT.$ret" "$EXP.$ret"
3bb695
+done
3bb695
Index: strace-4.24/tests-mx32/ioctl_evdev-success.test
3bb695
===================================================================
3bb695
--- strace-4.24.orig/tests-mx32/ioctl_evdev-success.test	2019-08-01 18:40:58.009521546 +0200
3bb695
+++ strace-4.24/tests-mx32/ioctl_evdev-success.test	2019-08-01 19:21:32.299062192 +0200
3bb695
@@ -3,11 +3,14 @@
3bb695
 . "${srcdir=.}/scno_tampering.sh"
3bb695
 
3bb695
 : ${IOCTL_INJECT_START=256}
3bb695
-: ${IOCTL_INJECT_RETVAL=8}
3bb695
 
3bb695
 run_prog
3bb695
-run_strace -a16 -e trace=ioctl \
3bb695
-	-e inject=ioctl:retval="${IOCTL_INJECT_RETVAL}":when="${IOCTL_INJECT_START}+" \
3bb695
-	../ioctl_evdev-success "${IOCTL_INJECT_START}" "${IOCTL_INJECT_RETVAL}"> "$EXP"
3bb695
-grep -v '^ioctl([012][,<]' < "$LOG" > "$OUT"
3bb695
-match_diff "$OUT" "$EXP"
3bb695
+
3bb695
+for ret in 0 2 8 15 16; do
3bb695
+	run_strace -a16 -e trace=ioctl \
3bb695
+		-e inject=ioctl:retval="${ret}":when="${IOCTL_INJECT_START}+" \
3bb695
+		../ioctl_evdev-success \
3bb695
+		"${IOCTL_INJECT_START}" "${ret}"> "$EXP.${ret}"
3bb695
+	grep -v '^ioctl([012][,<]' < "$LOG" > "$OUT.$ret"
3bb695
+	match_diff "$OUT.$ret" "$EXP.$ret"
3bb695
+done
3bb695
Index: strace-4.24/tests-m32/ioctl_evdev-success.c
3bb695
===================================================================
3bb695
--- strace-4.24.orig/tests-m32/ioctl_evdev-success.c	2019-08-01 18:40:58.009521546 +0200
3bb695
+++ strace-4.24/tests-m32/ioctl_evdev-success.c	2019-08-29 12:09:27.898700830 +0200
3bb695
@@ -2,6 +2,7 @@
3bb695
 
3bb695
 #ifdef HAVE_LINUX_INPUT_H
3bb695
 
3bb695
+# include <assert.h>
3bb695
 # include <inttypes.h>
3bb695
 # include <stdio.h>
3bb695
 # include <stdlib.h>
3bb695
@@ -9,17 +10,19 @@
3bb695
 # include <linux/input.h>
3bb695
 # include "print_fields.h"
3bb695
 
3bb695
+# define NUM_WORDS 4
3bb695
+
3bb695
 static const char *errstr;
3bb695
 
3bb695
 struct evdev_check {
3bb695
 	unsigned long cmd;
3bb695
 	const char *cmd_str;
3bb695
-	void *arg_ptr;
3bb695
-	void (*print_arg)(long rc, void *ptr, void *arg);
3bb695
+	const void *arg_ptr;
3bb695
+	void (*print_arg)(long rc, const void *ptr, const void *arg);
3bb695
 };
3bb695
 
3bb695
 static long
3bb695
-invoke_test_syscall(unsigned long cmd, void *p)
3bb695
+invoke_test_syscall(unsigned long cmd, const void *p)
3bb695
 {
3bb695
 	long rc = ioctl(-1, cmd, p);
3bb695
 	errstr = sprintrc(rc);
3bb695
@@ -31,7 +34,7 @@
3bb695
 }
3bb695
 
3bb695
 static void
3bb695
-test_evdev(struct evdev_check *check, void *arg)
3bb695
+test_evdev(struct evdev_check *check, const void *arg)
3bb695
 {
3bb695
 	long rc = invoke_test_syscall(check->cmd, check->arg_ptr);
3bb695
 	printf("ioctl(-1, %s, ", check->cmd_str);
3bb695
@@ -43,9 +46,9 @@
3bb695
 }
3bb695
 
3bb695
 static void
3bb695
-print_input_absinfo(long rc, void *ptr, void *arg)
3bb695
+print_input_absinfo(long rc, const void *ptr, const void *arg)
3bb695
 {
3bb695
-	struct input_absinfo *absinfo = ptr;
3bb695
+	const struct input_absinfo *absinfo = ptr;
3bb695
 
3bb695
 	if (rc < 0) {
3bb695
 		printf("%p", absinfo);
3bb695
@@ -67,9 +70,9 @@
3bb695
 }
3bb695
 
3bb695
 static void
3bb695
-print_input_id(long rc, void *ptr, void *arg)
3bb695
+print_input_id(long rc, const void *ptr, const void *arg)
3bb695
 {
3bb695
-	struct input_id *id = ptr;
3bb695
+	const struct input_id *id = ptr;
3bb695
 
3bb695
 	if (rc < 0) {
3bb695
 		printf("%p", id);
3bb695
@@ -84,10 +87,10 @@
3bb695
 
3bb695
 # ifdef EVIOCGMTSLOTS
3bb695
 static void
3bb695
-print_mtslots(long rc, void *ptr, void *arg)
3bb695
+print_mtslots(long rc, const void *ptr, const void *arg)
3bb695
 {
3bb695
-	int *buffer = ptr;
3bb695
-	const char **str = arg;
3bb695
+	const int *buffer = ptr;
3bb695
+	const char * const * str = arg;
3bb695
 	int num = atoi(*(str + 1));
3bb695
 
3bb695
 	if (rc < 0) {
3bb695
@@ -104,27 +107,26 @@
3bb695
 # endif
3bb695
 
3bb695
 static void
3bb695
-print_getbit(long rc, void *ptr, void *arg)
3bb695
+print_getbit(long rc, const void *ptr, const void *arg)
3bb695
 {
3bb695
-	const char **str = arg;
3bb695
-	int num = atoi(*str);
3bb695
+	const char * const *str = arg;
3bb695
 
3bb695
-	if (rc < 0) {
3bb695
+	if (rc <= 0) {
3bb695
 		printf("%p", ptr);
3bb695
 		return;
3bb695
 	}
3bb695
 
3bb695
 	printf("[");
3bb695
-	printf("%s", *(str + 1));
3bb695
-	for (unsigned int i = 2; i <= (unsigned) num; i++) {
3bb695
+	for (unsigned long i = 0; str[i]; i++) {
3bb695
 # if ! VERBOSE
3bb695
-		if (i > 4) {
3bb695
+		if (i >= 4) {
3bb695
 			printf(", ...");
3bb695
 			break;
3bb695
 		}
3bb695
 # endif
3bb695
-		printf(", ");
3bb695
-		printf("%s", *(str + i));
3bb695
+		if (i)
3bb695
+			printf(", ");
3bb695
+		printf("%s", str[i]);
3bb695
 	}
3bb695
 	printf("]");
3bb695
 }
3bb695
@@ -170,6 +172,7 @@
3bb695
 	TAIL_ALLOC_OBJECT_CONST_PTR(struct input_id, id);
3bb695
 	TAIL_ALLOC_OBJECT_CONST_PTR(struct input_absinfo, absinfo);
3bb695
 	TAIL_ALLOC_OBJECT_CONST_PTR(int, bad_addr_slot);
3bb695
+
3bb695
 # ifdef EVIOCGMTSLOTS
3bb695
 	int mtslots[] = { ABS_MT_SLOT, 1, 3 };
3bb695
 	/* we use the second element to indicate the number of values */
3bb695
@@ -183,36 +186,65 @@
3bb695
 	const char *invalid_mtslot_str[] = { invalid_str, "1", "1" };
3bb695
 # endif
3bb695
 
3bb695
+	enum { ULONG_BIT = sizeof(unsigned long) * 8 };
3bb695
+
3bb695
 	/* set more than 4 bits */
3bb695
-	unsigned long ev_more[] = { 1 << EV_ABS | 1 << EV_MSC | 1 << EV_LED | 1 << EV_SND | 1 << EV_PWR };
3bb695
-	/* we use the first element to indicate the number of set bits */
3bb695
-	/* ev_more_str[0] is "5" so the number of set bits is 5 */
3bb695
-	const char *ev_more_str[] = { "5", "EV_ABS", "EV_MSC", "EV_LED", "EV_SND", "EV_PWR" };
3bb695
+	static const unsigned long ev_more[NUM_WORDS] = {
3bb695
+		1 << EV_ABS | 1 << EV_MSC | 1 << EV_LED | 1 << EV_SND
3bb695
+		| 1 << EV_PWR };
3bb695
+	static const char * const ev_more_str_2[] = {
3bb695
+		"EV_ABS", "EV_MSC", NULL };
3bb695
+	static const char * const ev_more_str_3[] = {
3bb695
+		"EV_ABS", "EV_MSC", "EV_LED", "EV_SND", "EV_PWR", NULL };
3bb695
 
3bb695
 	/* set less than 4 bits */
3bb695
-	unsigned long ev_less[] = { 1 << EV_ABS | 1 << EV_MSC | 1 << EV_LED };
3bb695
-	const char *ev_less_str[] = { "3", "EV_ABS", "EV_MSC", "EV_LED" };
3bb695
+	static const unsigned long ev_less[NUM_WORDS] = {
3bb695
+		1 << EV_ABS | 1 << EV_MSC | 1 << EV_LED };
3bb695
+	static const char * const ev_less_str_2[] = {
3bb695
+		"EV_ABS", "EV_MSC", NULL };
3bb695
+	static const char * const ev_less_str_3[] = {
3bb695
+		"EV_ABS", "EV_MSC", "EV_LED", NULL };
3bb695
 
3bb695
 	/* set zero bit */
3bb695
-	unsigned long ev_zero[] = { 0x0 };
3bb695
-	const char *ev_zero_str[] = { "0", " 0 " };
3bb695
+	static const unsigned long ev_zero[NUM_WORDS] = { 0x0 };
3bb695
+	static const char * const ev_zero_str[] = { " 0 ", NULL };
3bb695
 
3bb695
 	/* KEY_MAX is 0x2ff which is greater than retval * 8 */
3bb695
-	unsigned long key[] = { 1 << KEY_1 | 1 << KEY_2, 0 };
3bb695
-	const char *key_str[] = { "2", "KEY_1", "KEY_2" };
3bb695
+	static const unsigned long key[NUM_WORDS] = {
3bb695
+		1 << KEY_1 | 1 << KEY_2,
3bb695
+		[ KEY_F12 / ULONG_BIT ] = 1 << (KEY_F12 % ULONG_BIT) };
3bb695
+
3bb695
+	static const char * const key_str_8[] = {
3bb695
+		"KEY_1", "KEY_2", NULL };
3bb695
+	static const char * const key_str_16[] = {
3bb695
+		"KEY_1", "KEY_2", "KEY_F12", NULL };
3bb695
+
3bb695
+	assert(sizeof(ev_more) >= (unsigned long) inject_retval);
3bb695
+	assert(sizeof(ev_less) >= (unsigned long) inject_retval);
3bb695
+	assert(sizeof(ev_zero) >= (unsigned long) inject_retval);
3bb695
+	assert(sizeof(key) >= (unsigned long) inject_retval);
3bb695
 
3bb695
 	struct {
3bb695
 		struct evdev_check check;
3bb695
-		void *ptr;
3bb695
+		const void *ptr;
3bb695
 	} a[] = {
3bb695
 		{ { ARG_STR(EVIOCGID), id, print_input_id }, NULL },
3bb695
 		{ { ARG_STR(EVIOCGABS(ABS_X)), absinfo, print_input_absinfo }, NULL },
3bb695
 		{ { ARG_STR(EVIOCGABS(ABS_Y)), absinfo, print_input_absinfo }, NULL },
3bb695
 		{ { ARG_STR(EVIOCGABS(ABS_Y)), absinfo, print_input_absinfo }, NULL },
3bb695
-		{ { ARG_STR(EVIOCGBIT(0, 0)), ev_more, print_getbit }, &ev_more_str },
3bb695
-		{ { ARG_STR(EVIOCGBIT(0, 0)), ev_less, print_getbit }, &ev_less_str },
3bb695
+		{ { ARG_STR(EVIOCGBIT(0, 0)), ev_more, print_getbit },
3bb695
+			inject_retval * 8 <= EV_LED
3bb695
+				? (const void *) &ev_more_str_2
3bb695
+				: (const void *) &ev_more_str_3 },
3bb695
+		{ { ARG_STR(EVIOCGBIT(0, 0)), ev_less, print_getbit },
3bb695
+			inject_retval * 8 <= EV_LED
3bb695
+				? (const void *) &ev_less_str_2
3bb695
+				: (const void *) &ev_less_str_3 },
3bb695
 		{ { ARG_STR(EVIOCGBIT(0, 0)), ev_zero, print_getbit }, &ev_zero_str },
3bb695
-		{ { ARG_STR(EVIOCGBIT(EV_KEY, 0)), key, print_getbit }, &key_str},
3bb695
+		{ { ARG_STR(EVIOCGBIT(EV_KEY, 0)), key, print_getbit },
3bb695
+			inject_retval * 8 <= KEY_F12
3bb695
+				? (const void *) &key_str_8
3bb695
+				: (const void *) &key_str_16 },
3bb695
 # ifdef EVIOCGMTSLOTS
3bb695
 		{ { ARG_STR(EVIOCGMTSLOTS(12)), mtslots, print_mtslots }, &mtslots_str },
3bb695
 		{ { ARG_STR(EVIOCGMTSLOTS(8)), invalid_mtslot, print_mtslots }, &invalid_mtslot_str }
3bb695
Index: strace-4.24/tests-mx32/ioctl_evdev-success.c
3bb695
===================================================================
3bb695
--- strace-4.24.orig/tests-mx32/ioctl_evdev-success.c	2019-08-01 18:40:58.009521546 +0200
3bb695
+++ strace-4.24/tests-mx32/ioctl_evdev-success.c	2019-08-29 12:09:30.350669261 +0200
3bb695
@@ -2,6 +2,7 @@
3bb695
 
3bb695
 #ifdef HAVE_LINUX_INPUT_H
3bb695
 
3bb695
+# include <assert.h>
3bb695
 # include <inttypes.h>
3bb695
 # include <stdio.h>
3bb695
 # include <stdlib.h>
3bb695
@@ -9,17 +10,19 @@
3bb695
 # include <linux/input.h>
3bb695
 # include "print_fields.h"
3bb695
 
3bb695
+# define NUM_WORDS 4
3bb695
+
3bb695
 static const char *errstr;
3bb695
 
3bb695
 struct evdev_check {
3bb695
 	unsigned long cmd;
3bb695
 	const char *cmd_str;
3bb695
-	void *arg_ptr;
3bb695
-	void (*print_arg)(long rc, void *ptr, void *arg);
3bb695
+	const void *arg_ptr;
3bb695
+	void (*print_arg)(long rc, const void *ptr, const void *arg);
3bb695
 };
3bb695
 
3bb695
 static long
3bb695
-invoke_test_syscall(unsigned long cmd, void *p)
3bb695
+invoke_test_syscall(unsigned long cmd, const void *p)
3bb695
 {
3bb695
 	long rc = ioctl(-1, cmd, p);
3bb695
 	errstr = sprintrc(rc);
3bb695
@@ -31,7 +34,7 @@
3bb695
 }
3bb695
 
3bb695
 static void
3bb695
-test_evdev(struct evdev_check *check, void *arg)
3bb695
+test_evdev(struct evdev_check *check, const void *arg)
3bb695
 {
3bb695
 	long rc = invoke_test_syscall(check->cmd, check->arg_ptr);
3bb695
 	printf("ioctl(-1, %s, ", check->cmd_str);
3bb695
@@ -43,9 +46,9 @@
3bb695
 }
3bb695
 
3bb695
 static void
3bb695
-print_input_absinfo(long rc, void *ptr, void *arg)
3bb695
+print_input_absinfo(long rc, const void *ptr, const void *arg)
3bb695
 {
3bb695
-	struct input_absinfo *absinfo = ptr;
3bb695
+	const struct input_absinfo *absinfo = ptr;
3bb695
 
3bb695
 	if (rc < 0) {
3bb695
 		printf("%p", absinfo);
3bb695
@@ -67,9 +70,9 @@
3bb695
 }
3bb695
 
3bb695
 static void
3bb695
-print_input_id(long rc, void *ptr, void *arg)
3bb695
+print_input_id(long rc, const void *ptr, const void *arg)
3bb695
 {
3bb695
-	struct input_id *id = ptr;
3bb695
+	const struct input_id *id = ptr;
3bb695
 
3bb695
 	if (rc < 0) {
3bb695
 		printf("%p", id);
3bb695
@@ -84,10 +87,10 @@
3bb695
 
3bb695
 # ifdef EVIOCGMTSLOTS
3bb695
 static void
3bb695
-print_mtslots(long rc, void *ptr, void *arg)
3bb695
+print_mtslots(long rc, const void *ptr, const void *arg)
3bb695
 {
3bb695
-	int *buffer = ptr;
3bb695
-	const char **str = arg;
3bb695
+	const int *buffer = ptr;
3bb695
+	const char * const * str = arg;
3bb695
 	int num = atoi(*(str + 1));
3bb695
 
3bb695
 	if (rc < 0) {
3bb695
@@ -104,27 +107,26 @@
3bb695
 # endif
3bb695
 
3bb695
 static void
3bb695
-print_getbit(long rc, void *ptr, void *arg)
3bb695
+print_getbit(long rc, const void *ptr, const void *arg)
3bb695
 {
3bb695
-	const char **str = arg;
3bb695
-	int num = atoi(*str);
3bb695
+	const char * const *str = arg;
3bb695
 
3bb695
-	if (rc < 0) {
3bb695
+	if (rc <= 0) {
3bb695
 		printf("%p", ptr);
3bb695
 		return;
3bb695
 	}
3bb695
 
3bb695
 	printf("[");
3bb695
-	printf("%s", *(str + 1));
3bb695
-	for (unsigned int i = 2; i <= (unsigned) num; i++) {
3bb695
+	for (unsigned long i = 0; str[i]; i++) {
3bb695
 # if ! VERBOSE
3bb695
-		if (i > 4) {
3bb695
+		if (i >= 4) {
3bb695
 			printf(", ...");
3bb695
 			break;
3bb695
 		}
3bb695
 # endif
3bb695
-		printf(", ");
3bb695
-		printf("%s", *(str + i));
3bb695
+		if (i)
3bb695
+			printf(", ");
3bb695
+		printf("%s", str[i]);
3bb695
 	}
3bb695
 	printf("]");
3bb695
 }
3bb695
@@ -170,6 +172,7 @@
3bb695
 	TAIL_ALLOC_OBJECT_CONST_PTR(struct input_id, id);
3bb695
 	TAIL_ALLOC_OBJECT_CONST_PTR(struct input_absinfo, absinfo);
3bb695
 	TAIL_ALLOC_OBJECT_CONST_PTR(int, bad_addr_slot);
3bb695
+
3bb695
 # ifdef EVIOCGMTSLOTS
3bb695
 	int mtslots[] = { ABS_MT_SLOT, 1, 3 };
3bb695
 	/* we use the second element to indicate the number of values */
3bb695
@@ -183,36 +186,65 @@
3bb695
 	const char *invalid_mtslot_str[] = { invalid_str, "1", "1" };
3bb695
 # endif
3bb695
 
3bb695
+	enum { ULONG_BIT = sizeof(unsigned long) * 8 };
3bb695
+
3bb695
 	/* set more than 4 bits */
3bb695
-	unsigned long ev_more[] = { 1 << EV_ABS | 1 << EV_MSC | 1 << EV_LED | 1 << EV_SND | 1 << EV_PWR };
3bb695
-	/* we use the first element to indicate the number of set bits */
3bb695
-	/* ev_more_str[0] is "5" so the number of set bits is 5 */
3bb695
-	const char *ev_more_str[] = { "5", "EV_ABS", "EV_MSC", "EV_LED", "EV_SND", "EV_PWR" };
3bb695
+	static const unsigned long ev_more[NUM_WORDS] = {
3bb695
+		1 << EV_ABS | 1 << EV_MSC | 1 << EV_LED | 1 << EV_SND
3bb695
+		| 1 << EV_PWR };
3bb695
+	static const char * const ev_more_str_2[] = {
3bb695
+		"EV_ABS", "EV_MSC", NULL };
3bb695
+	static const char * const ev_more_str_3[] = {
3bb695
+		"EV_ABS", "EV_MSC", "EV_LED", "EV_SND", "EV_PWR", NULL };
3bb695
 
3bb695
 	/* set less than 4 bits */
3bb695
-	unsigned long ev_less[] = { 1 << EV_ABS | 1 << EV_MSC | 1 << EV_LED };
3bb695
-	const char *ev_less_str[] = { "3", "EV_ABS", "EV_MSC", "EV_LED" };
3bb695
+	static const unsigned long ev_less[NUM_WORDS] = {
3bb695
+		1 << EV_ABS | 1 << EV_MSC | 1 << EV_LED };
3bb695
+	static const char * const ev_less_str_2[] = {
3bb695
+		"EV_ABS", "EV_MSC", NULL };
3bb695
+	static const char * const ev_less_str_3[] = {
3bb695
+		"EV_ABS", "EV_MSC", "EV_LED", NULL };
3bb695
 
3bb695
 	/* set zero bit */
3bb695
-	unsigned long ev_zero[] = { 0x0 };
3bb695
-	const char *ev_zero_str[] = { "0", " 0 " };
3bb695
+	static const unsigned long ev_zero[NUM_WORDS] = { 0x0 };
3bb695
+	static const char * const ev_zero_str[] = { " 0 ", NULL };
3bb695
 
3bb695
 	/* KEY_MAX is 0x2ff which is greater than retval * 8 */
3bb695
-	unsigned long key[] = { 1 << KEY_1 | 1 << KEY_2, 0 };
3bb695
-	const char *key_str[] = { "2", "KEY_1", "KEY_2" };
3bb695
+	static const unsigned long key[NUM_WORDS] = {
3bb695
+		1 << KEY_1 | 1 << KEY_2,
3bb695
+		[ KEY_F12 / ULONG_BIT ] = 1 << (KEY_F12 % ULONG_BIT) };
3bb695
+
3bb695
+	static const char * const key_str_8[] = {
3bb695
+		"KEY_1", "KEY_2", NULL };
3bb695
+	static const char * const key_str_16[] = {
3bb695
+		"KEY_1", "KEY_2", "KEY_F12", NULL };
3bb695
+
3bb695
+	assert(sizeof(ev_more) >= (unsigned long) inject_retval);
3bb695
+	assert(sizeof(ev_less) >= (unsigned long) inject_retval);
3bb695
+	assert(sizeof(ev_zero) >= (unsigned long) inject_retval);
3bb695
+	assert(sizeof(key) >= (unsigned long) inject_retval);
3bb695
 
3bb695
 	struct {
3bb695
 		struct evdev_check check;
3bb695
-		void *ptr;
3bb695
+		const void *ptr;
3bb695
 	} a[] = {
3bb695
 		{ { ARG_STR(EVIOCGID), id, print_input_id }, NULL },
3bb695
 		{ { ARG_STR(EVIOCGABS(ABS_X)), absinfo, print_input_absinfo }, NULL },
3bb695
 		{ { ARG_STR(EVIOCGABS(ABS_Y)), absinfo, print_input_absinfo }, NULL },
3bb695
 		{ { ARG_STR(EVIOCGABS(ABS_Y)), absinfo, print_input_absinfo }, NULL },
3bb695
-		{ { ARG_STR(EVIOCGBIT(0, 0)), ev_more, print_getbit }, &ev_more_str },
3bb695
-		{ { ARG_STR(EVIOCGBIT(0, 0)), ev_less, print_getbit }, &ev_less_str },
3bb695
+		{ { ARG_STR(EVIOCGBIT(0, 0)), ev_more, print_getbit },
3bb695
+			inject_retval * 8 <= EV_LED
3bb695
+				? (const void *) &ev_more_str_2
3bb695
+				: (const void *) &ev_more_str_3 },
3bb695
+		{ { ARG_STR(EVIOCGBIT(0, 0)), ev_less, print_getbit },
3bb695
+			inject_retval * 8 <= EV_LED
3bb695
+				? (const void *) &ev_less_str_2
3bb695
+				: (const void *) &ev_less_str_3 },
3bb695
 		{ { ARG_STR(EVIOCGBIT(0, 0)), ev_zero, print_getbit }, &ev_zero_str },
3bb695
-		{ { ARG_STR(EVIOCGBIT(EV_KEY, 0)), key, print_getbit }, &key_str},
3bb695
+		{ { ARG_STR(EVIOCGBIT(EV_KEY, 0)), key, print_getbit },
3bb695
+			inject_retval * 8 <= KEY_F12
3bb695
+				? (const void *) &key_str_8
3bb695
+				: (const void *) &key_str_16 },
3bb695
 # ifdef EVIOCGMTSLOTS
3bb695
 		{ { ARG_STR(EVIOCGMTSLOTS(12)), mtslots, print_mtslots }, &mtslots_str },
3bb695
 		{ { ARG_STR(EVIOCGMTSLOTS(8)), invalid_mtslot, print_mtslots }, &invalid_mtslot_str }