diff options
Diffstat (limited to 'src/tests/utests/chan2')
-rw-r--r-- | src/tests/utests/chan2/test.c | 50 |
1 files changed, 26 insertions, 24 deletions
diff --git a/src/tests/utests/chan2/test.c b/src/tests/utests/chan2/test.c index a2f8b3f..c972e79 100644 --- a/src/tests/utests/chan2/test.c +++ b/src/tests/utests/chan2/test.c @@ -1,9 +1,9 @@ #include <string.h> -#include <malloc.h> +#include <kogata/malloc.h> -#include <syscall.h> -#include <debug.h> +#include <kogata/syscall.h> +#include <kogata/debug.h> volatile int step = 0; // volatile because thread-shared @@ -15,6 +15,8 @@ const char* msg_d = "hello world"; void listen_thread(fd_t c1, fd_t c2) { dbg_printf("listen_thread started\n"); + dbg_printf("Got args: %d, %d\n", c1, c2); + sel_fd_t sel[2]; sel[0].fd = c1; sel[1].fd = c2; @@ -23,49 +25,49 @@ void listen_thread(fd_t c1, fd_t c2) { char buf[128]; dbg_printf("Doing first select...\n"); - ASSERT(select(sel, 2, -1)); + ASSERT(sc_select(sel, 2, -1)); dbg_printf("%x %x\n", sel[0].got_flags, sel[1].got_flags); ASSERT(sel[0].got_flags & SEL_READ); ASSERT(!(sel[1].got_flags & SEL_READ)); - ASSERT(read(c1, 0, strlen(msg_a), buf) == strlen(msg_a)); + ASSERT(sc_read(c1, 0, strlen(msg_a), buf) == strlen(msg_a)); ASSERT(strncmp(buf, msg_a, strlen(msg_a)) == 0); - ASSERT(write(c1, 0, strlen(msg_c), msg_c) == strlen(msg_c)); + ASSERT(sc_write(c1, 0, strlen(msg_c), msg_c) == strlen(msg_c)); step = 1; dbg_printf("Doing second select...\n"); - ASSERT(select(sel, 2, -1)); + ASSERT(sc_select(sel, 2, -1)); dbg_printf("%x %x\n", sel[0].got_flags, sel[1].got_flags); ASSERT(sel[1].got_flags & SEL_READ); ASSERT(!(sel[0].got_flags & SEL_READ)); - ASSERT(read(c2, 0, strlen(msg_b), buf) == strlen(msg_b)); + ASSERT(sc_read(c2, 0, strlen(msg_b), buf) == strlen(msg_b)); ASSERT(strncmp(buf, msg_b, strlen(msg_b)) == 0); - ASSERT(write(c2, 0, strlen(msg_d), msg_d) == strlen(msg_d)); + ASSERT(sc_write(c2, 0, strlen(msg_d), msg_d) == strlen(msg_d)); step = 2; dbg_printf("Doing third select...\n"); - ASSERT(select(sel, 2, -1)); + ASSERT(sc_select(sel, 2, -1)); dbg_printf("%x %x\n", sel[0].got_flags, sel[1].got_flags); ASSERT(sel[0].got_flags & SEL_ERROR); ASSERT(!(sel[1].got_flags & SEL_ERROR)); - close(c1); + sc_close(c1); step = 3; dbg_printf("Doing fourth select...\n"); - ASSERT(select(sel + 1, 1, -1)); + ASSERT(sc_select(sel + 1, 1, -1)); dbg_printf("%x\n", sel[1].got_flags); ASSERT(sel[1].got_flags & SEL_ERROR); - close(c2); + sc_close(c2); step = 4; - exit_thread(); + sc_exit_thread(); } int main(int argc, char **argv) { - fd_pair_t ch1 = make_channel(false); + fd_pair_t ch1 = sc_make_channel(false); ASSERT(ch1.a != 0 && ch1.b != 0); - fd_pair_t ch2 = make_channel(false); + fd_pair_t ch2 = sc_make_channel(false); ASSERT(ch2.a != 0 && ch2.b != 0); void* stack = malloc(0x1000); @@ -77,42 +79,42 @@ int main(int argc, char **argv) { *(--esp) = ch2.a; *(--esp) = ch1.a; *(--esp) = 0; // false return address - dbg_printf("launching waiter thread\n"); - ASSERT(sys_new_thread(listen_thread, esp)); + dbg_printf("launching waiter thread (args: %d, %d)\n", ch1.a, ch2.a); + ASSERT(sc_sys_new_thread(listen_thread, esp)); fd_t c1 = ch1.b, c2 = ch2.b; // -- the test on the first channel - ASSERT(write(c1, 0, strlen(msg_a), msg_a) == strlen(msg_a)); + ASSERT(sc_write(c1, 0, strlen(msg_a), msg_a) == strlen(msg_a)); dbg_printf("wait for step1 signal\n"); while(step != 1); dbg_printf("got step1 signal, proceeding\n"); - ASSERT(read(c1, 0, strlen(msg_c), buf) == strlen(msg_c)); + ASSERT(sc_read(c1, 0, strlen(msg_c), buf) == strlen(msg_c)); ASSERT(strncmp(msg_c, buf, strlen(msg_c)) == 0); // -- the test on the second channel - ASSERT(write(c2, 0, strlen(msg_b), msg_b) == strlen(msg_b)); + ASSERT(sc_write(c2, 0, strlen(msg_b), msg_b) == strlen(msg_b)); dbg_printf("wait for step2 signal\n"); while(step != 2); dbg_printf("got step2 signal, proceeding\n"); - ASSERT(read(c2, 0, strlen(msg_d), buf) == strlen(msg_d)); + ASSERT(sc_read(c2, 0, strlen(msg_d), buf) == strlen(msg_d)); ASSERT(strncmp(msg_d, buf, strlen(msg_d)) == 0); // -- closing stuff - close(c1); + sc_close(c1); dbg_printf("waiting for step3 signal\n"); while(step != 3); dbg_printf("got step3 signal, proceeding\n"); - close(c2); + sc_close(c2); dbg_printf("waiting for step4 signal\n"); while(step != 4); |