Skip to content

Commit

Permalink
cleanup(libsinsp_e2e): sys_call_test.cpp cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Roberto Scolaro <[email protected]>
  • Loading branch information
therealbobo committed Mar 20, 2024
1 parent 955c31a commit 8f07331
Showing 1 changed file with 44 additions and 36 deletions.
80 changes: 44 additions & 36 deletions test/libsinsp_e2e/sys_call_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ TEST_F(sys_call_test, open_close_dropping)
{
int callnum = 0;

before_open_t setup = [&](sinsp* inspector)
{
inspector->start_dropping_mode(1);
};

event_filter_t filter = [&](sinsp_evt* evt)
{
return (0 == strcmp(evt->get_name(), "open") || 0 == strcmp(evt->get_name(), "openat") ||
Expand All @@ -158,16 +163,8 @@ TEST_F(sys_call_test, open_close_dropping)

run_callback_t test = [](concurrent_object_handle<sinsp> inspector_handle)
{
{
std::scoped_lock inspector_handle_lock(inspector_handle);
inspector_handle->start_dropping_mode(1);
}
int fd = open("/tmp", O_RDONLY);
close(fd);
{
std::scoped_lock inspector_handle_lock(inspector_handle);
inspector_handle->stop_dropping_mode();
}
};

captured_event_callback_t callback = [&](const callback_param& param)
Expand All @@ -181,7 +178,12 @@ TEST_F(sys_call_test, open_close_dropping)
callnum++;
};

ASSERT_NO_FATAL_FAILURE({ event_capture::run(test, callback, filter); });
before_close_t cleanup = [&](sinsp* inspector)
{
inspector->stop_dropping_mode();
};

ASSERT_NO_FATAL_FAILURE({ event_capture::run(test, callback, filter, setup, cleanup); });
EXPECT_EQ(4, callnum);
}

Expand All @@ -206,27 +208,29 @@ TEST_F(sys_call_test, fcntl_getfd_dropping)
{
int callnum = 0;

before_open_t setup = [&](sinsp* inspector)
{
inspector->start_dropping_mode(1);
};

event_filter_t filter = [&](sinsp_evt* evt)
{
return 0 == strcmp(evt->get_name(), "fcntl") && m_tid_filter(evt);
};

run_callback_t test = [](concurrent_object_handle<sinsp> inspector_handle)
{
{
std::scoped_lock inspector_handle_lock(inspector_handle);
inspector_handle->start_dropping_mode(1);
}
fcntl(0, F_GETFL);
{
std::scoped_lock inspector_handle_lock(inspector_handle);
inspector_handle->stop_dropping_mode();
}
};

captured_event_callback_t callback = [&](const callback_param& param) { callnum++; };

ASSERT_NO_FATAL_FAILURE({ event_capture::run(test, callback, filter); });
before_close_t cleanup = [&](sinsp* inspector)
{
inspector->stop_dropping_mode();
};

ASSERT_NO_FATAL_FAILURE({ event_capture::run(test, callback, filter, setup, cleanup); });
EXPECT_EQ(0, callnum);
}

Expand All @@ -250,27 +254,29 @@ TEST_F(sys_call_test, bind_error_dropping)
{
int callnum = 0;

before_open_t setup = [&](sinsp* inspector)
{
inspector->start_dropping_mode(1);
};

event_filter_t filter = [&](sinsp_evt* evt)
{
return 0 == strcmp(evt->get_name(), "bind") && m_tid_filter(evt);
};

run_callback_t test = [](concurrent_object_handle<sinsp> inspector_handle)
{
{
std::scoped_lock inspector_handle_lock(inspector_handle);
inspector_handle->start_dropping_mode(1);
}
bind(0, NULL, 0);
{
std::scoped_lock inspector_handle_lock(inspector_handle);
inspector_handle->stop_dropping_mode();
}
};

captured_event_callback_t callback = [&](const callback_param& param) { callnum++; };

ASSERT_NO_FATAL_FAILURE({ event_capture::run(test, callback, filter); });
before_close_t cleanup = [&](sinsp* inspector)
{
inspector->stop_dropping_mode();
};

ASSERT_NO_FATAL_FAILURE({ event_capture::run(test, callback, filter, setup, cleanup); });
EXPECT_EQ(1, callnum);
}

Expand Down Expand Up @@ -298,28 +304,30 @@ TEST_F(sys_call_test, close_badfd_dropping)
{
int callnum = 0;

before_open_t setup = [&](sinsp* inspector)
{
inspector->start_dropping_mode(1);
};

event_filter_t filter = [&](sinsp_evt* evt)
{
return 0 == strcmp(evt->get_name(), "close") && m_tid_filter(evt);
};

run_callback_t test = [](concurrent_object_handle<sinsp> inspector_handle)
{
{
std::scoped_lock inspector_handle_lock(inspector_handle);
inspector_handle->start_dropping_mode(1);
}
close(-1);
close(INT_MAX);
{
std::scoped_lock inspector_handle_lock(inspector_handle);
inspector_handle->stop_dropping_mode();
}
};

captured_event_callback_t callback = [&](const callback_param& param) { callnum++; };

ASSERT_NO_FATAL_FAILURE({ event_capture::run(test, callback, filter); });
before_close_t cleanup = [&](sinsp* inspector)
{
inspector->stop_dropping_mode();
};

ASSERT_NO_FATAL_FAILURE({ event_capture::run(test, callback, filter, setup, cleanup); });
EXPECT_EQ(0, callnum);
}

Expand Down

0 comments on commit 8f07331

Please sign in to comment.