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