odyssey/tests/test_context_switch.c

51 lines
624 B
C
Raw Normal View History

2017-05-15 14:38:39 +00:00
/*
* machinarium.
*
* Cooperative multitasking engine.
*/
#include <machinarium.h>
#include <machinarium_test.h>
static int csw = 0;
static void
csw_worker(void *arg)
{
while (csw < 100000) {
machine_sleep(0);
2017-05-15 14:38:39 +00:00
csw++;
}
}
static void
csw_runner(void *arg)
{
int rc;
rc = machine_create_fiber(csw_worker, NULL);
2017-05-15 14:38:39 +00:00
test(rc != -1);
rc = machine_wait(rc);
2017-05-15 14:38:39 +00:00
test(rc != -1);
test(csw == 100000);
machine_stop();
2017-05-15 14:38:39 +00:00
}
void
test_context_switch(void)
{
machinarium_init();
int id;
id = machine_create(csw_runner, NULL);
test(id != -1);
2017-05-15 14:38:39 +00:00
int rc;
rc = machine_join(id);
2017-05-15 14:38:39 +00:00
test(rc != -1);
machinarium_free();
2017-05-15 14:38:39 +00:00
}