diff mbox series

[v5,11/11] Add wqueue09 test

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

Commit Message

Andrea Cervesato Jan. 27, 2022, 9:24 a.m. UTC
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 mbox series

Patch

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,
+};