diff mbox series

[v4,11/11] Add wqueue09 test

Message ID 20220107212058.19768-12-andrea.cervesato@suse.de
State Superseded
Headers show
Series watchqueue testing suite | expand

Commit Message

Andrea Cervesato Jan. 7, 2022, 9:20 p.m. UTC
This test is testing WATCH_META_LOSS_NOTIFICATION event

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.de>
---
 testcases/kernel/watchqueue/wqueue09.c | 52 ++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)
 create mode 100644 testcases/kernel/watchqueue/wqueue09.c
diff mbox series

Patch

diff --git a/testcases/kernel/watchqueue/wqueue09.c b/testcases/kernel/watchqueue/wqueue09.c
new file mode 100644
index 000000000..ac49bb8a0
--- /dev/null
+++ b/testcases/kernel/watchqueue/wqueue09.c
@@ -0,0 +1,52 @@ 
+// 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.
+ */
+
+#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,
+};