aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/iomgr
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2016-10-26 21:00:53 -0700
committerGravatar Craig Tiller <ctiller@google.com>2016-10-26 21:00:53 -0700
commit6e080a36515455f2db5b07465abdeacf3e21c3be (patch)
tree0aa4c9e0297a4408206c93d612efe3852c19fa57 /test/core/iomgr
parentf6f9cf39c677751fb46d42f303a07687e9bfb26a (diff)
parent3d357d901c5228cf8989aed8949b20d32baad77b (diff)
Merge branch 'buffer_pools_for_realsies' into grpc_slice
Diffstat (limited to 'test/core/iomgr')
-rw-r--r--test/core/iomgr/ev_epoll_linux_test.c8
-rw-r--r--test/core/iomgr/fd_posix_test.c11
-rw-r--r--test/core/iomgr/resolve_address_test.c1
-rw-r--r--test/core/iomgr/sockaddr_utils_test.c162
-rw-r--r--test/core/iomgr/socket_utils_test.c12
-rw-r--r--test/core/iomgr/tcp_client_posix_test.c35
-rw-r--r--test/core/iomgr/tcp_posix_test.c11
-rw-r--r--test/core/iomgr/tcp_server_posix_test.c77
-rw-r--r--test/core/iomgr/timer_heap_test.c11
-rw-r--r--test/core/iomgr/udp_server_test.c58
-rw-r--r--test/core/iomgr/wakeup_fd_cv_test.c10
11 files changed, 251 insertions, 145 deletions
diff --git a/test/core/iomgr/ev_epoll_linux_test.c b/test/core/iomgr/ev_epoll_linux_test.c
index 2547dc9871..564b05d7f4 100644
--- a/test/core/iomgr/ev_epoll_linux_test.c
+++ b/test/core/iomgr/ev_epoll_linux_test.c
@@ -30,10 +30,10 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
-#include <grpc/support/port_platform.h>
+#include "src/core/lib/iomgr/port.h"
/* This test only relevant on linux systems where epoll() is available */
-#ifdef GPR_LINUX_EPOLL
+#ifdef GRPC_LINUX_EPOLL
#include "src/core/lib/iomgr/ev_epoll_linux.h"
#include "src/core/lib/iomgr/ev_posix.h"
@@ -239,6 +239,6 @@ int main(int argc, char **argv) {
grpc_iomgr_shutdown();
return 0;
}
-#else /* defined(GPR_LINUX_EPOLL) */
+#else /* defined(GRPC_LINUX_EPOLL) */
int main(int argc, char **argv) { return 0; }
-#endif /* !defined(GPR_LINUX_EPOLL) */
+#endif /* !defined(GRPC_LINUX_EPOLL) */
diff --git a/test/core/iomgr/fd_posix_test.c b/test/core/iomgr/fd_posix_test.c
index 62dc24d85a..6166699fe6 100644
--- a/test/core/iomgr/fd_posix_test.c
+++ b/test/core/iomgr/fd_posix_test.c
@@ -31,6 +31,11 @@
*
*/
+#include "src/core/lib/iomgr/port.h"
+
+// This test won't work except with posix sockets enabled
+#ifdef GRPC_POSIX_SOCKET
+
#include "src/core/lib/iomgr/ev_posix.h"
#include <ctype.h>
@@ -548,3 +553,9 @@ int main(int argc, char **argv) {
grpc_iomgr_shutdown();
return 0;
}
+
+#else /* GRPC_POSIX_SOCKET */
+
+int main(int argc, char **argv) { return 1; }
+
+#endif /* GRPC_POSIX_SOCKET */
diff --git a/test/core/iomgr/resolve_address_test.c b/test/core/iomgr/resolve_address_test.c
index 4417d96043..2dd0d88b3f 100644
--- a/test/core/iomgr/resolve_address_test.c
+++ b/test/core/iomgr/resolve_address_test.c
@@ -36,6 +36,7 @@
#include <grpc/support/sync.h>
#include <grpc/support/time.h>
#include "src/core/lib/iomgr/executor.h"
+#include "src/core/lib/iomgr/iomgr.h"
#include "test/core/util/test_config.h"
static gpr_timespec test_deadline(void) {
diff --git a/test/core/iomgr/sockaddr_utils_test.c b/test/core/iomgr/sockaddr_utils_test.c
index a330314443..8569c697fe 100644
--- a/test/core/iomgr/sockaddr_utils_test.c
+++ b/test/core/iomgr/sockaddr_utils_test.c
@@ -31,6 +31,11 @@
*
*/
+/* With the addition of a libuv endpoint, sockaddr.h now includes uv.h when
+ using that endpoint. Because of various transitive includes in uv.h,
+ including windows.h on Windows, uv.h must be included before other system
+ headers. Therefore, sockaddr.h must always be included first */
+#include "src/core/lib/iomgr/sockaddr.h"
#include "src/core/lib/iomgr/sockaddr_utils.h"
#include <errno.h>
@@ -41,24 +46,28 @@
#include <grpc/support/port_platform.h>
#include "test/core/util/test_config.h"
-static struct sockaddr_in make_addr4(const uint8_t *data, size_t data_len) {
- struct sockaddr_in addr4;
- memset(&addr4, 0, sizeof(addr4));
- addr4.sin_family = AF_INET;
- GPR_ASSERT(data_len == sizeof(addr4.sin_addr.s_addr));
- memcpy(&addr4.sin_addr.s_addr, data, data_len);
- addr4.sin_port = htons(12345);
- return addr4;
+static grpc_resolved_address make_addr4(const uint8_t *data, size_t data_len) {
+ grpc_resolved_address resolved_addr4;
+ struct sockaddr_in *addr4 = (struct sockaddr_in *)resolved_addr4.addr;
+ memset(&resolved_addr4, 0, sizeof(resolved_addr4));
+ addr4->sin_family = AF_INET;
+ GPR_ASSERT(data_len == sizeof(addr4->sin_addr.s_addr));
+ memcpy(&addr4->sin_addr.s_addr, data, data_len);
+ addr4->sin_port = htons(12345);
+ resolved_addr4.len = sizeof(struct sockaddr_in);
+ return resolved_addr4;
}
-static struct sockaddr_in6 make_addr6(const uint8_t *data, size_t data_len) {
- struct sockaddr_in6 addr6;
- memset(&addr6, 0, sizeof(addr6));
- addr6.sin6_family = AF_INET6;
- GPR_ASSERT(data_len == sizeof(addr6.sin6_addr.s6_addr));
- memcpy(&addr6.sin6_addr.s6_addr, data, data_len);
- addr6.sin6_port = htons(12345);
- return addr6;
+static grpc_resolved_address make_addr6(const uint8_t *data, size_t data_len) {
+ grpc_resolved_address resolved_addr6;
+ struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)resolved_addr6.addr;
+ memset(&resolved_addr6, 0, sizeof(resolved_addr6));
+ addr6->sin6_family = AF_INET6;
+ GPR_ASSERT(data_len == sizeof(addr6->sin6_addr.s6_addr));
+ memcpy(&addr6->sin6_addr.s6_addr, data, data_len);
+ addr6->sin6_port = htons(12345);
+ resolved_addr6.len = sizeof(struct sockaddr_in6);
+ return resolved_addr6;
}
static const uint8_t kMapped[] = {0, 0, 0, 0, 0, 0, 0, 0,
@@ -72,102 +81,96 @@ static const uint8_t kIPv6[] = {0x20, 0x01, 0x0d, 0xb8, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 1};
static void test_sockaddr_is_v4mapped(void) {
- struct sockaddr_in input4;
- struct sockaddr_in6 input6;
- struct sockaddr_in output4;
- struct sockaddr_in expect4;
+ grpc_resolved_address input4;
+ grpc_resolved_address input6;
+ grpc_resolved_address output4;
+ grpc_resolved_address expect4;
gpr_log(GPR_INFO, "%s", "test_sockaddr_is_v4mapped");
/* v4mapped input should succeed. */
input6 = make_addr6(kMapped, sizeof(kMapped));
- GPR_ASSERT(grpc_sockaddr_is_v4mapped((const struct sockaddr *)&input6, NULL));
- GPR_ASSERT(
- grpc_sockaddr_is_v4mapped((const struct sockaddr *)&input6, &output4));
+ GPR_ASSERT(grpc_sockaddr_is_v4mapped(&input6, NULL));
+ GPR_ASSERT(grpc_sockaddr_is_v4mapped(&input6, &output4));
expect4 = make_addr4(kIPv4, sizeof(kIPv4));
GPR_ASSERT(memcmp(&expect4, &output4, sizeof(expect4)) == 0);
/* Non-v4mapped input should fail. */
input6 = make_addr6(kNotQuiteMapped, sizeof(kNotQuiteMapped));
- GPR_ASSERT(
- !grpc_sockaddr_is_v4mapped((const struct sockaddr *)&input6, NULL));
- GPR_ASSERT(
- !grpc_sockaddr_is_v4mapped((const struct sockaddr *)&input6, &output4));
+ GPR_ASSERT(!grpc_sockaddr_is_v4mapped(&input6, NULL));
+ GPR_ASSERT(!grpc_sockaddr_is_v4mapped(&input6, &output4));
/* Output is unchanged. */
GPR_ASSERT(memcmp(&expect4, &output4, sizeof(expect4)) == 0);
/* Plain IPv4 input should also fail. */
input4 = make_addr4(kIPv4, sizeof(kIPv4));
- GPR_ASSERT(
- !grpc_sockaddr_is_v4mapped((const struct sockaddr *)&input4, NULL));
+ GPR_ASSERT(!grpc_sockaddr_is_v4mapped(&input4, NULL));
}
static void test_sockaddr_to_v4mapped(void) {
- struct sockaddr_in input4;
- struct sockaddr_in6 input6;
- struct sockaddr_in6 output6;
- struct sockaddr_in6 expect6;
+ grpc_resolved_address input4;
+ grpc_resolved_address input6;
+ grpc_resolved_address output6;
+ grpc_resolved_address expect6;
gpr_log(GPR_INFO, "%s", "test_sockaddr_to_v4mapped");
/* IPv4 input should succeed. */
input4 = make_addr4(kIPv4, sizeof(kIPv4));
- GPR_ASSERT(
- grpc_sockaddr_to_v4mapped((const struct sockaddr *)&input4, &output6));
+ GPR_ASSERT(grpc_sockaddr_to_v4mapped(&input4, &output6));
expect6 = make_addr6(kMapped, sizeof(kMapped));
GPR_ASSERT(memcmp(&expect6, &output6, sizeof(output6)) == 0);
/* IPv6 input should fail. */
input6 = make_addr6(kIPv6, sizeof(kIPv6));
- GPR_ASSERT(
- !grpc_sockaddr_to_v4mapped((const struct sockaddr *)&input6, &output6));
+ GPR_ASSERT(!grpc_sockaddr_to_v4mapped(&input6, &output6));
/* Output is unchanged. */
GPR_ASSERT(memcmp(&expect6, &output6, sizeof(output6)) == 0);
/* Already-v4mapped input should also fail. */
input6 = make_addr6(kMapped, sizeof(kMapped));
- GPR_ASSERT(
- !grpc_sockaddr_to_v4mapped((const struct sockaddr *)&input6, &output6));
+ GPR_ASSERT(!grpc_sockaddr_to_v4mapped(&input6, &output6));
}
static void test_sockaddr_is_wildcard(void) {
- struct sockaddr_in wild4;
- struct sockaddr_in6 wild6;
- struct sockaddr_in6 wild_mapped;
- struct sockaddr dummy;
+ grpc_resolved_address wild4;
+ grpc_resolved_address wild6;
+ grpc_resolved_address wild_mapped;
+ grpc_resolved_address dummy;
+ struct sockaddr_in *wild4_addr;
+ struct sockaddr_in6 *wild6_addr;
+ struct sockaddr_in6 *wild_mapped_addr;
int port;
gpr_log(GPR_INFO, "%s", "test_sockaddr_is_wildcard");
/* Generate wildcards. */
grpc_sockaddr_make_wildcards(555, &wild4, &wild6);
- GPR_ASSERT(
- grpc_sockaddr_to_v4mapped((const struct sockaddr *)&wild4, &wild_mapped));
+ GPR_ASSERT(grpc_sockaddr_to_v4mapped(&wild4, &wild_mapped));
/* Test 0.0.0.0:555 */
port = -1;
- GPR_ASSERT(grpc_sockaddr_is_wildcard((const struct sockaddr *)&wild4, &port));
+ GPR_ASSERT(grpc_sockaddr_is_wildcard(&wild4, &port));
GPR_ASSERT(port == 555);
- memset(&wild4.sin_addr.s_addr, 0xbd, 1);
- GPR_ASSERT(
- !grpc_sockaddr_is_wildcard((const struct sockaddr *)&wild4, &port));
+ wild4_addr = (struct sockaddr_in *)&wild4.addr;
+ memset(&wild4_addr->sin_addr.s_addr, 0xbd, 1);
+ GPR_ASSERT(!grpc_sockaddr_is_wildcard(&wild4, &port));
/* Test [::]:555 */
port = -1;
- GPR_ASSERT(grpc_sockaddr_is_wildcard((const struct sockaddr *)&wild6, &port));
+ GPR_ASSERT(grpc_sockaddr_is_wildcard(&wild6, &port));
GPR_ASSERT(port == 555);
- memset(&wild6.sin6_addr.s6_addr, 0xbd, 1);
- GPR_ASSERT(
- !grpc_sockaddr_is_wildcard((const struct sockaddr *)&wild6, &port));
+ wild6_addr = (struct sockaddr_in6 *)&wild6.addr;
+ memset(&wild6_addr->sin6_addr.s6_addr, 0xbd, 1);
+ GPR_ASSERT(!grpc_sockaddr_is_wildcard(&wild6, &port));
/* Test [::ffff:0.0.0.0]:555 */
port = -1;
- GPR_ASSERT(
- grpc_sockaddr_is_wildcard((const struct sockaddr *)&wild_mapped, &port));
+ GPR_ASSERT(grpc_sockaddr_is_wildcard(&wild_mapped, &port));
GPR_ASSERT(port == 555);
- memset(&wild_mapped.sin6_addr.s6_addr, 0xbd, 1);
- GPR_ASSERT(
- !grpc_sockaddr_is_wildcard((const struct sockaddr *)&wild_mapped, &port));
+ wild_mapped_addr = (struct sockaddr_in6 *)&wild_mapped.addr;
+ memset(&wild_mapped_addr->sin6_addr.s6_addr, 0xbd, 1);
+ GPR_ASSERT(!grpc_sockaddr_is_wildcard(&wild_mapped, &port));
/* Test AF_UNSPEC. */
port = -1;
@@ -176,12 +179,12 @@ static void test_sockaddr_is_wildcard(void) {
GPR_ASSERT(port == -1);
}
-static void expect_sockaddr_str(const char *expected, void *addr,
- int normalize) {
+static void expect_sockaddr_str(const char *expected,
+ grpc_resolved_address *addr, int normalize) {
int result;
char *str;
gpr_log(GPR_INFO, " expect_sockaddr_str(%s)", expected);
- result = grpc_sockaddr_to_string(&str, (struct sockaddr *)addr, normalize);
+ result = grpc_sockaddr_to_string(&str, addr, normalize);
GPR_ASSERT(str != NULL);
GPR_ASSERT(result >= 0);
GPR_ASSERT((size_t)result == strlen(str));
@@ -189,19 +192,21 @@ static void expect_sockaddr_str(const char *expected, void *addr,
gpr_free(str);
}
-static void expect_sockaddr_uri(const char *expected, void *addr) {
+static void expect_sockaddr_uri(const char *expected,
+ grpc_resolved_address *addr) {
char *str;
gpr_log(GPR_INFO, " expect_sockaddr_uri(%s)", expected);
- str = grpc_sockaddr_to_uri((struct sockaddr *)addr);
+ str = grpc_sockaddr_to_uri(addr);
GPR_ASSERT(str != NULL);
GPR_ASSERT(strcmp(expected, str) == 0);
gpr_free(str);
}
static void test_sockaddr_to_string(void) {
- struct sockaddr_in input4;
- struct sockaddr_in6 input6;
- struct sockaddr dummy;
+ grpc_resolved_address input4;
+ grpc_resolved_address input6;
+ grpc_resolved_address dummy;
+ struct sockaddr *dummy_addr;
gpr_log(GPR_INFO, "%s", "test_sockaddr_to_string");
@@ -228,7 +233,8 @@ static void test_sockaddr_to_string(void) {
expect_sockaddr_uri("ipv6:[::fffe:c000:263]:12345", &input6);
memset(&dummy, 0, sizeof(dummy));
- dummy.sa_family = 123;
+ dummy_addr = (struct sockaddr *)dummy.addr;
+ dummy_addr->sa_family = 123;
expect_sockaddr_str("(sockaddr family=123)", &dummy, 0);
expect_sockaddr_str("(sockaddr family=123)", &dummy, 1);
GPR_ASSERT(grpc_sockaddr_to_uri(&dummy) == NULL);
@@ -237,24 +243,26 @@ static void test_sockaddr_to_string(void) {
}
static void test_sockaddr_set_get_port(void) {
- struct sockaddr_in input4;
- struct sockaddr_in6 input6;
- struct sockaddr dummy;
+ grpc_resolved_address input4;
+ grpc_resolved_address input6;
+ grpc_resolved_address dummy;
+ struct sockaddr *dummy_addr;
gpr_log(GPR_DEBUG, "test_sockaddr_set_get_port");
input4 = make_addr4(kIPv4, sizeof(kIPv4));
- GPR_ASSERT(grpc_sockaddr_get_port((struct sockaddr *)&input4) == 12345);
- GPR_ASSERT(grpc_sockaddr_set_port((struct sockaddr *)&input4, 54321));
- GPR_ASSERT(grpc_sockaddr_get_port((struct sockaddr *)&input4) == 54321);
+ GPR_ASSERT(grpc_sockaddr_get_port(&input4) == 12345);
+ GPR_ASSERT(grpc_sockaddr_set_port(&input4, 54321));
+ GPR_ASSERT(grpc_sockaddr_get_port(&input4) == 54321);
input6 = make_addr6(kIPv6, sizeof(kIPv6));
- GPR_ASSERT(grpc_sockaddr_get_port((struct sockaddr *)&input6) == 12345);
- GPR_ASSERT(grpc_sockaddr_set_port((struct sockaddr *)&input6, 54321));
- GPR_ASSERT(grpc_sockaddr_get_port((struct sockaddr *)&input6) == 54321);
+ GPR_ASSERT(grpc_sockaddr_get_port(&input6) == 12345);
+ GPR_ASSERT(grpc_sockaddr_set_port(&input6, 54321));
+ GPR_ASSERT(grpc_sockaddr_get_port(&input6) == 54321);
memset(&dummy, 0, sizeof(dummy));
- dummy.sa_family = 123;
+ dummy_addr = (struct sockaddr *)dummy.addr;
+ dummy_addr->sa_family = 123;
GPR_ASSERT(grpc_sockaddr_get_port(&dummy) == 0);
GPR_ASSERT(grpc_sockaddr_set_port(&dummy, 1234) == 0);
}
diff --git a/test/core/iomgr/socket_utils_test.c b/test/core/iomgr/socket_utils_test.c
index 297531c44d..67bc914c15 100644
--- a/test/core/iomgr/socket_utils_test.c
+++ b/test/core/iomgr/socket_utils_test.c
@@ -31,7 +31,11 @@
*
*/
-#include <grpc/support/port_platform.h>
+#include "src/core/lib/iomgr/port.h"
+
+// This test won't work except with posix sockets enabled
+#ifdef GRPC_POSIX_SOCKET
+
#include "src/core/lib/iomgr/socket_utils_posix.h"
#include <errno.h>
@@ -68,3 +72,9 @@ int main(int argc, char **argv) {
return 0;
}
+
+#else /* GRPC_POSIX_SOCKET */
+
+int main(int argc, char **argv) { return 1; }
+
+#endif /* GRPC_POSIX_SOCKET */
diff --git a/test/core/iomgr/tcp_client_posix_test.c b/test/core/iomgr/tcp_client_posix_test.c
index a8ba0a17e4..5fab826fb7 100644
--- a/test/core/iomgr/tcp_client_posix_test.c
+++ b/test/core/iomgr/tcp_client_posix_test.c
@@ -85,8 +85,8 @@ static void must_fail(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {
}
void test_succeeds(void) {
- struct sockaddr_in addr;
- socklen_t addr_len = sizeof(addr);
+ grpc_resolved_address resolved_addr;
+ struct sockaddr_in *addr = (struct sockaddr_in *)resolved_addr.addr;
int svr_fd;
int r;
int connections_complete_before;
@@ -95,13 +95,15 @@ void test_succeeds(void) {
gpr_log(GPR_DEBUG, "test_succeeds");
- memset(&addr, 0, sizeof(addr));
- addr.sin_family = AF_INET;
+ memset(&resolved_addr, 0, sizeof(resolved_addr));
+ resolved_addr.len = sizeof(struct sockaddr_in);
+ addr->sin_family = AF_INET;
/* create a dummy server */
svr_fd = socket(AF_INET, SOCK_STREAM, 0);
GPR_ASSERT(svr_fd >= 0);
- GPR_ASSERT(0 == bind(svr_fd, (struct sockaddr *)&addr, addr_len));
+ GPR_ASSERT(
+ 0 == bind(svr_fd, (struct sockaddr *)addr, (socklen_t)resolved_addr.len));
GPR_ASSERT(0 == listen(svr_fd, 1));
gpr_mu_lock(g_mu);
@@ -109,16 +111,17 @@ void test_succeeds(void) {
gpr_mu_unlock(g_mu);
/* connect to it */
- GPR_ASSERT(getsockname(svr_fd, (struct sockaddr *)&addr, &addr_len) == 0);
+ GPR_ASSERT(getsockname(svr_fd, (struct sockaddr *)addr,
+ (socklen_t *)&resolved_addr.len) == 0);
grpc_closure_init(&done, must_succeed, NULL);
grpc_tcp_client_connect(&exec_ctx, &done, &g_connecting, g_pollset_set, NULL,
- (struct sockaddr *)&addr, addr_len,
- gpr_inf_future(GPR_CLOCK_REALTIME));
+ &resolved_addr, gpr_inf_future(GPR_CLOCK_REALTIME));
/* await the connection */
do {
- addr_len = sizeof(addr);
- r = accept(svr_fd, (struct sockaddr *)&addr, &addr_len);
+ resolved_addr.len = sizeof(addr);
+ r = accept(svr_fd, (struct sockaddr *)addr,
+ (socklen_t *)&resolved_addr.len);
} while (r == -1 && errno == EINTR);
GPR_ASSERT(r >= 0);
close(r);
@@ -143,16 +146,17 @@ void test_succeeds(void) {
}
void test_fails(void) {
- struct sockaddr_in addr;
- socklen_t addr_len = sizeof(addr);
+ grpc_resolved_address resolved_addr;
+ struct sockaddr_in *addr = (struct sockaddr_in *)resolved_addr.addr;
int connections_complete_before;
grpc_closure done;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
gpr_log(GPR_DEBUG, "test_fails");
- memset(&addr, 0, sizeof(addr));
- addr.sin_family = AF_INET;
+ memset(&resolved_addr, 0, sizeof(resolved_addr));
+ resolved_addr.len = sizeof(struct sockaddr_in);
+ addr->sin_family = AF_INET;
gpr_mu_lock(g_mu);
connections_complete_before = g_connections_complete;
@@ -161,8 +165,7 @@ void test_fails(void) {
/* connect to a broken address */
grpc_closure_init(&done, must_fail, NULL);
grpc_tcp_client_connect(&exec_ctx, &done, &g_connecting, g_pollset_set, NULL,
- (struct sockaddr *)&addr, addr_len,
- gpr_inf_future(GPR_CLOCK_REALTIME));
+ &resolved_addr, gpr_inf_future(GPR_CLOCK_REALTIME));
gpr_mu_lock(g_mu);
diff --git a/test/core/iomgr/tcp_posix_test.c b/test/core/iomgr/tcp_posix_test.c
index a259390d5e..f23e23f03e 100644
--- a/test/core/iomgr/tcp_posix_test.c
+++ b/test/core/iomgr/tcp_posix_test.c
@@ -31,6 +31,11 @@
*
*/
+#include "src/core/lib/iomgr/port.h"
+
+// This test won't work except with posix sockets enabled
+#ifdef GRPC_POSIX_SOCKET
+
#include "src/core/lib/iomgr/tcp_posix.h"
#include <errno.h>
@@ -564,3 +569,9 @@ int main(int argc, char **argv) {
return 0;
}
+
+#else /* GRPC_POSIX_SOCKET */
+
+int main(int argc, char **argv) { return 1; }
+
+#endif /* GRPC_POSIX_SOCKET */
diff --git a/test/core/iomgr/tcp_server_posix_test.c b/test/core/iomgr/tcp_server_posix_test.c
index 856c8b2419..1b8a39c1be 100644
--- a/test/core/iomgr/tcp_server_posix_test.c
+++ b/test/core/iomgr/tcp_server_posix_test.c
@@ -31,6 +31,11 @@
*
*/
+#include "src/core/lib/iomgr/port.h"
+
+// This test won't work except with posix sockets enabled
+#ifdef GRPC_POSIX_SOCKET
+
#include "src/core/lib/iomgr/tcp_server.h"
#include <errno.h>
@@ -46,6 +51,7 @@
#include <grpc/support/time.h>
#include "src/core/lib/iomgr/iomgr.h"
+#include "src/core/lib/iomgr/resolve_address.h"
#include "src/core/lib/iomgr/sockaddr_utils.h"
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
@@ -151,17 +157,19 @@ static void test_no_op_with_start(void) {
static void test_no_op_with_port(void) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- struct sockaddr_in addr;
+ grpc_resolved_address resolved_addr;
+ struct sockaddr_in *addr = (struct sockaddr_in *)resolved_addr.addr;
grpc_tcp_server *s;
GPR_ASSERT(GRPC_ERROR_NONE ==
grpc_tcp_server_create(&exec_ctx, NULL, NULL, &s));
LOG_TEST("test_no_op_with_port");
- memset(&addr, 0, sizeof(addr));
- addr.sin_family = AF_INET;
+ memset(&resolved_addr, 0, sizeof(resolved_addr));
+ resolved_addr.len = sizeof(struct sockaddr_in);
+ addr->sin_family = AF_INET;
int port;
- GPR_ASSERT(grpc_tcp_server_add_port(s, (struct sockaddr *)&addr, sizeof(addr),
- &port) == GRPC_ERROR_NONE &&
+ GPR_ASSERT(grpc_tcp_server_add_port(s, &resolved_addr, &port) ==
+ GRPC_ERROR_NONE &&
port > 0);
grpc_tcp_server_unref(&exec_ctx, s);
@@ -170,17 +178,19 @@ static void test_no_op_with_port(void) {
static void test_no_op_with_port_and_start(void) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- struct sockaddr_in addr;
+ grpc_resolved_address resolved_addr;
+ struct sockaddr_in *addr = (struct sockaddr_in *)resolved_addr.addr;
grpc_tcp_server *s;
GPR_ASSERT(GRPC_ERROR_NONE ==
grpc_tcp_server_create(&exec_ctx, NULL, NULL, &s));
LOG_TEST("test_no_op_with_port_and_start");
int port;
- memset(&addr, 0, sizeof(addr));
- addr.sin_family = AF_INET;
- GPR_ASSERT(grpc_tcp_server_add_port(s, (struct sockaddr *)&addr, sizeof(addr),
- &port) == GRPC_ERROR_NONE &&
+ memset(&resolved_addr, 0, sizeof(resolved_addr));
+ resolved_addr.len = sizeof(struct sockaddr_in);
+ addr->sin_family = AF_INET;
+ GPR_ASSERT(grpc_tcp_server_add_port(s, &resolved_addr, &port) ==
+ GRPC_ERROR_NONE &&
port > 0);
grpc_tcp_server_start(&exec_ctx, s, NULL, 0, on_connect, NULL);
@@ -225,9 +235,11 @@ static void tcp_connect(grpc_exec_ctx *exec_ctx, const struct sockaddr *remote,
the same port should be tested. */
static void test_connect(unsigned n) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- struct sockaddr_storage addr;
- struct sockaddr_storage addr1;
- socklen_t addr_len = sizeof(addr);
+ grpc_resolved_address resolved_addr;
+ grpc_resolved_address resolved_addr1;
+ struct sockaddr_storage *addr = (struct sockaddr_storage *)resolved_addr.addr;
+ struct sockaddr_storage *addr1 =
+ (struct sockaddr_storage *)resolved_addr1.addr;
unsigned svr_fd_count;
int svr_port;
unsigned svr1_fd_count;
@@ -240,19 +252,20 @@ static void test_connect(unsigned n) {
server_weak_ref_init(&weak_ref);
LOG_TEST("test_connect");
gpr_log(GPR_INFO, "clients=%d", n);
- memset(&addr, 0, sizeof(addr));
- memset(&addr1, 0, sizeof(addr1));
- addr.ss_family = addr1.ss_family = AF_INET;
+ memset(&resolved_addr, 0, sizeof(resolved_addr));
+ memset(&resolved_addr1, 0, sizeof(resolved_addr1));
+ resolved_addr.len = sizeof(struct sockaddr_storage);
+ resolved_addr1.len = sizeof(struct sockaddr_storage);
+ addr->ss_family = addr1->ss_family = AF_INET;
GPR_ASSERT(GRPC_ERROR_NONE ==
- grpc_tcp_server_add_port(s, (struct sockaddr *)&addr, addr_len,
- &svr_port));
+ grpc_tcp_server_add_port(s, &resolved_addr, &svr_port));
GPR_ASSERT(svr_port > 0);
/* Cannot use wildcard (port==0), because add_port() will try to reuse the
same port as a previous add_port(). */
svr1_port = grpc_pick_unused_port_or_die();
- grpc_sockaddr_set_port((struct sockaddr *)&addr1, svr1_port);
- GPR_ASSERT(grpc_tcp_server_add_port(s, (struct sockaddr *)&addr1, addr_len,
- &svr_port) == GRPC_ERROR_NONE &&
+ grpc_sockaddr_set_port(&resolved_addr1, svr1_port);
+ GPR_ASSERT(grpc_tcp_server_add_port(s, &resolved_addr1, &svr_port) ==
+ GRPC_ERROR_NONE &&
svr_port == svr1_port);
/* Bad port_index. */
@@ -273,16 +286,18 @@ static void test_connect(unsigned n) {
int fd = grpc_tcp_server_port_fd(s, 0, i);
GPR_ASSERT(fd >= 0);
if (i == 0) {
- GPR_ASSERT(getsockname(fd, (struct sockaddr *)&addr, &addr_len) == 0);
- GPR_ASSERT(addr_len <= sizeof(addr));
+ GPR_ASSERT(getsockname(fd, (struct sockaddr *)addr,
+ (socklen_t *)&resolved_addr.len) == 0);
+ GPR_ASSERT(resolved_addr.len <= sizeof(*addr));
}
}
for (i = 0; i < svr1_fd_count; ++i) {
int fd = grpc_tcp_server_port_fd(s, 1, i);
GPR_ASSERT(fd >= 0);
if (i == 0) {
- GPR_ASSERT(getsockname(fd, (struct sockaddr *)&addr1, &addr_len) == 0);
- GPR_ASSERT(addr_len <= sizeof(addr1));
+ GPR_ASSERT(getsockname(fd, (struct sockaddr *)addr1,
+ (socklen_t *)&resolved_addr1.len) == 0);
+ GPR_ASSERT(resolved_addr1.len <= sizeof(*addr1));
}
}
@@ -292,7 +307,8 @@ static void test_connect(unsigned n) {
on_connect_result result;
int svr_fd;
on_connect_result_init(&result);
- tcp_connect(&exec_ctx, (struct sockaddr *)&addr, addr_len, &result);
+ tcp_connect(&exec_ctx, (struct sockaddr *)addr,
+ (socklen_t)resolved_addr.len, &result);
GPR_ASSERT(result.server_fd >= 0);
svr_fd = result.server_fd;
GPR_ASSERT(grpc_tcp_server_port_fd(s, result.port_index, result.fd_index) ==
@@ -306,7 +322,8 @@ static void test_connect(unsigned n) {
grpc_tcp_server_unref(&exec_ctx, result.server);
on_connect_result_init(&result);
- tcp_connect(&exec_ctx, (struct sockaddr *)&addr1, addr_len, &result);
+ tcp_connect(&exec_ctx, (struct sockaddr *)addr1,
+ (socklen_t)resolved_addr1.len, &result);
GPR_ASSERT(result.server_fd >= 0);
GPR_ASSERT(result.server_fd != svr_fd);
GPR_ASSERT(grpc_tcp_server_port_fd(s, result.port_index, result.fd_index) ==
@@ -355,3 +372,9 @@ int main(int argc, char **argv) {
gpr_free(g_pollset);
return 0;
}
+
+#else /* GRPC_POSIX_SOCKET */
+
+int main(int argc, char **argv) { return 1; }
+
+#endif /* GRPC_POSIX_SOCKET */
diff --git a/test/core/iomgr/timer_heap_test.c b/test/core/iomgr/timer_heap_test.c
index d1cb0047f2..410d972313 100644
--- a/test/core/iomgr/timer_heap_test.c
+++ b/test/core/iomgr/timer_heap_test.c
@@ -31,6 +31,11 @@
*
*/
+#include "src/core/lib/iomgr/port.h"
+
+// This test only works with the generic timer implementation
+#ifdef GRPC_TIMER_USE_GENERIC
+
#include "src/core/lib/iomgr/timer_heap.h"
#include <stdlib.h>
@@ -315,3 +320,9 @@ int main(int argc, char **argv) {
return 0;
}
+
+#else /* GRPC_TIMER_USE_GENERIC */
+
+int main(int argc, char **argv) { return 1; }
+
+#endif /* GRPC_TIMER_USE_GENERIC */
diff --git a/test/core/iomgr/udp_server_test.c b/test/core/iomgr/udp_server_test.c
index 71d2fb5bd4..d9f9cd748b 100644
--- a/test/core/iomgr/udp_server_test.c
+++ b/test/core/iomgr/udp_server_test.c
@@ -31,6 +31,11 @@
*
*/
+#include "src/core/lib/iomgr/port.h"
+
+// This test won't work except with posix sockets enabled
+#ifdef GRPC_POSIX_SOCKET
+
#include "src/core/lib/iomgr/udp_server.h"
#include <netinet/in.h>
@@ -98,14 +103,16 @@ static void test_no_op_with_start(void) {
static void test_no_op_with_port(void) {
g_number_of_orphan_calls = 0;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- struct sockaddr_in addr;
+ grpc_resolved_address resolved_addr;
+ struct sockaddr_in *addr = (struct sockaddr_in *)resolved_addr.addr;
grpc_udp_server *s = grpc_udp_server_create();
LOG_TEST("test_no_op_with_port");
- memset(&addr, 0, sizeof(addr));
- addr.sin_family = AF_INET;
- GPR_ASSERT(grpc_udp_server_add_port(s, (struct sockaddr *)&addr, sizeof(addr),
- on_read, on_fd_orphaned));
+ memset(&resolved_addr, 0, sizeof(resolved_addr));
+ resolved_addr.len = sizeof(struct sockaddr_in);
+ addr->sin_family = AF_INET;
+ GPR_ASSERT(
+ grpc_udp_server_add_port(s, &resolved_addr, on_read, on_fd_orphaned));
grpc_udp_server_destroy(&exec_ctx, s, NULL);
grpc_exec_ctx_finish(&exec_ctx);
@@ -117,14 +124,16 @@ static void test_no_op_with_port(void) {
static void test_no_op_with_port_and_start(void) {
g_number_of_orphan_calls = 0;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- struct sockaddr_in addr;
+ grpc_resolved_address resolved_addr;
+ struct sockaddr_in *addr = (struct sockaddr_in *)resolved_addr.addr;
grpc_udp_server *s = grpc_udp_server_create();
LOG_TEST("test_no_op_with_port_and_start");
- memset(&addr, 0, sizeof(addr));
- addr.sin_family = AF_INET;
- GPR_ASSERT(grpc_udp_server_add_port(s, (struct sockaddr *)&addr, sizeof(addr),
- on_read, on_fd_orphaned));
+ memset(&resolved_addr, 0, sizeof(resolved_addr));
+ resolved_addr.len = sizeof(struct sockaddr_in);
+ addr->sin_family = AF_INET;
+ GPR_ASSERT(
+ grpc_udp_server_add_port(s, &resolved_addr, on_read, on_fd_orphaned));
grpc_udp_server_start(&exec_ctx, s, NULL, 0, NULL);
@@ -138,8 +147,8 @@ static void test_no_op_with_port_and_start(void) {
static void test_receive(int number_of_clients) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- struct sockaddr_storage addr;
- socklen_t addr_len = sizeof(addr);
+ grpc_resolved_address resolved_addr;
+ struct sockaddr_storage *addr = (struct sockaddr_storage *)resolved_addr.addr;
int clifd, svrfd;
grpc_udp_server *s = grpc_udp_server_create();
int i;
@@ -152,15 +161,17 @@ static void test_receive(int number_of_clients) {
g_number_of_bytes_read = 0;
g_number_of_orphan_calls = 0;
- memset(&addr, 0, sizeof(addr));
- addr.ss_family = AF_INET;
- GPR_ASSERT(grpc_udp_server_add_port(s, (struct sockaddr *)&addr, addr_len,
- on_read, on_fd_orphaned));
+ memset(&resolved_addr, 0, sizeof(resolved_addr));
+ resolved_addr.len = sizeof(struct sockaddr_storage);
+ addr->ss_family = AF_INET;
+ GPR_ASSERT(
+ grpc_udp_server_add_port(s, &resolved_addr, on_read, on_fd_orphaned));
svrfd = grpc_udp_server_get_fd(s, 0);
GPR_ASSERT(svrfd >= 0);
- GPR_ASSERT(getsockname(svrfd, (struct sockaddr *)&addr, &addr_len) == 0);
- GPR_ASSERT(addr_len <= sizeof(addr));
+ GPR_ASSERT(getsockname(svrfd, (struct sockaddr *)addr,
+ (socklen_t *)&resolved_addr.len) == 0);
+ GPR_ASSERT(resolved_addr.len <= sizeof(struct sockaddr_storage));
pollsets[0] = g_pollset;
grpc_udp_server_start(&exec_ctx, s, pollsets, 1, NULL);
@@ -172,9 +183,10 @@ static void test_receive(int number_of_clients) {
number_of_reads_before = g_number_of_reads;
/* Create a socket, send a packet to the UDP server. */
- clifd = socket(addr.ss_family, SOCK_DGRAM, 0);
+ clifd = socket(addr->ss_family, SOCK_DGRAM, 0);
GPR_ASSERT(clifd >= 0);
- GPR_ASSERT(connect(clifd, (struct sockaddr *)&addr, addr_len) == 0);
+ GPR_ASSERT(connect(clifd, (struct sockaddr *)&addr,
+ (socklen_t)resolved_addr.len) == 0);
GPR_ASSERT(5 == write(clifd, "hello", 5));
while (g_number_of_reads == number_of_reads_before &&
gpr_time_cmp(deadline, gpr_now(deadline.clock_type)) > 0) {
@@ -229,3 +241,9 @@ int main(int argc, char **argv) {
grpc_iomgr_shutdown();
return 0;
}
+
+#else /* GRPC_POSIX_SOCKET */
+
+int main(int argc, char **argv) { return 1; }
+
+#endif /* GRPC_POSIX_SOCKET */
diff --git a/test/core/iomgr/wakeup_fd_cv_test.c b/test/core/iomgr/wakeup_fd_cv_test.c
index 952985ed7e..82452d2157 100644
--- a/test/core/iomgr/wakeup_fd_cv_test.c
+++ b/test/core/iomgr/wakeup_fd_cv_test.c
@@ -31,6 +31,10 @@
*
*/
+#include "src/core/lib/iomgr/port.h"
+
+#ifdef GRPC_POSIX_SOCKET
+
#include <pthread.h>
#include <grpc/support/log.h>
@@ -238,3 +242,9 @@ int main(int argc, char **argv) {
grpc_iomgr_platform_shutdown();
return 0;
}
+
+#else /* GRPC_POSIX_SOCKET */
+
+int main(int argc, char **argv) { return 1; }
+
+#endif /* GRPC_POSIX_SOCKET */