xref: /aosp_15_r20/external/ltp/testcases/kernel/watchqueue/wqueue08.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
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 key watch removal 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_watch_removal(struct watch_notification * n,LTP_ATTRIBUTE_UNUSED size_t len,unsigned int wtype)18*49cdfc7eSAndroid Build Coastguard Worker static void saw_watch_removal(struct watch_notification *n,
19*49cdfc7eSAndroid Build Coastguard Worker 			      LTP_ATTRIBUTE_UNUSED size_t len,
20*49cdfc7eSAndroid Build Coastguard Worker 			      unsigned int wtype)
21*49cdfc7eSAndroid Build Coastguard Worker {
22*49cdfc7eSAndroid Build Coastguard Worker 	if (wtype != WATCH_TYPE_META)
23*49cdfc7eSAndroid Build Coastguard Worker 		return;
24*49cdfc7eSAndroid Build Coastguard Worker 
25*49cdfc7eSAndroid Build Coastguard Worker 	if (n->subtype == WATCH_META_REMOVAL_NOTIFICATION)
26*49cdfc7eSAndroid Build Coastguard Worker 		tst_res(TPASS, "Meta removal notification received");
27*49cdfc7eSAndroid Build Coastguard Worker 	else
28*49cdfc7eSAndroid Build Coastguard Worker 		tst_res(TFAIL, "Event not recognized");
29*49cdfc7eSAndroid Build Coastguard Worker }
30*49cdfc7eSAndroid Build Coastguard Worker 
run(void)31*49cdfc7eSAndroid Build Coastguard Worker static void run(void)
32*49cdfc7eSAndroid Build Coastguard Worker {
33*49cdfc7eSAndroid Build Coastguard Worker 	int fd;
34*49cdfc7eSAndroid Build Coastguard Worker 	key_serial_t key;
35*49cdfc7eSAndroid Build Coastguard Worker 
36*49cdfc7eSAndroid Build Coastguard Worker 	fd = wqueue_watch(256, &wqueue_filter);
37*49cdfc7eSAndroid Build Coastguard Worker 	key = wqueue_add_key(fd);
38*49cdfc7eSAndroid Build Coastguard Worker 
39*49cdfc7eSAndroid Build Coastguard Worker 	/* if watch_id = -1 key is removed from the watch queue */
40*49cdfc7eSAndroid Build Coastguard Worker 	keyctl(KEYCTL_WATCH_KEY, key, fd, -1);
41*49cdfc7eSAndroid Build Coastguard Worker 	wqueue_consumer(fd, saw_watch_removal);
42*49cdfc7eSAndroid Build Coastguard Worker 
43*49cdfc7eSAndroid Build Coastguard Worker 	SAFE_CLOSE(fd);
44*49cdfc7eSAndroid Build Coastguard Worker }
45*49cdfc7eSAndroid Build Coastguard Worker 
46*49cdfc7eSAndroid Build Coastguard Worker static struct tst_test test = {
47*49cdfc7eSAndroid Build Coastguard Worker 	.test_all = run,
48*49cdfc7eSAndroid Build Coastguard Worker };
49