Skip to contentSkip to conversation

kernel/uevents: Fix compiler errors

PATCH New Jinhui huang 3 participants 6 messages Sep 3, 2019 – Sep 5, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 kernel/uevents: Fix compiler errors

1)Add uevents into "kernel/Makefile".
2)Define "sys/socket.h" in uevent02.c for struct sockaddr, fix incomplete
types on old relesase.
3)Add "lapi/uinput.h" and define "UI_GET_SYSNAME", then define the header
file in uevent03.c, fix implicit declaration on old relesase.

---
 include/lapi/uinput.h               | 16 ++++++++++++++++
 testcases/kernel/Makefile           |  1 +
 testcases/kernel/uevents/uevent02.c |  1 +
 testcases/kernel/uevents/uevent03.c |  3 +--
 4 files changed, 19 insertions(+), 2 deletions(-)
 create mode 100644 include/lapi/uinput.h
include/lapi/uinput.h new file +16 -0
new file mode 100644
index 0000000..87e3384
@@ -0,0 +1,16 @@
+// 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_ */
testcases/kernel/Makefile +1 -0
index 03ea253..3319b31 100644
@@ -54,6 +54,7 @@ SUBDIRS			+= connectors \
 			   security \
 			   sound \
 			   tracing \
+			   uevents \
 
 ifeq ($(WITH_POWER_MANAGEMENT_TESTSUITE),yes)
 SUBDIRS			+= power_management
testcases/kernel/uevents/uevent02.c +1 -0
index b94748c..9dd4cd6 100644
@@ -14,6 +14,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/wait.h>
+#include <sys/socket.h>
 #include <linux/if.h>
 #include <linux/if_tun.h>
 
testcases/kernel/uevents/uevent03.c +1 -2
index 991737e..9b901dc 100644
@@ -16,11 +16,10 @@
 #include <sys/wait.h>
 #include <sys/sysmacros.h>
 
-#include <linux/uinput.h>
-
 #include "tst_test.h"
 #include "tst_uinput.h"
 #include "uevent.h"
+#include "lapi/uinput.h"
 
 static int mouse_fd;
 
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 2/2 uevents/uevent03.c: Check if "UI_GET_SYSNAME" is supported

---
 testcases/kernel/uevents/uevent03.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
testcases/kernel/uevents/uevent03.c +13 -2
index 9b901dc..f676984 100644
@@ -52,7 +52,7 @@ static void get_minor_major(char *device, char *minor, char *major, size_t buf_s
 
 static void verify_uevent(void)
 {
-	int pid, fd;
+	int pid, fd, ret;
 	char sysname[64];
 	char add_msg[1024];
 	char rem_msg[1024];
@@ -167,7 +167,18 @@ static void verify_uevent(void)
 
 	create_uinput_mouse();
 
-	SAFE_IOCTL(mouse_fd, UI_GET_SYSNAME(sizeof(sysname)), sysname);
+	ret = ioctl(mouse_fd, UI_GET_SYSNAME(sizeof(sysname)), sysname);
+	if (ret < 0) {
+		if (errno == EINVAL) {
+			tst_brk(TCONF,
+				"kernel does not support UI_GET_SYSNAME");
+		} else {
+			tst_brk(TBROK,
+				"ioctl(%d, %s,...) failed",
+				mouse_fd, "UI_GET_SYSNAME");
+		}
+	}
+
 	handlers = get_input_handlers();
 
 	tst_res(TINFO, "Sysname: %s", sysname);
Signature · 1 line
1.8.3.1
#2 lore raw

PATCH 2/2 uevents/uevent03.c: Check if "UI_GET_SYSNAME" is supported

Hi!

Quoted 24 lines
---
 testcases/kernel/uevents/uevent03.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
testcases/kernel/uevents/uevent03.c +2 -2
index 9b901dc..f676984 100644
@@ -52,7 +52,7 @@ static void get_minor_major(char *device, char *minor, char *major, size_t buf_s
 
 static void verify_uevent(void)
 {
-	int pid, fd;
+	int pid, fd, ret;
 	char sysname[64];
 	char add_msg[1024];
 	char rem_msg[1024];
@@ -167,7 +167,18 @@ static void verify_uevent(void)
 
 	create_uinput_mouse();
 
-	SAFE_IOCTL(mouse_fd, UI_GET_SYSNAME(sizeof(sysname)), sysname);
+	ret = ioctl(mouse_fd, UI_GET_SYSNAME(sizeof(sysname)), sysname);

testcases/kernel/uevents/uevent03.c static void verify_uevent(void) · line 180

Quoted 10 lines
testcases/kernel/uevents/uevent03.c +10 -0
+	if (ret < 0) {
+		if (errno == EINVAL) {
+			tst_brk(TCONF,
+				"kernel does not support UI_GET_SYSNAME");
+		} else {
+			tst_brk(TBROK,
+				"ioctl(%d, %s,...) failed",
+				mouse_fd, "UI_GET_SYSNAME");
+		}
+	}

I do wonder if it makes sense to add a fallback that reads the sysname from /proc/bus/input/devices.

We do have the sysname as the last component of the SysFs= path.

I guess that it's probably not worth of the effort.

Quoted 11 lines
testcases/kernel/uevents/uevent03.c +0 -0
 	handlers = get_input_handlers();
 
 	tst_res(TINFO, "Sysname: %s", sysname);
Signature · 7 lines
1.8.3.1




-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis
[email protected]
#4 lore raw

PATCH 2/2 uevents/uevent03.c: Check if "UI_GET_SYSNAME" is supported

Quoted 5 lines · Cyril Hrubis

Hi!
I've pushed this patch, thanks.

Anyone can fix the test on older kernel later on, if there is a need.

Hi Cyril

I have sent a patch to use a generic way to get sysname for old kernel.

Thanks
Yang Xu