diff --git a/conts/libl4/include/l4lib/arch-arm/syslib.h b/conts/libl4/include/l4lib/arch-arm/syslib.h index dc52b7a..5e1c254 100644 --- a/conts/libl4/include/l4lib/arch-arm/syslib.h +++ b/conts/libl4/include/l4lib/arch-arm/syslib.h @@ -322,4 +322,15 @@ static inline void *l4_unmap_helper(void *virt, int npages) return 0; } +#define L4_EXIT_MASK 0xFFFF + +static inline void l4_exit(unsigned int exit_code) +{ + struct task_ids ids; + l4_getid(&ids); + l4_thread_control(THREAD_DESTROY | + (exit_code & L4_EXIT_MASK), + &ids); +} + #endif /* __L4LIB_SYSLIB_H__ */ diff --git a/conts/test/src/captest.c b/conts/test/src/captest.c index 767c019..b534a19 100644 --- a/conts/test/src/captest.c +++ b/conts/test/src/captest.c @@ -3,14 +3,14 @@ #include #include #include -static int result = 1; +#include int simple_pager_thread(void *arg) { int err; int res = *(int *)arg; struct task_ids ids; - int testres; + int testres = 0; l4_getid(&ids); @@ -30,7 +30,7 @@ int simple_pager_thread(void *arg) printf("Creation was supposed to fail " "with %d or %d, but err = %d\n", -ENOMEM, -ENOCAP, err); - testres = -1; + testres = 1; } else if (err == 0) { @@ -39,7 +39,7 @@ int simple_pager_thread(void *arg) } else { printf("Creation was supposed to succeed, " "but err = %d\n", err); - testres = -1; + testres = 1; } /* Destroy thread we created */ @@ -47,27 +47,25 @@ int simple_pager_thread(void *arg) res == 0) l4_thread_control(THREAD_DESTROY, &ids); - result = testres; - /* Destroy self */ - l4_getid(&ids); - l4_thread_control(THREAD_DESTROY, &ids); + l4_exit(testres); return 0; } -int wait_check_test(void) +int wait_check_test(struct task_ids *ids) { - /* Wait for thread to finish */ - while (result > 0) - ; - //l4_thread_switch(0); + int result; - if (result != 0) { - printf("Top-level test has failed\n"); + /* Wait for thread to finish */ + result = l4_thread_control(THREAD_WAIT, ids); + if (result < 0) { + printf("Waiting on (%d)'s exit failed.\n", ids->tid); return -1; + } else if (result > 0) { + printf("Top-level test has failed\n"); } - result = 1; + /* Else it is a success */ return 0; } @@ -94,7 +92,7 @@ int capability_test(void) } /* Wait for test to finish and check result */ - if (wait_check_test() < 0) + if (wait_check_test(&ids) < 0) goto out_err; #if 0 @@ -129,7 +127,7 @@ int capability_test(void) } /* Wait for test to finish and check result */ - if (wait_check_test() < 0) + if (wait_check_test(&ids) < 0) goto out_err; #if 0