uevent03: Use a generic way to get sysname
PATCH 1/1 uevent03: Use a generic way to get sysname
UI_GET_NAME was introduced since 3.15, this ioctl is used to get sysname. For better compatibility, we can use a generic way to get sysname by parsing /proc/bus/input/devices. So this case can also run on old kernel.
Also remove useless lapi/uinput.h.
--- include/lapi/uinput.h | 16 --------- include/tst_uinput.h | 8 +++++ libs/libltpuinput/tst_uinput.c | 40 ++++++++++++++++++++++ testcases/kernel/uevents/uevent03.c | 52 +++++++++++------------------ 4 files changed, 67 insertions(+), 49 deletions(-) delete mode 100644 include/lapi/uinput.h
include/lapi/uinput.h deleted +0 -16
@@ -1,16 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* -* Copyright (c) 2019 FUJITSU LIMITED. All rights reserved. -* Authors: Jinhui huang <[email protected]> -*/ - -#ifndef __LAPI_UINPUT_H_ -#define __LAPI_UINPUT_H_ - -#include <linux/uinput.h> - -#ifndef UI_GET_SYSNAME -#define UI_GET_SYSNAME (len) _IOC(_IOC_READ, UINPUT_IOCTL_BASE, 44, len) -#endif - -#endif /* __LAPI_UINPUT_H_ */
include/tst_uinput.h +8 -0
@@ -20,6 +20,14 @@ int open_uinput(void);*/ void create_input_device (int fd); +/** +* Parses /proc/bus/input/devices and returns the sysfs strings for our +* virtual device, which is the path of input devices. +* +* Returns newly allocated string, or NULL in a case of failure. +*/ +char *get_input_sysfs (void ); +/** * Parses /proc/bus/input/devices and returns the handlers strings for our * virtual device, which is list of input devices that receive events from the
libs/libltpuinput/tst_uinput.c +40 -0
@@ -42,8 +42,21 @@ int open_uinput(void)return -1 ; } + +#define SYSFS_PREFIX "Sysfs="#define HANDLERS_PREFIX "Handlers=" +static char *parse_sysfs (char *line) +{ +char *sysfs; + + sysfs =strstr (line,SYSFS_PREFIX ) +sizeof (SYSFS_PREFIX ) -1 ; + + sysfs[strlen (sysfs) -1 ] =0 ; + +return strdup (sysfs); +} +static char *parse_handlers (char *line) {char *handlers;
@@ -55,6 +68,33 @@ static char *parse_handlers(char *line)return strdup (handlers); } +char *get_input_sysfs (void ) +{ +FILE *file; +char line[1024 ]; +int flag =0 ; + + file =fopen ("/proc/bus/input/devices" ,"r" ); +if (!file) +return NULL ; + +while (fgets (line,sizeof (line), file)) { +if (strstr (line,"N: Name=\"" VIRTUAL_DEVICE "\"" )) + flag =1 ; + +if (flag) { +if (line[0 ] =='S' ) +return parse_sysfs (line); + +if (line[0 ] =='\n' ) + flag =0 ; + } + } + +fclose (file); +return NULL ; +} +char *get_input_handlers (void ) {FILE *file;
testcases/kernel/uevents/uevent03.c +19 -33
107 lines not on this page · raw message
Signature · 1 line
2.18.1
PATCH v2 1/1 uevent03: Use a generic way to get sysname
UI_GET_NAME was introduced since 3.15, this ioctl is used to get sysname. For better compatibility, we can use a generic way to get sysname by parsing /proc/bus/input/devices. So this case can also run on old kernel.
Also remove useless lapi/uinput.h.
-------------V1->V2:
make code non-redundant
-------------
--- include/lapi/uinput.h | 16 --------- include/tst_uinput.h | 11 +++--- libs/libltpuinput/tst_uinput.c | 29 +++++++++++----- testcases/kernel/uevents/uevent03.c | 52 +++++++++++------------------ 4 files changed, 44 insertions(+), 64 deletions(-) delete mode 100644 include/lapi/uinput.h
include/lapi/uinput.h deleted +0 -16
@@ -1,16 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* -* Copyright (c) 2019 FUJITSU LIMITED. All rights reserved. -* Authors: Jinhui huang <[email protected]> -*/ - -#ifndef __LAPI_UINPUT_H_ -#define __LAPI_UINPUT_H_ - -#include <linux/uinput.h> - -#ifndef UI_GET_SYSNAME -#define UI_GET_SYSNAME (len) _IOC(_IOC_READ, UINPUT_IOCTL_BASE, 44, len) -#endif - -#endif /* __LAPI_UINPUT_H_ */
include/tst_uinput.h +5 -6
@@ -21,14 +21,13 @@ int open_uinput(void);void create_input_device (int fd);/** -* Parses /proc/bus/input/devices and returns the handlers strings for our -* virtual device, which is list of input devices that receive events from the -* device separated by whitestpaces. +* Parses /proc/bus/input/devices and returns the strings for our virtual device. +* If passing 'H' to it, it returns HANDLERS string. If passing 'S' to it, it +* returns SYSFS string. * -* Returns newly allocated string, list of handlers separated by whitespaces, -* or NULL in a case of failure. +* Returns newly allocated string, or NULL in a case of failure. */ -char *get_input_handlers (void ); +char *get_input_field_value (char field);/** * Sets up the virtual device to appear as a mouse, this must be called before
libs/libltpuinput/tst_uinput.c +20 -9
@@ -42,20 +42,31 @@ int open_uinput(void)return -1 ; } + +#define SYSFS_PREFIX "Sysfs="#define HANDLERS_PREFIX "Handlers=" -static char *parse_handlers (char *line) +static char *parse_field (char *line,char field) { -char *handlers; - - handlers =strstr (line,HANDLERS_PREFIX ) +sizeof (HANDLERS_PREFIX ) -1 ; +char *value; + +switch (field) { +case 'H' : + value =strstr (line,HANDLERS_PREFIX ) +sizeof (HANDLERS_PREFIX ) -1 ; +break ; +case 'S' : + value =strstr (line,SYSFS_PREFIX ) +sizeof (SYSFS_PREFIX ) -1 ; +break ; +default : +return NULL ; + } - handlers[strlen (handlers) -1 ] =0 ; + value[strlen (value) -1 ] =0 ; -return strdup (handlers); +return strdup (value); } -char *get_input_handlers (void ) +char *get_input_field_value (char field) {FILE *file;char line[1024 ];
@@ -70,8 +81,8 @@ char *get_input_handlers(void) flag =1 ;if (flag) { -if (line[0 ] =='H' ) -return parse_handlers (line); +if (line[0 ] == field) +return parse_field (line, field);if (line[0 ] =='\n' ) flag =0 ;
testcases/kernel/uevents/uevent03.c +19 -33
106 lines not on this page · raw message
Signature · 1 line
2.18.1
PATCH v2 1/1 uevent03: Use a generic way to get sysname
Hi!
Nicely done, pushed, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]