From 647f3ab78d1156b1a8af80e0d7180f0f67e4ebb1 Mon Sep 17 00:00:00 2001 From: Dmitry Simonenko Date: Fri, 25 Nov 2016 13:28:43 +0300 Subject: [PATCH] flint: add second io connect test --- tests/test_io_connect_2.c | 53 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 tests/test_io_connect_2.c diff --git a/tests/test_io_connect_2.c b/tests/test_io_connect_2.c new file mode 100644 index 00000000..c3f19430 --- /dev/null +++ b/tests/test_io_connect_2.c @@ -0,0 +1,53 @@ + +/* + * machinarium. + * + * Cooperative multitasking engine. +*/ + +#include +#include + +static void +test_connect(void *arg) +{ + mm_t env = arg; + assert(mm_is_cancel(env)); + printf("child started\n"); + mmio_t client = mm_io_new(env); + int rc; + rc = mm_connect(client, "8.8.8.16", 1324, 0); + printf("child resumed\n"); + assert(rc < 0); + mm_close(client); + if (mm_is_cancel(env)) + printf("child marked as cancel\n"); + printf("child end\n"); +} + +static void +test_waiter(void *arg) +{ + mm_t env = arg; + + printf("waiter started\n"); + + int id = mm_create(env, test_connect, env); + mm_cancel(env, id); /* run cancelled */ + mm_sleep(env, 0); + mm_wait(env, id); + + printf("waiter 1 ended \n"); + mm_stop(env); +} + +int +main(int argc, char *argv[]) +{ + mm_t env = mm_new(); + mm_create(env, test_waiter, env); + mm_start(env); + printf("shutting down\n"); + mm_free(env); + return 0; +}