1f08c3bdfSopenharmony_ci/* 2f08c3bdfSopenharmony_ci * Copyright (c) 2015 Cedric Hnyda <chnyda@suse.com> 3f08c3bdfSopenharmony_ci * 4f08c3bdfSopenharmony_ci * This program is free software; you can redistribute it and/or 5f08c3bdfSopenharmony_ci * modify it under the terms of the GNU General Public License as 6f08c3bdfSopenharmony_ci * published by the Free Software Foundation; either version 2 of 7f08c3bdfSopenharmony_ci * the License, or (at your option) any later version. 8f08c3bdfSopenharmony_ci * 9f08c3bdfSopenharmony_ci * This program is distributed in the hope that it would be useful, 10f08c3bdfSopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of 11f08c3bdfSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12f08c3bdfSopenharmony_ci * GNU General Public License for more details. 13f08c3bdfSopenharmony_ci * 14f08c3bdfSopenharmony_ci * You should have received a copy of the GNU General Public License 15f08c3bdfSopenharmony_ci * along with this program; if not, write the Free Software Foundation, 16f08c3bdfSopenharmony_ci * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17f08c3bdfSopenharmony_ci */ 18f08c3bdfSopenharmony_ci 19f08c3bdfSopenharmony_ci /* 20f08c3bdfSopenharmony_ci * Create a virtual device (mouse), send events to /dev/uinput 21f08c3bdfSopenharmony_ci * and Check that events not advertised in the input device bits 22f08c3bdfSopenharmony_ci * are filtered. 23f08c3bdfSopenharmony_ci */ 24f08c3bdfSopenharmony_ci 25f08c3bdfSopenharmony_ci#include <linux/input.h> 26f08c3bdfSopenharmony_ci#include <linux/uinput.h> 27f08c3bdfSopenharmony_ci 28f08c3bdfSopenharmony_ci#include "test.h" 29f08c3bdfSopenharmony_ci#include "safe_macros.h" 30f08c3bdfSopenharmony_ci#include "lapi/fcntl.h" 31f08c3bdfSopenharmony_ci#include "input_helper.h" 32f08c3bdfSopenharmony_ci 33f08c3bdfSopenharmony_ci#define X_VALUE 10 34f08c3bdfSopenharmony_ci#define Y_VALUE 10 35f08c3bdfSopenharmony_ci 36f08c3bdfSopenharmony_ci#define NB_TEST 20 37f08c3bdfSopenharmony_ci 38f08c3bdfSopenharmony_cistatic void setup(void); 39f08c3bdfSopenharmony_cistatic void send_events(void); 40f08c3bdfSopenharmony_cistatic void cleanup(void); 41f08c3bdfSopenharmony_ci 42f08c3bdfSopenharmony_cistatic int fd; 43f08c3bdfSopenharmony_cistatic int fd2; 44f08c3bdfSopenharmony_ci 45f08c3bdfSopenharmony_cichar *TCID = "input05"; 46f08c3bdfSopenharmony_ci 47f08c3bdfSopenharmony_ciint main(int ac, char **av) 48f08c3bdfSopenharmony_ci{ 49f08c3bdfSopenharmony_ci int lc; 50f08c3bdfSopenharmony_ci int pid; 51f08c3bdfSopenharmony_ci 52f08c3bdfSopenharmony_ci tst_parse_opts(ac, av, NULL, NULL); 53f08c3bdfSopenharmony_ci 54f08c3bdfSopenharmony_ci setup(); 55f08c3bdfSopenharmony_ci 56f08c3bdfSopenharmony_ci for (lc = 0; TEST_LOOPING(lc); ++lc) { 57f08c3bdfSopenharmony_ci pid = tst_fork(); 58f08c3bdfSopenharmony_ci 59f08c3bdfSopenharmony_ci switch (pid) { 60f08c3bdfSopenharmony_ci case 0: 61f08c3bdfSopenharmony_ci send_events(); 62f08c3bdfSopenharmony_ci exit(0); 63f08c3bdfSopenharmony_ci case -1: 64f08c3bdfSopenharmony_ci tst_brkm(TBROK | TERRNO, cleanup, "fork() failed"); 65f08c3bdfSopenharmony_ci default: 66f08c3bdfSopenharmony_ci if (no_events_queued(fd2, 1)) 67f08c3bdfSopenharmony_ci tst_resm(TPASS, "No data received in eventX"); 68f08c3bdfSopenharmony_ci else 69f08c3bdfSopenharmony_ci tst_resm(TFAIL, "Data received in eventX"); 70f08c3bdfSopenharmony_ci break; 71f08c3bdfSopenharmony_ci } 72f08c3bdfSopenharmony_ci 73f08c3bdfSopenharmony_ci SAFE_WAITPID(NULL, pid, NULL, 0); 74f08c3bdfSopenharmony_ci } 75f08c3bdfSopenharmony_ci 76f08c3bdfSopenharmony_ci cleanup(); 77f08c3bdfSopenharmony_ci tst_exit(); 78f08c3bdfSopenharmony_ci} 79f08c3bdfSopenharmony_ci 80f08c3bdfSopenharmony_cistatic void setup(void) 81f08c3bdfSopenharmony_ci{ 82f08c3bdfSopenharmony_ci tst_require_root(); 83f08c3bdfSopenharmony_ci 84f08c3bdfSopenharmony_ci fd = open_uinput(); 85f08c3bdfSopenharmony_ci 86f08c3bdfSopenharmony_ci SAFE_IOCTL(NULL, fd, UI_SET_EVBIT, EV_KEY); 87f08c3bdfSopenharmony_ci SAFE_IOCTL(NULL, fd, UI_SET_KEYBIT, BTN_LEFT); 88f08c3bdfSopenharmony_ci 89f08c3bdfSopenharmony_ci create_device(fd); 90f08c3bdfSopenharmony_ci 91f08c3bdfSopenharmony_ci fd2 = open_device(); 92f08c3bdfSopenharmony_ci} 93f08c3bdfSopenharmony_ci 94f08c3bdfSopenharmony_cistatic void send_events(void) 95f08c3bdfSopenharmony_ci{ 96f08c3bdfSopenharmony_ci int nb; 97f08c3bdfSopenharmony_ci 98f08c3bdfSopenharmony_ci for (nb = 0; nb < NB_TEST; ++nb) { 99f08c3bdfSopenharmony_ci send_rel_move(fd, X_VALUE, Y_VALUE); 100f08c3bdfSopenharmony_ci usleep(1000); 101f08c3bdfSopenharmony_ci } 102f08c3bdfSopenharmony_ci} 103f08c3bdfSopenharmony_ci 104f08c3bdfSopenharmony_cistatic void cleanup(void) 105f08c3bdfSopenharmony_ci{ 106f08c3bdfSopenharmony_ci destroy_device(fd); 107f08c3bdfSopenharmony_ci} 108