[LTP] [PATCH] Verify virtual device availability

Andrea Cervesato
2024-12-10T14:13:52Z

From: Andrea Cervesato <andrea.cervesato@suse.com>

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.

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
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(+)

diff --git a/testcases/kernel/input/input01.c b/testcases/kernel/input/input01.c
index 0872204111b81fd19a1525ef7f099e8ddead9658..5e85133028e25ea4a4596475f9aa876cb913694d 100644
--- a/testcases/kernel/input/input01.c
+++ b/testcases/kernel/input/input01.c
@@ -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);

diff --git a/testcases/kernel/input/input02.c b/testcases/kernel/input/input02.c
index eeff54ed21cbff6eac2d90dc53c6447d379e29ed..8e48f12d9a1108c9a5b1d8452e07386d5534fbfb 100644
--- a/testcases/kernel/input/input02.c
+++ b/testcases/kernel/input/input02.c
@@ -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);

diff --git a/testcases/kernel/input/input03.c b/testcases/kernel/input/input03.c
index 4a3eb464ee0322b134f44158a08dbb4ed000216f..2e6161beefccc1133b654be8cf2529e97610960f 100644
--- a/testcases/kernel/input/input03.c
+++ b/testcases/kernel/input/input03.c
@@ -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);
diff --git a/testcases/kernel/input/input04.c b/testcases/kernel/input/input04.c
index 3c76d7c82ad7fe76f35f5a4ecfc78f27069d3fa0..fb13500fe6ab5eba7fed4640ed51dfbc8105cd09 100644
--- a/testcases/kernel/input/input04.c
+++ b/testcases/kernel/input/input04.c
@@ -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);

diff --git a/testcases/kernel/input/input05.c b/testcases/kernel/input/input05.c
index 4e5072a038ea8e4f7b8e0899d88a58bdf18e9e94..fa37ac7acb22b690b7bb35d9fe655d3e49532a61 100644
--- a/testcases/kernel/input/input05.c
+++ b/testcases/kernel/input/input05.c
@@ -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);
diff --git a/testcases/kernel/input/input06.c b/testcases/kernel/input/input06.c
index cb871cbaec0fc8e35182dc0256dc2672dae4a419..d3584a2b0b9f540b29def3d98b7c77db09faefe9 100644
--- a/testcases/kernel/input/input06.c
+++ b/testcases/kernel/input/input06.c
@@ -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);
diff --git a/testcases/kernel/uevents/uevent03.c b/testcases/kernel/uevents/uevent03.c
index 5b3dd701f0cf8f2f12a910b57d5f49d58712fe52..f7072db1c5f076e811e473438db3aa895644eaec 100644
--- a/testcases/kernel/uevents/uevent03.c
+++ b/testcases/kernel/uevents/uevent03.c
@@ -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,
--
Andrea Cervesato <andrea.cervesato@suse.com>