From 4fb61095811cda373c5b4eb71eea285726c9f9f4 Mon Sep 17 00:00:00 2001 From: Jason Dellaluce Date: Mon, 29 Jan 2024 17:01:13 +0000 Subject: [PATCH 1/2] refactor(userspace/libsinsp): move ifinfo tests under test dir and run it Signed-off-by: Jason Dellaluce --- userspace/libsinsp/test/CMakeLists.txt | 1 + userspace/libsinsp/{ifinfo_test.cpp => test/ifinfo.ut.cpp} | 0 2 files changed, 1 insertion(+) rename userspace/libsinsp/{ifinfo_test.cpp => test/ifinfo.ut.cpp} (100%) diff --git a/userspace/libsinsp/test/CMakeLists.txt b/userspace/libsinsp/test/CMakeLists.txt index 5476981278..118e869b76 100644 --- a/userspace/libsinsp/test/CMakeLists.txt +++ b/userspace/libsinsp/test/CMakeLists.txt @@ -115,6 +115,7 @@ set(LIBSINSP_UNIT_TESTS_SOURCES savefile.ut.cpp sinsp_stats.ut.cpp thread_table.ut.cpp + ifinfo.ut.cpp public_sinsp_API/event_related.cpp public_sinsp_API/sinsp_logger.cpp "${TEST_PLUGINS}" diff --git a/userspace/libsinsp/ifinfo_test.cpp b/userspace/libsinsp/test/ifinfo.ut.cpp similarity index 100% rename from userspace/libsinsp/ifinfo_test.cpp rename to userspace/libsinsp/test/ifinfo.ut.cpp From ee1dbbb859724384e9f0144b327cbf5471c052f9 Mon Sep 17 00:00:00 2001 From: Jason Dellaluce Date: Mon, 29 Jan 2024 17:07:10 +0000 Subject: [PATCH 2/2] fix(userspace/libsinsp): solve compilation issues with ifinfo tests Signed-off-by: Jason Dellaluce --- userspace/libsinsp/test/ifinfo.ut.cpp | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/userspace/libsinsp/test/ifinfo.ut.cpp b/userspace/libsinsp/test/ifinfo.ut.cpp index 1eb6de2120..ebe754e316 100644 --- a/userspace/libsinsp/test/ifinfo.ut.cpp +++ b/userspace/libsinsp/test/ifinfo.ut.cpp @@ -17,31 +17,31 @@ limitations under the License. */ #define VISIBILITY_PRIVATE + #include #include #include #include - -uint32_t parse_ipv4_addr(const char *dotted_notation) +static uint32_t parse_ipv4_addr(const char *dotted_notation) { uint32_t a, b, c, d; sscanf(dotted_notation, "%d.%d.%d.%d", &a, &b, &c, &d); return d << 24 | c << 16 | b << 8 | a; } -uint32_t parse_ipv4_netmask(const char *dotted_notation) +static uint32_t parse_ipv4_netmask(const char *dotted_notation) { return parse_ipv4_addr(dotted_notation); } -uint32_t parse_ipv4_broadcast(const char *dotted_notation) +static uint32_t parse_ipv4_broadcast(const char *dotted_notation) { return parse_ipv4_addr(dotted_notation); } -sinsp_ipv4_ifinfo make_ipv4_interface(const char *addr, const char *netmask, const char* broadcast, const char *name) +static sinsp_ipv4_ifinfo make_ipv4_interface(const char *addr, const char *netmask, const char* broadcast, const char *name) { return sinsp_ipv4_ifinfo( parse_ipv4_addr(addr), @@ -50,13 +50,13 @@ sinsp_ipv4_ifinfo make_ipv4_interface(const char *addr, const char *netmask, con name); } -sinsp_ipv4_ifinfo make_ipv4_localhost() +static sinsp_ipv4_ifinfo make_ipv4_localhost() { return make_ipv4_interface("127.0.0.1", "255.0.0.0", "127.0.0.1", "lo"); } -void convert_to_string(char* dest, size_t len, uint32_t addr) +static void convert_to_string(char* dest, size_t len, uint32_t addr) { snprintf( dest, @@ -68,8 +68,6 @@ void convert_to_string(char* dest, size_t len, uint32_t addr) ((addr & 0xFF000000) >> 24)); } - - #define EXPECT_ADDR_EQ(dotted_notation,addr) {\ char buf[17];\ convert_to_string(buf, sizeof(buf), addr);\ @@ -88,7 +86,7 @@ TEST(sinsp_network_interfaces, socket_is_of_wrong_type) { sinsp_fdinfo fd; fd.m_type = SCAP_FD_IPV4_SOCK; - fd.m_info.m_ipv4info.m_fields.m_l4proto = SCAP_L4_TCP; + fd.m_sockinfo.m_ipv4info.m_fields.m_l4proto = SCAP_L4_TCP; sinsp_network_interfaces interfaces; interfaces.update_fd(fd); } @@ -97,9 +95,9 @@ TEST(sinsp_network_interfaces, sip_and_dip_are_not_zero) { sinsp_fdinfo fd; fd.m_type = SCAP_FD_IPV4_SOCK; - fd.m_info.m_ipv4info.m_fields.m_l4proto = SCAP_L4_UDP; - fd.m_info.m_ipv4info.m_fields.m_sip = 1; - fd.m_info.m_ipv4info.m_fields.m_dip = 1; + fd.m_sockinfo.m_ipv4info.m_fields.m_l4proto = SCAP_L4_UDP; + fd.m_sockinfo.m_ipv4info.m_fields.m_sip = 1; + fd.m_sockinfo.m_ipv4info.m_fields.m_dip = 1; sinsp_network_interfaces interfaces; interfaces.update_fd(fd); }