diff --git a/.gitignore b/.gitignore index f4906c0d..09b55f86 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ example/cancel example/cancel_connect tests/env tests/create +tests/sleep tests/wait diff --git a/tests/makefile b/tests/makefile index 1b90f102..bbb23c14 100644 --- a/tests/makefile +++ b/tests/makefile @@ -4,12 +4,14 @@ CFLAGS = -I. -Wall -g -O0 -I../machinarium LFLAGS_LIB = ../machinarium/libmachinarium.a LFLAGS_LIB_UV = ~/temp/libuv/.libs/libuv.a -pthread LFLAGS = $(LFLAGS_LIB) $(LFLAGS_LIB_UV) -TESTS = env create wait +TESTS = env create sleep wait all: validate clean $(TESTS) env: $(CC) $(CFLAGS) env.c $(LFLAGS) -o env create: $(CC) $(CFLAGS) create.c $(LFLAGS) -o create +sleep: + $(CC) $(CFLAGS) sleep.c $(LFLAGS) -o sleep wait: $(CC) $(CFLAGS) wait.c $(LFLAGS) -o wait validate: diff --git a/tests/sleep.c b/tests/sleep.c new file mode 100644 index 00000000..fa547a4e --- /dev/null +++ b/tests/sleep.c @@ -0,0 +1,31 @@ + +/* + * machinarium. + * + * Cooperative multitasking engine. +*/ + +#include +#include + +static void +test_child(void *arg) +{ + mm_t env = arg; + printf("child started\n"); + printf("sleep 10 ms\n"); + mm_sleep(env, 10); + printf("sleep wakeup\n"); + printf("child ended\n"); + mm_stop(env); +} + +int +main(int argc, char *argv[]) +{ + mm_t env = mm_new(); + mm_create(env, test_child, env); + mm_start(env); + mm_free(env); + return 0; +}