odyssey/tests/test_wait.c

58 lines
719 B
C
Raw Normal View History

2017-05-15 13:48:28 +00:00
/*
* machinarium.
*
* Cooperative multitasking engine.
*/
#include <machinarium.h>
#include <machinarium_test.h>
static void
test_child_a(void *arg)
{
machine_sleep(100);
2017-05-15 13:48:28 +00:00
}
static void
test_child_b(void *arg)
{
machine_sleep(300);
2017-05-15 13:48:28 +00:00
}
static void
test_waiter(void *arg)
{
int64_t a, b;
b = machine_create_fiber(test_child_b, NULL);
2017-05-15 13:48:28 +00:00
test(b != -1);
a = machine_create_fiber(test_child_a, NULL);
2017-05-15 13:48:28 +00:00
test(a != -1);
int rc;
rc = machine_wait(a);
2017-05-15 13:48:28 +00:00
test(rc == 0);
rc = machine_wait(b);
2017-05-15 13:48:28 +00:00
test(rc == 0);
machine_stop();
2017-05-15 13:48:28 +00:00
}
void
test_wait(void)
{
machinarium_init();
int id;
id = machine_create(test_waiter, NULL);
test(id != -1);
2017-05-15 13:48:28 +00:00
int rc;
rc = machine_join(id);
2017-05-15 13:48:28 +00:00
test(rc != -1);
machinarium_free();
2017-05-15 13:48:28 +00:00
}