Skip to content

Commit

Permalink
Skip addrinfo tests when libc is statically linked
Browse files Browse the repository at this point in the history
Signed-off-by: Cole Miller <[email protected]>
  • Loading branch information
cole-miller committed Aug 29, 2024
1 parent 7a07c24 commit 5e9c7e7
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 13 deletions.
5 changes: 4 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ check_PROGRAMS += \
raft-core-fuzzy-test

libtest_la_SOURCES += \
test/raft/lib/addrinfo.c \
test/raft/lib/fault.c \
test/raft/lib/fsm.c \
test/raft/lib/heap.c \
Expand All @@ -224,6 +223,10 @@ libtest_la_SOURCES += \
test/raft/lib/tcp.c \
test/raft/lib/loop.c

if !WITH_STATIC_DEPS
libtest_la_SOURCES += test/raft/lib/addrinfo.c
endif

libraft_la_CFLAGS = $(AM_CFLAGS)
libraft_la_LDFLAGS = $(static) $(UV_LIBS)

Expand Down
6 changes: 3 additions & 3 deletions test/raft/integration/test_uv_tcp_connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ TEST(tcp_connect, connectByName, setUp, tearDown, 0, NULL)
}

/* Successfully connect to the peer by first IP */
TEST(tcp_connect, firstIP, setUp, tearDown, 0, NULL)
ADDRINFO_TEST(tcp_connect, firstIP, setUp, tearDown, 0, NULL)
{
struct fixture *f = data;
const struct AddrinfoResult results[] = {{"127.0.0.1", TCP_SERVER_PORT},
Expand All @@ -203,7 +203,7 @@ TEST(tcp_connect, firstIP, setUp, tearDown, 0, NULL)
}

/* Successfully connect to the peer by second IP */
TEST(tcp_connect, secondIP, setUp, tearDown, 0, NULL)
ADDRINFO_TEST(tcp_connect, secondIP, setUp, tearDown, 0, NULL)
{
struct fixture *f = data;
const struct AddrinfoResult results[] = {{"127.0.0.1", .6666},
Expand Down Expand Up @@ -332,7 +332,7 @@ TEST(tcp_connect, closeDuringConnectAbort, setUp, tearDownDeps, 0, NULL)

/* The transport gets closed right after the first connection attempt failed,
* while doing a second connection attempt. */
TEST(tcp_connect, closeDuringSecondConnect, setUp, tearDownDeps, 0, NULL)
ADDRINFO_TEST(tcp_connect, closeDuringSecondConnect, setUp, tearDownDeps, 0, NULL)
{
struct fixture *f = data;
struct uv_check_s check;
Expand Down
12 changes: 6 additions & 6 deletions test/raft/integration/test_uv_tcp_listen.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ TEST(tcp_listen, invalidAddress, setUp, tearDown, 0, invalidTcpListenParams)

/* Check success with addrinfo resolve to mutiple IP and first one is used to
* connect */
TEST(tcp_listen, firstOfTwo, setUp, tearDown, 0, NULL)
ADDRINFO_TEST(tcp_listen, firstOfTwo, setUp, tearDown, 0, NULL)
{
const struct AddrinfoResult results[] = {{"127.0.0.1", 9000},
{"127.0.0.2", 9000}};
Expand All @@ -252,7 +252,7 @@ TEST(tcp_listen, firstOfTwo, setUp, tearDown, 0, NULL)

/* Check success with addrinfo resolve to mutiple IP and second one is used to
* connect */
TEST(tcp_listen, secondOfTwo, setUp, tearDown, 0, NULL)
ADDRINFO_TEST(tcp_listen, secondOfTwo, setUp, tearDown, 0, NULL)
{
const struct AddrinfoResult results[] = {{"127.0.0.2", 9000},
{"127.0.0.1", 9000}};
Expand All @@ -268,7 +268,7 @@ TEST(tcp_listen, secondOfTwo, setUp, tearDown, 0, NULL)

/* Simulate port already in use error by addrinfo response contain the same IP
* twice */
TEST(tcp_listen, alreadyBound, setUp, tearDown, 0, NULL)
ADDRINFO_TEST(tcp_listen, alreadyBound, setUp, tearDown, 0, NULL)
{
/* We need to use the same endpoint three times as a simple duplicate will
* be skipped due to a glib strange behavior
Expand All @@ -282,7 +282,7 @@ TEST(tcp_listen, alreadyBound, setUp, tearDown, 0, NULL)
}

/* Error in bind first IP address */
TEST(tcp_listen, cannotBindFirst, setUp, tearDown, 0, NULL)
ADDRINFO_TEST(tcp_listen, cannotBindFirst, setUp, tearDown, 0, NULL)
{
const struct AddrinfoResult results[] = {{"192.0.2.0", 9000},
{"127.0.0.1", 9000}};
Expand All @@ -293,7 +293,7 @@ TEST(tcp_listen, cannotBindFirst, setUp, tearDown, 0, NULL)
}

/* Error in bind of second IP address */
TEST(tcp_listen, cannotBindSecond, setUp, tearDown, 0, NULL)
ADDRINFO_TEST(tcp_listen, cannotBindSecond, setUp, tearDown, 0, NULL)
{
const struct AddrinfoResult results[] = {{"127.0.0.1", 9000},
{"192.0.2.0", 9000}};
Expand All @@ -304,7 +304,7 @@ TEST(tcp_listen, cannotBindSecond, setUp, tearDown, 0, NULL)
}

/* Check error on general dns server failure */
TEST(tcp_listen, resolveFailure, setUp, tearDown, 0, NULL)
ADDRINFO_TEST(tcp_listen, resolveFailure, setUp, tearDown, 0, NULL)
{
struct fixture *f = data;
AddrinfoInjectSetResponse(EAI_FAIL, 0, NULL);
Expand Down
32 changes: 29 additions & 3 deletions test/raft/lib/addrinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,46 @@

#include "munit.h"

#define SET_UP_ADDRINFO AddrinfoInjectSetUp(params)
#define TEAR_DOWN_ADDRINFO AddrinfoInjectTearDown()

typedef struct AddrinfoResult
{
const char *ip;
const int port;
} AddrinfoResult_t;

#ifdef DQLITE_STATIC_LIBC

#define ADDRINFO_TEST(S, C, SETUP, TEAR_DOWN, OPTIONS, PARAMS) \
TEST(S, C, SETUP, TEAR_DOWN, OPTIONS, PARAMS) \
{ \
return MUNIT_SKIP; \
} \
static MUNIT_UNUSED MunitResult test_unused_##S##_##C( \
MUNIT_UNUSED const MunitParameter params[], MUNIT_UNUSED void *data)

#define SET_UP_ADDRINFO
#define TEAR_DOWN_ADDRINFO
#define AddrinfoInjectSetResponse(a, b, c) \
do { \
(void)a; \
(void)b; \
(void)c; \
} while (0)

#else /* ifndef DQLITE_STATIC_LIBC */

#define ADDRINFO_TEST(S, C, SETUP, TEAR_DOWN, OPTIONS, PARAMS) \
TEST(S, C, SETUP, TEAR_DOWN, OPTIONS, PARAMS)

#define SET_UP_ADDRINFO AddrinfoInjectSetUp(params)
#define TEAR_DOWN_ADDRINFO AddrinfoInjectTearDown()

void AddrinfoInjectSetResponse(int rv,
int num_results,
const struct AddrinfoResult *results);

void AddrinfoInjectSetUp(const MunitParameter params[]);
void AddrinfoInjectTearDown(void);

#endif /* ifdef DQLITE_STATIC_LIBC ... else */

#endif // #ifndef TEST_ADDRINFO_H

0 comments on commit 5e9c7e7

Please sign in to comment.