2 * This file is part of ioctl_evdev strace test.
4 * Copyright (c) 2016 Dmitry V. Levin <ldv@altlinux.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #ifdef HAVE_LINUX_INPUT_H
35 # include <inttypes.h>
38 # include <sys/ioctl.h>
39 # include <linux/input.h>
41 static const unsigned int magic = 0xdeadbeef;
42 static const unsigned long lmagic = (unsigned long) 0xdeadbeefbadc0ded;
45 init_magic(void *addr, const unsigned int size)
47 unsigned int *p = addr;
48 const unsigned int *end = addr + size - sizeof(int);
51 *(unsigned int *) p = magic;
56 print_envelope(const struct ff_envelope *const e)
58 printf(", envelope={attack_length=%hu, attack_level=%hu"
59 ", fade_length=%hu, fade_level=%#hx}",
60 e->attack_length, e->attack_level,
61 e->fade_length, e->fade_level);
63 # endif /* VERBOSE_IOCTL */
66 print_ffe_common(const struct ff_effect *const ffe, const char *const type_str)
68 printf("ioctl(-1, EVIOCSFF, {type=%s, id=%" PRIu16
69 ", direction=%" PRIu16 ", ",
70 type_str, ffe->id, ffe->direction);
72 printf("trigger={button=%hu, interval=%hu}"
73 ", replay={length=%hu, delay=%hu}",
74 ffe->trigger.button, ffe->trigger.interval,
75 ffe->replay.length, ffe->replay.delay);
76 # endif /* VERBOSE_IOCTL */
79 # define TEST_NULL_ARG(cmd) \
81 printf("ioctl(-1, %s, NULL) = -1 EBADF (%m)\n", #cmd)
86 TEST_NULL_ARG(EVIOCGVERSION);
87 TEST_NULL_ARG(EVIOCGEFFECTS);
88 TEST_NULL_ARG(EVIOCGID);
89 TEST_NULL_ARG(EVIOCGKEYCODE);
90 TEST_NULL_ARG(EVIOCSKEYCODE);
91 TEST_NULL_ARG(EVIOCSFF);
92 # ifdef EVIOCGKEYCODE_V2
93 TEST_NULL_ARG(EVIOCGKEYCODE_V2);
95 # ifdef EVIOCSKEYCODE_V2
96 TEST_NULL_ARG(EVIOCSKEYCODE_V2);
99 TEST_NULL_ARG(EVIOCGREP);
102 TEST_NULL_ARG(EVIOCSREP);
104 # ifdef EVIOCSCLOCKID
105 TEST_NULL_ARG(EVIOCSCLOCKID);
108 TEST_NULL_ARG(EVIOCGNAME(0));
109 TEST_NULL_ARG(EVIOCGPHYS(0));
110 TEST_NULL_ARG(EVIOCGUNIQ(0));
111 TEST_NULL_ARG(EVIOCGKEY(0));
112 TEST_NULL_ARG(EVIOCGLED(0));
113 # ifdef EVIOCGMTSLOTS
114 TEST_NULL_ARG(EVIOCGMTSLOTS(0));
117 TEST_NULL_ARG(EVIOCGPROP(0));
119 TEST_NULL_ARG(EVIOCGSND(0));
121 TEST_NULL_ARG(EVIOCGSW(0));
124 TEST_NULL_ARG(EVIOCGABS(ABS_X));
125 TEST_NULL_ARG(EVIOCSABS(ABS_X));
127 TEST_NULL_ARG(EVIOCGBIT(EV_SYN, 0));
128 TEST_NULL_ARG(EVIOCGBIT(EV_KEY, 1));
129 TEST_NULL_ARG(EVIOCGBIT(EV_REL, 2));
130 TEST_NULL_ARG(EVIOCGBIT(EV_ABS, 3));
131 TEST_NULL_ARG(EVIOCGBIT(EV_MSC, 4));
133 TEST_NULL_ARG(EVIOCGBIT(EV_SW, 5));
135 TEST_NULL_ARG(EVIOCGBIT(EV_LED, 6));
136 TEST_NULL_ARG(EVIOCGBIT(EV_SND, 7));
137 TEST_NULL_ARG(EVIOCGBIT(EV_REP, 8));
138 TEST_NULL_ARG(EVIOCGBIT(EV_FF, 9));
139 TEST_NULL_ARG(EVIOCGBIT(EV_PWR, 10));
140 TEST_NULL_ARG(EVIOCGBIT(EV_FF_STATUS, 11));
142 ioctl(-1, EVIOCGBIT(EV_MAX, 42), 0);
143 printf("ioctl(-1, EVIOCGBIT(%#x /* EV_??? */, 42), NULL)"
144 " = -1 EBADF (%m)\n", EV_MAX);
146 ioctl(-1, EVIOCRMFF, lmagic);
147 printf("ioctl(-1, EVIOCRMFF, %d) = -1 EBADF (%m)\n", (int) lmagic);
149 ioctl(-1, EVIOCGRAB, lmagic);
150 printf("ioctl(-1, EVIOCGRAB, %lu) = -1 EBADF (%m)\n", lmagic);
153 ioctl(-1, EVIOCREVOKE, lmagic);
154 printf("ioctl(-1, EVIOCREVOKE, %lu) = -1 EBADF (%m)\n", lmagic);
157 const unsigned int size = get_page_size();
158 void *const page = tail_alloc(size);
159 init_magic(page, size);
161 int *const val_int = tail_alloc(sizeof(*val_int));
164 # ifdef EVIOCSCLOCKID
165 ioctl(-1, EVIOCSCLOCKID, val_int);
166 printf("ioctl(-1, EVIOCSCLOCKID, [%u]) = -1 EBADF (%m)\n", *val_int);
169 int *pair_int = tail_alloc(sizeof(*pair_int) * 2);
170 pair_int[0] = 0xdeadbeef;
171 pair_int[1] = 0xbadc0ded;
174 ioctl(-1, EVIOCSREP, pair_int);
175 printf("ioctl(-1, EVIOCSREP, [%u, %u]) = -1 EBADF (%m)\n",
176 pair_int[0], pair_int[1]);
180 ioctl(-1, EVIOCSKEYCODE, pair_int);
181 printf("ioctl(-1, EVIOCSKEYCODE, [%u, %s]) = -1 EBADF (%m)\n",
182 pair_int[0], "KEY_ESC");
184 # ifdef EVIOCSKEYCODE_V2
185 struct input_keymap_entry *const ike = tail_alloc(sizeof(*ike));
186 init_magic(ike, sizeof(*ike));
189 ioctl(-1, EVIOCSKEYCODE_V2, ike);
190 printf("ioctl(-1, EVIOCSKEYCODE_V2, {flags=%" PRIu8
191 ", len=%" PRIu8 ", ", ike->flags, ike->len);
192 # ifdef VERBOSE_IOCTL
193 printf("index=%" PRIu16 ", keycode=%s, scancode=[",
194 ike->index, "KEY_1");
196 for (i = 0; i < ARRAY_SIZE(ike->scancode); ++i) {
199 printf("%" PRIx8, ike->scancode[i]);
206 printf("}) = -1 EBADF (%m)\n");
209 struct ff_effect *const ffe = tail_alloc(sizeof(*ffe));
210 init_magic(ffe, sizeof(*ffe));
212 ffe->type = FF_CONSTANT;
213 ioctl(-1, EVIOCSFF, ffe);
214 print_ffe_common(ffe, "FF_CONSTANT");
216 # ifdef VERBOSE_IOCTL
217 printf(", constant={level=%hd", ffe->u.constant.level);
218 print_envelope(&ffe->u.constant.envelope);
224 printf("}) = -1 EBADF (%m)\n");
226 # ifdef VERBOSE_IOCTL
228 ioctl(-1, EVIOCSFF, ffe);
229 print_ffe_common(ffe, "FF_RAMP");
230 printf(", ramp={start_level=%hd, end_level=%hd",
231 ffe->u.ramp.start_level, ffe->u.ramp.end_level);
232 print_envelope(&ffe->u.ramp.envelope);
234 printf("}}) = -1 EBADF (%m)\n");
236 ffe->type = FF_PERIODIC;
237 ioctl(-1, EVIOCSFF, ffe);
238 print_ffe_common(ffe, "FF_PERIODIC");
239 printf(", periodic={waveform=%hu, period=%hu, magnitude=%hd"
240 ", offset=%hd, phase=%hu",
241 ffe->u.periodic.waveform, ffe->u.periodic.period,
242 ffe->u.periodic.magnitude, ffe->u.periodic.offset,
243 ffe->u.periodic.phase);
244 print_envelope(&ffe->u.periodic.envelope);
245 printf(", custom_len=%u, custom_data=%p}",
246 ffe->u.periodic.custom_len, ffe->u.periodic.custom_data);
248 printf("}) = -1 EBADF (%m)\n");
250 ffe->type = FF_RUMBLE;
251 ioctl(-1, EVIOCSFF, ffe);
252 print_ffe_common(ffe, "FF_RUMBLE");
253 printf(", rumble={strong_magnitude=%hu, weak_magnitude=%hu}",
254 ffe->u.rumble.strong_magnitude, ffe->u.rumble.weak_magnitude);
256 printf("}) = -1 EBADF (%m)\n");
259 ioctl(-1, EVIOCSFF, ffe);
260 print_ffe_common(ffe, "0xff /* FF_??? */");
262 printf("}) = -1 EBADF (%m)\n");
265 ioctl(-1, _IOC(_IOC_READ, 0x45, 0x01, 0xff), lmagic);
266 printf("ioctl(-1, %s, %#lx) = -1 EBADF (%m)\n",
267 "_IOC(_IOC_READ, 0x45, 0x01, 0xff)", lmagic);
269 ioctl(-1, _IOC(_IOC_WRITE, 0x45, 0x01, 0xff), lmagic);
270 printf("ioctl(-1, %s, %#lx) = -1 EBADF (%m)\n",
271 "_IOC(_IOC_WRITE, 0x45, 0x01, 0xff)", lmagic);
273 ioctl(-1, _IOC(_IOC_READ|_IOC_WRITE, 0x45, 0xfe, 0xff), lmagic);
274 printf("ioctl(-1, %s, %#lx) = -1 EBADF (%m)\n",
275 "_IOC(_IOC_READ|_IOC_WRITE, 0x45, 0xfe, 0xff)", lmagic);
277 puts("+++ exited with 0 +++");
282 SKIP_MAIN_UNDEFINED("HAVE_LINUX_INPUT_H")