1*49cdfc7eSAndroid Build Coastguard Worker // SPDX-License-Identifier: GPL-2.0-or-later
2*49cdfc7eSAndroid Build Coastguard Worker /*
3*49cdfc7eSAndroid Build Coastguard Worker * Copyright (C) 2021 SUSE LLC Andrea Cervesato <[email protected]>
4*49cdfc7eSAndroid Build Coastguard Worker */
5*49cdfc7eSAndroid Build Coastguard Worker
6*49cdfc7eSAndroid Build Coastguard Worker /*\
7*49cdfc7eSAndroid Build Coastguard Worker * [Description]
8*49cdfc7eSAndroid Build Coastguard Worker *
9*49cdfc7eSAndroid Build Coastguard Worker * Test if keyctl update is correctly recognized by watch queue.
10*49cdfc7eSAndroid Build Coastguard Worker */
11*49cdfc7eSAndroid Build Coastguard Worker
12*49cdfc7eSAndroid Build Coastguard Worker #define _GNU_SOURCE
13*49cdfc7eSAndroid Build Coastguard Worker
14*49cdfc7eSAndroid Build Coastguard Worker #include "tst_test.h"
15*49cdfc7eSAndroid Build Coastguard Worker #include "lapi/keyctl.h"
16*49cdfc7eSAndroid Build Coastguard Worker #include "common.h"
17*49cdfc7eSAndroid Build Coastguard Worker
saw_key_updated(struct watch_notification * n,size_t len,unsigned int wtype)18*49cdfc7eSAndroid Build Coastguard Worker static void saw_key_updated(struct watch_notification *n, size_t len,
19*49cdfc7eSAndroid Build Coastguard Worker unsigned int wtype)
20*49cdfc7eSAndroid Build Coastguard Worker {
21*49cdfc7eSAndroid Build Coastguard Worker if (wqueue_key_event(n, len, wtype, NOTIFY_KEY_UPDATED))
22*49cdfc7eSAndroid Build Coastguard Worker tst_res(TPASS, "keyctl update has been recognized");
23*49cdfc7eSAndroid Build Coastguard Worker else
24*49cdfc7eSAndroid Build Coastguard Worker tst_res(TFAIL, "keyctl update has not been recognized");
25*49cdfc7eSAndroid Build Coastguard Worker }
26*49cdfc7eSAndroid Build Coastguard Worker
run(void)27*49cdfc7eSAndroid Build Coastguard Worker static void run(void)
28*49cdfc7eSAndroid Build Coastguard Worker {
29*49cdfc7eSAndroid Build Coastguard Worker int fd;
30*49cdfc7eSAndroid Build Coastguard Worker key_serial_t key;
31*49cdfc7eSAndroid Build Coastguard Worker
32*49cdfc7eSAndroid Build Coastguard Worker fd = wqueue_watch(256, &wqueue_filter);
33*49cdfc7eSAndroid Build Coastguard Worker key = wqueue_add_key(fd);
34*49cdfc7eSAndroid Build Coastguard Worker
35*49cdfc7eSAndroid Build Coastguard Worker keyctl(KEYCTL_UPDATE, key, "b", 1);
36*49cdfc7eSAndroid Build Coastguard Worker wqueue_consumer(fd, saw_key_updated);
37*49cdfc7eSAndroid Build Coastguard Worker
38*49cdfc7eSAndroid Build Coastguard Worker SAFE_CLOSE(fd);
39*49cdfc7eSAndroid Build Coastguard Worker }
40*49cdfc7eSAndroid Build Coastguard Worker
41*49cdfc7eSAndroid Build Coastguard Worker static struct tst_test test = {
42*49cdfc7eSAndroid Build Coastguard Worker .test_all = run,
43*49cdfc7eSAndroid Build Coastguard Worker };
44