mirror of https://github.com/yandex/odyssey.git
machinarium: add getaddrinfo tests
This commit is contained in:
parent
ffff1d7606
commit
3370cf43e7
|
@ -29,6 +29,9 @@ extern void test_connect_cancel1(void);
|
|||
extern void test_accept_timeout(void);
|
||||
extern void test_accept_cancel(void);
|
||||
|
||||
extern void test_getaddrinfo0(void);
|
||||
extern void test_getaddrinfo1(void);
|
||||
|
||||
extern void test_client_server(void);
|
||||
extern void test_client_server_readahead(void);
|
||||
extern void test_read_timeout(void);
|
||||
|
@ -54,6 +57,8 @@ main(int argc, char *argv[])
|
|||
machinarium_test(test_connect_cancel1);
|
||||
machinarium_test(test_accept_timeout);
|
||||
machinarium_test(test_accept_cancel);
|
||||
machinarium_test(test_getaddrinfo0);
|
||||
machinarium_test(test_getaddrinfo1);
|
||||
machinarium_test(test_client_server);
|
||||
machinarium_test(test_client_server_readahead);
|
||||
machinarium_test(test_read_timeout);
|
||||
|
|
|
@ -22,6 +22,8 @@ OBJECTS = machinarium_test.o \
|
|||
test_connect_cancel1.o \
|
||||
test_accept_timeout.o \
|
||||
test_accept_cancel.o \
|
||||
test_getaddrinfo0.o \
|
||||
test_getaddrinfo1.o \
|
||||
test_client_server.o \
|
||||
test_client_server_readahead.o \
|
||||
test_read_timeout.o \
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
|
||||
/*
|
||||
* machinarium.
|
||||
*
|
||||
* Cooperative multitasking engine.
|
||||
*/
|
||||
|
||||
#include <machinarium.h>
|
||||
#include <machinarium_test.h>
|
||||
|
||||
static void
|
||||
test_gai(void *arg)
|
||||
{
|
||||
machine_t machine = arg;
|
||||
machine_io_t io = machine_create_io(machine);
|
||||
test(io != NULL);
|
||||
struct addrinfo *res = NULL;
|
||||
int rc = machine_getaddrinfo(io, "localhost", "http", NULL, &res, INT_MAX);
|
||||
if (rc < 0) {
|
||||
printf("failed to resolve address\n");
|
||||
} else {
|
||||
test(res != NULL);
|
||||
if (res)
|
||||
freeaddrinfo(res);
|
||||
}
|
||||
machine_free_io(io);
|
||||
machine_stop(machine);
|
||||
}
|
||||
|
||||
void
|
||||
test_getaddrinfo0(void)
|
||||
{
|
||||
machine_t machine = machine_create();
|
||||
test(machine != NULL);
|
||||
|
||||
int rc;
|
||||
rc = machine_create_fiber(machine, test_gai, machine);
|
||||
test(rc != -1);
|
||||
|
||||
machine_start(machine);
|
||||
|
||||
rc = machine_free(machine);
|
||||
test(rc != -1);
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
|
||||
/*
|
||||
* machinarium.
|
||||
*
|
||||
* Cooperative multitasking engine.
|
||||
*/
|
||||
|
||||
#include <machinarium.h>
|
||||
#include <machinarium_test.h>
|
||||
|
||||
static void
|
||||
test_gai0(void *arg)
|
||||
{
|
||||
machine_t machine = arg;
|
||||
machine_io_t io = machine_create_io(machine);
|
||||
test(io != NULL);
|
||||
struct addrinfo *res = NULL;
|
||||
int rc = machine_getaddrinfo(io, "localhost", "http", NULL, &res, INT_MAX);
|
||||
if (rc < 0) {
|
||||
printf("failed to resolve address\n");
|
||||
} else {
|
||||
test(res != NULL);
|
||||
if (res)
|
||||
freeaddrinfo(res);
|
||||
}
|
||||
machine_free_io(io);
|
||||
}
|
||||
|
||||
static void
|
||||
test_gai1(void *arg)
|
||||
{
|
||||
machine_t machine = arg;
|
||||
machine_io_t io = machine_create_io(machine);
|
||||
test(io != NULL);
|
||||
struct addrinfo *res = NULL;
|
||||
int rc = machine_getaddrinfo(io, "localhost", "http", NULL, &res, INT_MAX);
|
||||
if (rc < 0) {
|
||||
printf("failed to resolve address\n");
|
||||
} else {
|
||||
test(res != NULL);
|
||||
if (res)
|
||||
freeaddrinfo(res);
|
||||
}
|
||||
machine_free_io(io);
|
||||
machine_stop(machine);
|
||||
}
|
||||
|
||||
void
|
||||
test_getaddrinfo1(void)
|
||||
{
|
||||
machine_t machine = machine_create();
|
||||
test(machine != NULL);
|
||||
|
||||
int rc;
|
||||
rc = machine_create_fiber(machine, test_gai0, machine);
|
||||
test(rc != -1);
|
||||
|
||||
rc = machine_create_fiber(machine, test_gai1, machine);
|
||||
test(rc != -1);
|
||||
|
||||
machine_start(machine);
|
||||
|
||||
rc = machine_free(machine);
|
||||
test(rc != -1);
|
||||
}
|
Loading…
Reference in New Issue