-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new(test): added initial driver tests for ia32.
Signed-off-by: Federico Di Pierro <[email protected]>
- Loading branch information
Showing
4 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ia32.cpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |