From ab4ed504a58f192dc6b6bc815e58c0f5afb913ce Mon Sep 17 00:00:00 2001 From: Chris Darroch Date: Mon, 11 Feb 2019 21:40:59 -0800 Subject: [PATCH] use --retval-file option in handler tests When the file specified with --retval-file exists, the test handlers log messages on each event; when the file does not exist, no messages are output from the test handlers. This commit has no functional change on the test suite, but once we add test handlers for projection events, we will need to toggle test handler output on and off, or else initial projection events triggered by external system processes may interfere with our tests. (If additional control proves necessary in the future, we can also add a list of valid process names or process groups to the control file and then only report handler events corresponding to those processes.) --- t/t200-event-ok.t | 4 +++- t/t201-event-err.t | 4 +++- t/t202-event-deny.t | 4 +++- t/t203-event-null.t | 4 +++- t/t204-event-allow.t | 4 +++- t/t700-vfs-event-ok.t | 4 +++- t/t701-vfs-event-err.t | 4 +++- t/t702-vfs-event-deny.t | 4 +++- t/t703-vfs-event-null.t | 4 +++- t/t704-vfs-event-allow.t | 4 +++- t/test_projfs_handlers.c | 21 ++++++++++++++------- t/test_vfsapi_handlers.c | 23 ++++++++++++++++------- 12 files changed, 60 insertions(+), 24 deletions(-) diff --git a/t/t200-event-ok.t b/t/t200-event-ok.t index 726701a..904497b 100755 --- a/t/t200-event-ok.t +++ b/t/t200-event-ok.t @@ -24,7 +24,8 @@ events are received and handled correctly. . ./test-lib.sh . "$TEST_DIRECTORY"/test-lib-event.sh -projfs_start test_projfs_handlers source target || exit 1 +projfs_start test_projfs_handlers source target --retval-file retval || exit 1 +touch retval projfs_event_printf notify create_dir d1 test_expect_success 'test event handler on parent directory creation' ' @@ -76,6 +77,7 @@ test_expect_success 'test permission granted on parent directory deletion' ' test_path_is_missing target/d1 ' +rm retval projfs_stop || exit 1 test_expect_success 'check all event notifications' ' diff --git a/t/t201-event-err.t b/t/t201-event-err.t index 5ddfe75..b37f7e5 100755 --- a/t/t201-event-err.t +++ b/t/t201-event-err.t @@ -24,7 +24,8 @@ events respond to handler errors. . ./test-lib.sh . "$TEST_DIRECTORY"/test-lib-event.sh -projfs_start test_projfs_handlers source target --retval ENOMEM || exit 1 +projfs_start test_projfs_handlers source target --retval-file retval || exit 1 +echo ENOMEM > retval # TODO: we expect mkdir to create a dir despite the handler error and # regardless of mkdir's failure exit code @@ -54,6 +55,7 @@ test_expect_success 'test event handler error on directory deletion' ' test_path_is_dir target/d1 ' +rm retval projfs_stop || exit 1 test_expect_success 'check all event notifications' ' diff --git a/t/t202-event-deny.t b/t/t202-event-deny.t index 76d2b6f..cfc77a2 100755 --- a/t/t202-event-deny.t +++ b/t/t202-event-deny.t @@ -24,7 +24,8 @@ denial responses from event handlers. . ./test-lib.sh . "$TEST_DIRECTORY"/test-lib-event.sh -projfs_start test_projfs_handlers source target --retval deny || exit 1 +projfs_start test_projfs_handlers source target --retval-file retval || exit 1 +echo deny > retval projfs_event_printf notify create_dir d1 test_expect_success 'test event handler on directory creation' ' @@ -50,6 +51,7 @@ test_expect_success 'test permission request denied on directory deletion' ' test_path_is_dir target/d1 ' +rm retval projfs_stop || exit 1 test_expect_success 'check all event notifications' ' diff --git a/t/t203-event-null.t b/t/t203-event-null.t index ccf875a..2084982 100755 --- a/t/t203-event-null.t +++ b/t/t203-event-null.t @@ -24,7 +24,8 @@ denial responses caused by event handlers returning null. . ./test-lib.sh . "$TEST_DIRECTORY"/test-lib-event.sh -projfs_start test_projfs_handlers source target --retval null || exit 1 +projfs_start test_projfs_handlers source target --retval-file retval || exit 1 +echo null > retval projfs_event_printf notify create_dir d1 test_expect_success 'test event handler on directory creation' ' @@ -50,6 +51,7 @@ test_expect_success 'test permission request denied on directory deletion' ' test_path_is_dir target/d1 ' +rm retval projfs_stop || exit 1 test_expect_success 'check all event notifications' ' diff --git a/t/t204-event-allow.t b/t/t204-event-allow.t index 91a6f15..97aef6c 100755 --- a/t/t204-event-allow.t +++ b/t/t204-event-allow.t @@ -24,7 +24,8 @@ explicit allowed responses from event handlers. . ./test-lib.sh . "$TEST_DIRECTORY"/test-lib-event.sh -projfs_start test_projfs_handlers source target --retval allow || exit 1 +projfs_start test_projfs_handlers source target --retval-file retval || exit 1 +echo allow > retval projfs_event_printf notify create_dir d1 test_expect_success 'test event handler on directory creation' ' @@ -50,6 +51,7 @@ test_expect_success 'test permission request allowed on directory deletion' ' test_path_is_missing target/d1 ' +rm retval projfs_stop || exit 1 test_expect_success 'check all event notifications' ' diff --git a/t/t700-vfs-event-ok.t b/t/t700-vfs-event-ok.t index ce24791..ccfaf82 100755 --- a/t/t700-vfs-event-ok.t +++ b/t/t700-vfs-event-ok.t @@ -24,7 +24,8 @@ events are received and handled correctly through the VFS API. . ./test-lib.sh . "$TEST_DIRECTORY"/test-lib-event.sh -projfs_start test_vfsapi_handlers source target || exit 1 +projfs_start test_vfsapi_handlers source target --retval-file retval || exit 1 +touch retval projfs_event_printf vfs create_dir d1 test_expect_success 'test event handler on parent directory creation' ' @@ -76,6 +77,7 @@ test_expect_success 'test permission granted on parent directory deletion' ' test_path_is_missing target/d1 ' +rm retval projfs_stop || exit 1 test_expect_success 'check all event notifications' ' diff --git a/t/t701-vfs-event-err.t b/t/t701-vfs-event-err.t index b1c01a2..cbd2f03 100755 --- a/t/t701-vfs-event-err.t +++ b/t/t701-vfs-event-err.t @@ -24,7 +24,8 @@ events respond to handler errors through the VFS API. . ./test-lib.sh . "$TEST_DIRECTORY"/test-lib-event.sh -projfs_start test_vfsapi_handlers source target --retval EOutOfMemory || exit 1 +projfs_start test_vfsapi_handlers source target --retval-file retval || exit 1 +echo EOutOfMemory > retval # TODO: we expect mkdir to create a dir despite the handler error and # regardless of mkdir's failure exit code @@ -54,6 +55,7 @@ test_expect_success 'test event handler error on directory deletion' ' test_path_is_dir target/d1 ' +rm retval projfs_stop || exit 1 test_expect_success 'check all event notifications' ' diff --git a/t/t702-vfs-event-deny.t b/t/t702-vfs-event-deny.t index 6f5f616..e3ea493 100755 --- a/t/t702-vfs-event-deny.t +++ b/t/t702-vfs-event-deny.t @@ -24,7 +24,8 @@ denial responses from event handlers through the VFS API. . ./test-lib.sh . "$TEST_DIRECTORY"/test-lib-event.sh -projfs_start test_vfsapi_handlers source target --retval deny || exit 1 +projfs_start test_vfsapi_handlers source target --retval-file retval || exit 1 +echo deny > retval # TODO: test_vfsapi_handlers always returns EPERM with --retval deny, unlike # test_projfs_handlers, so mkdir gets a handler error; like t701.1, @@ -58,6 +59,7 @@ test_expect_success 'test permission request denied on directory deletion' ' test_path_is_dir target/d1 ' +rm retval projfs_stop || exit 1 test_expect_success 'check all event notifications' ' diff --git a/t/t703-vfs-event-null.t b/t/t703-vfs-event-null.t index 4b80996..ed589e5 100755 --- a/t/t703-vfs-event-null.t +++ b/t/t703-vfs-event-null.t @@ -25,7 +25,8 @@ the VFS API. . ./test-lib.sh . "$TEST_DIRECTORY"/test-lib-event.sh -projfs_start test_vfsapi_handlers source target --retval null || exit 1 +projfs_start test_vfsapi_handlers source target --retval-file retval || exit 1 +echo null > retval # TODO: test_vfsapi_handlers always returns EINVAL with --retval null, unlike # test_projfs_handlers, so mkdir sees a handler error; like t701.1, @@ -59,6 +60,7 @@ test_expect_success 'test permission request denied on directory deletion' ' test_path_is_dir target/d1 ' +rm retval projfs_stop || exit 1 test_expect_success 'check all event notifications' ' diff --git a/t/t704-vfs-event-allow.t b/t/t704-vfs-event-allow.t index 0e9421d..c8100fd 100755 --- a/t/t704-vfs-event-allow.t +++ b/t/t704-vfs-event-allow.t @@ -24,7 +24,8 @@ explicit allowed responses from event handlers through the VFS API. . ./test-lib.sh . "$TEST_DIRECTORY"/test-lib-event.sh -projfs_start test_vfsapi_handlers source target --retval allow || exit 1 +projfs_start test_vfsapi_handlers source target --retval-file retval || exit 1 +echo allow > retval projfs_event_printf vfs create_dir d1 test_expect_success 'test event handler on directory creation' ' @@ -50,6 +51,7 @@ test_expect_success 'test permission request allowed on directory deletion' ' test_path_is_missing target/d1 ' +rm retval projfs_stop || exit 1 test_expect_success 'check all event notifications' ' diff --git a/t/test_projfs_handlers.c b/t/test_projfs_handlers.c index 838a625..482d825 100644 --- a/t/test_projfs_handlers.c +++ b/t/test_projfs_handlers.c @@ -28,15 +28,21 @@ static int test_handle_event(struct projfs_event *event, const char *desc, int perm) { - unsigned int ret_flags; + unsigned int opt_flags, ret_flags; + const char *retfile; int ret; - printf(" test %s for %s: " - "0x%04" PRIx64 "-%08" PRIx64 ", %d\n", - desc, event->path, - event->mask >> 32, event->mask & 0xFFFFFFFF, event->pid); + opt_flags = test_get_opts((TEST_OPT_RETVAL | TEST_OPT_RETFILE), + &ret, &ret_flags, &retfile); - test_get_opts(TEST_OPT_RETVAL, &ret, &ret_flags); + if ((opt_flags & TEST_OPT_RETFILE) == TEST_OPT_NONE || + (ret_flags & TEST_FILE_EXIST) != TEST_FILE_NONE) { + printf(" test %s for %s: " + "0x%04" PRIx64 "-%08" PRIx64 ", %d\n", + desc, event->path, + event->mask >> 32, event->mask & 0xFFFFFFFF, + event->pid); + } if ((ret_flags & TEST_VAL_SET) == TEST_VAL_UNSET) ret = perm ? PROJFS_ALLOW : 0; @@ -62,7 +68,8 @@ int main(int argc, char *const argv[]) struct projfs *fs; struct projfs_handlers handlers = { 0 }; - test_parse_mount_opts(argc, argv, TEST_OPT_RETVAL, + test_parse_mount_opts(argc, argv, + (TEST_OPT_RETVAL | TEST_OPT_RETFILE), &lower_path, &mount_path); handlers.handle_notify_event = &test_notify_event; diff --git a/t/test_vfsapi_handlers.c b/t/test_vfsapi_handlers.c index 231f9de..9826cac 100644 --- a/t/test_vfsapi_handlers.c +++ b/t/test_vfsapi_handlers.c @@ -39,20 +39,27 @@ static PrjFS_Result TestNotifyOperation( _In_ const char* destinationRelativePath ) { - unsigned int ret_flags; + unsigned int opt_flags, ret_flags; + const char *retfile; int ret; - printf(" TestNotifyOperation for %s: %d, %s, %hhd, 0x%08X\n", - relativePath, triggeringProcessId, triggeringProcessName, - isDirectory, notificationType); + opt_flags = test_get_opts((TEST_OPT_VFSAPI | TEST_OPT_RETVAL + | TEST_OPT_RETFILE), + &ret, &ret_flags, &retfile); + + if ((opt_flags & TEST_OPT_RETFILE) == TEST_OPT_NONE || + (ret_flags & TEST_FILE_EXIST) != TEST_FILE_NONE) { + printf(" TestNotifyOperation for %s: %d, %s, %hhd, 0x%08X\n", + relativePath, + triggeringProcessId, triggeringProcessName, + isDirectory, notificationType); + } (void)commandId; // prevent compiler warnings (void)providerId; (void)contentId; (void)destinationRelativePath; - test_get_opts((TEST_OPT_VFSAPI | TEST_OPT_RETVAL), &ret, &ret_flags); - if ((ret_flags & TEST_VAL_SET) == TEST_VAL_UNSET) ret = PrjFS_Result_Success; @@ -65,7 +72,9 @@ int main(int argc, char *const argv[]) PrjFS_MountHandle *handle; PrjFS_Callbacks callbacks = { 0 }; - test_parse_mount_opts(argc, argv, (TEST_OPT_VFSAPI | TEST_OPT_RETVAL), + test_parse_mount_opts(argc, argv, + (TEST_OPT_VFSAPI | TEST_OPT_RETVAL + | TEST_OPT_RETFILE), &lower_path, &mount_path); memset(&callbacks, 0, sizeof(PrjFS_Callbacks));