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

fix(userspace/libsinsp): restore ifinfo unit tests #1657

Merged
merged 2 commits into from
Jan 29, 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
1 change: 1 addition & 0 deletions userspace/libsinsp/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,31 @@ limitations under the License.
*/

#define VISIBILITY_PRIVATE

#include <libsinsp/sinsp.h>
#include <libsinsp/sinsp_int.h>
#include <libsinsp/ifinfo.h>

#include <gtest/gtest.h>


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),
Expand All @@ -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,
Expand All @@ -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);\
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down
Loading