machinarium: add test_getaddrinfo_3

This commit is contained in:
Dmitry Simonenko 2017-01-13 12:19:58 +03:00
parent 85b00a2d3e
commit f9a5fa50d3
3 changed files with 60 additions and 2 deletions

1
.gitignore vendored
View File

@ -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

View File

@ -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

View File

@ -0,0 +1,54 @@
/*
* machinarium.
*
* Cooperative multitasking engine.
*/
#include <machinarium.h>
#include <assert.h>
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;
}