Skip to content

Commit

Permalink
Add a test for syscalls in lithe
Browse files Browse the repository at this point in the history
Need to enable the #define in parlib for ALWAYS_BLOCK in
src/internal/syscalls.h in order to thest this properly.
  • Loading branch information
klueska committed Mar 23, 2015
1 parent 1461bce commit 3e093de
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ LIB_HHFILES = \
TEST_EXECS = \
test_cls \
test_mutex \
test_syscalls \
test_recursive_mutex \
test_condvar \
test_parent \
Expand Down Expand Up @@ -78,6 +79,11 @@ test_cls_CFLAGS = $(AM_CFLAGS)
test_cls_CFLAGS += -I$(srcdir)
test_cls_LDADD = -lithe $(LPARLIB)

test_syscalls_SOURCES = @TESTSDIR@/test-syscalls.c
test_syscalls_CFLAGS = $(AM_CFLAGS)
test_syscalls_CFLAGS += -I$(srcdir)
test_syscalls_LDADD = -lithe $(LPARLIB)

test_mutex_SOURCES = @TESTSDIR@/test-mutex.c
test_mutex_CFLAGS = $(AM_CFLAGS)
test_mutex_CFLAGS += -I$(srcdir)
Expand Down
67 changes: 67 additions & 0 deletions tests/test-syscalls.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <sys/types.h>
#include <fcntl.h>
#include <assert.h>
#include "src/mutex.h"
#include "src/fork_join_sched.h"

lithe_mutex_t mutex = LITHE_MUTEX_INITIALIZER(mutex);

void work(void *arg)
{
int id = (int)(long)arg;
const char str[] = "This is a test of the emergency broadcast system. This is only a test";

/* Setup the file. */
char filename[20];
sprintf(filename, "%d.dat", id);

/* Write the file. */
int fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0777);
assert(fd != -1);
int n = write(fd, str, strlen(str));
assert(n == strlen(str));
assert(close(fd) == 0);

/* Read the file. */
fd = open(filename, O_RDONLY);
assert(fd != -1);
char buf[sizeof(str)];
assert(read(fd, buf, sizeof(buf)-1) == sizeof(buf)-1);
buf[sizeof(buf)-1] = 0;
assert(memcmp(buf, str, sizeof(buf)) == 0);
assert(close(fd) == 0);

/* Remove the file. */
unlink(filename);

/* Finish up. */
lithe_mutex_lock(&mutex);
printf("context %p done with syscalls (count = %d)\n",
lithe_context_self(), id);
lithe_mutex_unlock(&mutex);
}

void root_run(int count)
{
lithe_fork_join_sched_t *sched = (lithe_fork_join_sched_t*)lithe_sched_current();
for(int i=0; i < count; i++) {
lithe_fork_join_context_create(sched, 4096, work, (void*)(long)i);
}
lithe_fork_join_sched_join_all(sched);
}

int main(int argc, char **argv)
{
printf("main start\n");
lithe_fork_join_sched_t *sched = lithe_fork_join_sched_create();
lithe_sched_enter(&sched->sched);
root_run(3500);
lithe_sched_exit(&sched->sched);
printf("main finish\n");
return 0;
}

0 comments on commit 3e093de

Please sign in to comment.