mirror of https://github.com/yandex/odyssey.git
machinarium: add create and sleep tests
This commit is contained in:
parent
40420f7714
commit
af3770be90
|
@ -9,10 +9,21 @@
|
|||
#include <machinarium_test.h>
|
||||
|
||||
extern void test_init(void);
|
||||
extern void test_create(void);
|
||||
|
||||
extern void test_sleep(void);
|
||||
extern void test_sleep_yield(void);
|
||||
extern void test_sleep_cancel0(void);
|
||||
extern void test_sleep_cancel1(void);
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
machinarium_test(test_init);
|
||||
machinarium_test(test_create);
|
||||
machinarium_test(test_sleep);
|
||||
machinarium_test(test_sleep_yield);
|
||||
machinarium_test(test_sleep_cancel0);
|
||||
machinarium_test(test_sleep_cancel1);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -7,10 +7,10 @@
|
|||
* cooperative multitasking engine.
|
||||
*/
|
||||
|
||||
#define machinarium_test(FUNCTION) \
|
||||
#define machinarium_test(function) \
|
||||
do { \
|
||||
(FUNCTION)(); \
|
||||
fprintf(stdout, "%s: ok\n", #FUNCTION); \
|
||||
(function)(); \
|
||||
fprintf(stdout, "%s: ok\n", #function); \
|
||||
} while (0);
|
||||
|
||||
#define test(expression) \
|
||||
|
|
|
@ -5,7 +5,12 @@ CFLAGS = -I. -Wall -g -O0 -I../src
|
|||
LFLAGS_LIB = ../src/libmachinarium.a -pthread -lssl -lcrypto
|
||||
LFLAGS = $(LFLAGS_LIB)
|
||||
OBJECTS = machinarium_test.o \
|
||||
test_init.o
|
||||
test_init.o \
|
||||
test_create.o \
|
||||
test_sleep.o \
|
||||
test_sleep_yield.o \
|
||||
test_sleep_cancel0.o \
|
||||
test_sleep_cancel1.o
|
||||
all: clean $(OBJECTS) machinarium_test
|
||||
machinarium_test:
|
||||
$(CC) $(OBJECTS) $(LFLAGS) -o machinarium_test
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
|
||||
/*
|
||||
* machinarium.
|
||||
*
|
||||
* Cooperative multitasking engine.
|
||||
*/
|
||||
|
||||
#include <machinarium.h>
|
||||
#include <machinarium_test.h>
|
||||
|
||||
static int fiber_call;
|
||||
|
||||
static void
|
||||
fiber(void *arg)
|
||||
{
|
||||
machine_t machine = arg;
|
||||
fiber_call++;
|
||||
machine_stop(machine);
|
||||
}
|
||||
|
||||
void
|
||||
test_create(void)
|
||||
{
|
||||
fiber_call = 0;
|
||||
machine_t machine = machine_create();
|
||||
test(machine != NULL);
|
||||
|
||||
int rc;
|
||||
rc = machine_create_fiber(machine, fiber, machine);
|
||||
test(rc != -1);
|
||||
|
||||
machine_start(machine);
|
||||
test(fiber_call == 1);
|
||||
|
||||
rc = machine_free(machine);
|
||||
test(rc != -1);
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
|
||||
/*
|
||||
* machinarium.
|
||||
*
|
||||
* Cooperative multitasking engine.
|
||||
*/
|
||||
|
||||
#include <machinarium.h>
|
||||
#include <machinarium_test.h>
|
||||
|
||||
static void
|
||||
test_sleep_fiber(void *arg)
|
||||
{
|
||||
machine_t machine = arg;
|
||||
machine_sleep(machine, 100);
|
||||
machine_stop(machine);
|
||||
}
|
||||
|
||||
void
|
||||
test_sleep(void)
|
||||
{
|
||||
machine_t machine = machine_create();
|
||||
test(machine != NULL);
|
||||
|
||||
int rc;
|
||||
rc = machine_create_fiber(machine, test_sleep_fiber, machine);
|
||||
test(rc != -1);
|
||||
|
||||
machine_start(machine);
|
||||
|
||||
rc = machine_free(machine);
|
||||
test(rc != -1);
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
|
||||
/*
|
||||
* machinarium.
|
||||
*
|
||||
* Cooperative multitasking engine.
|
||||
*/
|
||||
|
||||
#include <machinarium.h>
|
||||
#include <machinarium_test.h>
|
||||
|
||||
static void
|
||||
test_sleep_cancel0_child(void *arg)
|
||||
{
|
||||
machine_t machine = arg;
|
||||
machine_sleep(machine, 6000000);
|
||||
test(machine_cancelled(machine))
|
||||
}
|
||||
|
||||
static void
|
||||
test_sleep_cancel0_parent(void *arg)
|
||||
{
|
||||
machine_t machine = arg;
|
||||
|
||||
int64_t id;
|
||||
id = machine_create_fiber(machine, test_sleep_cancel0_child, machine);
|
||||
test(id != -1);
|
||||
|
||||
machine_sleep(machine, 0);
|
||||
|
||||
int rc;
|
||||
rc = machine_cancel(machine, id);
|
||||
test(rc == 0);
|
||||
|
||||
rc = machine_wait(machine, id);
|
||||
test(rc == 0);
|
||||
|
||||
machine_stop(machine);
|
||||
}
|
||||
|
||||
void
|
||||
test_sleep_cancel0(void)
|
||||
{
|
||||
machine_t machine = machine_create();
|
||||
test(machine != NULL);
|
||||
|
||||
int rc;
|
||||
rc = machine_create_fiber(machine, test_sleep_cancel0_parent, machine);
|
||||
test(rc != -1);
|
||||
|
||||
machine_start(machine);
|
||||
|
||||
rc = machine_free(machine);
|
||||
test(rc != -1);
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
|
||||
/*
|
||||
* machinarium.
|
||||
*
|
||||
* Cooperative multitasking engine.
|
||||
*/
|
||||
|
||||
#include <machinarium.h>
|
||||
#include <machinarium_test.h>
|
||||
|
||||
static void
|
||||
test_sleep_cancel1_fiber(void *arg)
|
||||
{
|
||||
machine_t machine = arg;
|
||||
test(machine_cancelled(machine))
|
||||
machine_sleep(machine, 6000000);
|
||||
machine_stop(machine);
|
||||
}
|
||||
|
||||
void
|
||||
test_sleep_cancel1(void)
|
||||
{
|
||||
machine_t machine = machine_create();
|
||||
test(machine != NULL);
|
||||
|
||||
int rc;
|
||||
rc = machine_create_fiber(machine, test_sleep_cancel1_fiber, machine);
|
||||
test(rc != -1);
|
||||
|
||||
rc = machine_cancel(machine, rc);
|
||||
test(rc == 0);
|
||||
|
||||
machine_start(machine);
|
||||
|
||||
rc = machine_free(machine);
|
||||
test(rc != -1);
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
|
||||
/*
|
||||
* machinarium.
|
||||
*
|
||||
* Cooperative multitasking engine.
|
||||
*/
|
||||
|
||||
#include <machinarium.h>
|
||||
#include <machinarium_test.h>
|
||||
|
||||
static void
|
||||
test_sleep_yield_fiber(void *arg)
|
||||
{
|
||||
machine_t machine = arg;
|
||||
machine_sleep(machine, 0);
|
||||
machine_stop(machine);
|
||||
}
|
||||
|
||||
void
|
||||
test_sleep_yield(void)
|
||||
{
|
||||
machine_t machine = machine_create();
|
||||
test(machine != NULL);
|
||||
|
||||
int rc;
|
||||
rc = machine_create_fiber(machine, test_sleep_yield_fiber, machine);
|
||||
test(rc != -1);
|
||||
|
||||
machine_start(machine);
|
||||
|
||||
rc = machine_free(machine);
|
||||
test(rc != -1);
|
||||
}
|
Loading…
Reference in New Issue