public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH v5 00/11] watchqueue testing suite
@ 2022-01-27  9:24 Andrea Cervesato
  2022-01-27  9:24 ` [LTP] [PATCH v5 01/11] Add KEYCTL_WATCH_KEY to lapi keyctl.h fallback Andrea Cervesato
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: Andrea Cervesato @ 2022-01-27  9:24 UTC (permalink / raw)
  To: ltp

This patch-set add a new testing suite for the watch queue kernel feature
described in https://www.kernel.org/doc/html/latest/watch_queue.html

Andrea Cervesato (11):
  Add KEYCTL_WATCH_KEY to lapi keyctl.h fallback
  Add lapi/watch_queue.h header fallback
  Add wqueue01 test
  Add wqueue02 test
  Add wqueue03 test
  Add wqueue04 test
  Add wqueue05 test
  Add wqueue06 test
  Add wqueue07 test
  Add wqueue08 test
  Add wqueue09 test

 include/lapi/keyctl.h                  |   4 +
 include/lapi/watch_queue.h             | 112 +++++++++++++++++
 runtest/watchqueue                     |   9 ++
 scenario_groups/default                |   1 +
 testcases/kernel/Makefile              |   1 +
 testcases/kernel/watchqueue/.gitignore |   9 ++
 testcases/kernel/watchqueue/Makefile   |   8 ++
 testcases/kernel/watchqueue/common.h   | 167 +++++++++++++++++++++++++
 testcases/kernel/watchqueue/wqueue01.c |  43 +++++++
 testcases/kernel/watchqueue/wqueue02.c |  43 +++++++
 testcases/kernel/watchqueue/wqueue03.c |  43 +++++++
 testcases/kernel/watchqueue/wqueue04.c |  43 +++++++
 testcases/kernel/watchqueue/wqueue05.c |  43 +++++++
 testcases/kernel/watchqueue/wqueue06.c |  42 +++++++
 testcases/kernel/watchqueue/wqueue07.c |  43 +++++++
 testcases/kernel/watchqueue/wqueue08.c |  48 +++++++
 testcases/kernel/watchqueue/wqueue09.c |  55 ++++++++
 17 files changed, 714 insertions(+)
 create mode 100644 include/lapi/watch_queue.h
 create mode 100644 runtest/watchqueue
 create mode 100644 testcases/kernel/watchqueue/.gitignore
 create mode 100644 testcases/kernel/watchqueue/Makefile
 create mode 100644 testcases/kernel/watchqueue/common.h
 create mode 100644 testcases/kernel/watchqueue/wqueue01.c
 create mode 100644 testcases/kernel/watchqueue/wqueue02.c
 create mode 100644 testcases/kernel/watchqueue/wqueue03.c
 create mode 100644 testcases/kernel/watchqueue/wqueue04.c
 create mode 100644 testcases/kernel/watchqueue/wqueue05.c
 create mode 100644 testcases/kernel/watchqueue/wqueue06.c
 create mode 100644 testcases/kernel/watchqueue/wqueue07.c
 create mode 100644 testcases/kernel/watchqueue/wqueue08.c
 create mode 100644 testcases/kernel/watchqueue/wqueue09.c

-- 
2.34.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [LTP] [PATCH v5 01/11] Add KEYCTL_WATCH_KEY to lapi keyctl.h fallback
  2022-01-27  9:24 [LTP] [PATCH v5 00/11] watchqueue testing suite Andrea Cervesato
@ 2022-01-27  9:24 ` Andrea Cervesato
  2022-01-27  9:24 ` [LTP] [PATCH v5 02/11] Add lapi/watch_queue.h header fallback Andrea Cervesato
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Andrea Cervesato @ 2022-01-27  9:24 UTC (permalink / raw)
  To: ltp

Added KEYCTL_WATCH_KEY keyctl syscall command that is required by
watch queue tests.

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.de>
---
 include/lapi/keyctl.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/include/lapi/keyctl.h b/include/lapi/keyctl.h
index d899345c9..3be782494 100644
--- a/include/lapi/keyctl.h
+++ b/include/lapi/keyctl.h
@@ -140,6 +140,10 @@ static inline key_serial_t keyctl_join_session_keyring(const char *name) {
 # define KEYCTL_INVALIDATE 21
 #endif
 
+#ifndef KEYCTL_WATCH_KEY
+# define KEYCTL_WATCH_KEY 32
+#endif
+
 /* key permissions */
 #ifndef KEY_POS_VIEW
 # define KEY_POS_VIEW    0x01000000
-- 
2.34.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [LTP] [PATCH v5 02/11] Add lapi/watch_queue.h header fallback
  2022-01-27  9:24 [LTP] [PATCH v5 00/11] watchqueue testing suite Andrea Cervesato
  2022-01-27  9:24 ` [LTP] [PATCH v5 01/11] Add KEYCTL_WATCH_KEY to lapi keyctl.h fallback Andrea Cervesato
@ 2022-01-27  9:24 ` Andrea Cervesato
  2022-01-27  9:24 ` [LTP] [PATCH v5 03/11] Add wqueue01 test Andrea Cervesato
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Andrea Cervesato @ 2022-01-27  9:24 UTC (permalink / raw)
  To: ltp

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.de>
---
 include/lapi/watch_queue.h | 112 +++++++++++++++++++++++++++++++++++++
 1 file changed, 112 insertions(+)
 create mode 100644 include/lapi/watch_queue.h

diff --git a/include/lapi/watch_queue.h b/include/lapi/watch_queue.h
new file mode 100644
index 000000000..438e62239
--- /dev/null
+++ b/include/lapi/watch_queue.h
@@ -0,0 +1,112 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ *
+ * This file is created to resolve conflicts between user space and kernel
+ * space fctnl.h declaration. linux/watch_queue.h is not handled, since
+ * user space fcntl.h redefines kernel space structures.
+ */
+
+#ifndef LAPI_WATCH_QUEUE_H__
+#define LAPI_WATCH_QUEUE_H__
+
+#include <stdint.h>
+#include "lapi/ioctl.h"
+#include "lapi/fcntl.h"
+
+#define O_NOTIFICATION_PIPE	O_EXCL	/* Parameter to pipe2() selecting notification pipe */
+
+#define IOC_WATCH_QUEUE_SET_SIZE	_IO('W', 0x60)	/* Set the size in pages */
+#define IOC_WATCH_QUEUE_SET_FILTER	_IO('W', 0x61)	/* Set the filter */
+
+enum watch_notification_type {
+	WATCH_TYPE_META		= 0,	/* Special record */
+	WATCH_TYPE_KEY_NOTIFY	= 1,	/* Key change event notification */
+	WATCH_TYPE__NR		= 2
+};
+
+enum watch_meta_notification_subtype {
+	WATCH_META_REMOVAL_NOTIFICATION	= 0,	/* Watched object was removed */
+	WATCH_META_LOSS_NOTIFICATION	= 1,	/* Data loss occurred */
+};
+
+/*
+ * Notification record header.  This is aligned to 64-bits so that subclasses
+ * can contain __u64 fields.
+ */
+struct watch_notification {
+	uint32_t			type:24;	/* enum watch_notification_type */
+	uint32_t			subtype:8;	/* Type-specific subtype (filterable) */
+	uint32_t			info;
+#define WATCH_INFO_LENGTH	0x0000007f	/* Length of record */
+#define WATCH_INFO_LENGTH__SHIFT 0
+#define WATCH_INFO_ID		0x0000ff00	/* ID of watchpoint */
+#define WATCH_INFO_ID__SHIFT	8
+#define WATCH_INFO_TYPE_INFO	0xffff0000	/* Type-specific info */
+#define WATCH_INFO_TYPE_INFO__SHIFT 16
+#define WATCH_INFO_FLAG_0	0x00010000	/* Type-specific info, flag bit 0 */
+#define WATCH_INFO_FLAG_1	0x00020000	/* ... */
+#define WATCH_INFO_FLAG_2	0x00040000
+#define WATCH_INFO_FLAG_3	0x00080000
+#define WATCH_INFO_FLAG_4	0x00100000
+#define WATCH_INFO_FLAG_5	0x00200000
+#define WATCH_INFO_FLAG_6	0x00400000
+#define WATCH_INFO_FLAG_7	0x00800000
+};
+
+/*
+ * Notification filtering rules (IOC_WATCH_QUEUE_SET_FILTER).
+ */
+struct watch_notification_type_filter {
+	uint32_t	type;			/* Type to apply filter to */
+	uint32_t	info_filter;		/* Filter on watch_notification::info */
+	uint32_t	info_mask;		/* Mask of relevant bits in info_filter */
+	uint32_t	subtype_filter[8];	/* Bitmask of subtypes to filter on */
+};
+
+struct watch_notification_filter {
+	uint32_t	nr_filters;		/* Number of filters */
+	uint32_t	__reserved;		/* Must be 0 */
+	struct watch_notification_type_filter filters[];
+};
+
+
+/*
+ * Extended watch removal notification.  This is used optionally if the type
+ * wants to indicate an identifier for the object being watched, if there is
+ * such.  This can be distinguished by the length.
+ *
+ * type -> WATCH_TYPE_META
+ * subtype -> WATCH_META_REMOVAL_NOTIFICATION
+ */
+struct watch_notification_removal {
+	struct watch_notification watch;
+	uint64_t	id;		/* Type-dependent identifier */
+};
+
+/*
+ * Type of key/keyring change notification.
+ */
+enum key_notification_subtype {
+	NOTIFY_KEY_INSTANTIATED	= 0, /* Key was instantiated (aux is error code) */
+	NOTIFY_KEY_UPDATED	= 1, /* Key was updated */
+	NOTIFY_KEY_LINKED	= 2, /* Key (aux) was added to watched keyring */
+	NOTIFY_KEY_UNLINKED	= 3, /* Key (aux) was removed from watched keyring */
+	NOTIFY_KEY_CLEARED	= 4, /* Keyring was cleared */
+	NOTIFY_KEY_REVOKED	= 5, /* Key was revoked */
+	NOTIFY_KEY_INVALIDATED	= 6, /* Key was invalidated */
+	NOTIFY_KEY_SETATTR	= 7, /* Key's attributes got changed */
+};
+
+/*
+ * Key/keyring notification record.
+ * - watch.type = WATCH_TYPE_KEY_NOTIFY
+ * - watch.subtype = enum key_notification_type
+ */
+struct key_notification {
+	struct watch_notification watch;
+	uint32_t	key_id;		/* The key/keyring affected */
+	uint32_t	aux;		/* Per-type auxiliary data */
+};
+
+#endif /* LAPI_WATCH_QUEUE_H__ */
-- 
2.34.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [LTP] [PATCH v5 03/11] Add wqueue01 test
  2022-01-27  9:24 [LTP] [PATCH v5 00/11] watchqueue testing suite Andrea Cervesato
  2022-01-27  9:24 ` [LTP] [PATCH v5 01/11] Add KEYCTL_WATCH_KEY to lapi keyctl.h fallback Andrea Cervesato
  2022-01-27  9:24 ` [LTP] [PATCH v5 02/11] Add lapi/watch_queue.h header fallback Andrea Cervesato
@ 2022-01-27  9:24 ` Andrea Cervesato
  2022-01-27  9:24 ` [LTP] [PATCH v5 04/11] Add wqueue02 test Andrea Cervesato
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Andrea Cervesato @ 2022-01-27  9:24 UTC (permalink / raw)
  To: ltp

This test is testing NOTIFY_KEY_UPDATED event

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.de>
---

In v5 wqueue_watch function is now handling pipe2 when CONFIG_WATCH_QUEUE is
not defined. Also added a better format for common.h and tests files.

 runtest/watchqueue                     |   1 +
 scenario_groups/default                |   1 +
 testcases/kernel/Makefile              |   1 +
 testcases/kernel/watchqueue/.gitignore |   1 +
 testcases/kernel/watchqueue/Makefile   |   8 ++
 testcases/kernel/watchqueue/common.h   | 167 +++++++++++++++++++++++++
 testcases/kernel/watchqueue/wqueue01.c |  43 +++++++
 7 files changed, 222 insertions(+)
 create mode 100644 runtest/watchqueue
 create mode 100644 testcases/kernel/watchqueue/.gitignore
 create mode 100644 testcases/kernel/watchqueue/Makefile
 create mode 100644 testcases/kernel/watchqueue/common.h
 create mode 100644 testcases/kernel/watchqueue/wqueue01.c

diff --git a/runtest/watchqueue b/runtest/watchqueue
new file mode 100644
index 000000000..782577d6d
--- /dev/null
+++ b/runtest/watchqueue
@@ -0,0 +1 @@
+wqueue01 wqueue01
diff --git a/scenario_groups/default b/scenario_groups/default
index 1dc2987d5..68bd5300d 100644
--- a/scenario_groups/default
+++ b/scenario_groups/default
@@ -30,3 +30,4 @@ cve
 crypto
 kernel_misc
 uevent
+watchqueue
diff --git a/testcases/kernel/Makefile b/testcases/kernel/Makefile
index 4604f1f38..d44856c57 100644
--- a/testcases/kernel/Makefile
+++ b/testcases/kernel/Makefile
@@ -38,6 +38,7 @@ SUBDIRS			+= connectors \
 			   sound \
 			   tracing \
 			   uevents \
+			   watchqueue \
 
 ifeq ($(WITH_POWER_MANAGEMENT_TESTSUITE),yes)
 SUBDIRS			+= power_management
diff --git a/testcases/kernel/watchqueue/.gitignore b/testcases/kernel/watchqueue/.gitignore
new file mode 100644
index 000000000..c61ac6165
--- /dev/null
+++ b/testcases/kernel/watchqueue/.gitignore
@@ -0,0 +1 @@
+wqueue01
diff --git a/testcases/kernel/watchqueue/Makefile b/testcases/kernel/watchqueue/Makefile
new file mode 100644
index 000000000..896d66d42
--- /dev/null
+++ b/testcases/kernel/watchqueue/Makefile
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+top_srcdir			?= ../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
+
+LDLIBS += $(KEYUTILS_LIBS)
diff --git a/testcases/kernel/watchqueue/common.h b/testcases/kernel/watchqueue/common.h
new file mode 100644
index 000000000..8ed38bd4a
--- /dev/null
+++ b/testcases/kernel/watchqueue/common.h
@@ -0,0 +1,167 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+#ifndef WQUEUE_COMMON_H__
+#define WQUEUE_COMMON_H__
+
+#define _GNU_SOURCE
+
+#include <unistd.h>
+#include "tst_test.h"
+#include "lapi/watch_queue.h"
+#include "lapi/keyctl.h"
+
+static struct watch_notification_filter wqueue_filter = {
+	.nr_filters	= 2,
+	.filters = {
+		[0]	= {
+			.type			= WATCH_TYPE_META,
+			.subtype_filter[0]	= UINT_MAX,
+		},
+		[1]	= {
+			.type			= WATCH_TYPE_KEY_NOTIFY,
+			.subtype_filter[0]	= UINT_MAX,
+		},
+	},
+};
+
+static inline int wqueue_key_event(struct watch_notification *n, size_t len,
+								   unsigned int wtype, int type)
+{
+	struct key_notification *k;
+	const char *msg;
+
+	if (wtype != WATCH_TYPE_KEY_NOTIFY)
+		return 0;
+
+	if (len != sizeof(struct key_notification))
+		tst_brk(TBROK, "Incorrect key message length");
+
+	switch (n->subtype) {
+	case NOTIFY_KEY_INSTANTIATED:
+		msg = "instantiated";
+		break;
+	case NOTIFY_KEY_UPDATED:
+		msg = "updated";
+		break;
+	case NOTIFY_KEY_LINKED:
+		msg = "linked";
+		break;
+	case NOTIFY_KEY_UNLINKED:
+		msg = "unlinked";
+		break;
+	case NOTIFY_KEY_CLEARED:
+		msg = "cleared";
+		break;
+	case NOTIFY_KEY_REVOKED:
+		msg = "revoked";
+		break;
+	case NOTIFY_KEY_INVALIDATED:
+		msg = "invalidated";
+		break;
+	case NOTIFY_KEY_SETATTR:
+		msg = "setattr";
+		break;
+	default:
+		msg = "Invalid notification";
+		break;
+	};
+
+	k = (struct key_notification *)n;
+	tst_res(TINFO, "KEY %08x change=%u[%s] aux=%u", k->key_id, n->subtype, msg,
+			k->aux);
+
+	if (n->subtype == type)
+		return 1;
+
+	return 0;
+}
+
+static inline key_serial_t wqueue_add_key(int fd)
+{
+	key_serial_t key;
+
+	key = add_key("user", "ltptestkey", "a", 1, KEY_SPEC_SESSION_KEYRING);
+	if (key == -1)
+		tst_brk(TBROK, "add_key error: %s", tst_strerrno(errno));
+
+	keyctl(KEYCTL_WATCH_KEY, key, fd, 0x01);
+	keyctl(KEYCTL_WATCH_KEY, KEY_SPEC_SESSION_KEYRING, fd, 0x02);
+
+	return key;
+}
+
+static inline int wqueue_watch(int buf_size,
+							   struct watch_notification_filter *filter)
+{
+	int pipefd[2];
+	int fd;
+
+	TEST(pipe2(pipefd, O_NOTIFICATION_PIPE));
+	if (TST_RET) {
+		switch (TST_ERR) {
+		case ENOPKG:
+			tst_brk(TCONF | TTERRNO, "CONFIG_WATCH_QUEUE is not set");
+			break;
+		case EINVAL:
+			tst_brk(TCONF | TTERRNO, "O_NOTIFICATION_PIPE is not supported");
+			break;
+		default:
+			tst_brk(TBROK | TTERRNO, "pipe2() returned %ld", TST_RET);
+		}
+	}
+
+	fd = pipefd[0];
+
+	SAFE_IOCTL(fd, IOC_WATCH_QUEUE_SET_SIZE, buf_size);
+	SAFE_IOCTL(fd, IOC_WATCH_QUEUE_SET_FILTER, filter);
+
+	return fd;
+}
+
+typedef void (*wqueue_callback)(struct watch_notification *n, size_t len,
+								unsigned int wtype);
+
+static void wqueue_consumer(int fd, wqueue_callback cb)
+{
+	unsigned char buffer[433], *p, *end;
+	union {
+		struct watch_notification n;
+		unsigned char buf1[128];
+	} n;
+	ssize_t buf_len;
+
+	tst_res(TINFO, "Reading watch queue events");
+
+	buf_len = SAFE_READ(0, fd, buffer, sizeof(buffer));
+
+	p = buffer;
+	end = buffer + buf_len;
+	while (p < end) {
+		size_t largest, len;
+
+		largest = end - p;
+		if (largest > 128)
+			largest = 128;
+
+		if (largest < sizeof(struct watch_notification))
+			tst_brk(TBROK, "Short message header: %zu", largest);
+
+		memcpy(&n, p, largest);
+
+		tst_res(TINFO, "NOTIFY[%03zx]: ty=%06x sy=%02x i=%08x", p - buffer,
+				n.n.type, n.n.subtype, n.n.info);
+
+		len = n.n.info & WATCH_INFO_LENGTH;
+		if (len < sizeof(n.n) || len > largest)
+			tst_brk(TBROK, "Bad message length: %zu/%zu", len, largest);
+
+		cb(&n.n, len, n.n.type);
+
+		p += len;
+	}
+}
+
+#endif
diff --git a/testcases/kernel/watchqueue/wqueue01.c b/testcases/kernel/watchqueue/wqueue01.c
new file mode 100644
index 000000000..7ee2845ef
--- /dev/null
+++ b/testcases/kernel/watchqueue/wqueue01.c
@@ -0,0 +1,43 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Test if keyctl update is correctly recognized by watch queue.
+ */
+
+#define _GNU_SOURCE
+
+#include "tst_test.h"
+#include "lapi/keyctl.h"
+#include "common.h"
+
+static void saw_key_updated(struct watch_notification *n, size_t len,
+							unsigned int wtype)
+{
+	if (wqueue_key_event(n, len, wtype, NOTIFY_KEY_UPDATED))
+		tst_res(TPASS, "keyctl update has been recognized");
+	else
+		tst_res(TFAIL, "keyctl update 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_UPDATE, key, "b", 1);
+	wqueue_consumer(fd, saw_key_updated);
+
+	SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+};
-- 
2.34.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [LTP] [PATCH v5 04/11] Add wqueue02 test
  2022-01-27  9:24 [LTP] [PATCH v5 00/11] watchqueue testing suite Andrea Cervesato
                   ` (2 preceding siblings ...)
  2022-01-27  9:24 ` [LTP] [PATCH v5 03/11] Add wqueue01 test Andrea Cervesato
@ 2022-01-27  9:24 ` Andrea Cervesato
  2022-01-27  9:24 ` [LTP] [PATCH v5 05/11] Add wqueue03 test Andrea Cervesato
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Andrea Cervesato @ 2022-01-27  9:24 UTC (permalink / raw)
  To: ltp

This test is testing NOTIFY_KEY_UNLINKED event

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.de>
---
 runtest/watchqueue                     |  1 +
 testcases/kernel/watchqueue/.gitignore |  1 +
 testcases/kernel/watchqueue/wqueue02.c | 43 ++++++++++++++++++++++++++
 3 files changed, 45 insertions(+)
 create mode 100644 testcases/kernel/watchqueue/wqueue02.c

diff --git a/runtest/watchqueue b/runtest/watchqueue
index 782577d6d..0d442ff01 100644
--- a/runtest/watchqueue
+++ b/runtest/watchqueue
@@ -1 +1,2 @@
 wqueue01 wqueue01
+wqueue02 wqueue02
diff --git a/testcases/kernel/watchqueue/.gitignore b/testcases/kernel/watchqueue/.gitignore
index c61ac6165..4f8695201 100644
--- a/testcases/kernel/watchqueue/.gitignore
+++ b/testcases/kernel/watchqueue/.gitignore
@@ -1 +1,2 @@
 wqueue01
+wqueue02
diff --git a/testcases/kernel/watchqueue/wqueue02.c b/testcases/kernel/watchqueue/wqueue02.c
new file mode 100644
index 000000000..72df32b69
--- /dev/null
+++ b/testcases/kernel/watchqueue/wqueue02.c
@@ -0,0 +1,43 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Test if keyctl unlink is correctly recognized by watch queue.
+ */
+
+#define _GNU_SOURCE
+
+#include "tst_test.h"
+#include "lapi/keyctl.h"
+#include "common.h"
+
+static void saw_key_unlinked(struct watch_notification *n, size_t len,
+							 unsigned int wtype)
+{
+	if (wqueue_key_event(n, len, wtype, NOTIFY_KEY_UNLINKED))
+		tst_res(TPASS, "keyctl unlink has been recognized");
+	else
+		tst_res(TFAIL, "keyctl unlink 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_UNLINK, key, KEY_SPEC_SESSION_KEYRING);
+	wqueue_consumer(fd, saw_key_unlinked);
+
+	SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+};
-- 
2.34.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [LTP] [PATCH v5 05/11] Add wqueue03 test
  2022-01-27  9:24 [LTP] [PATCH v5 00/11] watchqueue testing suite Andrea Cervesato
                   ` (3 preceding siblings ...)
  2022-01-27  9:24 ` [LTP] [PATCH v5 04/11] Add wqueue02 test Andrea Cervesato
@ 2022-01-27  9:24 ` Andrea Cervesato
  2022-01-27  9:24 ` [LTP] [PATCH v5 06/11] Add wqueue04 test Andrea Cervesato
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Andrea Cervesato @ 2022-01-27  9:24 UTC (permalink / raw)
  To: ltp

This test is testing NOTIFY_KEY_REVOKED event

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.de>
---
 runtest/watchqueue                     |  1 +
 testcases/kernel/watchqueue/.gitignore |  1 +
 testcases/kernel/watchqueue/wqueue03.c | 43 ++++++++++++++++++++++++++
 3 files changed, 45 insertions(+)
 create mode 100644 testcases/kernel/watchqueue/wqueue03.c

diff --git a/runtest/watchqueue b/runtest/watchqueue
index 0d442ff01..0606db1e0 100644
--- a/runtest/watchqueue
+++ b/runtest/watchqueue
@@ -1,2 +1,3 @@
 wqueue01 wqueue01
 wqueue02 wqueue02
+wqueue03 wqueue03
diff --git a/testcases/kernel/watchqueue/.gitignore b/testcases/kernel/watchqueue/.gitignore
index 4f8695201..36a7473d8 100644
--- a/testcases/kernel/watchqueue/.gitignore
+++ b/testcases/kernel/watchqueue/.gitignore
@@ -1,2 +1,3 @@
 wqueue01
 wqueue02
+wqueue03
diff --git a/testcases/kernel/watchqueue/wqueue03.c b/testcases/kernel/watchqueue/wqueue03.c
new file mode 100644
index 000000000..e6e4c2091
--- /dev/null
+++ b/testcases/kernel/watchqueue/wqueue03.c
@@ -0,0 +1,43 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Test if keyctl revoke is correctly recognized by watch queue.
+ */
+
+#define _GNU_SOURCE
+
+#include "tst_test.h"
+#include "lapi/keyctl.h"
+#include "common.h"
+
+static void saw_key_revoked(struct watch_notification *n, size_t len,
+							unsigned int wtype)
+{
+	if (wqueue_key_event(n, len, wtype, NOTIFY_KEY_REVOKED))
+		tst_res(TPASS, "keyctl revoke has been recognized");
+	else
+		tst_res(TFAIL, "keyctl revoke 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_REVOKE, key);
+	wqueue_consumer(fd, saw_key_revoked);
+
+	SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+};
-- 
2.34.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [LTP] [PATCH v5 06/11] Add wqueue04 test
  2022-01-27  9:24 [LTP] [PATCH v5 00/11] watchqueue testing suite Andrea Cervesato
                   ` (4 preceding siblings ...)
  2022-01-27  9:24 ` [LTP] [PATCH v5 05/11] Add wqueue03 test Andrea Cervesato
@ 2022-01-27  9:24 ` Andrea Cervesato
  2022-01-27  9:24 ` [LTP] [PATCH v5 07/11] Add wqueue05 test Andrea Cervesato
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Andrea Cervesato @ 2022-01-27  9:24 UTC (permalink / raw)
  To: ltp

This test is testing NOTIFY_KEY_LINKED event

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.de>
---
 runtest/watchqueue                     |  1 +
 testcases/kernel/watchqueue/.gitignore |  1 +
 testcases/kernel/watchqueue/wqueue04.c | 43 ++++++++++++++++++++++++++
 3 files changed, 45 insertions(+)
 create mode 100644 testcases/kernel/watchqueue/wqueue04.c

diff --git a/runtest/watchqueue b/runtest/watchqueue
index 0606db1e0..cd897f4b4 100644
--- a/runtest/watchqueue
+++ b/runtest/watchqueue
@@ -1,3 +1,4 @@
 wqueue01 wqueue01
 wqueue02 wqueue02
 wqueue03 wqueue03
+wqueue04 wqueue04
diff --git a/testcases/kernel/watchqueue/.gitignore b/testcases/kernel/watchqueue/.gitignore
index 36a7473d8..13f492dbe 100644
--- a/testcases/kernel/watchqueue/.gitignore
+++ b/testcases/kernel/watchqueue/.gitignore
@@ -1,3 +1,4 @@
 wqueue01
 wqueue02
 wqueue03
+wqueue04
diff --git a/testcases/kernel/watchqueue/wqueue04.c b/testcases/kernel/watchqueue/wqueue04.c
new file mode 100644
index 000000000..dd585f2dc
--- /dev/null
+++ b/testcases/kernel/watchqueue/wqueue04.c
@@ -0,0 +1,43 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Test if keyctl link is correctly recognized by watch queue.
+ */
+
+#define _GNU_SOURCE
+
+#include "tst_test.h"
+#include "lapi/keyctl.h"
+#include "common.h"
+
+static void saw_key_linked(struct watch_notification *n, size_t len,
+						   unsigned int wtype)
+{
+	if (wqueue_key_event(n, len, wtype, NOTIFY_KEY_LINKED))
+		tst_res(TPASS, "keyctl link has been recognized");
+	else
+		tst_res(TFAIL, "keyctl link 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_LINK, key, KEY_SPEC_SESSION_KEYRING);
+	wqueue_consumer(fd, saw_key_linked);
+
+	SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+};
-- 
2.34.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [LTP] [PATCH v5 07/11] Add wqueue05 test
  2022-01-27  9:24 [LTP] [PATCH v5 00/11] watchqueue testing suite Andrea Cervesato
                   ` (5 preceding siblings ...)
  2022-01-27  9:24 ` [LTP] [PATCH v5 06/11] Add wqueue04 test Andrea Cervesato
@ 2022-01-27  9:24 ` Andrea Cervesato
  2022-01-27  9:24 ` [LTP] [PATCH v5 08/11] Add wqueue06 test Andrea Cervesato
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Andrea Cervesato @ 2022-01-27  9:24 UTC (permalink / raw)
  To: ltp

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.de>
---
 runtest/watchqueue                     |  1 +
 testcases/kernel/watchqueue/.gitignore |  1 +
 testcases/kernel/watchqueue/wqueue05.c | 43 ++++++++++++++++++++++++++
 3 files changed, 45 insertions(+)
 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 13f492dbe..9f4ac81e7 100644
--- a/testcases/kernel/watchqueue/.gitignore
+++ b/testcases/kernel/watchqueue/.gitignore
@@ -2,3 +2,4 @@ wqueue01
 wqueue02
 wqueue03
 wqueue04
+wqueue05
diff --git a/testcases/kernel/watchqueue/wqueue05.c b/testcases/kernel/watchqueue/wqueue05.c
new file mode 100644
index 000000000..173e8fc73
--- /dev/null
+++ b/testcases/kernel/watchqueue/wqueue05.c
@@ -0,0 +1,43 @@
+// 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.
+ */
+
+#define _GNU_SOURCE
+
+#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,
+};
-- 
2.34.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [LTP] [PATCH v5 08/11] Add wqueue06 test
  2022-01-27  9:24 [LTP] [PATCH v5 00/11] watchqueue testing suite Andrea Cervesato
                   ` (6 preceding siblings ...)
  2022-01-27  9:24 ` [LTP] [PATCH v5 07/11] Add wqueue05 test Andrea Cervesato
@ 2022-01-27  9:24 ` Andrea Cervesato
  2022-01-27  9:24 ` [LTP] [PATCH v5 09/11] Add wqueue07 test Andrea Cervesato
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Andrea Cervesato @ 2022-01-27  9:24 UTC (permalink / raw)
  To: ltp

This test is testing NOTIFY_KEY_INVALIDATED event

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

diff --git a/runtest/watchqueue b/runtest/watchqueue
index 596d45154..de086b6a7 100644
--- a/runtest/watchqueue
+++ b/runtest/watchqueue
@@ -3,3 +3,4 @@ wqueue02 wqueue02
 wqueue03 wqueue03
 wqueue04 wqueue04
 wqueue05 wqueue05
+wqueue06 wqueue06
diff --git a/testcases/kernel/watchqueue/.gitignore b/testcases/kernel/watchqueue/.gitignore
index 9f4ac81e7..e167b500d 100644
--- a/testcases/kernel/watchqueue/.gitignore
+++ b/testcases/kernel/watchqueue/.gitignore
@@ -3,3 +3,4 @@ wqueue02
 wqueue03
 wqueue04
 wqueue05
+wqueue06
diff --git a/testcases/kernel/watchqueue/wqueue06.c b/testcases/kernel/watchqueue/wqueue06.c
new file mode 100644
index 000000000..d7806998e
--- /dev/null
+++ b/testcases/kernel/watchqueue/wqueue06.c
@@ -0,0 +1,42 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Test if keyctl clear is correctly recognized by watch queue.
+ */
+
+#define _GNU_SOURCE
+
+#include "tst_test.h"
+#include "lapi/keyctl.h"
+#include "common.h"
+
+static void saw_key_cleared(struct watch_notification *n, size_t len,
+							unsigned int wtype)
+{
+	if (wqueue_key_event(n, len, wtype, NOTIFY_KEY_CLEARED))
+		tst_res(TPASS, "keyctl clear has been recognized");
+	else
+		tst_res(TFAIL, "keyctl clear has not been recognized");
+}
+
+static void run(void)
+{
+	int fd;
+
+	fd = wqueue_watch(256, &wqueue_filter);
+	wqueue_add_key(fd);
+
+	keyctl(KEYCTL_CLEAR, KEY_SPEC_SESSION_KEYRING);
+	wqueue_consumer(fd, saw_key_cleared);
+
+	SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+};
-- 
2.34.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [LTP] [PATCH v5 09/11] Add wqueue07 test
  2022-01-27  9:24 [LTP] [PATCH v5 00/11] watchqueue testing suite Andrea Cervesato
                   ` (7 preceding siblings ...)
  2022-01-27  9:24 ` [LTP] [PATCH v5 08/11] Add wqueue06 test Andrea Cervesato
@ 2022-01-27  9:24 ` Andrea Cervesato
  2022-01-27  9:24 ` [LTP] [PATCH v5 10/11] Add wqueue08 test Andrea Cervesato
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Andrea Cervesato @ 2022-01-27  9:24 UTC (permalink / raw)
  To: ltp

This test is testing NOTIFY_KEY_SETATTR event

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.de>
---
 runtest/watchqueue                     |  1 +
 testcases/kernel/watchqueue/.gitignore |  1 +
 testcases/kernel/watchqueue/wqueue07.c | 43 ++++++++++++++++++++++++++
 3 files changed, 45 insertions(+)
 create mode 100644 testcases/kernel/watchqueue/wqueue07.c

diff --git a/runtest/watchqueue b/runtest/watchqueue
index de086b6a7..bdb461018 100644
--- a/runtest/watchqueue
+++ b/runtest/watchqueue
@@ -4,3 +4,4 @@ wqueue03 wqueue03
 wqueue04 wqueue04
 wqueue05 wqueue05
 wqueue06 wqueue06
+wqueue07 wqueue07
diff --git a/testcases/kernel/watchqueue/.gitignore b/testcases/kernel/watchqueue/.gitignore
index e167b500d..891b19775 100644
--- a/testcases/kernel/watchqueue/.gitignore
+++ b/testcases/kernel/watchqueue/.gitignore
@@ -4,3 +4,4 @@ wqueue03
 wqueue04
 wqueue05
 wqueue06
+wqueue07
diff --git a/testcases/kernel/watchqueue/wqueue07.c b/testcases/kernel/watchqueue/wqueue07.c
new file mode 100644
index 000000000..b2bd98b6a
--- /dev/null
+++ b/testcases/kernel/watchqueue/wqueue07.c
@@ -0,0 +1,43 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Test if keyctl setperm is correctly recognized by watch queue.
+ */
+
+#define _GNU_SOURCE
+
+#include "tst_test.h"
+#include "lapi/keyctl.h"
+#include "common.h"
+
+static void saw_key_setattr(struct watch_notification *n, size_t len,
+							unsigned int wtype)
+{
+	if (wqueue_key_event(n, len, wtype, NOTIFY_KEY_SETATTR))
+		tst_res(TPASS, "keyctl setattr has been recognized");
+	else
+		tst_res(TFAIL, "keyctl setattr 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_SETPERM, key, KEY_POS_ALL | KEY_USR_ALL);
+	wqueue_consumer(fd, saw_key_setattr);
+
+	SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+};
-- 
2.34.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [LTP] [PATCH v5 10/11] Add wqueue08 test
  2022-01-27  9:24 [LTP] [PATCH v5 00/11] watchqueue testing suite Andrea Cervesato
                   ` (8 preceding siblings ...)
  2022-01-27  9:24 ` [LTP] [PATCH v5 09/11] Add wqueue07 test Andrea Cervesato
@ 2022-01-27  9:24 ` Andrea Cervesato
  2022-01-27  9:24 ` [LTP] [PATCH v5 11/11] Add wqueue09 test Andrea Cervesato
  2022-01-27 16:14 ` [LTP] [PATCH v5 00/11] watchqueue testing suite Cyril Hrubis
  11 siblings, 0 replies; 13+ messages in thread
From: Andrea Cervesato @ 2022-01-27  9:24 UTC (permalink / raw)
  To: ltp

This test is testing WATCH_META_REMOVAL_NOTIFICATION event

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.de>
---
 runtest/watchqueue                     |  1 +
 testcases/kernel/watchqueue/.gitignore |  1 +
 testcases/kernel/watchqueue/wqueue08.c | 48 ++++++++++++++++++++++++++
 3 files changed, 50 insertions(+)
 create mode 100644 testcases/kernel/watchqueue/wqueue08.c

diff --git a/runtest/watchqueue b/runtest/watchqueue
index bdb461018..badf7afb0 100644
--- a/runtest/watchqueue
+++ b/runtest/watchqueue
@@ -5,3 +5,4 @@ wqueue04 wqueue04
 wqueue05 wqueue05
 wqueue06 wqueue06
 wqueue07 wqueue07
+wqueue08 wqueue08
diff --git a/testcases/kernel/watchqueue/.gitignore b/testcases/kernel/watchqueue/.gitignore
index 891b19775..0f998fe79 100644
--- a/testcases/kernel/watchqueue/.gitignore
+++ b/testcases/kernel/watchqueue/.gitignore
@@ -5,3 +5,4 @@ wqueue04
 wqueue05
 wqueue06
 wqueue07
+wqueue08
diff --git a/testcases/kernel/watchqueue/wqueue08.c b/testcases/kernel/watchqueue/wqueue08.c
new file mode 100644
index 000000000..4933c5e0e
--- /dev/null
+++ b/testcases/kernel/watchqueue/wqueue08.c
@@ -0,0 +1,48 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Test if key watch removal is correctly recognized by watch queue.
+ */
+
+#define _GNU_SOURCE
+
+#include "tst_test.h"
+#include "lapi/keyctl.h"
+#include "common.h"
+
+static void saw_watch_removal(struct watch_notification *n,
+							  LTP_ATTRIBUTE_UNUSED size_t len,
+							  unsigned int wtype)
+{
+	if (wtype != WATCH_TYPE_META)
+		return;
+
+	if (n->subtype == WATCH_META_REMOVAL_NOTIFICATION)
+		tst_res(TPASS, "Meta removal notification received");
+	else
+		tst_res(TFAIL, "Event not recognized");
+}
+
+static void run(void)
+{
+	int fd;
+	key_serial_t key;
+
+	fd = wqueue_watch(256, &wqueue_filter);
+	key = wqueue_add_key(fd);
+
+	/* if watch_id = -1 key is removed from the watch queue */
+	keyctl(KEYCTL_WATCH_KEY, key, fd, -1);
+	wqueue_consumer(fd, saw_watch_removal);
+
+	SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+};
-- 
2.34.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [LTP] [PATCH v5 11/11] Add wqueue09 test
  2022-01-27  9:24 [LTP] [PATCH v5 00/11] watchqueue testing suite Andrea Cervesato
                   ` (9 preceding siblings ...)
  2022-01-27  9:24 ` [LTP] [PATCH v5 10/11] Add wqueue08 test Andrea Cervesato
@ 2022-01-27  9:24 ` Andrea Cervesato
  2022-01-27 16:14 ` [LTP] [PATCH v5 00/11] watchqueue testing suite Cyril Hrubis
  11 siblings, 0 replies; 13+ messages in thread
From: Andrea Cervesato @ 2022-01-27  9:24 UTC (permalink / raw)
  To: ltp

This test is testing WATCH_META_LOSS_NOTIFICATION event

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.de>
---
 runtest/watchqueue                     |  1 +
 testcases/kernel/watchqueue/.gitignore |  1 +
 testcases/kernel/watchqueue/wqueue09.c | 55 ++++++++++++++++++++++++++
 3 files changed, 57 insertions(+)
 create mode 100644 testcases/kernel/watchqueue/wqueue09.c

diff --git a/runtest/watchqueue b/runtest/watchqueue
index badf7afb0..bd6b0a423 100644
--- a/runtest/watchqueue
+++ b/runtest/watchqueue
@@ -6,3 +6,4 @@ wqueue05 wqueue05
 wqueue06 wqueue06
 wqueue07 wqueue07
 wqueue08 wqueue08
+wqueue09 wqueue09
diff --git a/testcases/kernel/watchqueue/.gitignore b/testcases/kernel/watchqueue/.gitignore
index 0f998fe79..dcfcd8272 100644
--- a/testcases/kernel/watchqueue/.gitignore
+++ b/testcases/kernel/watchqueue/.gitignore
@@ -6,3 +6,4 @@ wqueue05
 wqueue06
 wqueue07
 wqueue08
+wqueue09
diff --git a/testcases/kernel/watchqueue/wqueue09.c b/testcases/kernel/watchqueue/wqueue09.c
new file mode 100644
index 000000000..f0e429ead
--- /dev/null
+++ b/testcases/kernel/watchqueue/wqueue09.c
@@ -0,0 +1,55 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Fill the watch queue and wait for a notification loss.
+ */
+
+#define _GNU_SOURCE
+
+#include "tst_test.h"
+#include "lapi/keyctl.h"
+#include "common.h"
+
+static int data_lost;
+
+static void saw_data_loss(struct watch_notification *n,
+						  LTP_ATTRIBUTE_UNUSED size_t len, unsigned int wtype)
+{
+	if (wtype != WATCH_TYPE_META)
+		return;
+
+	if (n->subtype == WATCH_META_LOSS_NOTIFICATION)
+		data_lost = 1;
+}
+
+static void run(void)
+{
+	int fd;
+	key_serial_t key;
+
+	fd = wqueue_watch(1, &wqueue_filter);
+
+	key = wqueue_add_key(fd);
+	keyctl(KEYCTL_UPDATE, key, "b", 1);
+	keyctl(KEYCTL_REVOKE, key);
+
+	data_lost = 0;
+	while (!data_lost)
+		wqueue_consumer(fd, saw_data_loss);
+
+	SAFE_CLOSE(fd);
+
+	if (data_lost)
+		tst_res(TPASS, "Meta loss notification received");
+	else
+		tst_res(TFAIL, "Event not recognized");
+}
+
+static struct tst_test test = {
+	.test_all = run,
+};
-- 
2.34.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [LTP] [PATCH v5 00/11] watchqueue testing suite
  2022-01-27  9:24 [LTP] [PATCH v5 00/11] watchqueue testing suite Andrea Cervesato
                   ` (10 preceding siblings ...)
  2022-01-27  9:24 ` [LTP] [PATCH v5 11/11] Add wqueue09 test Andrea Cervesato
@ 2022-01-27 16:14 ` Cyril Hrubis
  11 siblings, 0 replies; 13+ messages in thread
From: Cyril Hrubis @ 2022-01-27 16:14 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: ltp

Hi!
Pushed with two minor changes, thanks.

* There is no need to define _GNU_SOURCE in common.h when it's defined
  in each respective test

* The function declaration that span over two lines were
  misaligned, looks like your tabwidth != 8

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2022-01-27 16:12 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-01-27  9:24 [LTP] [PATCH v5 00/11] watchqueue testing suite Andrea Cervesato
2022-01-27  9:24 ` [LTP] [PATCH v5 01/11] Add KEYCTL_WATCH_KEY to lapi keyctl.h fallback Andrea Cervesato
2022-01-27  9:24 ` [LTP] [PATCH v5 02/11] Add lapi/watch_queue.h header fallback Andrea Cervesato
2022-01-27  9:24 ` [LTP] [PATCH v5 03/11] Add wqueue01 test Andrea Cervesato
2022-01-27  9:24 ` [LTP] [PATCH v5 04/11] Add wqueue02 test Andrea Cervesato
2022-01-27  9:24 ` [LTP] [PATCH v5 05/11] Add wqueue03 test Andrea Cervesato
2022-01-27  9:24 ` [LTP] [PATCH v5 06/11] Add wqueue04 test Andrea Cervesato
2022-01-27  9:24 ` [LTP] [PATCH v5 07/11] Add wqueue05 test Andrea Cervesato
2022-01-27  9:24 ` [LTP] [PATCH v5 08/11] Add wqueue06 test Andrea Cervesato
2022-01-27  9:24 ` [LTP] [PATCH v5 09/11] Add wqueue07 test Andrea Cervesato
2022-01-27  9:24 ` [LTP] [PATCH v5 10/11] Add wqueue08 test Andrea Cervesato
2022-01-27  9:24 ` [LTP] [PATCH v5 11/11] Add wqueue09 test Andrea Cervesato
2022-01-27 16:14 ` [LTP] [PATCH v5 00/11] watchqueue testing suite Cyril Hrubis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox