flint: add fiber sleep tests

This commit is contained in:
Dmitry Simonenko 2016-11-24 16:53:36 +03:00
parent a1b53f1d33
commit 654a9e1e08
3 changed files with 35 additions and 1 deletions

1
.gitignore vendored
View File

@ -7,4 +7,5 @@ example/cancel
example/cancel_connect
tests/env
tests/create
tests/sleep
tests/wait

View File

@ -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:

31
tests/sleep.c Normal file
View File

@ -0,0 +1,31 @@
/*
* machinarium.
*
* Cooperative multitasking engine.
*/
#include <machinarium.h>
#include <assert.h>
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;
}