2018-04-04 14:35:50 +00:00
|
|
|
|
|
|
|
#include <machinarium.h>
|
|
|
|
#include <odyssey_test.h>
|
|
|
|
|
|
|
|
static int gai_complete = 0;
|
|
|
|
|
2020-12-28 11:22:53 +00:00
|
|
|
static void test_gai_coroutine(void *arg)
|
2018-04-04 14:35:50 +00:00
|
|
|
{
|
|
|
|
(void)arg;
|
|
|
|
struct addrinfo *res = NULL;
|
2020-12-28 11:22:53 +00:00
|
|
|
int rc = machine_getaddrinfo("localhost", "http", NULL, &res,
|
|
|
|
UINT32_MAX);
|
2018-04-04 14:35:50 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
printf("failed to resolve address\n");
|
|
|
|
} else {
|
|
|
|
test(res != NULL);
|
|
|
|
if (res)
|
|
|
|
freeaddrinfo(res);
|
|
|
|
}
|
|
|
|
gai_complete++;
|
|
|
|
}
|
|
|
|
|
2020-12-28 11:22:53 +00:00
|
|
|
static void test_gai(void *arg)
|
2018-04-04 14:35:50 +00:00
|
|
|
{
|
|
|
|
(void)arg;
|
|
|
|
int rc;
|
|
|
|
int workers[100];
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < 100; i++) {
|
|
|
|
rc = machine_coroutine_create(test_gai_coroutine, NULL);
|
|
|
|
test(rc != -1);
|
|
|
|
workers[i] = rc;
|
|
|
|
}
|
|
|
|
for (i = 0; i < 100; i++) {
|
|
|
|
machine_join(workers[i]);
|
|
|
|
}
|
|
|
|
test(gai_complete == 100);
|
|
|
|
}
|
|
|
|
|
2020-12-28 11:22:53 +00:00
|
|
|
void machinarium_test_getaddrinfo2(void)
|
2018-04-04 14:35:50 +00:00
|
|
|
{
|
|
|
|
machinarium_init();
|
|
|
|
|
|
|
|
int id;
|
|
|
|
id = machine_create("test", test_gai, NULL);
|
|
|
|
test(id != -1);
|
|
|
|
|
|
|
|
int rc;
|
|
|
|
rc = machine_wait(id);
|
|
|
|
test(rc != -1);
|
|
|
|
|
|
|
|
machinarium_free();
|
|
|
|
}
|