mirror of https://github.com/yandex/odyssey.git
machinarium: add context-switch test
This commit is contained in:
parent
f0ad7a3db9
commit
22123c7823
|
@ -10,6 +10,7 @@
|
|||
|
||||
extern void test_init(void);
|
||||
extern void test_create(void);
|
||||
extern void test_context_switch(void);
|
||||
|
||||
extern void test_sleep(void);
|
||||
extern void test_sleep_yield(void);
|
||||
|
@ -33,6 +34,7 @@ main(int argc, char *argv[])
|
|||
{
|
||||
machinarium_test(test_init);
|
||||
machinarium_test(test_create);
|
||||
machinarium_test(test_context_switch);
|
||||
machinarium_test(test_sleep);
|
||||
machinarium_test(test_sleep_yield);
|
||||
machinarium_test(test_sleep_cancel0);
|
||||
|
|
|
@ -7,6 +7,7 @@ LFLAGS = $(LFLAGS_LIB)
|
|||
OBJECTS = machinarium_test.o \
|
||||
test_init.o \
|
||||
test_create.o \
|
||||
test_context_switch.o \
|
||||
test_sleep.o \
|
||||
test_sleep_yield.o \
|
||||
test_sleep_cancel0.o \
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
|
||||
/*
|
||||
* machinarium.
|
||||
*
|
||||
* Cooperative multitasking engine.
|
||||
*/
|
||||
|
||||
#include <machinarium.h>
|
||||
#include <machinarium_test.h>
|
||||
|
||||
static int csw = 0;
|
||||
|
||||
static void
|
||||
csw_worker(void *arg)
|
||||
{
|
||||
machine_t machine = arg;
|
||||
while (csw < 100000) {
|
||||
machine_sleep(machine, 0);
|
||||
csw++;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
csw_runner(void *arg)
|
||||
{
|
||||
machine_t machine = arg;
|
||||
|
||||
int rc;
|
||||
rc = machine_create_fiber(machine, csw_worker, machine);
|
||||
test(rc != -1);
|
||||
|
||||
rc = machine_wait(machine, rc);
|
||||
test(rc != -1);
|
||||
test(csw == 100000);
|
||||
|
||||
machine_stop(machine);
|
||||
}
|
||||
|
||||
void
|
||||
test_context_switch(void)
|
||||
{
|
||||
machine_t machine = machine_create();
|
||||
test(machine != NULL);
|
||||
|
||||
int rc;
|
||||
rc = machine_create_fiber(machine, csw_runner, machine);
|
||||
test(rc != -1);
|
||||
|
||||
machine_start(machine);
|
||||
|
||||
rc = machine_free(machine);
|
||||
test(rc != -1);
|
||||
}
|
Loading…
Reference in New Issue