Skip to content

Commit

Permalink
chore(libsinsp_e2e): improve test stability
Browse files Browse the repository at this point in the history
Signed-off-by: Roberto Scolaro <roberto.scolaro21@gmail.com>
  • Loading branch information
therealbobo committed Apr 2, 2024
1 parent 3bbae8d commit 9606866
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 2 additions & 0 deletions test/libsinsp_e2e/suppress_events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ static void test_helper_quotactl(test_helper_args& hargs)

ASSERT_GT(st.n_suppressed, 0u);
ASSERT_EQ(0u, st.n_tids_suppressed);

inspector->clear_suppress_events_comm();
};

ASSERT_NO_FATAL_FAILURE({
Expand Down
43 changes: 42 additions & 1 deletion test/libsinsp_e2e/sys_call_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,11 @@ TEST_F(sys_call_test, getsetuid_and_gid)
static const uint32_t test_gid = 6566;
int callnum = 0;

uint32_t orig_uid = getuid();
uint32_t orig_euid = geteuid();
uint32_t orig_gid = getgid();
uint32_t orig_egid = getegid();

event_filter_t filter = [&](sinsp_evt* evt) { return m_tid_filter(evt); };

run_callback_t test = [&](concurrent_object_handle<sinsp> inspector_handle)
Expand Down Expand Up @@ -1073,7 +1078,22 @@ TEST_F(sys_call_test, getsetuid_and_gid)
break;
}
};

ASSERT_NO_FATAL_FAILURE({ event_capture::run(test, callback, filter); });

// This has to be done without a callback otherwise the test will not
// work.
int result = 0;
result += setuid(orig_uid);
result += seteuid(orig_euid);
result += setgid(orig_gid);
result += setegid(orig_egid);

if(result != 0)
{
FAIL() << "Cannot restore initial id state.";
}

EXPECT_EQ(12, callnum);
}

Expand Down Expand Up @@ -1416,7 +1436,7 @@ TEST_F(sys_call_test, poll_timeout)

EXPECT_EQ(res, 1);

string fds = e->get_param_value_str("fds");
std::string fds = e->get_param_value_str("fds");

EXPECT_TRUE(fds == "0:f0 1:f4" || fds == "0:p0 1:f4" || fds == "0:f0 1:p4" ||
fds == "0:p0 1:p4");
Expand Down Expand Up @@ -1488,6 +1508,12 @@ TEST_F(sys_call_test, getsetresuid_and_gid)
uint32_t uids[3];
uint32_t gids[3];

uint32_t orig_uids[3];
uint32_t orig_gids[3];

//getresuid(&orig_uids[0], &orig_uids[1], &orig_uids[2]);
//getresgid(&orig_gids[0], &orig_gids[1], &orig_gids[2]);

// Clean environment
int ret = system("userdel testsetresuid");
ret = system("groupdel testsetresgid");
Expand Down Expand Up @@ -1580,6 +1606,21 @@ TEST_F(sys_call_test, getsetresuid_and_gid)
EXPECT_EQ("root", e->get_param_value_str("sgid"));
}
};

before_close_t cleanup = [&](sinsp* inspector)
{
int result = 0;

result += setresuid(orig_uids[0], orig_uids[1], orig_uids[2]);
result += setresgid(orig_gids[0], orig_gids[1], orig_gids[2]);

if(result != 0)
{
FAIL() << "Cannot restore initial id state.";
}
};

//ASSERT_NO_FATAL_FAILURE({ event_capture::run(test, callback, filter, event_capture::do_nothing, cleanup); });
ASSERT_NO_FATAL_FAILURE({ event_capture::run(test, callback, filter); });
EXPECT_EQ(8, callnum);
}
Expand Down

0 comments on commit 9606866

Please sign in to comment.