xref: /aosp_15_r20/external/ltp/testcases/kernel/watchqueue/wqueue06.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
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  * Test if keyctl clear is correctly recognized by watch queue.
10  */
11 
12 #define _GNU_SOURCE
13 
14 #include "tst_test.h"
15 #include "lapi/keyctl.h"
16 #include "common.h"
17 
saw_key_cleared(struct watch_notification * n,size_t len,unsigned int wtype)18 static void saw_key_cleared(struct watch_notification *n, size_t len,
19                             unsigned int wtype)
20 {
21 	if (wqueue_key_event(n, len, wtype, NOTIFY_KEY_CLEARED))
22 		tst_res(TPASS, "keyctl clear has been recognized");
23 	else
24 		tst_res(TFAIL, "keyctl clear has not been recognized");
25 }
26 
run(void)27 static void run(void)
28 {
29 	int fd;
30 
31 	fd = wqueue_watch(256, &wqueue_filter);
32 	wqueue_add_key(fd);
33 
34 	keyctl(KEYCTL_CLEAR, KEY_SPEC_SESSION_KEYRING);
35 	wqueue_consumer(fd, saw_key_cleared);
36 
37 	SAFE_CLOSE(fd);
38 }
39 
40 static struct tst_test test = {
41 	.test_all = run,
42 };
43