Skip to content

Commit

Permalink
new(test): added initial driver tests for ia32.
Browse files Browse the repository at this point in the history
Signed-off-by: Federico Di Pierro <[email protected]>
  • Loading branch information
FedeDP committed Oct 3, 2023
1 parent 68491c1 commit 68ef5f2
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
9 changes: 9 additions & 0 deletions test/drivers/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
message(STATUS "Drivers tests build enabled")

## Configure ia32 action test
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/test_suites/actions_suite/ia32.cpp.in ${CMAKE_CURRENT_SOURCE_DIR}/test_suites/actions_suite/ia32.cpp)

## Syscall_exit suite files.
file(GLOB_RECURSE SYSCALL_EXIT_TEST_SUITE ${CMAKE_CURRENT_SOURCE_DIR}/test_suites/syscall_exit_suite/*.cpp)

Expand Down Expand Up @@ -37,12 +40,18 @@ set(DRIVERS_TEST_LINK_LIBRARIES
"${GTEST_MAIN_LIB}"
)

add_executable(ia32 ./helpers/ia32.c)
set_target_properties(ia32 PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32")

set(DRIVERS_TEST_DEPENDECIES
scap
gtest
ia32
)

add_executable(drivers_test ${DRIVERS_TEST_SOURCES})
target_include_directories(drivers_test ${DRIVERS_TEST_INCLUDE})
target_link_libraries(drivers_test ${DRIVERS_TEST_LINK_LIBRARIES})
add_dependencies(drivers_test ${DRIVERS_TEST_DEPENDECIES})


18 changes: 18 additions & 0 deletions test/drivers/helpers/ia32.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* This file gets compiled with -m32 flag by drivers tests CMakefile,
* and is a dep of drivers_test executable.
* It just triggers ia32 syscalls to check whether we are able to capture them.
*/

#include <unistd.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <linux/net.h> /* Definition of SYS_* constants */

int main() {
syscall(__NR_close, -1);
unsigned long args[3] = {0};
syscall(__NR_socketcall, SYS_SOCKET, args);
syscall(__NR_socketcall, SYS_ACCEPT4, -1, NULL, NULL, 0);
return 0;
}
1 change: 1 addition & 0 deletions test/drivers/test_suites/actions_suite/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ia32.cpp
48 changes: 48 additions & 0 deletions test/drivers/test_suites/actions_suite/ia32.cpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "../../event_class/event_class.h"

TEST(Actions, ia32)
{
/* Here we capture all syscalls... this process will send some
* specific syscalls and we have to check that they are extracted in order
* from the buffers.
*/
auto evt_test = get_syscall_event_test();

evt_test->enable_capture();

/*=============================== TRIGGER SYSCALL ===========================*/
pid_t ret_pid = syscall(__NR_fork);
if(ret_pid == 0)
{
char* const argv[] = {NULL};
char* const envp[] = {NULL};
// Pin process to a single core, so that events get sent in order
cpu_set_t my_set;
CPU_ZERO(&my_set);
CPU_SET(1, &my_set);
sched_setaffinity(0, sizeof(cpu_set_t), &my_set);

execve("${CMAKE_CURRENT_BINARY_DIR}/ia32", argv, envp);
exit(EXIT_FAILURE);
}
assert_syscall_state(SYSCALL_SUCCESS, "fork", ret_pid, NOT_EQUAL, -1);
int status = 0;
int options = 0;
assert_syscall_state(SYSCALL_SUCCESS, "wait4", syscall(__NR_wait4, ret_pid, &status, options, NULL), NOT_EQUAL, -1);

if(__WEXITSTATUS(status) == EXIT_FAILURE || __WIFSIGNALED(status) != 0)
{
FAIL() << "Fork failed..." << std::endl;
}

/* Disable the capture: no more events from now. */
evt_test->disable_capture();

/* Retrieve events in order. */
evt_test->assert_event_presence(ret_pid, PPME_SYSCALL_CLOSE_E);
evt_test->assert_event_presence(ret_pid, PPME_SYSCALL_CLOSE_X);
evt_test->assert_event_presence(ret_pid, PPME_SOCKET_SOCKET_E);
evt_test->assert_event_presence(ret_pid, PPME_SOCKET_SOCKET_X);
evt_test->assert_event_presence(ret_pid, PPME_SOCKET_ACCEPT4_6_E);
evt_test->assert_event_presence(ret_pid, PPME_SOCKET_ACCEPT4_6_X);
}

0 comments on commit 68ef5f2

Please sign in to comment.