2018-04-04 14:35:50 +00:00
|
|
|
|
|
|
|
#include <machinarium.h>
|
|
|
|
#include <odyssey_test.h>
|
|
|
|
|
2020-12-28 11:22:53 +00:00
|
|
|
static void coroutine(void *arg)
|
2018-04-04 14:35:50 +00:00
|
|
|
{
|
|
|
|
(void)arg;
|
|
|
|
machine_sleep(100);
|
2020-03-20 07:50:05 +00:00
|
|
|
machine_stop_current();
|
2018-04-04 14:35:50 +00:00
|
|
|
}
|
|
|
|
|
2020-12-28 11:22:53 +00:00
|
|
|
void machinarium_test_sleep(void)
|
2018-04-04 14:35:50 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
|
2020-12-28 11:22:53 +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
|
|
|
}
|
|
|
|
|
2020-12-28 11:22:53 +00:00
|
|
|
void machinarium_test_sleep_random(void)
|
2019-12-01 17:27:03 +00:00
|
|
|
{
|
|
|
|
machinarium_init();
|
|
|
|
|
|
|
|
int n = 100;
|
|
|
|
int id[n];
|
2020-04-02 11:00:56 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2020-04-02 11:00:56 +00:00
|
|
|
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();
|
|
|
|
}
|