1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (C) 2021 SUSE LLC Andrea Cervesato <[email protected]>
4 */
5
6 /*\
7 * [Description]
8 *
9 * Fill the watch queue and wait for a notification loss.
10 */
11
12 #define _GNU_SOURCE
13
14 #include <unistd.h>
15 #include "tst_test.h"
16 #include "lapi/keyctl.h"
17 #include "common.h"
18
19 #define WATCH_QUEUE_NOTE_SIZE 128
20
21 static int data_lost;
22 static key_serial_t key;
23 static int fd;
24
saw_data_loss(struct watch_notification * n,LTP_ATTRIBUTE_UNUSED size_t len,unsigned int wtype)25 static void saw_data_loss(struct watch_notification *n,
26 LTP_ATTRIBUTE_UNUSED size_t len, unsigned int wtype)
27 {
28 if (wtype != WATCH_TYPE_META)
29 return;
30
31 if (n->subtype == WATCH_META_LOSS_NOTIFICATION)
32 data_lost = 1;
33 }
34
setup(void)35 static void setup(void)
36 {
37 fd = wqueue_watch(1, &wqueue_filter);
38 key = wqueue_add_key(fd);
39 }
40
run(void)41 static void run(void)
42 {
43 int i, iterations;
44
45 iterations = (getpagesize() / WATCH_QUEUE_NOTE_SIZE) * 2;
46 for (i = 0; i < iterations; i++)
47 keyctl(KEYCTL_UPDATE, key, "b", 1);
48
49 data_lost = 0;
50 while (!data_lost)
51 wqueue_consumer(fd, saw_data_loss);
52
53 if (data_lost)
54 tst_res(TPASS, "Meta loss notification received");
55 else
56 tst_res(TFAIL, "Event not recognized");
57 }
58
cleanup(void)59 static void cleanup(void)
60 {
61 keyctl(KEYCTL_REVOKE, key);
62 SAFE_CLOSE(fd);
63 }
64
65 static struct tst_test test = {
66 .test_all = run,
67 .setup = setup,
68 .cleanup = cleanup,
69 };
70