odyssey/test/machinarium/test_sleep.c

54 lines
842 B
C
Raw Normal View History

#include <machinarium.h>
#include <odyssey_test.h>
static void coroutine(void *arg)
{
(void)arg;
machine_sleep(100);
2020-03-20 07:50:05 +00:00
machine_stop_current();
}
void machinarium_test_sleep(void)
{
machinarium_init();
int id;
id = machine_create("test", coroutine, NULL);
test(id != -1);
int rc;
rc = machine_wait(id);
test(rc != -1);
machinarium_free();
}
2019-12-01 17:27:03 +00:00
static void coroutine_random_sleep(void *arg)
2019-12-01 17:27:03 +00:00
{
(void)arg;
long int duration = machine_lrand48();
machine_sleep(duration & 0xFF);
2020-03-20 07:50:05 +00:00
machine_stop_current();
2019-12-01 17:27:03 +00:00
}
void machinarium_test_sleep_random(void)
2019-12-01 17:27:03 +00:00
{
machinarium_init();
int n = 100;
int id[n];
for (int i = 0; i < n; i++) {
2019-12-01 17:27:03 +00:00
id[i] = machine_create("test", coroutine_random_sleep, NULL);
test(id[i] != -1);
}
for (int i = 0; i < n; i++) {
2019-12-01 17:27:03 +00:00
int rc;
rc = machine_wait(id[i]);
test(rc != -1);
}
machinarium_free();
}