Skip to content
This repository has been archived by the owner on Jul 8, 2024. It is now read-only.

Commit

Permalink
use --retval-file option in handler tests
Browse files Browse the repository at this point in the history
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.)
  • Loading branch information
chrisd8088 committed Feb 12, 2019
1 parent 4e31fff commit ab4ed50
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 24 deletions.
4 changes: 3 additions & 1 deletion t/t200-event-ok.t
Original file line number Diff line number Diff line change
Expand Up @@ -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' '
Expand Down Expand Up @@ -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' '
Expand Down
4 changes: 3 additions & 1 deletion t/t201-event-err.t
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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' '
Expand Down
4 changes: 3 additions & 1 deletion t/t202-event-deny.t
Original file line number Diff line number Diff line change
Expand Up @@ -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' '
Expand All @@ -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' '
Expand Down
4 changes: 3 additions & 1 deletion t/t203-event-null.t
Original file line number Diff line number Diff line change
Expand Up @@ -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' '
Expand All @@ -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' '
Expand Down
4 changes: 3 additions & 1 deletion t/t204-event-allow.t
Original file line number Diff line number Diff line change
Expand Up @@ -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' '
Expand All @@ -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' '
Expand Down
4 changes: 3 additions & 1 deletion t/t700-vfs-event-ok.t
Original file line number Diff line number Diff line change
Expand Up @@ -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' '
Expand Down Expand Up @@ -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' '
Expand Down
4 changes: 3 additions & 1 deletion t/t701-vfs-event-err.t
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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' '
Expand Down
4 changes: 3 additions & 1 deletion t/t702-vfs-event-deny.t
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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' '
Expand Down
4 changes: 3 additions & 1 deletion t/t703-vfs-event-null.t
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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' '
Expand Down
4 changes: 3 additions & 1 deletion t/t704-vfs-event-allow.t
Original file line number Diff line number Diff line change
Expand Up @@ -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' '
Expand All @@ -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' '
Expand Down
21 changes: 14 additions & 7 deletions t/test_projfs_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
23 changes: 16 additions & 7 deletions t/test_vfsapi_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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));
Expand Down

0 comments on commit ab4ed50

Please sign in to comment.