]> granicus.if.org Git - strace/blobdiff - tests/ioctl_evdev.c
tests: extend TEST_NETLINK_OBJECT macro
[strace] / tests / ioctl_evdev.c
index 5e22894c1d64447316f264dc580e7069f1b7d6de..9d16cecf0877febd26f437572e3b2b738de13dfc 100644 (file)
@@ -1,7 +1,8 @@
 /*
- * This file is part of ioctl_block strace test.
+ * This file is part of ioctl_evdev strace test.
  *
  * Copyright (c) 2016 Dmitry V. Levin <ldv@altlinux.org>
+ * Copyright (c) 2016-2017 The strace developers.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 # include <linux/input.h>
 
 static const unsigned int magic = 0xdeadbeef;
-static const unsigned long lmagic = (unsigned long) 0xdeadbeefbadc0ded;
+static const unsigned long lmagic = (unsigned long) 0xdeadbeefbadc0dedULL;
 
-static void
-init_magic(void *addr, const unsigned int size)
-{
-       unsigned int *p = addr;
-       const unsigned int *end = addr + size - sizeof(int);
-
-       for (; p <= end; ++p)
-               *(unsigned int *) p = magic;
-}
-
-# ifdef VERBOSE_IOCTL
+# if VERBOSE
 static void
 print_envelope(const struct ff_envelope *const e)
 {
@@ -60,7 +51,7 @@ print_envelope(const struct ff_envelope *const e)
               e->attack_length, e->attack_level,
               e->fade_length, e->fade_level);
 }
-# endif /* VERBOSE_IOCTL */
+# endif /* VERBOSE */
 
 static void
 print_ffe_common(const struct ff_effect *const ffe, const char *const type_str)
@@ -68,17 +59,19 @@ print_ffe_common(const struct ff_effect *const ffe, const char *const type_str)
        printf("ioctl(-1, EVIOCSFF, {type=%s, id=%" PRIu16
               ", direction=%" PRIu16 ", ",
               type_str, ffe->id, ffe->direction);
-# ifdef VERBOSE_IOCTL
+# if VERBOSE
        printf("trigger={button=%hu, interval=%hu}"
               ", replay={length=%hu, delay=%hu}",
               ffe->trigger.button, ffe->trigger.interval,
               ffe->replay.length, ffe->replay.delay);
-# endif /* VERBOSE_IOCTL */
+# endif /* VERBOSE */
 }
 
-# define TEST_NULL_ARG(cmd) \
-       ioctl(-1, cmd, 0); \
-       printf("ioctl(-1, %s, NULL) = -1 EBADF (%m)\n", #cmd)
+# define TEST_NULL_ARG(cmd)                                            \
+       do {                                                            \
+               ioctl(-1, cmd, 0);                                      \
+               printf("ioctl(-1, %s, NULL) = -1 EBADF (%m)\n", #cmd);  \
+       } while (0)
 
 int
 main(void)
@@ -107,6 +100,7 @@ main(void)
 
        TEST_NULL_ARG(EVIOCGNAME(0));
        TEST_NULL_ARG(EVIOCGPHYS(0));
+       TEST_NULL_ARG(EVIOCGUNIQ(0));
        TEST_NULL_ARG(EVIOCGKEY(0));
        TEST_NULL_ARG(EVIOCGLED(0));
 # ifdef EVIOCGMTSLOTS
@@ -155,9 +149,9 @@ main(void)
 
        const unsigned int size = get_page_size();
        void *const page = tail_alloc(size);
-       init_magic(page, size);
+       fill_memory(page, size);
 
-       int *const val_int = tail_alloc(sizeof(*val_int));
+       TAIL_ALLOC_OBJECT_CONST_PTR(int, val_int);
        *val_int = magic;
 
 # ifdef EVIOCSCLOCKID
@@ -181,14 +175,14 @@ main(void)
               pair_int[0], "KEY_ESC");
 
 # ifdef EVIOCSKEYCODE_V2
-       struct input_keymap_entry *const ike = tail_alloc(sizeof(*ike));
-       init_magic(ike, sizeof(*ike));
+       TAIL_ALLOC_OBJECT_CONST_PTR(struct input_keymap_entry, ike);
+       fill_memory(ike, sizeof(*ike));
        ike->keycode = 2;
 
        ioctl(-1, EVIOCSKEYCODE_V2, ike);
        printf("ioctl(-1, EVIOCSKEYCODE_V2, {flags=%" PRIu8
               ", len=%" PRIu8 ", ", ike->flags, ike->len);
-#  ifdef VERBOSE_IOCTL
+#  if VERBOSE
        printf("index=%" PRIu16 ", keycode=%s, scancode=[",
               ike->index, "KEY_1");
        unsigned int i;
@@ -205,14 +199,14 @@ main(void)
        printf("}) = -1 EBADF (%m)\n");
 # endif
 
-       struct ff_effect *const ffe = tail_alloc(sizeof(*ffe));
-       init_magic(ffe, sizeof(*ffe));
+       TAIL_ALLOC_OBJECT_CONST_PTR(struct ff_effect, ffe);
+       fill_memory(ffe, sizeof(*ffe));
 
        ffe->type = FF_CONSTANT;
        ioctl(-1, EVIOCSFF, ffe);
        print_ffe_common(ffe, "FF_CONSTANT");
 
-#  ifdef VERBOSE_IOCTL
+#  if VERBOSE
        printf(", constant={level=%hd", ffe->u.constant.level);
        print_envelope(&ffe->u.constant.envelope);
        printf("}");
@@ -222,7 +216,7 @@ main(void)
        errno = EBADF;
        printf("}) = -1 EBADF (%m)\n");
 
-#  ifdef VERBOSE_IOCTL
+#  if VERBOSE
        ffe->type = FF_RAMP;
        ioctl(-1, EVIOCSFF, ffe);
        print_ffe_common(ffe, "FF_RAMP");
@@ -261,18 +255,22 @@ main(void)
        printf("}) = -1 EBADF (%m)\n");
 #  endif
 
-       ioctl(-1, _IOC(_IOC_READ, 0x45, 0x01, 0xff), lmagic);
+       ioctl(-1, _IOC(_IOC_READ, 0x45, 0x1, 0xff), lmagic);
        printf("ioctl(-1, %s, %#lx) = -1 EBADF (%m)\n",
-              "_IOC(_IOC_READ, 0x45, 0x01, 0xff)", lmagic);
+              "_IOC(_IOC_READ, 0x45, 0x1, 0xff)", lmagic);
 
-       ioctl(-1, _IOC(_IOC_WRITE, 0x45, 0x01, 0xff), lmagic);
+       ioctl(-1, _IOC(_IOC_WRITE, 0x45, 0x1, 0xff), lmagic);
        printf("ioctl(-1, %s, %#lx) = -1 EBADF (%m)\n",
-              "_IOC(_IOC_WRITE, 0x45, 0x01, 0xff)", lmagic);
+              "_IOC(_IOC_WRITE, 0x45, 0x1, 0xff)", lmagic);
 
        ioctl(-1, _IOC(_IOC_READ|_IOC_WRITE, 0x45, 0xfe, 0xff), lmagic);
        printf("ioctl(-1, %s, %#lx) = -1 EBADF (%m)\n",
               "_IOC(_IOC_READ|_IOC_WRITE, 0x45, 0xfe, 0xff)", lmagic);
 
+       ioctl(-1, _IOC(_IOC_READ|_IOC_WRITE, 0x45, 0, 0), lmagic);
+       printf("ioctl(-1, %s, %#lx) = -1 EBADF (%m)\n",
+              "_IOC(_IOC_READ|_IOC_WRITE, 0x45, 0, 0)", lmagic);
+
        puts("+++ exited with 0 +++");
        return 0;
 }