From 5a5032dd4ce43aed1330ad31430f8c9b3e833a72 Mon Sep 17 00:00:00 2001 From: Yang Gao Date: Wed, 1 Apr 2015 13:54:44 -0700 Subject: [PATCH] Add a macro to enable replacing the default with a custom port picker --- include/grpc/support/port_platform.h | 2 +- test/core/util/port_posix.c | 7 ++++--- test/core/util/test_config.h | 4 ++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/include/grpc/support/port_platform.h b/include/grpc/support/port_platform.h index 9b639cf82de..41185dbf640 100644 --- a/include/grpc/support/port_platform.h +++ b/include/grpc/support/port_platform.h @@ -199,7 +199,7 @@ #endif #if defined(GPR_POSIX_SOCKET) + defined(GPR_WIN32) != 1 -#error Must define exactly one of GPR_POSIX_POLLSET, GPR_WIN32 +#error Must define exactly one of GPR_POSIX_SOCKET, GPR_WIN32 #endif typedef int16_t gpr_int16; diff --git a/test/core/util/port_posix.c b/test/core/util/port_posix.c index 36f13e1b51e..7467c2f9ea4 100644 --- a/test/core/util/port_posix.c +++ b/test/core/util/port_posix.c @@ -32,7 +32,8 @@ */ #include -#ifdef GPR_POSIX_SOCKET +#include "test/core/util/test_config.h" +#if defined(GPR_POSIX_SOCKET) && defined(GRPC_TEST_PICK_PORT) #include "test/core/util/port.h" @@ -125,7 +126,7 @@ int grpc_pick_unused_port(void) { } else { port = 0; } - + if (!is_port_available(&port, is_tcp)) { continue; } @@ -155,4 +156,4 @@ int grpc_pick_unused_port_or_die(void) { return port; } -#endif /* GPR_POSIX_SOCKET */ +#endif /* GPR_POSIX_SOCKET && GRPC_TEST_PICK_PORT */ diff --git a/test/core/util/test_config.h b/test/core/util/test_config.h index 668a069f267..0b3c54373d9 100644 --- a/test/core/util/test_config.h +++ b/test/core/util/test_config.h @@ -59,6 +59,10 @@ extern "C" { gpr_time_add(gpr_now(), \ gpr_time_from_micros(GRPC_TEST_SLOWDOWN_FACTOR * 1e3 * (x))) +#ifndef GRPC_TEST_CUSTOM_PICK_PORT +#define GRPC_TEST_PICK_PORT +#endif + void grpc_test_init(int argc, char **argv); #ifdef __cplusplus