diff options
author | Adele Zhou <adelez@google.com> | 2017-11-29 09:59:34 -0800 |
---|---|---|
committer | Adele Zhou <adelez@google.com> | 2017-11-30 17:10:28 -0800 |
commit | c8bf2da1e0f36fe3a6f271140153fad8e9df8dbd (patch) | |
tree | 371319d2efd0ffcbe7db5351460089e80b96941a /test/core/util | |
parent | 379105d4f0a07cec0a708ce3b0ad9ed686d05457 (diff) |
Enabling hermetic testing for running tests on Foundry.
Diffstat (limited to 'test/core/util')
-rw-r--r-- | test/core/util/BUILD | 4 | ||||
-rw-r--r-- | test/core/util/port_hermetic.cc | 41 | ||||
-rw-r--r-- | test/core/util/test_config.h | 2 |
3 files changed, 46 insertions, 1 deletions
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 |