From c799c23c1e8f3c0457f77518f15f60725b2d980c Mon Sep 17 00:00:00 2001 From: Melissa Kilby Date: Mon, 11 Mar 2024 17:37:32 +0000 Subject: [PATCH] update(tests): define explicit SUCESSFUL container lookup status Signed-off-by: Melissa Kilby --- .../container_parser_cri_containerd.ut.cpp | 2 ++ .../container_engine/container_parser_cri_crio.ut.cpp | 2 ++ userspace/libsinsp/test/events_plugin.ut.cpp | 9 +++++++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/userspace/libsinsp/test/container_engine/container_parser_cri_containerd.ut.cpp b/userspace/libsinsp/test/container_engine/container_parser_cri_containerd.ut.cpp index 3e580347ddf..2c6023b89f4 100644 --- a/userspace/libsinsp/test/container_engine/container_parser_cri_containerd.ut.cpp +++ b/userspace/libsinsp/test/container_engine/container_parser_cri_containerd.ut.cpp @@ -647,6 +647,7 @@ TEST_F(sinsp_with_test_input, container_parser_cri_containerd) "blkio=/k8s.io/3ad7b26ded6d8e7b23da7d48fe889434573036c27ae5a74837233de441c3601e", "memory=/k8s.io/3ad7b26ded6d8e7b23da7d48fe889434573036c27ae5a74837233de441c3601e"}; std::string cgroupsv = test_utils::to_null_delimited(cgroups); + container.set_lookup_status(sinsp_container_lookup::state::SUCCESSFUL); std::string container_json = m_inspector.m_container_manager.container_to_json(container); add_event_advance_ts(increasing_ts(), parent_tid, PPME_SYSCALL_CLONE_20_E, 0); add_event_advance_ts(increasing_ts(), parent_tid, PPME_SYSCALL_CLONE_20_X, 20, child_tid, "bash", empty_bytebuf, (uint64_t)1, (uint64_t)1, (uint64_t)0, "", (uint64_t)0, (uint64_t)0, (uint64_t)0, (uint32_t)12088, (uint32_t)7208, (uint32_t)0, "bash", scap_const_sized_buffer{cgroupsv.data(), cgroupsv.size()}, (uint32_t)(PPM_CL_CLONE_CHILD_CLEARTID | PPM_CL_CLONE_CHILD_SETTID | PPM_CL_CLONE_NEWPID | PPM_CL_CHILD_IN_PIDNS), (uint32_t)1000, (uint32_t)1000, (uint64_t)parent_tid, (uint64_t)parent_pid); @@ -782,6 +783,7 @@ TEST_F(sinsp_with_test_input, container_parser_cri_containerd_sandbox_container) "blkio=/k8s.io/63060edc2d3aa803ab559f2393776b151f99fc5b05035b21db66b3b62246ad6a", "memory=/k8s.io/63060edc2d3aa803ab559f2393776b151f99fc5b05035b21db66b3b62246ad6a"}; std::string cgroupsv = test_utils::to_null_delimited(cgroups); + container.set_lookup_status(sinsp_container_lookup::state::SUCCESSFUL); std::string container_json = m_inspector.m_container_manager.container_to_json(container); add_event_advance_ts(increasing_ts(), parent_tid, PPME_SYSCALL_CLONE_20_E, 0); add_event_advance_ts(increasing_ts(), parent_tid, PPME_SYSCALL_CLONE_20_X, 20, child_tid, "bash", empty_bytebuf, (uint64_t)1, (uint64_t)1, (uint64_t)0, "", (uint64_t)0, (uint64_t)0, (uint64_t)0, (uint32_t)12088, (uint32_t)7208, (uint32_t)0, "bash", scap_const_sized_buffer{cgroupsv.data(), cgroupsv.size()}, (uint32_t)(PPM_CL_CLONE_CHILD_CLEARTID | PPM_CL_CLONE_CHILD_SETTID | PPM_CL_CLONE_NEWPID | PPM_CL_CHILD_IN_PIDNS), (uint32_t)1000, (uint32_t)1000, (uint64_t)parent_tid, (uint64_t)parent_pid); diff --git a/userspace/libsinsp/test/container_engine/container_parser_cri_crio.ut.cpp b/userspace/libsinsp/test/container_engine/container_parser_cri_crio.ut.cpp index d5c59896bf2..f15ec4e3033 100644 --- a/userspace/libsinsp/test/container_engine/container_parser_cri_crio.ut.cpp +++ b/userspace/libsinsp/test/container_engine/container_parser_cri_crio.ut.cpp @@ -643,6 +643,7 @@ TEST_F(sinsp_with_test_input, container_parser_cri_crio) "pids=/pod_123.slice/pod_123-456.slice/crio-49ecc282021562c567a8159ef424a06cdd8637efdca5953de9794eafe29adcad.scope", "misc=/pod_123.slice/pod_123-456.slice/crio-49ecc282021562c567a8159ef424a06cdd8637efdca5953de9794eafe29adcad.scope"}; std::string cgroupsv = test_utils::to_null_delimited(cgroups); + container.set_lookup_status(sinsp_container_lookup::state::SUCCESSFUL); std::string container_json = m_inspector.m_container_manager.container_to_json(container); add_event_advance_ts(increasing_ts(), parent_tid, PPME_SYSCALL_CLONE_20_E, 0); add_event_advance_ts(increasing_ts(), parent_tid, PPME_SYSCALL_CLONE_20_X, 20, child_tid, "bash", empty_bytebuf, (uint64_t)1, (uint64_t)1, (uint64_t)0, "", (uint64_t)0, (uint64_t)0, (uint64_t)0, (uint32_t)12088, (uint32_t)7208, (uint32_t)0, "bash", scap_const_sized_buffer{cgroupsv.data(), cgroupsv.size()}, (uint32_t)(PPM_CL_CLONE_CHILD_CLEARTID | PPM_CL_CLONE_CHILD_SETTID | PPM_CL_CLONE_NEWPID | PPM_CL_CHILD_IN_PIDNS), (uint32_t)1000, (uint32_t)1000, (uint64_t)parent_tid, (uint64_t)parent_pid); @@ -745,6 +746,7 @@ TEST_F(sinsp_with_test_input, container_parser_cri_crio_sandbox_container) "pids=/pod_123.slice/pod_123-456.slice/crio-1f04600dc6949359da68eee5fe7c4069706a567c07d1ef89fe3bbfdeac7a6dca.scope", "misc=/pod_123.slice/pod_123-456.slice/crio-1f04600dc6949359da68eee5fe7c4069706a567c07d1ef89fe3bbfdeac7a6dca.scope"}; std::string cgroupsv = test_utils::to_null_delimited(cgroups); + container.set_lookup_status(sinsp_container_lookup::state::SUCCESSFUL); std::string container_json = m_inspector.m_container_manager.container_to_json(container); add_event_advance_ts(increasing_ts(), parent_tid, PPME_SYSCALL_CLONE_20_E, 0); add_event_advance_ts(increasing_ts(), parent_tid, PPME_SYSCALL_CLONE_20_X, 20, child_tid, "bash", empty_bytebuf, (uint64_t)1, (uint64_t)1, (uint64_t)0, "", (uint64_t)0, (uint64_t)0, (uint64_t)0, (uint32_t)12088, (uint32_t)7208, (uint32_t)0, "bash", scap_const_sized_buffer{cgroupsv.data(), cgroupsv.size()}, (uint32_t)(PPM_CL_CLONE_CHILD_CLEARTID | PPM_CL_CLONE_CHILD_SETTID | PPM_CL_CLONE_NEWPID | PPM_CL_CHILD_IN_PIDNS), (uint32_t)1000, (uint32_t)1000, (uint64_t)parent_tid, (uint64_t)parent_pid); diff --git a/userspace/libsinsp/test/events_plugin.ut.cpp b/userspace/libsinsp/test/events_plugin.ut.cpp index fda0ecc554b..06eaa36efab 100644 --- a/userspace/libsinsp/test/events_plugin.ut.cpp +++ b/userspace/libsinsp/test/events_plugin.ut.cpp @@ -131,8 +131,13 @@ TEST_F(sinsp_with_test_input, event_sources) ASSERT_FALSE(field_has_value(evt, "evt.asynctype")); // metaevents have the "syscall" event source - evt = add_event_advance_ts(increasing_ts(), 1, PPME_CONTAINER_JSON_E, 1, "{\"value\": 1}"); - ASSERT_EQ(evt->get_type(), PPME_CONTAINER_JSON_E); + std::shared_ptr container = std::make_shared(); + container->m_type = CT_CONTAINERD; + container->m_id = "3ad7b26ded6d"; + container->set_lookup_status(sinsp_container_lookup::state::SUCCESSFUL); + std::string container_json = m_inspector.m_container_manager.container_to_json(*container); + evt = add_event_advance_ts(increasing_ts(), -1, PPME_CONTAINER_JSON_2_E, 1, container_json.c_str()); + ASSERT_EQ(evt->get_type(), PPME_CONTAINER_JSON_2_E); ASSERT_EQ(evt->get_source_idx(), syscall_source_idx); ASSERT_EQ(std::string(evt->get_source_name()), syscall_source_name); ASSERT_EQ(get_field_as_string(evt, "evt.source"), syscall_source_name);