mirror of https://github.com/yandex/odyssey.git
machinarium: add basic queue tests
This commit is contained in:
parent
978d757842
commit
c1b40108bf
|
@ -0,0 +1,34 @@
|
|||
|
||||
/*
|
||||
* machinarium.
|
||||
*
|
||||
* Cooperative multitasking engine.
|
||||
*/
|
||||
|
||||
#include <machinarium.h>
|
||||
#include <machinarium_test.h>
|
||||
|
||||
static void
|
||||
test_fiber(void *arg)
|
||||
{
|
||||
machine_queue_t queue;
|
||||
queue = machine_queue_create();
|
||||
test(queue != NULL);
|
||||
machine_queue_free(queue);
|
||||
}
|
||||
|
||||
void
|
||||
test_queue_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,47 @@
|
|||
|
||||
/*
|
||||
* machinarium.
|
||||
*
|
||||
* Cooperative multitasking engine.
|
||||
*/
|
||||
|
||||
#include <machinarium.h>
|
||||
#include <machinarium_test.h>
|
||||
|
||||
static void
|
||||
test_fiber(void *arg)
|
||||
{
|
||||
machine_queue_t queue;
|
||||
queue = machine_queue_create();
|
||||
test(queue != NULL);
|
||||
|
||||
machine_msg_t msg;
|
||||
msg = machine_msg_create(123);
|
||||
test(msg != NULL);
|
||||
|
||||
machine_queue_put(queue, msg);
|
||||
|
||||
machine_msg_t msg_in;
|
||||
msg_in = machine_queue_get(queue, 0);
|
||||
test(msg_in != NULL);
|
||||
test(msg_in == msg);
|
||||
machine_msg_free(msg_in);
|
||||
|
||||
machine_queue_free(queue);
|
||||
}
|
||||
|
||||
void
|
||||
test_queue_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_queue_t queue;
|
||||
|
||||
static void
|
||||
test_fiber2(void *arg)
|
||||
{
|
||||
machine_msg_t msg;
|
||||
msg = machine_queue_get(queue, UINT_MAX);
|
||||
test(msg != NULL);
|
||||
test(machine_msg_get_type(msg) == 123);
|
||||
machine_msg_free(msg);
|
||||
|
||||
msg = machine_msg_create(321);
|
||||
machine_queue_put(queue, msg);
|
||||
}
|
||||
|
||||
static void
|
||||
test_fiber(void *arg)
|
||||
{
|
||||
queue = machine_queue_create();
|
||||
test(queue != NULL);
|
||||
|
||||
int id;
|
||||
id = machine_fiber_create(test_fiber2, NULL);
|
||||
|
||||
machine_msg_t msg;
|
||||
msg = machine_msg_create(123);
|
||||
test(msg != NULL);
|
||||
machine_queue_put(queue, msg);
|
||||
|
||||
machine_sleep(0);
|
||||
|
||||
msg = machine_queue_get(queue, UINT_MAX);
|
||||
test(msg != NULL);
|
||||
test(machine_msg_get_type(msg) == 321);
|
||||
machine_msg_free(msg);
|
||||
|
||||
machine_join(id);
|
||||
|
||||
machine_queue_free(queue);
|
||||
}
|
||||
|
||||
void
|
||||
test_queue_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,68 @@
|
|||
|
||||
/*
|
||||
* machinarium.
|
||||
*
|
||||
* Cooperative multitasking engine.
|
||||
*/
|
||||
|
||||
#include <machinarium.h>
|
||||
#include <machinarium_test.h>
|
||||
|
||||
static machine_queue_t queue;
|
||||
|
||||
static void
|
||||
test_fiber2(void *arg)
|
||||
{
|
||||
machine_msg_t msg;
|
||||
msg = machine_queue_get(queue, UINT_MAX);
|
||||
test(msg != NULL);
|
||||
test(machine_msg_get_type(msg) == 123);
|
||||
machine_msg_free(msg);
|
||||
|
||||
msg = machine_msg_create(321);
|
||||
machine_queue_put(queue, msg);
|
||||
}
|
||||
|
||||
static void
|
||||
test_fiber(void *arg)
|
||||
{
|
||||
queue = machine_queue_create();
|
||||
test(queue != 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_queue_put(queue, msg);
|
||||
|
||||
machine_sleep(0);
|
||||
machine_sleep(0);
|
||||
|
||||
msg = machine_queue_get(queue, UINT_MAX);
|
||||
test(msg != NULL);
|
||||
test(machine_msg_get_type(msg) == 321);
|
||||
machine_msg_free(msg);
|
||||
|
||||
machine_join(id);
|
||||
|
||||
machine_queue_free(queue);
|
||||
}
|
||||
|
||||
void
|
||||
test_queue_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();
|
||||
}
|
Loading…
Reference in New Issue