2 * This file is part of ioctl_block 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(EVIOCGKEY(0));
111 TEST_NULL_ARG(EVIOCGLED(0));
112 # ifdef EVIOCGMTSLOTS
113 TEST_NULL_ARG(EVIOCGMTSLOTS(0));
116 TEST_NULL_ARG(EVIOCGPROP(0));
118 TEST_NULL_ARG(EVIOCGSND(0));
120 TEST_NULL_ARG(EVIOCGSW(0));
123 TEST_NULL_ARG(EVIOCGABS(ABS_X));
124 TEST_NULL_ARG(EVIOCSABS(ABS_X));
126 TEST_NULL_ARG(EVIOCGBIT(EV_SYN, 0));
127 TEST_NULL_ARG(EVIOCGBIT(EV_KEY, 1));
128 TEST_NULL_ARG(EVIOCGBIT(EV_REL, 2));
129 TEST_NULL_ARG(EVIOCGBIT(EV_ABS, 3));
130 TEST_NULL_ARG(EVIOCGBIT(EV_MSC, 4));
132 TEST_NULL_ARG(EVIOCGBIT(EV_SW, 5));
134 TEST_NULL_ARG(EVIOCGBIT(EV_LED, 6));
135 TEST_NULL_ARG(EVIOCGBIT(EV_SND, 7));
136 TEST_NULL_ARG(EVIOCGBIT(EV_REP, 8));
137 TEST_NULL_ARG(EVIOCGBIT(EV_FF, 9));
138 TEST_NULL_ARG(EVIOCGBIT(EV_PWR, 10));
139 TEST_NULL_ARG(EVIOCGBIT(EV_FF_STATUS, 11));
141 ioctl(-1, EVIOCGBIT(EV_MAX, 42), 0);
142 printf("ioctl(-1, EVIOCGBIT(%#x /* EV_??? */, 42), NULL)"
143 " = -1 EBADF (%m)\n", EV_MAX);
145 ioctl(-1, EVIOCRMFF, lmagic);
146 printf("ioctl(-1, EVIOCRMFF, %d) = -1 EBADF (%m)\n", (int) lmagic);
148 ioctl(-1, EVIOCGRAB, lmagic);
149 printf("ioctl(-1, EVIOCGRAB, %lu) = -1 EBADF (%m)\n", lmagic);
152 ioctl(-1, EVIOCREVOKE, lmagic);
153 printf("ioctl(-1, EVIOCREVOKE, %lu) = -1 EBADF (%m)\n", lmagic);
156 const unsigned int size = get_page_size();
157 void *const page = tail_alloc(size);
158 init_magic(page, size);
160 int *const val_int = tail_alloc(sizeof(*val_int));
163 # ifdef EVIOCSCLOCKID
164 ioctl(-1, EVIOCSCLOCKID, val_int);
165 printf("ioctl(-1, EVIOCSCLOCKID, [%u]) = -1 EBADF (%m)\n", *val_int);
168 int *pair_int = tail_alloc(sizeof(*pair_int) * 2);
169 pair_int[0] = 0xdeadbeef;
170 pair_int[1] = 0xbadc0ded;
173 ioctl(-1, EVIOCSREP, pair_int);
174 printf("ioctl(-1, EVIOCSREP, [%u, %u]) = -1 EBADF (%m)\n",
175 pair_int[0], pair_int[1]);
179 ioctl(-1, EVIOCSKEYCODE, pair_int);
180 printf("ioctl(-1, EVIOCSKEYCODE, [%u, %s]) = -1 EBADF (%m)\n",
181 pair_int[0], "KEY_ESC");
183 # ifdef EVIOCSKEYCODE_V2
184 struct input_keymap_entry *const ike = tail_alloc(sizeof(*ike));
185 init_magic(ike, sizeof(*ike));
188 ioctl(-1, EVIOCSKEYCODE_V2, ike);
189 printf("ioctl(-1, EVIOCSKEYCODE_V2, {flags=%" PRIu8
190 ", len=%" PRIu8 ", ", ike->flags, ike->len);
191 # ifdef VERBOSE_IOCTL
192 printf("index=%" PRIu16 ", keycode=%s, scancode=[",
193 ike->index, "KEY_1");
195 for (i = 0; i < ARRAY_SIZE(ike->scancode); ++i) {
198 printf("%" PRIx8, ike->scancode[i]);
205 printf("}) = -1 EBADF (%m)\n");
208 struct ff_effect *const ffe = tail_alloc(sizeof(*ffe));
209 init_magic(ffe, sizeof(*ffe));
211 ffe->type = FF_CONSTANT;
212 ioctl(-1, EVIOCSFF, ffe);
213 print_ffe_common(ffe, "FF_CONSTANT");
215 # ifdef VERBOSE_IOCTL
216 printf(", constant={level=%hd", ffe->u.constant.level);
217 print_envelope(&ffe->u.constant.envelope);
223 printf("}) = -1 EBADF (%m)\n");
225 # ifdef VERBOSE_IOCTL
227 ioctl(-1, EVIOCSFF, ffe);
228 print_ffe_common(ffe, "FF_RAMP");
229 printf(", ramp={start_level=%hd, end_level=%hd",
230 ffe->u.ramp.start_level, ffe->u.ramp.end_level);
231 print_envelope(&ffe->u.ramp.envelope);
233 printf("}}) = -1 EBADF (%m)\n");
235 ffe->type = FF_PERIODIC;
236 ioctl(-1, EVIOCSFF, ffe);
237 print_ffe_common(ffe, "FF_PERIODIC");
238 printf(", periodic={waveform=%hu, period=%hu, magnitude=%hd"
239 ", offset=%hd, phase=%hu",
240 ffe->u.periodic.waveform, ffe->u.periodic.period,
241 ffe->u.periodic.magnitude, ffe->u.periodic.offset,
242 ffe->u.periodic.phase);
243 print_envelope(&ffe->u.periodic.envelope);
244 printf(", custom_len=%u, custom_data=%p}",
245 ffe->u.periodic.custom_len, ffe->u.periodic.custom_data);
247 printf("}) = -1 EBADF (%m)\n");
249 ffe->type = FF_RUMBLE;
250 ioctl(-1, EVIOCSFF, ffe);
251 print_ffe_common(ffe, "FF_RUMBLE");
252 printf(", rumble={strong_magnitude=%hu, weak_magnitude=%hu}",
253 ffe->u.rumble.strong_magnitude, ffe->u.rumble.weak_magnitude);
255 printf("}) = -1 EBADF (%m)\n");
258 ioctl(-1, EVIOCSFF, ffe);
259 print_ffe_common(ffe, "0xff /* FF_??? */");
261 printf("}) = -1 EBADF (%m)\n");
264 ioctl(-1, _IOC(_IOC_READ, 0x45, 0x01, 0xff), lmagic);
265 printf("ioctl(-1, %s, %#lx) = -1 EBADF (%m)\n",
266 "_IOC(_IOC_READ, 0x45, 0x01, 0xff)", lmagic);
268 ioctl(-1, _IOC(_IOC_WRITE, 0x45, 0x01, 0xff), lmagic);
269 printf("ioctl(-1, %s, %#lx) = -1 EBADF (%m)\n",
270 "_IOC(_IOC_WRITE, 0x45, 0x01, 0xff)", lmagic);
272 ioctl(-1, _IOC(_IOC_READ|_IOC_WRITE, 0x45, 0xfe, 0xff), lmagic);
273 printf("ioctl(-1, %s, %#lx) = -1 EBADF (%m)\n",
274 "_IOC(_IOC_READ|_IOC_WRITE, 0x45, 0xfe, 0xff)", lmagic);
276 puts("+++ exited with 0 +++");
281 SKIP_MAIN_UNDEFINED("HAVE_LINUX_INPUT_H")