diff --git a/tests/makefile b/tests/makefile index a326aa54..0fb43e3c 100644 --- a/tests/makefile +++ b/tests/makefile @@ -8,6 +8,8 @@ TESTS = test_new \ test_create \ test_sleep \ test_wait \ + test_condition \ + test_condition_2 \ test_io_new \ test_getaddrinfo \ test_getaddrinfo_2 \ @@ -32,6 +34,10 @@ test_sleep: $(CC) $(CFLAGS) test_sleep.c $(LFLAGS) -o test_sleep test_wait: $(CC) $(CFLAGS) test_wait.c $(LFLAGS) -o test_wait +test_condition: + $(CC) $(CFLAGS) test_condition.c $(LFLAGS) -o test_condition +test_condition_2: + $(CC) $(CFLAGS) test_condition_2.c $(LFLAGS) -o test_condition_2 test_io_new: $(CC) $(CFLAGS) test_io_new.c $(LFLAGS) -o test_io_new test_getaddrinfo: diff --git a/tests/test_condition.c b/tests/test_condition.c new file mode 100644 index 00000000..a60cddb4 --- /dev/null +++ b/tests/test_condition.c @@ -0,0 +1,46 @@ + +/* + * machinarium. + * + * Cooperative multitasking engine. +*/ + +#include +#include + +static void +test_condition(void *arg) +{ + mm_t env = arg; + printf("condition fiber started\n"); + int rc = mm_condition(env, 1000); + assert(rc == 0); + printf("condition fiber ended\n"); +} + +static void +test_waiter(void *arg) +{ + mm_t env = arg; + + printf("waiter started\n"); + + int a = mm_create(env, test_condition, env); + + mm_sleep(env, 0); + mm_signal(env, a); + mm_sleep(env, 0); + + printf("waiter ended\n"); + mm_stop(env); +} + +int +main(int argc, char *argv[]) +{ + mm_t env = mm_new(); + mm_create(env, test_waiter, env); + mm_start(env); + mm_free(env); + return 0; +}