Skip to content

Commit

Permalink
fix(libsinsp_e2e): make sys_call_tests more reliable
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 688dda2 commit 6fcacfa
Showing 1 changed file with 34 additions and 14 deletions.
48 changes: 34 additions & 14 deletions test/libsinsp_e2e/sys_call_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,15 @@ TEST_F(sys_call_test, open_close)

captured_event_callback_t callback = [&](const callback_param& param)
{
if ((0 == strcmp(param.m_evt->get_name(), "open") ||
0 == strcmp(param.m_evt->get_name(), "openat")) &&
param.m_evt->get_direction() == SCAP_ED_OUT)
if((0 == strcmp(param.m_evt->get_name(), "open") || 0 == strcmp(param.m_evt->get_name(), "openat") ||
0 == strcmp(param.m_evt->get_name(), "close")) && "<f>/tmp" == param.m_evt->get_param_value_str("fd"))
{
EXPECT_EQ("<f>/tmp", param.m_evt->get_param_value_str("fd"));
callnum++;
}
callnum++;
};

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

TEST_F(sys_call_test, open_close_dropping)
Expand All @@ -169,13 +167,11 @@ TEST_F(sys_call_test, open_close_dropping)

captured_event_callback_t callback = [&](const callback_param& param)
{
if ((0 == strcmp(param.m_evt->get_name(), "open") ||
0 == strcmp(param.m_evt->get_name(), "openat")) &&
param.m_evt->get_direction() == SCAP_ED_OUT)
if((0 == strcmp(param.m_evt->get_name(), "open") || 0 == strcmp(param.m_evt->get_name(), "openat") ||
0 == strcmp(param.m_evt->get_name(), "close")) && "<f>/tmp" == param.m_evt->get_param_value_str("fd"))
{
EXPECT_EQ("<f>/tmp", param.m_evt->get_param_value_str("fd"));
callnum++;
}
callnum++;
};

before_close_t cleanup = [&](sinsp* inspector)
Expand All @@ -184,7 +180,7 @@ TEST_F(sys_call_test, open_close_dropping)
};

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

TEST_F(sys_call_test, fcntl_getfd)
Expand Down Expand Up @@ -294,7 +290,19 @@ TEST_F(sys_call_test, close_badfd)
close(INT_MAX);
};

captured_event_callback_t callback = [&](const callback_param& param) { callnum++; };
captured_event_callback_t callback = [&](const callback_param& param)
{
int fd = param.m_evt->get_param(0)->as<int64_t>();
if(param.m_evt->get_direction() == SCAP_ED_IN &&
(fd == -1 || fd == INT_MAX))
{
callnum++;
}
else if(param.m_evt->get_direction() == SCAP_ED_OUT && fd == -EBADF)
{
callnum++;
}
};

ASSERT_NO_FATAL_FAILURE({ event_capture::run(test, callback, filter); });
EXPECT_EQ(4, callnum);
Expand All @@ -320,7 +328,19 @@ TEST_F(sys_call_test, close_badfd_dropping)
close(INT_MAX);
};

captured_event_callback_t callback = [&](const callback_param& param) { callnum++; };
captured_event_callback_t callback = [&](const callback_param& param)
{
int fd = param.m_evt->get_param(0)->as<int64_t>();
if(param.m_evt->get_direction() == SCAP_ED_IN &&
(fd == -1 || fd == INT_MAX))
{
callnum++;
}
else if(param.m_evt->get_direction() == SCAP_ED_OUT && fd == -EBADF)
{
callnum++;
}
};

before_close_t cleanup = [&](sinsp* inspector)
{
Expand Down

0 comments on commit 6fcacfa

Please sign in to comment.