Skip to content

Commit

Permalink
Add syscall tests and so harness
Browse files Browse the repository at this point in the history
Add two tests performing syscalls, to show the running syscalls
themselves from within a restricted DDC environment works. I think this
is useful to have for future potential work (e.g., could we provide a
compartment-safe printing function, instead of crashing with `printf`,
if making `printf` be compatible proves hard).

Adds a harness to be able to run `so` files natively, without having to
go through the compartment library. Useful for debugging / differential
testing.
  • Loading branch information
0152la committed Feb 23, 2024
1 parent 46783df commit a648fe5
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ endfunction()

# Library tests
set(func_binaries
"so_harness"
"test_map"
#"test_args_near_unmapped"
#"test_two_comps"
Expand All @@ -123,6 +124,8 @@ set(comp_binaries
"simple_call_internal"
"simple_call_external"
"simple_external"
"simple_syscall_getpid"
"simple_syscall_write"
#"time"
#"lua_simple"
#"lua_script"
Expand All @@ -136,6 +139,8 @@ set(tests
"simple_libc"
"simple_call_internal"
"simple_call_external"
"simple_syscall_getpid"
"simple_syscall_write"
#"time"
#"lua_simple"
#"lua_script"
Expand Down
11 changes: 11 additions & 0 deletions tests/simple_syscall_getpid.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <assert.h>
#include <unistd.h>

int
main(void)
{
long int sc_pid = syscall(20);
pid_t pid = getpid();
assert(pid == sc_pid);
return 0;
}
16 changes: 16 additions & 0 deletions tests/simple_syscall_write.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <unistd.h>
#include <string.h>
#include <err.h>

int
main(void)
{
char* buf = "Hello World!\n";
long int sc_write = syscall(4, STDOUT_FILENO, buf, strlen(buf));
if (sc_write == -1)
{
err(1, "Error calling `syscall`:");
}
return 0;
}

32 changes: 32 additions & 0 deletions tests/so_harness.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <dlfcn.h>
#include <err.h>

#include <assert.h>
#include <stdio.h>

int
main(int argc, char **argv)
{
if (argc != 2)
{
errx(1, "Expected one argument - path to `so` file to wrap.\n");
}
void *handle = dlopen(argv[1], RTLD_LAZY);
if (!handle)
{
errx(1, "`dlopen` error: %s\n", dlerror());
}

dlerror();
void (*handle_main)() = (void (*)(void)) dlsym(handle, "main");
char *sym_err = dlerror();
if (sym_err)
{
errx(1, "`dlsym` error: %s\n", sym_err);
}

handle_main();

dlclose(handle);
return 0;
}

0 comments on commit a648fe5

Please sign in to comment.