diff --git a/userspace/libsinsp/test/filterchecks/evt.cpp b/userspace/libsinsp/test/filterchecks/evt.cpp index 8e1cfda7b5..c28d2dc4ee 100644 --- a/userspace/libsinsp/test/filterchecks/evt.cpp +++ b/userspace/libsinsp/test/filterchecks/evt.cpp @@ -23,15 +23,12 @@ TEST_F(sinsp_with_test_input, EVT_FILTER_is_open_create) { open_inspector(); - std::string path = "/home/file.txt"; - int64_t fd = 3; - // In the enter event we don't send the `PPM_O_F_CREATED` sinsp_evt* evt = add_event_advance_ts(increasing_ts(), 1, PPME_SYSCALL_OPEN_E, 3, - path.c_str(), + sinsp_test_input::open_params::default_path, (uint32_t)PPM_O_RDWR | PPM_O_CREAT, (uint32_t)0); ASSERT_EQ(get_field_as_string(evt, "evt.is_open_create"), "false"); @@ -39,20 +36,12 @@ TEST_F(sinsp_with_test_input, EVT_FILTER_is_open_create) { // The `fdinfo` is not populated in the enter event ASSERT_FALSE(evt->get_fd_info()); - evt = add_event_advance_ts(increasing_ts(), - 1, - PPME_SYSCALL_OPEN_X, - 6, - fd, - path.c_str(), - (uint32_t)PPM_O_RDWR | PPM_O_CREAT | PPM_O_F_CREATED, - (uint32_t)0, - (uint32_t)5, - (uint64_t)123); + uint32_t flags = PPM_O_RDWR | PPM_O_CREAT | PPM_O_F_CREATED; + evt = generate_open_x_event(sinsp_test_input::open_params{.flags = flags}); ASSERT_EQ(get_field_as_string(evt, "evt.is_open_create"), "true"); ASSERT_TRUE(evt->get_fd_info()); - ASSERT_EQ(evt->get_fd_info()->m_openflags, PPM_O_RDWR | PPM_O_CREAT | PPM_O_F_CREATED); + ASSERT_EQ(evt->get_fd_info()->m_openflags, flags); } TEST_F(sinsp_with_test_input, EVT_FILTER_is_lower_layer) { diff --git a/userspace/libsinsp/test/sinsp_with_test_input.cpp b/userspace/libsinsp/test/sinsp_with_test_input.cpp index fec6b862d6..e6694a132e 100644 --- a/userspace/libsinsp/test/sinsp_with_test_input.cpp +++ b/userspace/libsinsp/test/sinsp_with_test_input.cpp @@ -359,6 +359,20 @@ sinsp_evt* sinsp_with_test_input::generate_getcwd_failed_entry_event(int64_t tid path.c_str()); } +sinsp_evt* sinsp_with_test_input::generate_open_x_event(sinsp_test_input::open_params params, + int64_t tid_caller) { + return add_event_advance_ts(increasing_ts(), + tid_caller, + PPME_SYSCALL_OPEN_X, + 6, + params.fd, + params.path, + params.flags, + params.mode, + params.dev, + params.ino); +} + //=============================== PROCESS GENERATION =========================== void sinsp_with_test_input::add_thread(const scap_threadinfo& tinfo, diff --git a/userspace/libsinsp/test/sinsp_with_test_input.h b/userspace/libsinsp/test/sinsp_with_test_input.h index 547e40da80..5ec82aeffb 100644 --- a/userspace/libsinsp/test/sinsp_with_test_input.h +++ b/userspace/libsinsp/test/sinsp_with_test_input.h @@ -34,6 +34,23 @@ limitations under the License. #define INIT_PID INIT_TID #define INIT_PTID 0 +namespace sinsp_test_input { +struct open_params { + static constexpr int32_t default_fd = 4; + static constexpr const char* default_path = "/home/file.txt"; + // Used for some filter checks + static constexpr const char* default_directory = "/home"; + static constexpr const char* default_filename = "file.txt"; + + int32_t fd = default_fd; + const char* path = default_path; + uint32_t flags = 0; + uint32_t mode = 0; + uint32_t dev = 0; + uint64_t ino = 0; +}; +} // namespace sinsp_test_input + class sinsp_with_test_input : public ::testing::Test { protected: sinsp_with_test_input(); @@ -192,6 +209,8 @@ class sinsp_with_test_input : public ::testing::Test { sinsp_evt* generate_proc_exit_event(int64_t tid_to_remove, int64_t reaper_tid); sinsp_evt* generate_random_event(int64_t tid_caller = INIT_TID); sinsp_evt* generate_getcwd_failed_entry_event(int64_t tid_caller = INIT_TID); + sinsp_evt* generate_open_x_event(sinsp_test_input::open_params params = {}, + int64_t tid_caller = INIT_TID); //=============================== PROCESS GENERATION ===========================