aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt2
-rw-r--r--Makefile2
-rw-r--r--bazel/grpc_build_system.bzl4
-rw-r--r--build.yaml1
-rw-r--r--grpc.gyp2
-rw-r--r--test/core/util/BUILD4
-rw-r--r--test/core/util/port_hermetic.cc41
-rw-r--r--test/core/util/test_config.h2
-rw-r--r--third_party/zlib.BUILD2
-rw-r--r--tools/run_tests/generated/sources_and_headers.json3
10 files changed, 58 insertions, 5 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 760e4fa585..3bb627aa7d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1622,6 +1622,7 @@ add_library(grpc_test_util
test/core/util/parse_hexstring.cc
test/core/util/passthru_endpoint.cc
test/core/util/port.cc
+ test/core/util/port_hermetic.cc
test/core/util/port_server_client.cc
test/core/util/slice_splitter.cc
test/core/util/tracer_util.cc
@@ -1890,6 +1891,7 @@ add_library(grpc_test_util_unsecure
test/core/util/parse_hexstring.cc
test/core/util/passthru_endpoint.cc
test/core/util/port.cc
+ test/core/util/port_hermetic.cc
test/core/util/port_server_client.cc
test/core/util/slice_splitter.cc
test/core/util/tracer_util.cc
diff --git a/Makefile b/Makefile
index 3ce3005924..f5106cb265 100644
--- a/Makefile
+++ b/Makefile
@@ -3628,6 +3628,7 @@ LIBGRPC_TEST_UTIL_SRC = \
test/core/util/parse_hexstring.cc \
test/core/util/passthru_endpoint.cc \
test/core/util/port.cc \
+ test/core/util/port_hermetic.cc \
test/core/util/port_server_client.cc \
test/core/util/slice_splitter.cc \
test/core/util/tracer_util.cc \
@@ -3887,6 +3888,7 @@ LIBGRPC_TEST_UTIL_UNSECURE_SRC = \
test/core/util/parse_hexstring.cc \
test/core/util/passthru_endpoint.cc \
test/core/util/port.cc \
+ test/core/util/port_hermetic.cc \
test/core/util/port_server_client.cc \
test/core/util/slice_splitter.cc \
test/core/util/tracer_util.cc \
diff --git a/bazel/grpc_build_system.bzl b/bazel/grpc_build_system.bzl
index b35ca73745..591fdb5936 100644
--- a/bazel/grpc_build_system.bzl
+++ b/bazel/grpc_build_system.bzl
@@ -26,7 +26,7 @@
def grpc_cc_library(name, srcs = [], public_hdrs = [], hdrs = [],
external_deps = [], deps = [], standalone = False,
language = "C++", testonly = False, visibility = None,
- alwayslink = 0):
+ alwayslink = 0, defines = []):
copts = []
if language.upper() == "C":
copts = ["-std=c99"]
@@ -35,7 +35,7 @@ def grpc_cc_library(name, srcs = [], public_hdrs = [], hdrs = [],
srcs = srcs,
defines = select({
"//:grpc_no_ares": ["GRPC_ARES=0"],
- "//conditions:default": [],
+ "//conditions:default": defines,
}),
hdrs = hdrs + public_hdrs,
deps = deps + ["//external:" + dep for dep in external_deps],
diff --git a/build.yaml b/build.yaml
index 0908f7efd2..0f6ac5631c 100644
--- a/build.yaml
+++ b/build.yaml
@@ -736,6 +736,7 @@ filegroups:
- test/core/util/parse_hexstring.cc
- test/core/util/passthru_endpoint.cc
- test/core/util/port.cc
+ - test/core/util/port_hermetic.cc
- test/core/util/port_server_client.cc
- test/core/util/slice_splitter.cc
- test/core/util/tracer_util.cc
diff --git a/grpc.gyp b/grpc.gyp
index f2033b47b0..7e6a06c876 100644
--- a/grpc.gyp
+++ b/grpc.gyp
@@ -511,6 +511,7 @@
'test/core/util/parse_hexstring.cc',
'test/core/util/passthru_endpoint.cc',
'test/core/util/port.cc',
+ 'test/core/util/port_hermetic.cc',
'test/core/util/port_server_client.cc',
'test/core/util/slice_splitter.cc',
'test/core/util/tracer_util.cc',
@@ -721,6 +722,7 @@
'test/core/util/parse_hexstring.cc',
'test/core/util/passthru_endpoint.cc',
'test/core/util/port.cc',
+ 'test/core/util/port_hermetic.cc',
'test/core/util/port_server_client.cc',
'test/core/util/slice_splitter.cc',
'test/core/util/tracer_util.cc',
diff --git a/test/core/util/BUILD b/test/core/util/BUILD
index 6443553466..9884e04627 100644
--- a/test/core/util/BUILD
+++ b/test/core/util/BUILD
@@ -53,6 +53,7 @@ grpc_cc_library(
"parse_hexstring.cc",
"passthru_endpoint.cc",
"port.cc",
+ "port_hermetic.cc",
"port_server_client.cc",
"reconnect_server.cc",
"slice_splitter.cc",
@@ -73,6 +74,9 @@ grpc_cc_library(
"tracer_util.h",
"trickle_endpoint.h",
],
+ defines = [
+ "GRPC_HERMETIC_TESTS=1",
+ ],
language = "C++",
deps = [
":gpr_test_util",
diff --git a/test/core/util/port_hermetic.cc b/test/core/util/port_hermetic.cc
new file mode 100644
index 0000000000..3650816763
--- /dev/null
+++ b/test/core/util/port_hermetic.cc
@@ -0,0 +1,41 @@
+/*
+ *
+ * Copyright 2017 gRPC authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "src/core/lib/iomgr/port.h"
+#include "test/core/util/test_config.h"
+#if defined(GRPC_HERMETIC_TESTS)
+
+#include "test/core/util/port.h"
+
+#define LOWER_PORT 49152
+static int s_allocated_port = LOWER_PORT;
+
+int grpc_pick_unused_port_or_die(void) {
+ int allocated_port = s_allocated_port++;
+ if (s_allocated_port == 65536) {
+ s_allocated_port = LOWER_PORT;
+ }
+
+ return allocated_port;
+}
+
+void grpc_recycle_unused_port(int port) {
+ (void) port;
+}
+
+#endif /* GRPC_HERMETIC_TESTS */
diff --git a/test/core/util/test_config.h b/test/core/util/test_config.h
index 775ffac949..ee60441653 100644
--- a/test/core/util/test_config.h
+++ b/test/core/util/test_config.h
@@ -33,7 +33,7 @@ gpr_timespec grpc_timeout_seconds_to_deadline(int64_t time_s);
/* Converts a given timeout (in milliseconds) to a deadline. */
gpr_timespec grpc_timeout_milliseconds_to_deadline(int64_t time_ms);
-#ifndef GRPC_TEST_CUSTOM_PICK_PORT
+#if !defined(GRPC_TEST_CUSTOM_PICK_PORT) && !defined(GRPC_HERMETIC_TESTS)
#define GRPC_TEST_PICK_PORT
#endif
diff --git a/third_party/zlib.BUILD b/third_party/zlib.BUILD
index 7879a81c68..a71c85fa98 100644
--- a/third_party/zlib.BUILD
+++ b/third_party/zlib.BUILD
@@ -27,7 +27,7 @@ cc_library(
"zutil.h",
],
includes = [
- "include",
+ ".",
],
linkstatic = 1,
visibility = [
diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json
index c868acf8d3..c957638181 100644
--- a/tools/run_tests/generated/sources_and_headers.json
+++ b/tools/run_tests/generated/sources_and_headers.json
@@ -8932,7 +8932,8 @@
"test/core/util/mock_endpoint.h",
"test/core/util/parse_hexstring.h",
"test/core/util/passthru_endpoint.h",
- "test/core/util/port.h",
+ "test/core/util/port.h",
+ "test/core/util/port_hermetic.cc",
"test/core/util/port_server_client.h",
"test/core/util/slice_splitter.h",
"test/core/util/tracer_util.h",