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 invalidate 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_invalidated(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_INVALIDATED))
22f08c3bdfSopenharmony_ci		tst_res(TPASS, "keyctl invalidate has been recognized");
23f08c3bdfSopenharmony_ci	else
24f08c3bdfSopenharmony_ci		tst_res(TFAIL, "keyctl invalidate has not been recognized");
25f08c3bdfSopenharmony_ci}
26f08c3bdfSopenharmony_ci
27f08c3bdfSopenharmony_cistatic void run(void)
28f08c3bdfSopenharmony_ci{
29f08c3bdfSopenharmony_ci	int fd;
30f08c3bdfSopenharmony_ci	key_serial_t key;
31f08c3bdfSopenharmony_ci
32f08c3bdfSopenharmony_ci	fd = wqueue_watch(256, &wqueue_filter);
33f08c3bdfSopenharmony_ci	key = wqueue_add_key(fd);
34f08c3bdfSopenharmony_ci
35f08c3bdfSopenharmony_ci	keyctl(KEYCTL_INVALIDATE, key);
36f08c3bdfSopenharmony_ci	wqueue_consumer(fd, saw_key_invalidated);
37f08c3bdfSopenharmony_ci
38f08c3bdfSopenharmony_ci	SAFE_CLOSE(fd);
39f08c3bdfSopenharmony_ci}
40f08c3bdfSopenharmony_ci
41f08c3bdfSopenharmony_cistatic struct tst_test test = {
42f08c3bdfSopenharmony_ci	.test_all = run,
43f08c3bdfSopenharmony_ci};
44