Fanotify tests for v5.19-rc5
v2 cover Fanotify tests for v5.19-rc5
Hi Petr,
This updates the tests to validate the current ENOTDIR behavior of fanotify that was merged for v5.19-rc5 and v5.18.10.
This is a retroactive change for APIs FAN_REPORT_TARGET_FID and FAN_RENAME introduced in v5.17.
The current upstream behavior is already documented in man pages [1].
Thanks,
Amir.
Changes since v1:
- Split comment in generic code to per test case comment
- Added RVB and Tested-by
[1] https://lore.kernel.org/linux-man/[email protected]/
Amir Goldstein (2):
syscalls/fanotify14: Encode the expected errno in test case syscalls/fanotify14: Add test cases for events not allowed on non-dir
testcases/kernel/syscalls/fanotify/fanotify.h | 4 +- .../kernel/syscalls/fanotify/fanotify14.c | 117 +++++++++++++----- 2 files changed, 92 insertions(+), 29 deletions(-)
Signature · 5 lines
2.25.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 1/2 syscalls/fanotify14: Encode the expected errno in test case
So we can add test cases for errors other than EINVAL. Move comments from generic code to per test case.
--- .../kernel/syscalls/fanotify/fanotify14.c | 46 ++++++++----------- 1 file changed, 20 insertions(+), 26 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify14.c +20 -26
@@ -41,38 +41,43 @@ static struct test_case_t {unsigned int init_flags;unsigned int mark_flags;unsigned long long mask; +int expected_errno; } test_cases[] = { { - FAN_CLASS_CONTENT | FAN_REPORT_FID, 0, 0 + /* FAN_REPORT_FID without class FAN_CLASS_NOTIF is not valid */ + FAN_CLASS_CONTENT | FAN_REPORT_FID, 0, 0, EINVAL }, { - FAN_CLASS_PRE_CONTENT | FAN_REPORT_FID, 0, 0 + /* FAN_REPORT_FID without class FAN_CLASS_NOTIF is not valid */ + FAN_CLASS_PRE_CONTENT | FAN_REPORT_FID, 0, 0, EINVAL }, { - FAN_CLASS_NOTIF, 0, INODE_EVENTS + /* INODE_EVENTS in mask without class FAN_REPORT_FID are not valid */ + FAN_CLASS_NOTIF, 0, INODE_EVENTS, EINVAL }, { - FAN_CLASS_NOTIF | FAN_REPORT_FID, FAN_MARK_MOUNT, INODE_EVENTS + /* INODE_EVENTS in mask with FAN_MARK_MOUNT are not valid */ + FAN_CLASS_NOTIF | FAN_REPORT_FID, FAN_MARK_MOUNT, INODE_EVENTS, EINVAL }, { /* FAN_REPORT_NAME without FAN_REPORT_DIR_FID is not valid */ - FAN_CLASS_NOTIF | FAN_REPORT_NAME, 0, 0 + FAN_CLASS_NOTIF | FAN_REPORT_NAME, 0, 0, EINVAL }, { /* FAN_REPORT_NAME without FAN_REPORT_DIR_FID is not valid */ - FAN_CLASS_NOTIF | FAN_REPORT_FID | FAN_REPORT_NAME, 0, 0 + FAN_CLASS_NOTIF | FAN_REPORT_FID | FAN_REPORT_NAME, 0, 0, EINVAL }, { /* FAN_REPORT_TARGET_FID without FAN_REPORT_FID is not valid */ - FAN_CLASS_NOTIF | FAN_REPORT_TARGET_FID | FAN_REPORT_DFID_NAME, 0, 0 + FAN_CLASS_NOTIF | FAN_REPORT_TARGET_FID | FAN_REPORT_DFID_NAME, 0, 0, EINVAL }, { /* FAN_REPORT_TARGET_FID without FAN_REPORT_NAME is not valid */ - FAN_CLASS_NOTIF | FAN_REPORT_TARGET_FID | FAN_REPORT_DFID_FID, 0, 0 + FAN_CLASS_NOTIF | FAN_REPORT_TARGET_FID | FAN_REPORT_DFID_FID, 0, 0, EINVAL }, { /* FAN_RENAME without FAN_REPORT_NAME is not valid */ - FAN_CLASS_NOTIF | FAN_REPORT_DFID_FID, 0, FAN_RENAME + FAN_CLASS_NOTIF | FAN_REPORT_DFID_FID, 0, FAN_RENAME, EINVAL }, };
@@ -83,17 +88,12 @@ static void do_test(unsigned int number) fanotify_fd =fanotify_init (tc->init_flags,O_RDONLY );if (fanotify_fd <0 ) { -/* -* EINVAL is to be returned to the calling process when -* an invalid notification class is specified in -* conjunction with FAN_REPORT_FID. -*/ -if (errno ==EINVAL ) { +if (errno == tc->expected_errno) {tst_res (TPASS ,"fanotify_fd=%d, fanotify_init(%x, O_RDONLY) " -"failed with error EINVAL as expected" , +"failed with error %d as expected" , fanotify_fd, - tc->init_flags); + tc->init_flags, tc->expected_errno);return ; } tst_brk(TBROK | TERRNO,
@@ -120,22 +120,16 @@ static void do_test(unsigned int number) ret =fanotify_mark (fanotify_fd,FAN_MARK_ADD | tc->mark_flags, tc->mask,AT_FDCWD ,FILE1 );if (ret <0 ) { -/* -* EINVAL is to be returned to the calling process when -* attempting to use INODE_EVENTS without FAN_REPORT_FID -* specified on the notification group, or using -* INODE_EVENTS with mark type FAN_MARK_MOUNT. -*/ -if (errno ==EINVAL ) { +if (errno == tc->expected_errno) {tst_res (TPASS ,"ret=%d, fanotify_mark(%d, FAN_MARK_ADD | %x, " -"%llx, AT_FDCWD, %s) failed with error EINVAL " +"%llx, AT_FDCWD, %s) failed with error %d " "as expected" , ret, fanotify_fd, tc->mark_flags, tc->mask, -FILE1 ); +FILE1 , tc->expected_errno); goto out; } tst_brk(TBROK | TERRNO,
Signature · 5 lines
2.25.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 2/2 syscalls/fanotify14: Add test cases for events not allowed on non-dir
In reply to Amir GoldsteinDirent events are meaningless in mask of non-dir inode and so do the flags FAN_ONDIR FAN_EVENT_ON_CHILD.
With fanotify_init flag FAN_REPORT_TARGET_FID, they are also not allowed. Make sure that trying to add them to non-dir inode mark mask results in ENOTDIR error and that trying to add them to directory or filesystem mark does not fail.
Also add validity check for legacy FAN_MARK_ONLYDIR and add more information to error when safe_fanotify_mark() fails.
--- testcases/kernel/syscalls/fanotify/fanotify.h | 4 +- .../kernel/syscalls/fanotify/fanotify14.c | 73 ++++++++++++++++++- 2 files changed, 73 insertions(+), 4 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify.h +3 -1
@@ -48,7 +48,9 @@ static inline int safe_fanotify_mark(const char *file, const int lineno, rval =fanotify_mark (fd, flags, mask, dfd, pathname);if (rval ==-1 ) { -tst_brk_ (file, lineno,TBROK |TERRNO ,"fanotify_mark() failed" ); +tst_brk_ (file, lineno,TBROK |TERRNO , +"fanotify_mark(%d, 0x%x, 0x%lx, ..., %s) failed" , + fd, flags, mask, pathname); }if (rval <-1 ) {
testcases/kernel/syscalls/fanotify/fanotify14.c +70 -3
122 lines not on this page · raw message
Signature · 5 lines
2.25.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Amir,
thanks a lot for v2, merged.
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp