mirror of https://github.com/yandex/odyssey.git
machinarium: add channel tests
This commit is contained in:
parent
ed10ceeb5b
commit
d51534fd0b
|
@ -29,6 +29,8 @@
|
|||
|
||||
#include <openssl/ssl.h>
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/engine.h>
|
||||
#include <openssl/conf.h>
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/err.h>
|
||||
|
||||
|
|
|
@ -37,8 +37,6 @@ void mm_call(mm_call_t *call, int time_ms)
|
|||
|
||||
mm_fiber_t *fiber;
|
||||
fiber = mm_scheduler_current(scheduler);
|
||||
if (mm_fiber_is_cancelled(fiber))
|
||||
return;
|
||||
|
||||
fiber->call_ptr = call;
|
||||
call->fiber = fiber;
|
||||
|
@ -47,6 +45,15 @@ void mm_call(mm_call_t *call, int time_ms)
|
|||
call->arg = call;
|
||||
call->timedout = 0;
|
||||
call->status = 0;
|
||||
if (mm_fiber_is_cancelled(fiber)) {
|
||||
call->status = ECANCELED;
|
||||
call->timedout = 0;
|
||||
call->active = 0;
|
||||
call->cancel_function = NULL;
|
||||
call->arg = NULL;
|
||||
fiber->call_ptr = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
mm_timer_start(clock, &call->timer, mm_call_timer_cb,
|
||||
call, time_ms);
|
||||
|
|
|
@ -78,7 +78,7 @@ mm_channel_read(mm_channel_t *channel, int time_ms)
|
|||
fetch:
|
||||
if (channel->incoming_count > 0) {
|
||||
mm_list_t *first;
|
||||
first = mm_list_pop(&channel->readers);
|
||||
first = mm_list_pop(&channel->incoming);
|
||||
channel->incoming_count--;
|
||||
mm_msg_t *msg;
|
||||
msg = mm_container_of(first, mm_msg_t, link);
|
||||
|
|
|
@ -21,6 +21,13 @@ extern void test_join(void);
|
|||
extern void test_condition0(void);
|
||||
extern void test_condition1(void);
|
||||
|
||||
extern void test_channel_create(void);
|
||||
extern void test_channel_rw0(void);
|
||||
extern void test_channel_rw1(void);
|
||||
extern void test_channel_rw2(void);
|
||||
extern void test_channel_timeout(void);
|
||||
extern void test_channel_cancel(void);
|
||||
|
||||
extern void test_io_new(void);
|
||||
extern void test_connect(void);
|
||||
extern void test_connect_timeout(void);
|
||||
|
@ -50,6 +57,12 @@ main(int argc, char *argv[])
|
|||
machinarium_test(test_join);
|
||||
machinarium_test(test_condition0);
|
||||
machinarium_test(test_condition1);
|
||||
machinarium_test(test_channel_create);
|
||||
machinarium_test(test_channel_rw0);
|
||||
machinarium_test(test_channel_rw1);
|
||||
machinarium_test(test_channel_rw2);
|
||||
machinarium_test(test_channel_timeout);
|
||||
machinarium_test(test_channel_cancel);
|
||||
machinarium_test(test_io_new);
|
||||
machinarium_test(test_connect);
|
||||
machinarium_test(test_connect_timeout);
|
||||
|
|
|
@ -15,6 +15,12 @@ OBJECTS = machinarium_test.o \
|
|||
test_join.o \
|
||||
test_condition0.o \
|
||||
test_condition1.o \
|
||||
test_channel_create.o \
|
||||
test_channel_rw0.o \
|
||||
test_channel_rw1.o \
|
||||
test_channel_rw2.o \
|
||||
test_channel_timeout.o \
|
||||
test_channel_cancel.o \
|
||||
test_io_new.o \
|
||||
test_connect.o \
|
||||
test_connect_timeout.o \
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
|
||||
/*
|
||||
* machinarium.
|
||||
*
|
||||
* Cooperative multitasking engine.
|
||||
*/
|
||||
|
||||
#include <machinarium.h>
|
||||
#include <machinarium_test.h>
|
||||
|
||||
static machine_channel_t channel;
|
||||
|
||||
static void
|
||||
test_fiber2(void *arg)
|
||||
{
|
||||
machine_msg_t msg;
|
||||
msg = machine_channel_read(channel, UINT_MAX);
|
||||
test(msg == NULL);
|
||||
test(machine_cancelled());
|
||||
}
|
||||
|
||||
static void
|
||||
test_fiber(void *arg)
|
||||
{
|
||||
channel = machine_channel_create();
|
||||
test(channel != NULL);
|
||||
|
||||
int id;
|
||||
id = machine_fiber_create(test_fiber2, NULL);
|
||||
machine_sleep(0);
|
||||
machine_cancel(id);
|
||||
machine_join(id);
|
||||
|
||||
machine_channel_free(channel);
|
||||
}
|
||||
|
||||
void
|
||||
test_channel_cancel(void)
|
||||
{
|
||||
machinarium_init();
|
||||
|
||||
int id;
|
||||
id = machine_create("test", test_fiber, NULL);
|
||||
test(id != -1);
|
||||
|
||||
int rc;
|
||||
rc = machine_wait(id);
|
||||
test(rc != -1);
|
||||
|
||||
machinarium_free();
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
|
||||
/*
|
||||
* machinarium.
|
||||
*
|
||||
* Cooperative multitasking engine.
|
||||
*/
|
||||
|
||||
#include <machinarium.h>
|
||||
#include <machinarium_test.h>
|
||||
|
||||
static void
|
||||
test_fiber(void *arg)
|
||||
{
|
||||
machine_channel_t channel;
|
||||
channel = machine_channel_create();
|
||||
test(channel != NULL);
|
||||
machine_channel_free(channel);
|
||||
}
|
||||
|
||||
void
|
||||
test_channel_create(void)
|
||||
{
|
||||
machinarium_init();
|
||||
|
||||
int id;
|
||||
id = machine_create("test", test_fiber, NULL);
|
||||
test(id != -1);
|
||||
|
||||
int rc;
|
||||
rc = machine_wait(id);
|
||||
test(rc != -1);
|
||||
|
||||
machinarium_free();
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
|
||||
/*
|
||||
* machinarium.
|
||||
*
|
||||
* Cooperative multitasking engine.
|
||||
*/
|
||||
|
||||
#include <machinarium.h>
|
||||
#include <machinarium_test.h>
|
||||
|
||||
static void
|
||||
test_fiber(void *arg)
|
||||
{
|
||||
machine_channel_t channel;
|
||||
channel = machine_channel_create();
|
||||
|
||||
machine_msg_t msg;
|
||||
msg = machine_msg_create(123);
|
||||
test(msg != NULL);
|
||||
|
||||
machine_channel_write(channel, msg);
|
||||
|
||||
machine_msg_t msg_in;
|
||||
msg_in = machine_channel_read(channel, 0);
|
||||
test(msg_in != NULL);
|
||||
test(msg_in == msg);
|
||||
|
||||
machine_msg_free(msg);
|
||||
|
||||
test(channel != NULL);
|
||||
machine_channel_free(channel);
|
||||
}
|
||||
|
||||
void
|
||||
test_channel_rw0(void)
|
||||
{
|
||||
machinarium_init();
|
||||
|
||||
int id;
|
||||
id = machine_create("test", test_fiber, NULL);
|
||||
test(id != -1);
|
||||
|
||||
int rc;
|
||||
rc = machine_wait(id);
|
||||
test(rc != -1);
|
||||
|
||||
machinarium_free();
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
|
||||
/*
|
||||
* machinarium.
|
||||
*
|
||||
* Cooperative multitasking engine.
|
||||
*/
|
||||
|
||||
#include <machinarium.h>
|
||||
#include <machinarium_test.h>
|
||||
|
||||
static machine_channel_t channel;
|
||||
|
||||
static void
|
||||
test_fiber2(void *arg)
|
||||
{
|
||||
machine_msg_t msg;
|
||||
msg = machine_channel_read(channel, UINT_MAX);
|
||||
test(msg != NULL);
|
||||
test(machine_msg_get_type(msg) == 123);
|
||||
machine_msg_free(msg);
|
||||
|
||||
msg = machine_msg_create(321);
|
||||
machine_channel_write(channel, msg);
|
||||
}
|
||||
|
||||
static void
|
||||
test_fiber(void *arg)
|
||||
{
|
||||
channel = machine_channel_create();
|
||||
test(channel != NULL);
|
||||
|
||||
int id;
|
||||
id = machine_fiber_create(test_fiber2, NULL);
|
||||
|
||||
machine_msg_t msg;
|
||||
msg = machine_msg_create(123);
|
||||
test(msg != NULL);
|
||||
machine_channel_write(channel, msg);
|
||||
|
||||
machine_sleep(0);
|
||||
|
||||
msg = machine_channel_read(channel, UINT_MAX);
|
||||
test(msg != NULL);
|
||||
test(machine_msg_get_type(msg) == 321);
|
||||
machine_msg_free(msg);
|
||||
|
||||
machine_join(id);
|
||||
|
||||
machine_channel_free(channel);
|
||||
}
|
||||
|
||||
void
|
||||
test_channel_rw1(void)
|
||||
{
|
||||
machinarium_init();
|
||||
|
||||
int id;
|
||||
id = machine_create("test", test_fiber, NULL);
|
||||
test(id != -1);
|
||||
|
||||
int rc;
|
||||
rc = machine_wait(id);
|
||||
test(rc != -1);
|
||||
|
||||
machinarium_free();
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
|
||||
/*
|
||||
* machinarium.
|
||||
*
|
||||
* Cooperative multitasking engine.
|
||||
*/
|
||||
|
||||
#include <machinarium.h>
|
||||
#include <machinarium_test.h>
|
||||
|
||||
static machine_channel_t channel;
|
||||
|
||||
static void
|
||||
test_fiber2(void *arg)
|
||||
{
|
||||
machine_msg_t msg;
|
||||
msg = machine_channel_read(channel, UINT_MAX);
|
||||
test(msg != NULL);
|
||||
test(machine_msg_get_type(msg) == 123);
|
||||
machine_msg_free(msg);
|
||||
|
||||
msg = machine_msg_create(321);
|
||||
machine_channel_write(channel, msg);
|
||||
}
|
||||
|
||||
static void
|
||||
test_fiber(void *arg)
|
||||
{
|
||||
channel = machine_channel_create();
|
||||
test(channel != NULL);
|
||||
|
||||
int id;
|
||||
id = machine_fiber_create(test_fiber2, NULL);
|
||||
machine_sleep(0);
|
||||
|
||||
machine_msg_t msg;
|
||||
msg = machine_msg_create(123);
|
||||
test(msg != NULL);
|
||||
machine_channel_write(channel, msg);
|
||||
|
||||
machine_sleep(0);
|
||||
|
||||
msg = machine_channel_read(channel, UINT_MAX);
|
||||
test(msg != NULL);
|
||||
test(machine_msg_get_type(msg) == 321);
|
||||
machine_msg_free(msg);
|
||||
|
||||
machine_join(id);
|
||||
|
||||
machine_channel_free(channel);
|
||||
}
|
||||
|
||||
void
|
||||
test_channel_rw2(void)
|
||||
{
|
||||
machinarium_init();
|
||||
|
||||
int id;
|
||||
id = machine_create("test", test_fiber, NULL);
|
||||
test(id != -1);
|
||||
|
||||
int rc;
|
||||
rc = machine_wait(id);
|
||||
test(rc != -1);
|
||||
|
||||
machinarium_free();
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
|
||||
/*
|
||||
* machinarium.
|
||||
*
|
||||
* Cooperative multitasking engine.
|
||||
*/
|
||||
|
||||
#include <machinarium.h>
|
||||
#include <machinarium_test.h>
|
||||
|
||||
static void
|
||||
test_fiber(void *arg)
|
||||
{
|
||||
machine_channel_t channel;
|
||||
channel = machine_channel_create();
|
||||
|
||||
machine_msg_t msg;
|
||||
msg = machine_channel_read(channel, 100);
|
||||
test(msg == NULL);
|
||||
|
||||
test(channel != NULL);
|
||||
machine_channel_free(channel);
|
||||
}
|
||||
|
||||
void
|
||||
test_channel_timeout(void)
|
||||
{
|
||||
machinarium_init();
|
||||
|
||||
int id;
|
||||
id = machine_create("test", test_fiber, NULL);
|
||||
test(id != -1);
|
||||
|
||||
int rc;
|
||||
rc = machine_wait(id);
|
||||
test(rc != -1);
|
||||
|
||||
machinarium_free();
|
||||
}
|
Loading…
Reference in New Issue