From 24301717d4a3d482b80963e6c2878124e42f5cef Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Tue, 18 Oct 2016 14:10:28 -0700 Subject: Allow specifying extra flags for C++ interop server. --- test/cpp/interop/interop_test.cc | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'test') diff --git a/test/cpp/interop/interop_test.cc b/test/cpp/interop/interop_test.cc index 8e71a2bb29..c066598d36 100644 --- a/test/cpp/interop/interop_test.cc +++ b/test/cpp/interop/interop_test.cc @@ -44,17 +44,21 @@ #include #include +#include #include #include #include #include #include "test/core/util/port.h" +#include "test/cpp/util/test_config.h" extern "C" { #include "src/core/lib/iomgr/socket_utils_posix.h" #include "src/core/lib/support/string.h" } +DEFINE_string(extra_server_flags, "", "Extra flags to pass to server."); + int test_client(const char* root, const char* host, int port) { int status; pid_t cli; @@ -80,6 +84,7 @@ int test_client(const char* root, const char* host, int port) { } int main(int argc, char** argv) { + grpc::testing::InitTest(&argc, &argv, true); char* me = argv[0]; char* lslash = strrchr(me, '/'); char root[1024]; @@ -105,15 +110,19 @@ int main(int argc, char** argv) { /* start the server */ svr = fork(); if (svr == 0) { - char* binary_path; - char* port_arg; - gpr_asprintf(&binary_path, "%s/interop_server", root); - gpr_asprintf(&port_arg, "--port=%d", port); - - execl(binary_path, binary_path, port_arg, NULL); - - gpr_free(binary_path); - gpr_free(port_arg); + const size_t num_args = 3 + !FLAGS_extra_server_flags.empty(); + char** args = (char**)gpr_malloc(sizeof(char*) * num_args); + memset(args, 0, sizeof(char*) * num_args); + gpr_asprintf(&args[0], "%s/interop_server", root); + gpr_asprintf(&args[1], "--port=%d", port); + if (!FLAGS_extra_server_flags.empty()) { + args[2] = gpr_strdup(FLAGS_extra_server_flags.c_str()); + } + execv(args[0], args); + for (size_t i = 0; i < num_args - 1; ++i) { + gpr_free(args[i]); + } + gpr_free(args); return 1; } /* wait a little */ -- cgit v1.2.3 From e3dd1d7d11e278e640924102959bd86ca7e60cdb Mon Sep 17 00:00:00 2001 From: Makarand Dharmapurikar Date: Thu, 20 Oct 2016 10:37:39 -0700 Subject: modify stress_test command line options Modify command line options to be consistent with interop_client. --- Makefile | 4 ++ build.yaml | 1 + test/cpp/interop/stress_test.cc | 79 +++++++++++++++++++--- tools/run_tests/sources_and_headers.json | 1 + .../vcxproj/test/stress_test/stress_test.vcxproj | 2 + .../test/stress_test/stress_test.vcxproj.filters | 3 + 6 files changed, 82 insertions(+), 8 deletions(-) (limited to 'test') diff --git a/Makefile b/Makefile index 38be9e658c..b0b527df5e 100644 --- a/Makefile +++ b/Makefile @@ -13077,6 +13077,7 @@ STRESS_TEST_SRC = \ $(GENDIR)/src/proto/grpc/testing/messages.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.grpc.pb.cc \ $(GENDIR)/src/proto/grpc/testing/metrics.pb.cc $(GENDIR)/src/proto/grpc/testing/metrics.grpc.pb.cc \ $(GENDIR)/src/proto/grpc/testing/test.pb.cc $(GENDIR)/src/proto/grpc/testing/test.grpc.pb.cc \ + test/cpp/interop/client_helper.cc \ test/cpp/interop/interop_client.cc \ test/cpp/interop/stress_interop_client.cc \ test/cpp/interop/stress_test.cc \ @@ -13119,6 +13120,8 @@ $(OBJDIR)/$(CONFIG)/src/proto/grpc/testing/metrics.o: $(LIBDIR)/$(CONFIG)/libgr $(OBJDIR)/$(CONFIG)/src/proto/grpc/testing/test.o: $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a +$(OBJDIR)/$(CONFIG)/test/cpp/interop/client_helper.o: $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a + $(OBJDIR)/$(CONFIG)/test/cpp/interop/interop_client.o: $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a $(OBJDIR)/$(CONFIG)/test/cpp/interop/stress_interop_client.o: $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a @@ -13134,6 +13137,7 @@ ifneq ($(NO_DEPS),true) -include $(STRESS_TEST_OBJS:.o=.dep) endif endif +$(OBJDIR)/$(CONFIG)/test/cpp/interop/client_helper.o: $(GENDIR)/src/proto/grpc/testing/empty.pb.cc $(GENDIR)/src/proto/grpc/testing/empty.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/metrics.pb.cc $(GENDIR)/src/proto/grpc/testing/metrics.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/test.pb.cc $(GENDIR)/src/proto/grpc/testing/test.grpc.pb.cc $(OBJDIR)/$(CONFIG)/test/cpp/interop/interop_client.o: $(GENDIR)/src/proto/grpc/testing/empty.pb.cc $(GENDIR)/src/proto/grpc/testing/empty.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/metrics.pb.cc $(GENDIR)/src/proto/grpc/testing/metrics.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/test.pb.cc $(GENDIR)/src/proto/grpc/testing/test.grpc.pb.cc $(OBJDIR)/$(CONFIG)/test/cpp/interop/stress_interop_client.o: $(GENDIR)/src/proto/grpc/testing/empty.pb.cc $(GENDIR)/src/proto/grpc/testing/empty.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/metrics.pb.cc $(GENDIR)/src/proto/grpc/testing/metrics.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/test.pb.cc $(GENDIR)/src/proto/grpc/testing/test.grpc.pb.cc $(OBJDIR)/$(CONFIG)/test/cpp/interop/stress_test.o: $(GENDIR)/src/proto/grpc/testing/empty.pb.cc $(GENDIR)/src/proto/grpc/testing/empty.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/metrics.pb.cc $(GENDIR)/src/proto/grpc/testing/metrics.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/test.pb.cc $(GENDIR)/src/proto/grpc/testing/test.grpc.pb.cc diff --git a/build.yaml b/build.yaml index 2a06653103..85485f6a9e 100644 --- a/build.yaml +++ b/build.yaml @@ -3351,6 +3351,7 @@ targets: - src/proto/grpc/testing/messages.proto - src/proto/grpc/testing/metrics.proto - src/proto/grpc/testing/test.proto + - test/cpp/interop/client_helper.cc - test/cpp/interop/interop_client.cc - test/cpp/interop/stress_interop_client.cc - test/cpp/interop/stress_test.cc diff --git a/test/cpp/interop/stress_test.cc b/test/cpp/interop/stress_test.cc index 5647cb5531..dac8015762 100644 --- a/test/cpp/interop/stress_test.cc +++ b/test/cpp/interop/stress_test.cc @@ -46,6 +46,7 @@ #include "src/proto/grpc/testing/metrics.grpc.pb.h" #include "src/proto/grpc/testing/metrics.pb.h" +#include "test/cpp/interop/client_helper.h" #include "test/cpp/interop/interop_client.h" #include "test/cpp/interop/stress_interop_client.h" #include "test/cpp/util/metrics_server.h" @@ -68,7 +69,8 @@ DEFINE_int32(test_duration_secs, -1, DEFINE_string(server_addresses, "localhost:8080", "The list of server" - " addresses in the format:\n" + "addresses. This option is ignored if either\n" + "server_port or server_host is specified. The format is: \n" " \":,:...:\"\n" " Note: can be servername or IP address."); @@ -79,6 +81,34 @@ DEFINE_int32(num_stubs_per_channel, 1, "indicates the max number of parallel RPC calls on each channel " "at any given time."); +DEFINE_string(test_case, "", + "Configure different test cases. Valid options are:\n\n" + "all : all test cases;\n" + "cancel_after_begin : cancel stream after starting it;\n" + "cancel_after_first_response: cancel on first response;\n" + "client_compressed_streaming : compressed request streaming with " + "client_compressed_unary : single compressed request;\n" + "client_streaming : request streaming with single response;\n" + "compute_engine_creds: large_unary with compute engine auth;\n" + "custom_metadata: server will echo custom metadata;\n" + "empty_stream : bi-di stream with no request/response;\n" + "empty_unary : empty (zero bytes) request and response;\n" + "half_duplex : half-duplex streaming;\n" + "jwt_token_creds: large_unary with JWT token auth;\n" + "large_unary : single request and (large) response;\n" + "oauth2_auth_token: raw oauth2 access token auth;\n" + "per_rpc_creds: raw oauth2 access token on a single rpc;\n" + "ping_pong : full-duplex streaming;\n" + "response streaming;\n" + "server_compressed_streaming : single request with compressed " + "server_compressed_unary : single compressed response;\n" + "server_streaming : single request with response streaming;\n" + "slow_consumer : single request with response streaming with " + "slow client consumer;\n" + "status_code_and_message: verify status code & message;\n" + "timeout_on_sleeping_server: deadline exceeds on stream;\n" + "unimplemented_method: client calls an unimplemented_method;\n"); + // TODO(sreek): Add more test cases here in future DEFINE_string(test_cases, "", "List of test cases to call along with the" @@ -115,6 +145,17 @@ DEFINE_bool(do_not_abort_on_transient_failures, true, "If set to 'true', abort() is not called in case of transient " "failures like temporary connection failures."); +// Options from client.cc (for compatibility with interop test). +// TODO(sreek): Consolidate overlapping options +DEFINE_bool(use_tls, false, "Whether to use tls."); +DEFINE_bool(use_test_ca, false, "False to use SSL roots for google"); +DEFINE_int32(server_port, 0, "Server port."); +DEFINE_string(server_host, "127.0.0.1", "Server host to connect to"); +DEFINE_string(server_host_override, "foo.test.google.fr", + "Override the server host which is sent in HTTP header"); +DEFINE_string(service_account_key_file, "", + "Path to service account json key file."); + using grpc::testing::kTestCaseList; using grpc::testing::MetricsService; using grpc::testing::MetricsServiceImpl; @@ -200,6 +241,8 @@ bool ParseTestCasesString(const grpc::string& test_cases, void LogParameterInfo(const std::vector& addresses, const std::vector>& tests) { gpr_log(GPR_INFO, "server_addresses: %s", FLAGS_server_addresses.c_str()); + gpr_log(GPR_INFO, "server_host: %s", FLAGS_server_host.c_str()); + gpr_log(GPR_INFO, "server_port: %d", FLAGS_server_port); gpr_log(GPR_INFO, "test_cases : %s", FLAGS_test_cases.c_str()); gpr_log(GPR_INFO, "sleep_duration_ms: %d", FLAGS_sleep_duration_ms); gpr_log(GPR_INFO, "test_duration_secs: %d", FLAGS_test_duration_secs); @@ -243,11 +286,24 @@ int main(int argc, char** argv) { // Parse the server addresses std::vector server_addresses; - ParseCommaDelimitedString(FLAGS_server_addresses, server_addresses); + if (FLAGS_server_port != 0) { + // We are using interop_client style cmdline options. + const int host_port_buf_size = 1024; + char host_port[host_port_buf_size]; + snprintf(host_port, host_port_buf_size, "%s:%d", FLAGS_server_host.c_str(), + FLAGS_server_port); + std::string host_port_str(host_port); + ParseCommaDelimitedString(host_port_str, server_addresses); + } else { + ParseCommaDelimitedString(FLAGS_server_addresses, server_addresses); + } // Parse test cases and weights if (FLAGS_test_cases.length() == 0) { - gpr_log(GPR_ERROR, "Not running tests. The 'test_cases' string is empty"); + // We are using interop_client style test_case option + FLAGS_test_cases = FLAGS_test_case + ":100"; + } else if (FLAGS_test_case != "") { + gpr_log(GPR_ERROR, "specify --test_case or --test_cases but not both."); return 1; } @@ -283,9 +339,13 @@ int main(int argc, char** argv) { // Create channel(s) for each server for (int channel_idx = 0; channel_idx < FLAGS_num_channels_per_server; channel_idx++) { - // TODO (sreek). This won't work for tests that require Authentication - std::shared_ptr channel( - grpc::CreateChannel(*it, grpc::InsecureChannelCredentials())); + gpr_log(GPR_INFO, "Starting test with %s channel_idx=%d..", it->c_str(), channel_idx); + std::shared_ptr channel; + if (FLAGS_use_tls) { + channel = grpc::testing::CreateChannelForTestCase(FLAGS_test_case); + } else { + channel = grpc::CreateChannel(*it, grpc::InsecureChannelCredentials()); + } // Create stub(s) for each channel for (int stub_idx = 0; stub_idx < FLAGS_num_stubs_per_channel; @@ -311,8 +371,11 @@ int main(int argc, char** argv) { } // Start metrics server before waiting for the stress test threads - std::unique_ptr metrics_server = - metrics_service.StartServer(FLAGS_metrics_port); + if (FLAGS_metrics_port > 0) { + std::unique_ptr metrics_server = + metrics_service.StartServer(FLAGS_metrics_port); + } + // Wait for the stress test threads to complete for (auto it = test_threads.begin(); it != test_threads.end(); it++) { diff --git a/tools/run_tests/sources_and_headers.json b/tools/run_tests/sources_and_headers.json index 7cfb1d4c17..aa5789bdd4 100644 --- a/tools/run_tests/sources_and_headers.json +++ b/tools/run_tests/sources_and_headers.json @@ -3135,6 +3135,7 @@ "language": "c++", "name": "stress_test", "src": [ + "test/cpp/interop/client_helper.cc", "test/cpp/interop/client_helper.h", "test/cpp/interop/interop_client.cc", "test/cpp/interop/interop_client.h", diff --git a/vsprojects/vcxproj/test/stress_test/stress_test.vcxproj b/vsprojects/vcxproj/test/stress_test/stress_test.vcxproj index ba2ed468b9..8e1b6bb3a6 100644 --- a/vsprojects/vcxproj/test/stress_test/stress_test.vcxproj +++ b/vsprojects/vcxproj/test/stress_test/stress_test.vcxproj @@ -198,6 +198,8 @@ + + diff --git a/vsprojects/vcxproj/test/stress_test/stress_test.vcxproj.filters b/vsprojects/vcxproj/test/stress_test/stress_test.vcxproj.filters index 08367b79af..476c04ec95 100644 --- a/vsprojects/vcxproj/test/stress_test/stress_test.vcxproj.filters +++ b/vsprojects/vcxproj/test/stress_test/stress_test.vcxproj.filters @@ -13,6 +13,9 @@ src\proto\grpc\testing + + test\cpp\interop + test\cpp\interop -- cgit v1.2.3 From f01f7b6d6ce078655710ae8076ed0352ee8340e6 Mon Sep 17 00:00:00 2001 From: Makarand Dharmapurikar Date: Fri, 21 Oct 2016 09:07:06 -0700 Subject: clang-format fixes --- test/cpp/interop/stress_test.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/cpp/interop/stress_test.cc b/test/cpp/interop/stress_test.cc index dac8015762..46d09b7f28 100644 --- a/test/cpp/interop/stress_test.cc +++ b/test/cpp/interop/stress_test.cc @@ -339,7 +339,8 @@ int main(int argc, char** argv) { // Create channel(s) for each server for (int channel_idx = 0; channel_idx < FLAGS_num_channels_per_server; channel_idx++) { - gpr_log(GPR_INFO, "Starting test with %s channel_idx=%d..", it->c_str(), channel_idx); + gpr_log(GPR_INFO, "Starting test with %s channel_idx=%d..", it->c_str(), + channel_idx); std::shared_ptr channel; if (FLAGS_use_tls) { channel = grpc::testing::CreateChannelForTestCase(FLAGS_test_case); @@ -376,7 +377,6 @@ int main(int argc, char** argv) { metrics_service.StartServer(FLAGS_metrics_port); } - // Wait for the stress test threads to complete for (auto it = test_threads.begin(); it != test_threads.end(); it++) { it->join(); -- cgit v1.2.3