1 /* 2 * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org> 3 * Copyright (c) 2015-2017 The strace developers. 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #include "tests.h" 30 #include <fcntl.h> 31 #include <stdio.h> 32 #include <stdint.h> 33 #include <unistd.h> 34 #include <termios.h> 35 #include <sys/ioctl.h> 36 37 #ifdef HAVE_LINUX_MMTIMER_H 38 # include <linux/mmtimer.h> 39 #endif 40 #ifdef HAVE_LINUX_HIDDEV_H 41 # include <linux/hiddev.h> 42 #endif 43 #ifdef HAVE_LINUX_INPUT_H 44 # include <linux/input.h> 45 #endif 46 47 #include <linux/videodev2.h> 48 49 #if defined MMTIMER_GETRES \ 50 && defined VIDIOC_ENUMINPUT \ 51 && defined HIDIOCGVERSION \ 52 && defined HIDIOCGPHYS \ 53 && defined EVIOCGBIT \ 54 && defined EV_KEY 55 56 int 57 main(void) 58 { 59 uint64_t data = 0; 60 61 #ifndef POWERPC 62 struct termios tty; 63 (void) ioctl(-1, TCGETS, &tty); 64 printf("ioctl(-1, TCGETS, %p)" 65 " = -1 EBADF (%m)\n", &tty); 66 #endif 67 68 (void) ioctl(-1, MMTIMER_GETRES, &data); 69 printf("ioctl(-1, MMTIMER_GETRES, %p)" 70 " = -1 EBADF (%m)\n", &data); 71 72 (void) ioctl(-1, VIDIOC_ENUMINPUT, 0); 73 printf("ioctl(-1, VIDIOC_ENUMINPUT, NULL)" 74 " = -1 EBADF (%m)\n"); 75 76 (void) ioctl(-1, HIDIOCGVERSION, &data); 77 printf("ioctl(-1, HIDIOCGRDESCSIZE or HIDIOCGVERSION, %p)" 78 " = -1 EBADF (%m)\n", &data); 79 80 (void) ioctl(-1, HIDIOCGPHYS(8), &data); 81 printf("ioctl(-1, HIDIOCGPHYS(8), %p)" 82 " = -1 EBADF (%m)\n", &data); 83 84 (void) ioctl(-1, EVIOCGBIT(EV_KEY, 8), &data); 85 printf("ioctl(-1, EVIOCGBIT(EV_KEY, 8), %p)" 86 " = -1 EBADF (%m)\n", &data); 87 88 (void) ioctl(-1, _IOR('M', 13, int), &data); 89 # ifdef HAVE_STRUCT_MTD_WRITE_REQ 90 printf("ioctl(-1, MIXER_READ(13) or OTPSELECT, [MTD_OTP_OFF])" 91 " = -1 EBADF (%m)\n"); 92 # else 93 printf("ioctl(-1, MIXER_READ(13) or OTPSELECT, %p)" 94 " = -1 EBADF (%m)\n", &data); 95 # endif 96 97 (void) ioctl(-1, _IOC(_IOC_WRITE, 0xde, 0, 0), (kernel_ulong_t) -1ULL); 98 printf("ioctl(-1, _IOC(_IOC_WRITE, 0xde, 0, 0), %#lx)" 99 " = -1 EBADF (%m)\n", -1UL); 100 101 (void) ioctl(-1, _IOR(0xde, 0xad, data), &data); 102 printf("ioctl(-1, _IOC(_IOC_READ, 0xde, 0xad, 0x8), %p)" 103 " = -1 EBADF (%m)\n", &data); 104 105 puts("+++ exited with 0 +++"); 106 return 0; 107 } 108 109 #else 110 111 SKIP_MAIN_UNDEFINED("MMTIMER_GETRES && VIDIOC_ENUMINPUT" 112 " && HIDIOCGVERSION && HIDIOCGPHYS" 113 " && EVIOCGBIT && EV_KEY") 114 115 #endif 116