Skip to content

Commit

Permalink
fix(libsinsp_e2e): make forking_clone_fs more reliable
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 9, 2024
1 parent fb087ae commit 1ce9a95
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions test/libsinsp_e2e/forking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,14 +346,16 @@ TEST_F(sys_call_test, forking_clone_fs)
char bcwd[1024];
int prfd;
int ptid; // parent tid
int flags = CLONE_FILES | CLONE_FS | CLONE_VM;
int drflags = PPM_CL_CLONE_FILES | PPM_CL_CLONE_FS | PPM_CL_CLONE_VM;
int child_tid;
int parent_res;
int flags = CLONE_FILES | CLONE_FS | CLONE_VM | CLONE_PARENT_SETTID;
int drflags = PPM_CL_CLONE_FILES | PPM_CL_CLONE_FS | PPM_CL_CLONE_VM | PPM_CL_CLONE_PARENT_SETTID;

//
// FILTER
//
event_filter_t filter = [&](sinsp_evt* evt)
{ return evt->get_tid() == ptid || evt->get_tid() == ctid; };
{ return evt->get_tid() == ptid || evt->get_tid() == child_tid; };

//
// TEST CODE
Expand Down Expand Up @@ -392,19 +394,21 @@ TEST_F(sys_call_test, forking_clone_fs)

/* Create child; child commences execution in childFunc() */

if (clone(clone_callback_1, stackTop, flags, &cp) == -1)
pid_t clone_tid = clone(clone_callback_1, stackTop, flags, &cp,
&child_tid);
if (clone_tid == -1)
FAIL();

/* Parent falls through to here. Wait for child; __WCLONE option is
required for child notifying with signal other than SIGCHLD. */

pid = waitpid(-1, &status, __WCLONE);
pid = waitpid(clone_tid, &status, __WCLONE);
if (pid == -1)
FAIL();

close(cp.fd);
parent_res = -errno;

sleep(1);
free(stack);
};

Expand All @@ -426,7 +430,7 @@ TEST_F(sys_call_test, forking_clone_fs)

if (res == 0)
{
EXPECT_EQ(ctid, ti->m_tid);
EXPECT_EQ(child_tid, ti->m_tid);
}
else
{
Expand All @@ -447,7 +451,7 @@ TEST_F(sys_call_test, forking_clone_fs)
{
sinsp_threadinfo* ti = e->get_thread_info(false);

if (ti->m_tid == ptid || ti->m_tid == ctid)
if (ti->m_tid == ptid || ti->m_tid == child_tid)
{
int64_t clfd = std::stoll(e->get_param_value_str("fd", false));

Expand All @@ -470,9 +474,12 @@ TEST_F(sys_call_test, forking_clone_fs)

if (ti->m_tid == ptid)
{
EXPECT_GT(0, res);
if(ti->get_fd(prfd)->tostring_clean().find(FILENAME) != std::string::npos)
{
EXPECT_EQ(parent_res, res);
}
}
else if (ti->m_tid == ctid)
else if (ti->m_tid == child_tid)
{
EXPECT_EQ(0, res);
}
Expand Down

0 comments on commit 1ce9a95

Please # to comment.