machinarium: add condition/signal test

This commit is contained in:
Dmitry Simonenko 2017-02-01 15:58:28 +03:00
parent 7b08be8d08
commit b544857cde
2 changed files with 52 additions and 0 deletions

View File

@ -8,6 +8,8 @@ TESTS = test_new \
test_create \ test_create \
test_sleep \ test_sleep \
test_wait \ test_wait \
test_condition \
test_condition_2 \
test_io_new \ test_io_new \
test_getaddrinfo \ test_getaddrinfo \
test_getaddrinfo_2 \ test_getaddrinfo_2 \
@ -32,6 +34,10 @@ test_sleep:
$(CC) $(CFLAGS) test_sleep.c $(LFLAGS) -o test_sleep $(CC) $(CFLAGS) test_sleep.c $(LFLAGS) -o test_sleep
test_wait: test_wait:
$(CC) $(CFLAGS) test_wait.c $(LFLAGS) -o 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: test_io_new:
$(CC) $(CFLAGS) test_io_new.c $(LFLAGS) -o test_io_new $(CC) $(CFLAGS) test_io_new.c $(LFLAGS) -o test_io_new
test_getaddrinfo: test_getaddrinfo:

46
tests/test_condition.c Normal file
View File

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