watchqueue testing suite
v4 cover watchqueue testing suite
This patch-set add a new testing suite for the watch queue kernel feature described in https://www.kernel.org/doc/html/latest/watch_queue.html
Andrea Cervesato (11):
Add KEYCTL_WATCH_KEY to lapi/keyctl.h fallback
Add lapi/watch_queue.h header fallback
Add wqueue01 test
Add wqueue02 test
Add wqueue03 test
Add wqueue04 test
Add wqueue05 test
Add wqueue06 test
Add wqueue07 test
Add wqueue08 test
Add wqueue09 test
include/lapi/keyctl.h | 4 + include/lapi/watch_queue.h | 112 +++++++++++++++++++ runtest/watchqueue | 9 ++ scenario_groups/default | 1 + testcases/kernel/Makefile | 1 + testcases/kernel/watchqueue/.gitignore | 9 ++ testcases/kernel/watchqueue/Makefile | 8 ++ testcases/kernel/watchqueue/common.h | 149 +++++++++++++++++++++++++ testcases/kernel/watchqueue/wqueue01.c | 40 +++++++ testcases/kernel/watchqueue/wqueue02.c | 40 +++++++ testcases/kernel/watchqueue/wqueue03.c | 40 +++++++ testcases/kernel/watchqueue/wqueue04.c | 40 +++++++ testcases/kernel/watchqueue/wqueue05.c | 40 +++++++ testcases/kernel/watchqueue/wqueue06.c | 39 +++++++ testcases/kernel/watchqueue/wqueue07.c | 40 +++++++ testcases/kernel/watchqueue/wqueue08.c | 44 ++++++++ testcases/kernel/watchqueue/wqueue09.c | 52 +++++++++ 17 files changed, 668 insertions(+) create mode 100644 include/lapi/watch_queue.h create mode 100644 runtest/watchqueue create mode 100644 testcases/kernel/watchqueue/.gitignore create mode 100644 testcases/kernel/watchqueue/Makefile create mode 100644 testcases/kernel/watchqueue/common.h create mode 100644 testcases/kernel/watchqueue/wqueue01.c create mode 100644 testcases/kernel/watchqueue/wqueue02.c create mode 100644 testcases/kernel/watchqueue/wqueue03.c create mode 100644 testcases/kernel/watchqueue/wqueue04.c create mode 100644 testcases/kernel/watchqueue/wqueue05.c create mode 100644 testcases/kernel/watchqueue/wqueue06.c create mode 100644 testcases/kernel/watchqueue/wqueue07.c create mode 100644 testcases/kernel/watchqueue/wqueue08.c create mode 100644 testcases/kernel/watchqueue/wqueue09.c
Signature · 5 lines
2.34.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v4 1/11 Add KEYCTL_WATCH_KEY to lapi/keyctl.h fallback
--- include/lapi/keyctl.h | 4 ++++ 1 file changed, 4 insertions(+)
include/lapi/keyctl.h +4 -0
@@ -140,6 +140,10 @@ static inline key_serial_t keyctl_join_session_keyring(const char *name) {# define KEYCTL_INVALIDATE 21#endif +#ifndef KEYCTL_WATCH_KEY +# define KEYCTL_WATCH_KEY 32 +#endif +/* key permissions */ #ifndef KEY_POS_VIEW # define KEY_POS_VIEW 0x01000000
Signature · 5 lines
2.34.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v4 2/11 Add lapi/watch_queue.h header fallback
In reply to Andrea Cervesato--- include/lapi/watch_queue.h | 112 +++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 include/lapi/watch_queue.h
include/lapi/watch_queue.h new file +112 -0
@@ -0,0 +1,112 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2021 SUSE LLC Andrea Cervesato <[email protected]> +* +* This file is created to resolve conflicts between user space and kernel +* space fctnl.h declaration. linux/watch_queue.h is not handled, since +* user space fcntl.h redefines kernel space structures. +*/ + +#ifndef LAPI_WATCH_QUEUE_H__ +#define LAPI_WATCH_QUEUE_H__ + +#include <stdint.h> +#include "lapi/ioctl.h" +#include "lapi/fcntl.h" + +#define O_NOTIFICATION_PIPE O_EXCL/* Parameter to pipe2() selecting notification pipe */ + +#define IOC_WATCH_QUEUE_SET_SIZE _IO('W', 0x60)/* Set the size in pages */ +#define IOC_WATCH_QUEUE_SET_FILTER _IO('W', 0x61)/* Set the filter */ + +enum watch_notification_type { +WATCH_TYPE_META =0 ,/* Special record */ +WATCH_TYPE_KEY_NOTIFY =1 ,/* Key change event notification */ +WATCH_TYPE__NR =2 +}; + +enum watch_meta_notification_subtype { +WATCH_META_REMOVAL_NOTIFICATION =0 ,/* Watched object was removed */ +WATCH_META_LOSS_NOTIFICATION =1 ,/* Data loss occurred */ +}; + +/* +* Notification record header. This is aligned to 64-bits so that subclasses +* can contain __u64 fields. +*/ +struct watch_notification { +uint32_t type:24 ;/* enum watch_notification_type */ +uint32_t subtype:8 ;/* Type-specific subtype (filterable) */ +uint32_t info; +#define WATCH_INFO_LENGTH 0x0000007f/* Length of record */ +#define WATCH_INFO_LENGTH__SHIFT 0 +#define WATCH_INFO_ID 0x0000ff00/* ID of watchpoint */ +#define WATCH_INFO_ID__SHIFT 8 +#define WATCH_INFO_TYPE_INFO 0xffff0000/* Type-specific info */ +#define WATCH_INFO_TYPE_INFO__SHIFT 16 +#define WATCH_INFO_FLAG_0 0x00010000/* Type-specific info, flag bit 0 */ +#define WATCH_INFO_FLAG_1 0x00020000/* ... */ +#define WATCH_INFO_FLAG_2 0x00040000 +#define WATCH_INFO_FLAG_3 0x00080000 +#define WATCH_INFO_FLAG_4 0x00100000 +#define WATCH_INFO_FLAG_5 0x00200000 +#define WATCH_INFO_FLAG_6 0x00400000 +#define WATCH_INFO_FLAG_7 0x00800000 +}; + +/* +* Notification filtering rules (IOC_WATCH_QUEUE_SET_FILTER). +*/ +struct watch_notification_type_filter { +uint32_t type;/* Type to apply filter to */ +uint32_t info_filter;/* Filter on watch_notification::info */ +uint32_t info_mask;/* Mask of relevant bits in info_filter */ +uint32_t subtype_filter[8 ];/* Bitmask of subtypes to filter on */ +}; + +struct watch_notification_filter { +uint32_t nr_filters;/* Number of filters */ +uint32_t __reserved;/* Must be 0 */ +struct watch_notification_type_filter filters[]; +}; + + +/* +* Extended watch removal notification. This is used optionally if the type +* wants to indicate an identifier for the object being watched, if there is +* such. This can be distinguished by the length. +* +* type -> WATCH_TYPE_META +* subtype -> WATCH_META_REMOVAL_NOTIFICATION +*/ +struct watch_notification_removal { +struct watch_notification watch; +uint64_t id;/* Type-dependent identifier */ +}; + +/* +* Type of key/keyring change notification. +*/ +enum key_notification_subtype { +NOTIFY_KEY_INSTANTIATED =0 ,/* Key was instantiated (aux is error code) */ +NOTIFY_KEY_UPDATED =1 ,/* Key was updated */ +NOTIFY_KEY_LINKED =2 ,/* Key (aux) was added to watched keyring */ +NOTIFY_KEY_UNLINKED =3 ,/* Key (aux) was removed from watched keyring */ +NOTIFY_KEY_CLEARED =4 ,/* Keyring was cleared */ +NOTIFY_KEY_REVOKED =5 ,/* Key was revoked */ +NOTIFY_KEY_INVALIDATED =6 ,/* Key was invalidated */ +NOTIFY_KEY_SETATTR =7 ,/* Key's attributes got changed */ +}; + +/* +* Key/keyring notification record. +* - watch.type = WATCH_TYPE_KEY_NOTIFY +* - watch.subtype = enum key_notification_type +*/ +struct key_notification { +struct watch_notification watch; +uint32_t key_id;/* The key/keyring affected */ +uint32_t aux;/* Per-type auxiliary data */ +}; + +#endif /* LAPI_WATCH_QUEUE_H__ */
Signature · 5 lines
2.34.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v4 3/11 Add wqueue01 test
In reply to Andrea CervesatoThis test is testing NOTIFY_KEY_UPDATED event
--- runtest/watchqueue | 9 ++ scenario_groups/default | 1 + testcases/kernel/Makefile | 1 + testcases/kernel/watchqueue/.gitignore | 9 ++ testcases/kernel/watchqueue/Makefile | 8 ++ testcases/kernel/watchqueue/common.h | 149 +++++++++++++++++++++++++ testcases/kernel/watchqueue/wqueue01.c | 40 +++++++ 7 files changed, 217 insertions(+) create mode 100644 runtest/watchqueue create mode 100644 testcases/kernel/watchqueue/.gitignore create mode 100644 testcases/kernel/watchqueue/Makefile create mode 100644 testcases/kernel/watchqueue/common.h create mode 100644 testcases/kernel/watchqueue/wqueue01.c
runtest/watchqueue new file +9 -0
@@ -0,0 +1,9 @@ +wqueue01 wqueue01 +wqueue02 wqueue02 +wqueue03 wqueue03 +wqueue04 wqueue04 +wqueue05 wqueue05 +wqueue06 wqueue06 +wqueue07 wqueue07 +wqueue08 wqueue08 +wqueue09 wqueue09
scenario_groups/default +1 -0
@@ -30,3 +30,4 @@ cve crypto kernel_misc uevent +watchqueue
testcases/kernel/Makefile +1 -0
@@ -38,6 +38,7 @@ SUBDIRS += connectors \ sound \ tracing \ uevents \ + watchqueue \ ifeq ($(WITH_POWER_MANAGEMENT_TESTSUITE),yes) SUBDIRS += power_management
testcases/kernel/watchqueue/.gitignore new file +9 -0
@@ -0,0 +1,9 @@ +wqueue01 +wqueue02 +wqueue03 +wqueue04 +wqueue05 +wqueue06 +wqueue07 +wqueue08 +wqueue09
testcases/kernel/watchqueue/Makefile new file +8 -0
@@ -0,0 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + +top_srcdir ?= ../../.. + +include $(top_srcdir)/include/mk/testcases.mk +include $(top_srcdir)/include/mk/generic_leaf_target.mk + +LDLIBS += $(KEYUTILS_LIBS)
testcases/kernel/watchqueue/common.h new file +149 -0
149 lines not on this page · raw message
testcases/kernel/watchqueue/wqueue01.c new file +40 -0
@@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2021 SUSE LLC Andrea Cervesato <[email protected]> +*/ + +/*\ +* [Description] +* +* Test if keyctl update is correctly recognized by watch queue. +*/ + +#include "tst_test.h" +#include "lapi/keyctl.h" +#include "common.h" + +static void saw_key_updated (struct watch_notification *n,size_t len,unsigned int wtype) +{ +if (wqueue_key_event (n, len, wtype,NOTIFY_KEY_UPDATED )) +tst_res (TPASS ,"keyctl update has been recognized" ); +else +tst_res (TFAIL ,"keyctl update has not been recognized" ); +} + +static void run (void ) +{ +int fd; +key_serial_t key; + + fd =wqueue_watch (256 , &wqueue_filter); + key =wqueue_add_key (fd); + +keyctl (KEYCTL_UPDATE , key,"b" ,1 ); +wqueue_consumer (fd, saw_key_updated); + +SAFE_CLOSE (fd); +} + +static struct tst_test test = { + .test_all = run, +};
Signature · 5 lines
2.34.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v4 03/11] Add wqueue01 test
Hi!
Quoted 22 lines
Signed-off-by Andrea Cervesato <[email protected]>--- runtest/watchqueue | 9 ++ scenario_groups/default | 1 + testcases/kernel/Makefile | 1 + testcases/kernel/watchqueue/.gitignore | 9 ++ testcases/kernel/watchqueue/Makefile | 8 ++ testcases/kernel/watchqueue/common.h | 149 +++++++++++++++++++++++++ testcases/kernel/watchqueue/wqueue01.c | 40 +++++++ 7 files changed, 217 insertions(+) create mode 100644 runtest/watchqueue create mode 100644 testcases/kernel/watchqueue/.gitignore create mode 100644 testcases/kernel/watchqueue/Makefile create mode 100644 testcases/kernel/watchqueue/common.h create mode 100644 testcases/kernel/watchqueue/wqueue01.cruntest/watchqueue new file +0
-0
runtest/watchqueue line 9
Quoted 9 lines
runtest/watchqueue new file +9
-0@@ -0,0 +1,9 @@ +wqueue01 wqueue01 +wqueue02 wqueue02 +wqueue03 wqueue03 +wqueue04 wqueue04 +wqueue05 wqueue05 +wqueue06 wqueue06 +wqueue07 wqueue07 +wqueue08 wqueue08 +wqueue09 wqueue09
While this is minor, such entries should be added with each respective test.
Quoted 27 lines
scenario_groups/default +1
-0@@ -30,3 +30,4 @@ cve crypto kernel_misc uevent +watchqueuetestcases/kernel/Makefile +1
-0@@ -38,6 +38,7 @@ SUBDIRS += connectors \ sound \ tracing \ uevents \ + watchqueue \ ifeq ($(WITH_POWER_MANAGEMENT_TESTSUITE),yes) SUBDIRS += power_managementtestcases/kernel/watchqueue/.gitignore new file +0
-0
testcases/kernel/watchqueue/.gitignore line 9
Quoted 9 lines
testcases/kernel/watchqueue/.gitignore new file +9
-0@@ -0,0 +1,9 @@ +wqueue01 +wqueue02 +wqueue03 +wqueue04 +wqueue05 +wqueue06 +wqueue07 +wqueue08 +wqueue09
Same here.
Quoted 107 lines
testcases/kernel/watchqueue/Makefile new file +8
-0@@ -0,0 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + +top_srcdir ?= ../../.. + +include $(top_srcdir)/include/mk/testcases.mk +include $(top_srcdir)/include/mk/generic_leaf_target.mk + +LDLIBS += $(KEYUTILS_LIBS)testcases/kernel/watchqueue/common.h new file +87
-0@@ -0,0 +1,149 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2021 SUSE LLC Andrea Cervesato <[email protected]> +*/ + +#ifndef WQUEUE_COMMON_H__ +#define WQUEUE_COMMON_H__ + +#include "tst_test.h" +#include "lapi/watch_queue.h" +#include "lapi/keyctl.h" + +static struct watch_notification_filter wqueue_filter = { + .nr_filters =2 , + .filters = { + [0 ] = { + .type =WATCH_TYPE_META , + .subtype_filter[0 ] =UINT_MAX , + }, + [1 ] = { + .type =WATCH_TYPE_KEY_NOTIFY , + .subtype_filter[0 ] =UINT_MAX , + }, + }, +}; + +static inline int wqueue_key_event (struct watch_notification *n,size_t len,unsigned int wtype,int type) +{ +struct key_notification *k; +const char * msg; + +if (wtype !=WATCH_TYPE_KEY_NOTIFY ) +return 0 ; + +if (len !=sizeof (struct key_notification )) +tst_brk (TBROK ,"Incorrect key message length" ); + +switch (n->subtype) { +case NOTIFY_KEY_INSTANTIATED : + msg ="instantiated" ; +break ; +case NOTIFY_KEY_UPDATED : + msg ="updated" ; +break ; +case NOTIFY_KEY_LINKED : + msg ="linked" ; +break ; +case NOTIFY_KEY_UNLINKED : + msg ="unlinked" ; +break ; +case NOTIFY_KEY_CLEARED : + msg ="cleared" ; +break ; +case NOTIFY_KEY_REVOKED : + msg ="revoked" ; +break ; +case NOTIFY_KEY_INVALIDATED : + msg ="invalidated" ; +break ; +case NOTIFY_KEY_SETATTR : + msg ="setattr" ; +break ; +default : + msg ="Invalid notification" ; +break ; + }; + + k = (struct key_notification *)n; +tst_res (TINFO ,"KEY %08x change=%u[%s] aux=%u" , + k->key_id, n->subtype, msg, k->aux); + +if (n->subtype == type) +return 1 ; + +return 0 ; +} + +static inline key_serial_t wqueue_add_key (int fd) +{ +key_serial_t key; + + key =add_key ("user" ,"ltptestkey" ,"a" ,1 ,KEY_SPEC_SESSION_KEYRING ); +if (key ==-1 ) +tst_brk (TBROK ,"add_key error: %s" ,tst_strerrno (errno)); + +keyctl (KEYCTL_WATCH_KEY , key, fd,0x01 ); +keyctl (KEYCTL_WATCH_KEY ,KEY_SPEC_SESSION_KEYRING , fd,0x02 );
testcases/kernel/watchqueue/common.h line 97
Quoted 10 lines
testcases/kernel/watchqueue/common.h new file +10
-0+ +return key; +} + +static inline int wqueue_watch (int buf_size,struct watch_notification_filter *filter) +{ +int pipefd[2 ]; +int fd; + +SAFE_PIPE2 (pipefd,O_NOTIFICATION_PIPE );
We can get two different errors here that should be translated to TCONF.
If you look at watch_queue.h in the linux kernel sources it looks like:
#ifdef CONFIG_WATCH_QUEUE
...
#else
static inline int watch_queue_init(struct pipe_inode_info *pipe)
{
return -ENOPKG;
}#endif
So in the case that CONFIG_WATCH_QUEUE is not set pipe2() with O_NOTIFICATION_PIPE will fail with errno set to ENOPKG.
And on kernels that are older than the watch queue implementation we will trip over:
if (flags & ~(O_CLOEXEC | O_NONBLOCK | O_DIRECT))
return -EINVAL;In the __do_pipe_flags() function and the call will fail with EINVAL instead.
So this code should look like:
TEST(pipe2(pipefd, O_NOTIFICATION_PIPE));
if (TST_RET) {
switch (TST_ERR) {
case ENOPKG:
tst_brk(TCONF | TTERRNO, "CONFIG_WATCH_QUEUE is not set");
break;
case EINVAL:
tst_brk(TCONF | TTERRNO, "O_NOTIFICATION_PIPE is not supported");
break;
default:
tst_brk(TBROK | TTERRNO, "pipe2() returned %ld", TST_RET);
}
}Quoted 103 lines
testcases/kernel/watchqueue/common.h new file +51
-0+ fd = pipefd[0 ]; + +SAFE_IOCTL (fd,IOC_WATCH_QUEUE_SET_SIZE , buf_size); +SAFE_IOCTL (fd,IOC_WATCH_QUEUE_SET_FILTER , filter); + +return fd; +} + +typedef void (*wqueue_callback ) (struct watch_notification *n,size_t len,unsigned int wtype); + +static void wqueue_consumer (int fd,wqueue_callback cb) +{ +unsigned char buffer[433 ], *p, *end; +union { +struct watch_notification n; +unsigned char buf1[128 ]; + } n; +ssize_t buf_len; + +tst_res (TINFO ,"Reading watch queue events" ); + + buf_len =SAFE_READ (0 , fd, buffer,sizeof (buffer)); + + p = buffer; + end = buffer + buf_len; +while (p < end) { +size_t largest, len; + + largest = end - p; +if (largest >128 ) + largest =128 ; + +if (largest <sizeof (struct watch_notification )) +tst_brk (TBROK ,"Short message header: %zu" , largest); + +memcpy (&n, p, largest); + +tst_res (TINFO ,"NOTIFY[%03zx]: ty=%06x sy=%02x i=%08x" , + p - buffer, n.n.type, n.n.subtype, n.n.info); + + len = n.n.info &WATCH_INFO_LENGTH ; +if (len <sizeof (n.n) || len > largest) +tst_brk (TBROK ,"Bad message length: %zu/%zu" , len, largest); + +cb (&n.n, len, n.n.type); + + p += len; + } +} + +#endif testcases/kernel/watchqueue/wqueue01.c new file +40
-0@@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2021 SUSE LLC Andrea Cervesato <[email protected]> +*/ + +/*\ +* [Description] +* +* Test if keyctl update is correctly recognized by watch queue. +*/ + +#include "tst_test.h" +#include "lapi/keyctl.h" +#include "common.h" + +static void saw_key_updated (struct watch_notification *n,size_t len,unsigned int wtype) +{ +if (wqueue_key_event (n, len, wtype,NOTIFY_KEY_UPDATED )) +tst_res (TPASS ,"keyctl update has been recognized" ); +else +tst_res (TFAIL ,"keyctl update has not been recognized" ); +} + +static void run (void ) +{ +int fd; +key_serial_t key; + + fd =wqueue_watch (256 , &wqueue_filter); + key =wqueue_add_key (fd); + +keyctl (KEYCTL_UPDATE , key,"b" ,1 ); +wqueue_consumer (fd, saw_key_updated); + +SAFE_CLOSE (fd); +} + +static struct tst_test test = { + .test_all = run, +};Signature · 5 lines
2.34.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v4 4/11 Add wqueue02 test
In reply to Andrea CervesatoThis test is testing NOTIFY_KEY_UNLINKED event
--- testcases/kernel/watchqueue/wqueue02.c | 40 ++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 testcases/kernel/watchqueue/wqueue02.c
testcases/kernel/watchqueue/wqueue02.c new file +40 -0
@@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2021 SUSE LLC Andrea Cervesato <[email protected]> +*/ + +/*\ +* [Description] +* +* Test if keyctl unlink is correctly recognized by watch queue. +*/ + +#include "tst_test.h" +#include "lapi/keyctl.h" +#include "common.h" + +static void saw_key_unlinked (struct watch_notification *n,size_t len,unsigned int wtype) +{ +if (wqueue_key_event (n, len, wtype,NOTIFY_KEY_UNLINKED )) +tst_res (TPASS ,"keyctl unlink has been recognized" ); +else +tst_res (TFAIL ,"keyctl unlink has not been recognized" ); +} + +static void run (void ) +{ +int fd; +key_serial_t key; + + fd =wqueue_watch (256 , &wqueue_filter); + key =wqueue_add_key (fd); + +keyctl (KEYCTL_UNLINK , key,KEY_SPEC_SESSION_KEYRING ); +wqueue_consumer (fd, saw_key_unlinked); + +SAFE_CLOSE (fd); +} + +static struct tst_test test = { + .test_all = run, +};
Signature · 5 lines
2.34.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v4 5/11 Add wqueue03 test
In reply to Andrea CervesatoThis test is testing NOTIFY_KEY_REVOKED event
--- testcases/kernel/watchqueue/wqueue03.c | 40 ++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 testcases/kernel/watchqueue/wqueue03.c
testcases/kernel/watchqueue/wqueue03.c new file +40 -0
@@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2021 SUSE LLC Andrea Cervesato <[email protected]> +*/ + +/*\ +* [Description] +* +* Test if keyctl revoke is correctly recognized by watch queue. +*/ + +#include "tst_test.h" +#include "lapi/keyctl.h" +#include "common.h" + +static void saw_key_revoked (struct watch_notification *n,size_t len,unsigned int wtype) +{ +if (wqueue_key_event (n, len, wtype,NOTIFY_KEY_REVOKED )) +tst_res (TPASS ,"keyctl revoke has been recognized" ); +else +tst_res (TFAIL ,"keyctl revoke has not been recognized" ); +} + +static void run (void ) +{ +int fd; +key_serial_t key; + + fd =wqueue_watch (256 , &wqueue_filter); + key =wqueue_add_key (fd); + +keyctl (KEYCTL_REVOKE , key); +wqueue_consumer (fd, saw_key_revoked); + +SAFE_CLOSE (fd); +} + +static struct tst_test test = { + .test_all = run, +};
Signature · 5 lines
2.34.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v4 6/11 Add wqueue04 test
In reply to Andrea CervesatoThis test is testing NOTIFY_KEY_LINKED event
--- testcases/kernel/watchqueue/wqueue04.c | 40 ++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 testcases/kernel/watchqueue/wqueue04.c
testcases/kernel/watchqueue/wqueue04.c new file +40 -0
@@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2021 SUSE LLC Andrea Cervesato <[email protected]> +*/ + +/*\ +* [Description] +* +* Test if keyctl link is correctly recognized by watch queue. +*/ + +#include "tst_test.h" +#include "lapi/keyctl.h" +#include "common.h" + +static void saw_key_linked (struct watch_notification *n,size_t len,unsigned int wtype) +{ +if (wqueue_key_event (n, len, wtype,NOTIFY_KEY_LINKED )) +tst_res (TPASS ,"keyctl link has been recognized" ); +else +tst_res (TFAIL ,"keyctl link has not been recognized" ); +} + +static void run (void ) +{ +int fd; +key_serial_t key; + + fd =wqueue_watch (256 , &wqueue_filter); + key =wqueue_add_key (fd); + +keyctl (KEYCTL_LINK , key,KEY_SPEC_SESSION_KEYRING ); +wqueue_consumer (fd, saw_key_linked); + +SAFE_CLOSE (fd); +} + +static struct tst_test test = { + .test_all = run, +};
Signature · 5 lines
2.34.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v4 7/11 Add wqueue05 test
In reply to Andrea CervesatoThis test is testing NOTIFY_KEY_INVALIDATED event
--- testcases/kernel/watchqueue/wqueue05.c | 40 ++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 testcases/kernel/watchqueue/wqueue05.c
testcases/kernel/watchqueue/wqueue05.c new file +40 -0
@@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2021 SUSE LLC Andrea Cervesato <[email protected]> +*/ + +/*\ +* [Description] +* +* Test if keyctl invalidate is correctly recognized by watch queue. +*/ + +#include "tst_test.h" +#include "lapi/keyctl.h" +#include "common.h" + +static void saw_key_invalidated (struct watch_notification *n,size_t len,unsigned int wtype) +{ +if (wqueue_key_event (n, len, wtype,NOTIFY_KEY_INVALIDATED )) +tst_res (TPASS ,"keyctl invalidate has been recognized" ); +else +tst_res (TFAIL ,"keyctl invalidate has not been recognized" ); +} + +static void run (void ) +{ +int fd; +key_serial_t key; + + fd =wqueue_watch (256 , &wqueue_filter); + key =wqueue_add_key (fd); + +keyctl (KEYCTL_INVALIDATE , key); +wqueue_consumer (fd, saw_key_invalidated); + +SAFE_CLOSE (fd); +} + +static struct tst_test test = { + .test_all = run, +};
Signature · 5 lines
2.34.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v4 8/11 Add wqueue06 test
In reply to Andrea CervesatoThis test is testing NOTIFY_KEY_CLEARED event
--- testcases/kernel/watchqueue/wqueue06.c | 39 ++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 testcases/kernel/watchqueue/wqueue06.c
testcases/kernel/watchqueue/wqueue06.c new file +39 -0
@@ -0,0 +1,39 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2021 SUSE LLC Andrea Cervesato <[email protected]> +*/ + +/*\ +* [Description] +* +* Test if keyctl clear is correctly recognized by watch queue. +*/ + +#include "tst_test.h" +#include "lapi/keyctl.h" +#include "common.h" + +static void saw_key_cleared (struct watch_notification *n,size_t len,unsigned int wtype) +{ +if (wqueue_key_event (n, len, wtype,NOTIFY_KEY_CLEARED )) +tst_res (TPASS ,"keyctl clear has been recognized" ); +else +tst_res (TFAIL ,"keyctl clear has not been recognized" ); +} + +static void run (void ) +{ +int fd; + + fd =wqueue_watch (256 , &wqueue_filter); +wqueue_add_key (fd); + +keyctl (KEYCTL_CLEAR ,KEY_SPEC_SESSION_KEYRING ); +wqueue_consumer (fd, saw_key_cleared); + +SAFE_CLOSE (fd); +} + +static struct tst_test test = { + .test_all = run, +};
Signature · 5 lines
2.34.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v4 9/11 Add wqueue07 test
In reply to Andrea CervesatoThis test is testing NOTIFY_KEY_SETATTR event
--- testcases/kernel/watchqueue/wqueue07.c | 40 ++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 testcases/kernel/watchqueue/wqueue07.c
testcases/kernel/watchqueue/wqueue07.c new file +40 -0
@@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2021 SUSE LLC Andrea Cervesato <[email protected]> +*/ + +/*\ +* [Description] +* +* Test if keyctl setperm is correctly recognized by watch queue. +*/ + +#include "tst_test.h" +#include "lapi/keyctl.h" +#include "common.h" + +static void saw_key_setattr (struct watch_notification *n,size_t len,unsigned int wtype) +{ +if (wqueue_key_event (n, len, wtype,NOTIFY_KEY_SETATTR )) +tst_res (TPASS ,"keyctl setattr has been recognized" ); +else +tst_res (TFAIL ,"keyctl setattr has not been recognized" ); +} + +static void run (void ) +{ +int fd; +key_serial_t key; + + fd =wqueue_watch (256 , &wqueue_filter); + key =wqueue_add_key (fd); + +keyctl (KEYCTL_SETPERM , key,KEY_POS_ALL |KEY_USR_ALL ); +wqueue_consumer (fd, saw_key_setattr); + +SAFE_CLOSE (fd); +} + +static struct tst_test test = { + .test_all = run, +};
Signature · 5 lines
2.34.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v4 10/11 Add wqueue08 test
In reply to Andrea CervesatoThis test is testing WATCH_META_REMOVAL_NOTIFICATION event
--- testcases/kernel/watchqueue/wqueue08.c | 44 ++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 testcases/kernel/watchqueue/wqueue08.c
testcases/kernel/watchqueue/wqueue08.c new file +44 -0
@@ -0,0 +1,44 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2021 SUSE LLC Andrea Cervesato <[email protected]> +*/ + +/*\ +* [Description] +* +* Test if key watch removal is correctly recognized by watch queue. +*/ + +#include "tst_test.h" +#include "lapi/keyctl.h" +#include "common.h" + +static void saw_watch_removal(struct watch_notification *n, LTP_ATTRIBUTE_UNUSED size_t len, unsigned int wtype) +{ +if (wtype !=WATCH_TYPE_META ) +return ; + +if (n->subtype ==WATCH_META_REMOVAL_NOTIFICATION ) +tst_res (TPASS ,"Meta removal notification received" ); +else +tst_res (TFAIL ,"Event not recognized" ); +} + +static void run (void ) +{ +int fd; +key_serial_t key; + + fd =wqueue_watch (256 , &wqueue_filter); + key =wqueue_add_key (fd); + +/* if watch_id = -1 key is removed from the watch queue */ +keyctl (KEYCTL_WATCH_KEY , key, fd,-1 ); +wqueue_consumer (fd, saw_watch_removal); + +SAFE_CLOSE (fd); +} + +static struct tst_test test = { + .test_all = run, +};
Signature · 5 lines
2.34.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v4 11/11 Add wqueue09 test
In reply to Andrea CervesatoThis test is testing WATCH_META_LOSS_NOTIFICATION event
--- testcases/kernel/watchqueue/wqueue09.c | 52 ++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 testcases/kernel/watchqueue/wqueue09.c
testcases/kernel/watchqueue/wqueue09.c new file +52 -0
@@ -0,0 +1,52 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2021 SUSE LLC Andrea Cervesato <[email protected]> +*/ + +/*\ +* [Description] +* +* Fill the watch queue and wait for a notification loss. +*/ + +#include "tst_test.h" +#include "lapi/keyctl.h" +#include "common.h" + +static int data_lost; + +static void saw_data_loss(struct watch_notification *n, LTP_ATTRIBUTE_UNUSED size_t len, unsigned int wtype) +{ +if (wtype !=WATCH_TYPE_META ) +return ; + +if (n->subtype ==WATCH_META_LOSS_NOTIFICATION ) + data_lost =1 ; +} + +static void run (void ) +{ +int fd; +key_serial_t key; + + fd =wqueue_watch (1 , &wqueue_filter); + + key =wqueue_add_key (fd); +keyctl (KEYCTL_UPDATE , key,"b" ,1 ); +keyctl (KEYCTL_REVOKE , key); + + data_lost =0 ; +while (!data_lost) +wqueue_consumer (fd, saw_data_loss); + +SAFE_CLOSE (fd); + +if (data_lost) +tst_res (TPASS ,"Meta loss notification received" ); +else +tst_res (TFAIL ,"Event not recognized" ); +} + +static struct tst_test test = { + .test_all = run, +};
Signature · 5 lines
2.34.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp