Skip to content

Commit

Permalink
tests: fix broken test names_sc_set_names_corner_cases
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Terzolo <andrea.terzolo@polito.it>
  • Loading branch information
Andreagit97 committed Mar 14, 2023
1 parent 9bc456f commit 79e70df
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions userspace/libscap/linux/scap_ppm_sc.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,8 @@ static const ppm_sc_code *g_events_to_sc_map[] = {
[PPME_SYSCALL_PPOLL_X] = (ppm_sc_code[]){PPM_SC_PPOLL, -1},
[PPME_SYSCALL_MOUNT_E] = (ppm_sc_code[]){PPM_SC_MOUNT, -1},
[PPME_SYSCALL_MOUNT_X] = (ppm_sc_code[]){PPM_SC_MOUNT, -1},
[PPME_SYSCALL_UMOUNT_E] = (ppm_sc_code[]){PPM_SC_UMOUNT2, -1},
[PPME_SYSCALL_UMOUNT_X] = (ppm_sc_code[]){PPM_SC_UMOUNT2, -1},
[PPME_SYSCALL_UMOUNT_E] = (ppm_sc_code[]){PPM_SC_UMOUNT, -1},
[PPME_SYSCALL_UMOUNT_X] = (ppm_sc_code[]){PPM_SC_UMOUNT, -1},
[PPME_K8S_E] = NULL,
[PPME_K8S_X] = NULL,
[PPME_SYSCALL_SEMGET_E] = (ppm_sc_code[]){PPM_SC_SEMGET, -1},
Expand Down
18 changes: 10 additions & 8 deletions userspace/libsinsp/test/public_sinsp_API/interesting_syscalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,17 +200,19 @@ TEST(interesting_syscalls, names_to_sc_set)
}

/* This test asserts the behavior of `names_to_sc_set` API when corner cases like `accept/accept4` are involved */
/// todo: @Andreagit97 revisit this test after new APIs to convert from event_names -> sc_set and sc_set -> event_names.
TEST(interesting_syscalls, names_sc_set_names_corner_cases)
{
static std::unordered_set<std::string> sc_set_names_truth = {"accept",
"accept4", "execve", "syncfs", "eventfd", "eventfd2", "umount",
"pipe", "pipe2", "signalfd", "signalfd4"};
/* INCONSISTENCY: `names_to_sc_set` is converting event names to ppm_sc, but this was not its original scope, the original scope was to convert sc_names -> to sc_set */
std::unordered_set<std::string> event_names{"accept", "execve", "syncfs", "eventfd", "umount", "pipe", "signalfd"};
auto sc_set = libsinsp::events::names_to_sc_set(event_names);
libsinsp::events::set<ppm_sc_code> expected_sc_set{PPM_SC_ACCEPT, PPM_SC_ACCEPT4, PPM_SC_EXECVE, PPM_SC_SYNCFS, PPM_SC_EVENTFD, PPM_SC_EVENTFD2, PPM_SC_UMOUNT, PPM_SC_PIPE, PPM_SC_PIPE2, PPM_SC_SIGNALFD, PPM_SC_SIGNALFD4};
ASSERT_PPM_SC_CODES_EQ(sc_set, expected_sc_set);

auto tmp_sc_set = libsinsp::events::names_to_sc_set(std::unordered_set<std::string>{"accept",
"execve", "syncfs", "eventfd", "umount", "pipe", "signalfd"});

auto sc_set_names = libsinsp::events::sc_set_to_names(tmp_sc_set);
ASSERT_NAMES_EQ(sc_set_names_truth, sc_set_names);
/* Please note that here we are converting sc_set to sc_names not event_names! */
auto sc_names = libsinsp::events::sc_set_to_names(sc_set);
static std::unordered_set<std::string> expected_sc_names = {"accept", "accept4", "execve", "syncfs", "eventfd", "eventfd2", "umount", "pipe", "pipe2", "signalfd", "signalfd4"};
ASSERT_NAMES_EQ(expected_sc_names, sc_names);
}

TEST(interesting_syscalls, event_set_to_sc_set)
Expand Down

0 comments on commit 79e70df

Please sign in to comment.