Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(test/libsinsp_e2e): use unique ptr e2e tests inspector #1754

Merged
merged 2 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,12 @@ jobs:
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
fetch-depth: 0

- name: Fix kernel mmap rnd bits
# Asan in llvm 14 provided in ubuntu 22.04 is incompatible with
# high-entropy ASLR in much newer kernels that GitHub runners are
# using leading to random crashes: https://reviews.llvm.org/D148280
run: sudo sysctl vm.mmap_rnd_bits=28

- name: Install deps ⛓️
run: |
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/e2e_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ jobs:
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
fetch-depth: 0

- name: Fix kernel mmap rnd bits
# Asan in llvm 14 provided in ubuntu 22.04 is incompatible with
# high-entropy ASLR in much newer kernels that GitHub runners are
# using leading to random crashes: https://reviews.llvm.org/D148280
run: sudo sysctl vm.mmap_rnd_bits=28

- name: Install deps ⛓️
run: |
Expand Down
13 changes: 10 additions & 3 deletions test/libsinsp_e2e/container/container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,16 @@ TEST_F(sys_call_test, container_clone_nspid)
{
FAIL();
}

wait(NULL);
free(stack);
else if (ctid == 0)
{
free(stack);
_exit(0);
}
else
{
free(stack);
waitpid(ctid, NULL, 0);
}
};

//
Expand Down
21 changes: 6 additions & 15 deletions test/libsinsp_e2e/event_capture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ unsigned long event_capture::m_buffer_dim = DEFAULT_DRIVER_BUFFER_BYTES_DIM;

concurrent_object_handle<sinsp> event_capture::get_inspector_handle()
{
return {m_inspector, m_inspector_mutex};
return {m_inspector.get(), m_inspector_mutex};
}

void event_capture::capture()
Expand All @@ -40,7 +40,7 @@ void event_capture::capture()
{ // Begin init synchronized section
std::scoped_lock init_lock(m_inspector_mutex, m_object_state_mutex);

m_inspector = new sinsp();
m_inspector = std::make_unique<sinsp>();

m_inspector->m_thread_manager->set_max_thread_table_size(m_max_thread_table_size);
m_inspector->m_thread_timeout_ns = m_thread_timeout_ns;
Expand All @@ -49,9 +49,9 @@ void event_capture::capture()

m_inspector->set_get_procs_cpu_from_driver(true);

m_param.m_inspector = m_inspector;
m_param.m_inspector = m_inspector.get();

m_before_open(m_inspector);
m_before_open(m_inspector.get());

ASSERT_FALSE(m_inspector->is_capture());
ASSERT_FALSE(m_inspector->is_live());
Expand Down Expand Up @@ -79,7 +79,6 @@ void event_capture::capture()
m_capture_started = true;
m_condition_started.notify_one();
}
delete m_inspector;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to delete unique ptr anymore.
Also, sinsp dtor autoamtically calls stop capture and scap_close for us.

return;
}

Expand All @@ -95,7 +94,7 @@ void event_capture::capture()
{
m_dump_filename = std::string(LIBSINSP_TEST_CAPTURES_PATH) + test_info->test_case_name() + "_" +
test_info->name() + ".scap";
dumper = std::make_unique<sinsp_cycledumper>(m_inspector, m_dump_filename.c_str(),
dumper = std::make_unique<sinsp_cycledumper>(m_inspector.get(), m_dump_filename.c_str(),
0, 0, 0, 0, true);
}
} // End init synchronized section
Expand Down Expand Up @@ -165,11 +164,7 @@ void event_capture::capture()

{ // Begin teardown synchronized section
std::scoped_lock teardown_lock(m_inspector_mutex, m_object_state_mutex);
m_before_close(m_inspector);

m_inspector->stop_capture();

delete m_inspector;
m_before_close(m_inspector.get());

m_capture_stopped = true;
m_condition_stopped.notify_one();
Expand All @@ -180,10 +175,6 @@ void event_capture::capture()

void event_capture::stop_capture()
{
if (m_inspector)
{
m_inspector->stop_capture();
}
{
std::scoped_lock init_lock(m_inspector_mutex, m_object_state_mutex);
m_capture_stopped = true;
Expand Down
2 changes: 1 addition & 1 deletion test/libsinsp_e2e/event_capture.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ class event_capture
std::string m_start_failure_message;
std::string m_dump_filename;
callback_param m_param;
sinsp* m_inspector;
std::unique_ptr<sinsp> m_inspector;
sinsp_mode_t m_mode;
uint64_t m_max_timeouts;
};
Loading