From f9a5fa50d3e868d37fa1c83bac291cbdc1dc48f0 Mon Sep 17 00:00:00 2001 From: Dmitry Simonenko Date: Fri, 13 Jan 2017 12:19:58 +0300 Subject: [PATCH] machinarium: add test_getaddrinfo_3 --- .gitignore | 1 + tests/makefile | 7 +++-- tests/test_getaddrinfo_3.c | 54 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 tests/test_getaddrinfo_3.c diff --git a/.gitignore b/.gitignore index ab7d8d3d..c548cc3c 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ tests/test_wait tests/test_io_new tests/test_getaddrinfo tests/test_getaddrinfo_2 +tests/test_getaddrinfo_3 tests/test_client_server tests/test_client_server_ra tests/test_cancel_sleep diff --git a/tests/makefile b/tests/makefile index 283027e2..16c94bc4 100644 --- a/tests/makefile +++ b/tests/makefile @@ -11,6 +11,7 @@ TESTS = test_new \ test_io_new \ test_getaddrinfo \ test_getaddrinfo_2 \ + test_getaddrinfo_3 \ test_client_server \ test_client_server_ra \ test_cancel_sleep \ @@ -37,6 +38,8 @@ test_getaddrinfo: $(CC) $(CFLAGS) test_getaddrinfo.c $(LFLAGS) -o test_getaddrinfo test_getaddrinfo_2: $(CC) $(CFLAGS) test_getaddrinfo_2.c $(LFLAGS) -o test_getaddrinfo_2 +test_getaddrinfo_3: + $(CC) $(CFLAGS) test_getaddrinfo_3.c $(LFLAGS) -o test_getaddrinfo_3 test_client_server: $(CC) $(CFLAGS) test_client_server.c $(LFLAGS) -o test_client_server test_client_server_ra: @@ -60,9 +63,9 @@ echo: benchmark: $(CC) $(CFLAGS) benchmark.c $(LFLAGS) -o benchmark validate: - @if [ ! -f $(LFLAGS_LIB) ]; then \ + @if [ ! -f ../lib/libmachinarium.a ]; then \ echo ""; \ - echo "Please build the library first."; \ + echo "Please build the static library first."; \ echo ""; \ exit 1; \ fi diff --git a/tests/test_getaddrinfo_3.c b/tests/test_getaddrinfo_3.c new file mode 100644 index 00000000..f7359e60 --- /dev/null +++ b/tests/test_getaddrinfo_3.c @@ -0,0 +1,54 @@ + +/* + * machinarium. + * + * Cooperative multitasking engine. +*/ + +#include +#include + +static void +fiber_1(void *arg) +{ + mm_t env = arg; + mm_io_t io = mm_io_new(env); + struct addrinfo *res = NULL; + int rc = mm_getaddrinfo(io, "localhost", "http", NULL, &res, 0); + if (rc < 0) { + printf("failed to resolve address\n"); + } else { + assert(res != NULL); + } + if (res) + freeaddrinfo(res); + mm_close(io); +} + +static void +fiber_2(void *arg) +{ + mm_t env = arg; + mm_io_t io = mm_io_new(env); + struct addrinfo *res = NULL; + int rc = mm_getaddrinfo(io, "localhost", "http", NULL, &res, 0); + if (rc < 0) { + printf("failed to resolve address\n"); + } else { + assert(res != NULL); + } + if (res) + freeaddrinfo(res); + mm_close(io); +} + +int +main(int argc, char *argv[]) +{ + mm_t env = mm_new(); + mm_create(env, fiber_1, env); + mm_create(env, fiber_2, env); + mm_start(env); + mm_free(env); + return 0; +}