diff --git a/tests/test_queue_create.c b/tests/test_queue_create.c new file mode 100644 index 00000000..6ae96ef5 --- /dev/null +++ b/tests/test_queue_create.c @@ -0,0 +1,34 @@ + +/* + * machinarium. + * + * Cooperative multitasking engine. +*/ + +#include +#include + +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(); +} diff --git a/tests/test_queue_rw0.c b/tests/test_queue_rw0.c new file mode 100644 index 00000000..fc243885 --- /dev/null +++ b/tests/test_queue_rw0.c @@ -0,0 +1,47 @@ + +/* + * machinarium. + * + * Cooperative multitasking engine. +*/ + +#include +#include + +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(); +} diff --git a/tests/test_queue_rw1.c b/tests/test_queue_rw1.c new file mode 100644 index 00000000..62bb2077 --- /dev/null +++ b/tests/test_queue_rw1.c @@ -0,0 +1,66 @@ + +/* + * machinarium. + * + * Cooperative multitasking engine. +*/ + +#include +#include + +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(); +} diff --git a/tests/test_queue_rw2.c b/tests/test_queue_rw2.c new file mode 100644 index 00000000..3a76cb7d --- /dev/null +++ b/tests/test_queue_rw2.c @@ -0,0 +1,68 @@ + +/* + * machinarium. + * + * Cooperative multitasking engine. +*/ + +#include +#include + +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(); +}