diff options
author | Yash Tibrewal <yashkt@google.com> | 2018-11-16 10:58:12 -0800 |
---|---|---|
committer | Yash Tibrewal <yashkt@google.com> | 2018-11-16 11:11:04 -0800 |
commit | fc332d2c9247832af90792a59ff6d391e84bc8ae (patch) | |
tree | 4bd1db687960ca851f87d237a36f55190ac52f27 /test/core/util | |
parent | 0eb9a3e783237cd46c8ba6d3b33228f537cafbfc (diff) | |
parent | 9cfacc48ee2e9f8db083d578c84881551734b1f0 (diff) |
Merge master
Diffstat (limited to 'test/core/util')
-rw-r--r-- | test/core/util/port_isolated_runtime_environment.cc | 31 | ||||
-rw-r--r-- | test/core/util/ubsan_suppressions.txt | 14 |
2 files changed, 32 insertions, 13 deletions
diff --git a/test/core/util/port_isolated_runtime_environment.cc b/test/core/util/port_isolated_runtime_environment.cc index ff8342ff4a..1f678c08e5 100644 --- a/test/core/util/port_isolated_runtime_environment.cc +++ b/test/core/util/port_isolated_runtime_environment.cc @@ -16,9 +16,12 @@ * */ -/* When running tests on remote machines, the framework takes a round-robin pick - * of a port within certain range. There is no need to recycle ports. +/* When individual tests run in an isolated runtime environment (e.g. each test + * runs in a separate container) the framework takes a round-robin pick of a + * port within certain range. There is no need to recycle ports. */ +#include <grpc/support/atm.h> +#include <grpc/support/log.h> #include <grpc/support/time.h> #include <stdlib.h> #include "src/core/lib/iomgr/port.h" @@ -27,23 +30,25 @@ #include "test/core/util/port.h" -#define MIN_PORT 49152 -#define MAX_PORT 65536 +#define MIN_PORT 1025 +#define MAX_PORT 32766 -int get_random_starting_port() { +static int get_random_port_offset() { srand(gpr_now(GPR_CLOCK_REALTIME).tv_nsec); - return rand() % (MAX_PORT - MIN_PORT + 1) + MIN_PORT; + double rnd = static_cast<double>(rand()) / + (static_cast<double>(RAND_MAX) + 1.0); // values from [0,1) + return static_cast<int>(rnd * (MAX_PORT - MIN_PORT + 1)); } -static int s_allocated_port = get_random_starting_port(); +static int s_initial_offset = get_random_port_offset(); +static gpr_atm s_pick_counter = 0; int grpc_pick_unused_port_or_die(void) { - int allocated_port = s_allocated_port++; - if (s_allocated_port == MAX_PORT) { - s_allocated_port = MIN_PORT; - } - - return allocated_port; + int orig_counter_val = + static_cast<int>(gpr_atm_full_fetch_add(&s_pick_counter, 1)); + GPR_ASSERT(orig_counter_val < (MAX_PORT - MIN_PORT + 1)); + return MIN_PORT + + (s_initial_offset + orig_counter_val) % (MAX_PORT - MIN_PORT + 1); } void grpc_recycle_unused_port(int port) { (void)port; } diff --git a/test/core/util/ubsan_suppressions.txt b/test/core/util/ubsan_suppressions.txt index 2268adc169..63898ea3b1 100644 --- a/test/core/util/ubsan_suppressions.txt +++ b/test/core/util/ubsan_suppressions.txt @@ -15,3 +15,17 @@ enum:message_compress_test enum:transport_security_test enum:algorithm_test alignment:transport_security_test +# TODO(jtattermusch): address issues and remove the supressions +nonnull-attribute:gsec_aes_gcm_aead_crypter_decrypt_iovec +nonnull-attribute:gsec_test_random_encrypt_decrypt +nonnull-attribute:gsec_test_multiple_random_encrypt_decrypt +nonnull-attribute:gsec_test_copy +nonnull-attribute:gsec_test_encrypt_decrypt_test_vector +alignment:absl::little_endian::Store64 +alignment:absl::little_endian::Load64 +float-divide-by-zero:grpc::testing::postprocess_scenario_result +enum:grpc_op_string +nonnull-attribute:grpc_lb_addresses_copy +signed-integer-overflow:chrono +enum:grpc_http2_error_to_grpc_status +enum:grpc_chttp2_cancel_stream
\ No newline at end of file |