[LTP] [PATCH v2 06/10] Add wqueue05 test

Andrea Cervesato andrea.cervesato@suse.com
Fri Jan 7 11:59:09 CET 2022


This test is testing NOTIFY_KEY_INVALIDATED event

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 runtest/watchqueue                     |  1 +
 testcases/kernel/watchqueue/.gitignore |  3 +-
 testcases/kernel/watchqueue/wqueue05.c | 41 ++++++++++++++++++++++++++
 3 files changed, 44 insertions(+), 1 deletion(-)
 create mode 100644 testcases/kernel/watchqueue/wqueue05.c

diff --git a/runtest/watchqueue b/runtest/watchqueue
index cd897f4b4..596d45154 100644
--- a/runtest/watchqueue
+++ b/runtest/watchqueue
@@ -2,3 +2,4 @@ wqueue01 wqueue01
 wqueue02 wqueue02
 wqueue03 wqueue03
 wqueue04 wqueue04
+wqueue05 wqueue05
diff --git a/testcases/kernel/watchqueue/.gitignore b/testcases/kernel/watchqueue/.gitignore
index 469efd595..d3e563a04 100644
--- a/testcases/kernel/watchqueue/.gitignore
+++ b/testcases/kernel/watchqueue/.gitignore
@@ -1,4 +1,5 @@
 wqueue01
 wqueue02
 wqueue03
-wqueue04
\ No newline at end of file
+wqueue04
+wqueue05
\ No newline at end of file
diff --git a/testcases/kernel/watchqueue/wqueue05.c b/testcases/kernel/watchqueue/wqueue05.c
new file mode 100644
index 000000000..561778891
--- /dev/null
+++ b/testcases/kernel/watchqueue/wqueue05.c
@@ -0,0 +1,41 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Test if keyctl invalidate is correctly recognized by watch queue.
+ */
+
+#include "tst_test.h"
+#include "lapi/keyctl.h"
+#include "common.h"
+
+static void saw_key_invalidated(struct watch_notification *n, size_t len, unsigned int wtype)
+{
+	if (wqueue_key_event(n, len, wtype, NOTIFY_KEY_INVALIDATED))
+		tst_res(TPASS, "keyctl invalidate has been recognized");
+	else
+		tst_res(TFAIL, "keyctl invalidate has not been recognized");
+}
+
+static void run(void)
+{
+	int fd;
+	key_serial_t key;
+
+	fd = wqueue_watch(256, &wqueue_filter);
+	key = wqueue_add_key(fd);
+
+	keyctl(KEYCTL_INVALIDATE, key);
+	wqueue_consumer(fd, saw_key_invalidated);
+
+	SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.needs_root = 1,
+};
-- 
2.34.1



More information about the ltp mailing list