From 32c0153f8181feb89e0abf2ef47c02fb63f70063 Mon Sep 17 00:00:00 2001 From: Yuchen Zeng Date: Wed, 2 Aug 2017 16:09:08 -0700 Subject: Make port picking functions overridable --- test/core/util/port.c | 12 +++++++++--- test/core/util/port.h | 6 +++--- 2 files changed, 12 insertions(+), 6 deletions(-) (limited to 'test/core/util') diff --git a/test/core/util/port.c b/test/core/util/port.c index f430c543bd..4df7572f27 100644 --- a/test/core/util/port.c +++ b/test/core/util/port.c @@ -79,7 +79,7 @@ static void chose_port(int port) { chosen_ports[num_chosen_ports - 1] = port; } -int grpc_pick_unused_port(void) { +static int grpc_pick_unused_port_impl(void) { int port = grpc_pick_port_using_server(); if (port != 0) { chose_port(port); @@ -88,7 +88,7 @@ int grpc_pick_unused_port(void) { return port; } -int grpc_pick_unused_port_or_die(void) { +static int grpc_pick_unused_port_or_die_impl(void) { int port = grpc_pick_unused_port(); if (port == 0) { fprintf(stderr, @@ -101,6 +101,12 @@ int grpc_pick_unused_port_or_die(void) { return port; } -void grpc_recycle_unused_port(int port) { GPR_ASSERT(free_chosen_port(port)); } +static void grpc_recycle_unused_port_impl(int port) { + GPR_ASSERT(free_chosen_port(port)); +} + +int (*grpc_pick_unused_port)(void) = grpc_pick_unused_port_impl; +int (*grpc_pick_unused_port_or_die)(void) = grpc_pick_unused_port_or_die_impl; +void (*grpc_recycle_unused_port)(int port) = grpc_recycle_unused_port_impl; #endif /* GRPC_TEST_PICK_PORT */ diff --git a/test/core/util/port.h b/test/core/util/port.h index 154e8f830c..0e15f397a5 100644 --- a/test/core/util/port.h +++ b/test/core/util/port.h @@ -25,16 +25,16 @@ extern "C" { /* pick a port number that is currently unused by either tcp or udp. return 0 on failure. */ -int grpc_pick_unused_port(void); +extern int (*grpc_pick_unused_port)(void); /* pick a port number that is currently unused by either tcp or udp. abort on failure. */ -int grpc_pick_unused_port_or_die(void); +extern int (*grpc_pick_unused_port_or_die)(void); /* Return a port which was previously returned by grpc_pick_unused_port(). * Implementations of grpc_pick_unused_port() backed by a portserver may limit * the total number of ports available; this lets a binary return its allocated * ports back to the server if it is going to allocate a large number. */ -void grpc_recycle_unused_port(int port); +extern void (*grpc_recycle_unused_port)(int port); #ifdef __cplusplus } -- cgit v1.2.3 From 36969385e50ac6340129b85df11de72b23ec05e2 Mon Sep 17 00:00:00 2001 From: Yuchen Zeng Date: Wed, 2 Aug 2017 16:40:24 -0700 Subject: Group the port picking functions --- test/core/util/port.c | 25 ++++++++++++++++++++++--- test/core/util/port.h | 15 ++++++++++++--- 2 files changed, 34 insertions(+), 6 deletions(-) (limited to 'test/core/util') diff --git a/test/core/util/port.c b/test/core/util/port.c index 4df7572f27..b1fc722858 100644 --- a/test/core/util/port.c +++ b/test/core/util/port.c @@ -105,8 +105,27 @@ static void grpc_recycle_unused_port_impl(int port) { GPR_ASSERT(free_chosen_port(port)); } -int (*grpc_pick_unused_port)(void) = grpc_pick_unused_port_impl; -int (*grpc_pick_unused_port_or_die)(void) = grpc_pick_unused_port_or_die_impl; -void (*grpc_recycle_unused_port)(int port) = grpc_recycle_unused_port_impl; +static grpc_pick_port_functions g_pick_port_functions = { + grpc_pick_unused_port_impl, grpc_pick_unused_port_or_die_impl, + grpc_recycle_unused_port_impl}; + +int grpc_pick_unused_port(void) { + return g_pick_port_functions.pick_unused_port_fn(); +} + +int grpc_pick_unused_port_or_die(void) { + return g_pick_port_functions.pick_unused_port_or_die_fn(); +} + +void grpc_recycle_unused_port(int port) { + g_pick_port_functions.recycle_unused_port_fn(port); +} + +void grpc_set_pick_port_functions(grpc_pick_port_functions functions) { + GPR_ASSERT(functions.pick_unused_port_fn != NULL); + GPR_ASSERT(functions.pick_unused_port_or_die_fn != NULL); + GPR_ASSERT(functions.recycle_unused_port_fn != NULL); + g_pick_port_functions = functions; +} #endif /* GRPC_TEST_PICK_PORT */ diff --git a/test/core/util/port.h b/test/core/util/port.h index 0e15f397a5..602099dea6 100644 --- a/test/core/util/port.h +++ b/test/core/util/port.h @@ -23,18 +23,27 @@ extern "C" { #endif +typedef struct grpc_pick_port_functions { + int (*pick_unused_port_fn)(void); + int (*pick_unused_port_or_die_fn)(void); + void (*recycle_unused_port_fn)(int port); +} grpc_pick_port_functions; + /* pick a port number that is currently unused by either tcp or udp. return 0 on failure. */ -extern int (*grpc_pick_unused_port)(void); +int grpc_pick_unused_port(void); /* pick a port number that is currently unused by either tcp or udp. abort on failure. */ -extern int (*grpc_pick_unused_port_or_die)(void); +int grpc_pick_unused_port_or_die(void); /* Return a port which was previously returned by grpc_pick_unused_port(). * Implementations of grpc_pick_unused_port() backed by a portserver may limit * the total number of ports available; this lets a binary return its allocated * ports back to the server if it is going to allocate a large number. */ -extern void (*grpc_recycle_unused_port)(int port); +void grpc_recycle_unused_port(int port); + +/** Request the family of pick_port functions in \a functions be used. */ +void grpc_set_pick_port_functions(grpc_pick_port_functions functions); #ifdef __cplusplus } -- cgit v1.2.3 From 81522c8ebeb97e906f2f0ece1b15266434c364af Mon Sep 17 00:00:00 2001 From: Vijay Pai Date: Tue, 1 Aug 2017 16:07:33 -0700 Subject: Add unsecure libraries to bazel build targets --- test/core/util/BUILD | 24 +++++++++++++++++++++- test/cpp/common/BUILD | 2 +- test/cpp/microbenchmarks/BUILD | 4 ++-- test/cpp/server/BUILD | 8 ++++---- test/cpp/util/BUILD | 45 ++++++++++++++++++++++++------------------ 5 files changed, 56 insertions(+), 27 deletions(-) (limited to 'test/core/util') diff --git a/test/core/util/BUILD b/test/core/util/BUILD index 9d899bc7be..1268c2cd10 100644 --- a/test/core/util/BUILD +++ b/test/core/util/BUILD @@ -38,7 +38,7 @@ grpc_cc_library( ) grpc_cc_library( - name = "grpc_test_util", + name = "grpc_test_util_base", srcs = [ "debugger_macros.c", "grpc_profiler.c", @@ -68,10 +68,32 @@ grpc_cc_library( language = "C", deps = [ ":gpr_test_util", + "//:grpc_common", + ], +) + +grpc_cc_library( + name = "grpc_test_util", + srcs = [], + hdrs = [], + language = "C", + deps = [ + ":grpc_test_util_base", "//:grpc", ], ) +grpc_cc_library( + name = "grpc_test_util_unsecure", + srcs = [], + hdrs = [], + language = "C", + deps = [ + ":grpc_test_util_base", + "//:grpc_unsecure", + ], +) + grpc_cc_library( name = "one_corpus_entry_fuzzer", srcs = ["one_corpus_entry_fuzzer.c"], diff --git a/test/cpp/common/BUILD b/test/cpp/common/BUILD index bd1173322a..be9c279f13 100644 --- a/test/cpp/common/BUILD +++ b/test/cpp/common/BUILD @@ -27,7 +27,7 @@ grpc_cc_test( name = "alarm_cpp_test", srcs = ["alarm_cpp_test.cc"], deps = [ - "//:grpc++", + "//:grpc++_unsecure", "//test/core/util:gpr_test_util", ], external_deps = [ diff --git a/test/cpp/microbenchmarks/BUILD b/test/cpp/microbenchmarks/BUILD index 5e1bcee89f..442da38426 100644 --- a/test/cpp/microbenchmarks/BUILD +++ b/test/cpp/microbenchmarks/BUILD @@ -40,9 +40,9 @@ grpc_cc_library( "helpers.h", ], deps = [ - "//:grpc++", + "//:grpc++_unsecure", "//src/proto/grpc/testing:echo_proto", - "//test/core/util:grpc_test_util", + "//test/core/util:grpc_test_util_unsecure", ], external_deps = [ "benchmark", diff --git a/test/cpp/server/BUILD b/test/cpp/server/BUILD index 512241e350..3f63be2aa3 100644 --- a/test/cpp/server/BUILD +++ b/test/cpp/server/BUILD @@ -20,9 +20,9 @@ grpc_cc_test( name = "server_builder_test", srcs = ["server_builder_test.cc"], deps = [ - "//:grpc++", + "//:grpc++_unsecure", "//src/proto/grpc/testing:echo_proto", - "//test/core/util:grpc_test_util", + "//test/core/util:grpc_test_util_unsecure", ], external_deps = [ "gtest", @@ -33,9 +33,9 @@ grpc_cc_test( name = "server_request_call_test", srcs = ["server_request_call_test.cc"], deps = [ - "//:grpc++", + "//:grpc++_unsecure", "//src/proto/grpc/testing:echo_proto", - "//test/core/util:grpc_test_util", + "//test/core/util:grpc_test_util_unsecure", ], external_deps = [ "gtest", diff --git a/test/cpp/util/BUILD b/test/cpp/util/BUILD index c9b0d6c1df..fbdec05698 100644 --- a/test/cpp/util/BUILD +++ b/test/cpp/util/BUILD @@ -24,16 +24,6 @@ package( ], ) -# The following builds a shared-object to confirm that grpc++_unsecure -# builds properly. Build-only is sufficient here -grpc_cc_binary( - name = "testso.so", - srcs = [], - linkshared = 1, - linkopts = ['-Wl,--no-undefined'], - deps = ["//:grpc++_unsecure"], -) - grpc_cc_library( name = "test_config", srcs = [ @@ -64,26 +54,43 @@ grpc_cc_library( ], ) +GRPCXX_TESTUTIL_SRCS = [ + "byte_buffer_proto_helper.cc", + "string_ref_helper.cc", + "subprocess.cc", +] + +GRPCXX_TESTUTIL_HDRS = [ + "byte_buffer_proto_helper.h", + "string_ref_helper.h", + "subprocess.h", +] + grpc_cc_library( name = "test_util", - srcs = [ - "byte_buffer_proto_helper.cc", + srcs = GRPCXX_TESTUTIL_SRCS + [ "create_test_channel.cc", - "string_ref_helper.cc", - "subprocess.cc", "test_credentials_provider.cc", ], - hdrs = [ - "byte_buffer_proto_helper.h", + hdrs = GRPCXX_TESTUTIL_HDRS + [ "create_test_channel.h", - "string_ref_helper.h", - "subprocess.h", "test_credentials_provider.h", ], deps = [ "//:grpc++", "//test/core/end2end:ssl_test_data", - "//test/core/util:gpr_test_util", + ], + external_deps = [ + "protobuf", + ], +) + +grpc_cc_library( + name = "test_util_unsecure", + srcs = GRPCXX_TESTUTIL_SRCS, + hdrs = GRPCXX_TESTUTIL_HDRS, + deps = [ + "//:grpc++_unsecure", ], external_deps = [ "protobuf", -- cgit v1.2.3