Skip to contentSkip to conversation

Verify virtual device availability

PATCH In review Andrea Cervesato 3 participants 5 messages Dec 10, 2024 – Dec 11, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Verify virtual device availability

From: Andrea Cervesato <[email protected]>

Virtual device is supposed to be found in /dev/uinput or /dev/input/uinput, but in some cases this is not true. For instance, a kernel which is not exposing any virtual device. This patch is meant to verify that the device is available and we eventually skip test if it's not found.

---
Just skip tests which cannot find any virtual device in the current system.

---
 testcases/kernel/input/input01.c    | 3 +++
 testcases/kernel/input/input02.c    | 3 +++
 testcases/kernel/input/input03.c    | 2 ++
 testcases/kernel/input/input04.c    | 3 +++
 testcases/kernel/input/input05.c    | 3 +++
 testcases/kernel/input/input06.c    | 2 ++
 testcases/kernel/uevents/uevent03.c | 3 +++
 7 files changed, 19 insertions(+)
testcases/kernel/input/input01.c +3 -0
index 0872204111b81fd19a1525ef7f099e8ddead9658..5e85133028e25ea4a4596475f9aa876cb913694d 100644
@@ -53,6 +53,9 @@ static void run(void)
 static void setup(void)
 {
 	fd_send = open_uinput();
+	if (fd_send == -1)
+		tst_brk(TCONF, "Virtual device is not available");
+
 	setup_mouse_events(fd_send);
 	create_input_device(fd_send);
 
testcases/kernel/input/input02.c +3 -0
index eeff54ed21cbff6eac2d90dc53c6447d379e29ed..8e48f12d9a1108c9a5b1d8452e07386d5534fbfb 100644
@@ -53,6 +53,9 @@ static void run(void)
 static void setup(void)
 {
 	fd_send = open_uinput();
+	if (fd_send == -1)
+		tst_brk(TCONF, "Virtual device is not available");
+
 	setup_mouse_events(fd_send);
 	create_input_device(fd_send);
 
testcases/kernel/input/input03.c +2 -0
index 4a3eb464ee0322b134f44158a08dbb4ed000216f..2e6161beefccc1133b654be8cf2529e97610960f 100644
@@ -82,6 +82,8 @@ static void run(void)
 static void setup(void)
 {
 	fd_send = open_uinput();
+	if (fd_send == -1)
+		tst_brk(TCONF, "Virtual device is not available");
 
 	setup_mouse_events(fd_send);
 	SAFE_IOCTL(fd_send, UI_SET_EVBIT, EV_KEY);
testcases/kernel/input/input04.c +3 -0
index 3c76d7c82ad7fe76f35f5a4ecfc78f27069d3fa0..fb13500fe6ab5eba7fed4640ed51dfbc8105cd09 100644
@@ -33,6 +33,9 @@ static void run(void)
 static void setup(void)
 {
 	fd_send = open_uinput();
+	if (fd_send == -1)
+		tst_brk(TCONF, "Virtual device is not available");
+
 	setup_mouse_events(fd_send);
 	create_input_device(fd_send);
 
testcases/kernel/input/input05.c +3 -0
index 4e5072a038ea8e4f7b8e0899d88a58bdf18e9e94..fa37ac7acb22b690b7bb35d9fe655d3e49532a61 100644
@@ -38,6 +38,9 @@ static void run(void)
 static void setup(void)
 {
 	fd_send = open_uinput();
+	if (fd_send == -1)
+		tst_brk(TCONF, "Virtual device is not available");
+
 	SAFE_IOCTL(fd_send, UI_SET_EVBIT, EV_KEY);
 	SAFE_IOCTL(fd_send, UI_SET_KEYBIT, BTN_LEFT);
 	create_input_device(fd_send);
testcases/kernel/input/input06.c +2 -0
index cb871cbaec0fc8e35182dc0256dc2672dae4a419..d3584a2b0b9f540b29def3d98b7c77db09faefe9 100644
@@ -178,6 +178,8 @@ static void run(void)
 static void setup(void)
 {
 	fd_send = open_uinput();
+	if (fd_send == -1)
+		tst_brk(TCONF, "Virtual device is not available");
 
 	SAFE_IOCTL(fd_send, UI_SET_EVBIT, EV_KEY);
 	SAFE_IOCTL(fd_send, UI_SET_EVBIT, EV_REP);
testcases/kernel/uevents/uevent03.c +3 -0
index 5b3dd701f0cf8f2f12a910b57d5f49d58712fe52..f7072db1c5f076e811e473438db3aa895644eaec 100644
@@ -27,6 +27,9 @@ static int mouse_fd;
 static void create_uinput_mouse(void)
 {
 	mouse_fd = open_uinput();
+	if (mouse_fd == -1)
+		tst_brk(TCONF, "Virtual device is not available");
+
 	setup_mouse_events(mouse_fd);
 	create_input_device(mouse_fd);
 }

---
base-commit: b5e2ea3cc02a2466c5bee3b0e650869f4ddf438c
change-id: 20241210-fix_input_suite-5c9c2546aaa2

Best regards,

Signature · 5 lines
Andrea Cervesato <[email protected]>


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw
In reply to Andrea Cervesato

Hi Andrea,

...

testcases/kernel/input/input01.c static void run(void) · line 57

Quoted 5 lines

static void setup(void)
{

testcases/kernel/input/input01.c +2 -0
 	fd_send = open_uinput();
+	if (fd_send == -1)
+		tst_brk(TCONF, "Virtual device is not available");

Thinking about it twice, how about renaming the function safe_open_uinput() and add tst_brk(TCONF, ...) there?

Function is not used in library where tst_brk(TCONF, ...) would be problematic, therefore I would not even bother with having SAFE_OPEN_UINPUT() which would evaluate open_uinput().

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw

Hi Petr,

Quoted 11 lines · Petr Vorel

Hi Andrea,

...

Review

Quoted 5 lines
  static void setup(void)
  {
  	fd_send = open_uinput();
(quoted diff) +2 -0
+	if (fd_send == -1)
+		tst_brk(TCONF, "Virtual device is not available");

Thinking about it twice, how about renaming the function safe_open_uinput() and add tst_brk(TCONF, ...) there?

Quoted 3 lines

Function is not used in library where tst_brk(TCONF, ...) would be problematic, therefore I would not even bother with having SAFE_OPEN_UINPUT() which would evaluate open_uinput().

Usually SAFE_* macros just TBROK the tests, so I'm not sure about this approach. Alternatives?

Quoted 2 lines

Kind regards,
Petr

Andrea

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp