OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * |
| 3 * Copyright 2015-2016, Google Inc. |
| 4 * All rights reserved. |
| 5 * |
| 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions are |
| 8 * met: |
| 9 * |
| 10 * * Redistributions of source code must retain the above copyright |
| 11 * notice, this list of conditions and the following disclaimer. |
| 12 * * Redistributions in binary form must reproduce the above |
| 13 * copyright notice, this list of conditions and the following disclaimer |
| 14 * in the documentation and/or other materials provided with the |
| 15 * distribution. |
| 16 * * Neither the name of Google Inc. nor the names of its |
| 17 * contributors may be used to endorse or promote products derived from |
| 18 * this software without specific prior written permission. |
| 19 * |
| 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 * |
| 32 */ |
| 33 |
| 34 #include <memory> |
| 35 |
| 36 #include <unistd.h> |
| 37 |
| 38 #include <grpc/grpc.h> |
| 39 #include <grpc/support/log.h> |
| 40 #include <gflags/gflags.h> |
| 41 #include <grpc++/channel.h> |
| 42 #include <grpc++/client_context.h> |
| 43 |
| 44 #include "test/cpp/interop/client_helper.h" |
| 45 #include "test/cpp/interop/interop_client.h" |
| 46 #include "test/cpp/util/test_config.h" |
| 47 |
| 48 DEFINE_bool(use_tls, false, "Whether to use tls."); |
| 49 DEFINE_bool(use_test_ca, false, "False to use SSL roots for google"); |
| 50 DEFINE_int32(server_port, 0, "Server port."); |
| 51 DEFINE_string(server_host, "127.0.0.1", "Server host to connect to"); |
| 52 DEFINE_string(server_host_override, "foo.test.google.fr", |
| 53 "Override the server host which is sent in HTTP header"); |
| 54 DEFINE_string(test_case, "large_unary", |
| 55 "Configure different test cases. Valid options are: " |
| 56 "empty_unary : empty (zero bytes) request and response; " |
| 57 "large_unary : single request and (large) response; " |
| 58 "large_compressed_unary : single request and compressed (large) " |
| 59 "response; " |
| 60 "client_streaming : request streaming with single response; " |
| 61 "server_streaming : single request with response streaming; " |
| 62 "server_compressed_streaming : single request with compressed " |
| 63 "response streaming; " |
| 64 "slow_consumer : single request with response; " |
| 65 " streaming with slow client consumer; " |
| 66 "half_duplex : half-duplex streaming; " |
| 67 "ping_pong : full-duplex streaming; " |
| 68 "cancel_after_begin : cancel stream after starting it; " |
| 69 "cancel_after_first_response: cancel on first response; " |
| 70 "timeout_on_sleeping_server: deadline exceeds on stream; " |
| 71 "empty_stream : bi-di stream with no request/response; " |
| 72 "compute_engine_creds: large_unary with compute engine auth; " |
| 73 "jwt_token_creds: large_unary with JWT token auth; " |
| 74 "oauth2_auth_token: raw oauth2 access token auth; " |
| 75 "per_rpc_creds: raw oauth2 access token on a single rpc; " |
| 76 "status_code_and_message: verify status code & message; " |
| 77 "custom_metadata: server will echo custom metadata;" |
| 78 "all : all of above."); |
| 79 DEFINE_string(default_service_account, "", |
| 80 "Email of GCE default service account"); |
| 81 DEFINE_string(service_account_key_file, "", |
| 82 "Path to service account json key file."); |
| 83 DEFINE_string(oauth_scope, "", "Scope for OAuth tokens."); |
| 84 |
| 85 using grpc::testing::CreateChannelForTestCase; |
| 86 using grpc::testing::GetServiceAccountJsonKey; |
| 87 |
| 88 int main(int argc, char** argv) { |
| 89 grpc::testing::InitTest(&argc, &argv, true); |
| 90 gpr_log(GPR_INFO, "Testing these cases: %s", FLAGS_test_case.c_str()); |
| 91 int ret = 0; |
| 92 grpc::testing::InteropClient client( |
| 93 CreateChannelForTestCase(FLAGS_test_case)); |
| 94 if (FLAGS_test_case == "empty_unary") { |
| 95 client.DoEmpty(); |
| 96 } else if (FLAGS_test_case == "large_unary") { |
| 97 client.DoLargeUnary(); |
| 98 } else if (FLAGS_test_case == "large_compressed_unary") { |
| 99 client.DoLargeCompressedUnary(); |
| 100 } else if (FLAGS_test_case == "client_streaming") { |
| 101 client.DoRequestStreaming(); |
| 102 } else if (FLAGS_test_case == "server_streaming") { |
| 103 client.DoResponseStreaming(); |
| 104 } else if (FLAGS_test_case == "server_compressed_streaming") { |
| 105 client.DoResponseCompressedStreaming(); |
| 106 } else if (FLAGS_test_case == "slow_consumer") { |
| 107 client.DoResponseStreamingWithSlowConsumer(); |
| 108 } else if (FLAGS_test_case == "half_duplex") { |
| 109 client.DoHalfDuplex(); |
| 110 } else if (FLAGS_test_case == "ping_pong") { |
| 111 client.DoPingPong(); |
| 112 } else if (FLAGS_test_case == "cancel_after_begin") { |
| 113 client.DoCancelAfterBegin(); |
| 114 } else if (FLAGS_test_case == "cancel_after_first_response") { |
| 115 client.DoCancelAfterFirstResponse(); |
| 116 } else if (FLAGS_test_case == "timeout_on_sleeping_server") { |
| 117 client.DoTimeoutOnSleepingServer(); |
| 118 } else if (FLAGS_test_case == "empty_stream") { |
| 119 client.DoEmptyStream(); |
| 120 } else if (FLAGS_test_case == "compute_engine_creds") { |
| 121 client.DoComputeEngineCreds(FLAGS_default_service_account, |
| 122 FLAGS_oauth_scope); |
| 123 } else if (FLAGS_test_case == "jwt_token_creds") { |
| 124 grpc::string json_key = GetServiceAccountJsonKey(); |
| 125 client.DoJwtTokenCreds(json_key); |
| 126 } else if (FLAGS_test_case == "oauth2_auth_token") { |
| 127 client.DoOauth2AuthToken(FLAGS_default_service_account, FLAGS_oauth_scope); |
| 128 } else if (FLAGS_test_case == "per_rpc_creds") { |
| 129 grpc::string json_key = GetServiceAccountJsonKey(); |
| 130 client.DoPerRpcCreds(json_key); |
| 131 } else if (FLAGS_test_case == "status_code_and_message") { |
| 132 client.DoStatusWithMessage(); |
| 133 } else if (FLAGS_test_case == "custom_metadata") { |
| 134 client.DoCustomMetadata(); |
| 135 } else if (FLAGS_test_case == "all") { |
| 136 client.DoEmpty(); |
| 137 client.DoLargeUnary(); |
| 138 client.DoRequestStreaming(); |
| 139 client.DoResponseStreaming(); |
| 140 client.DoResponseCompressedStreaming(); |
| 141 client.DoHalfDuplex(); |
| 142 client.DoPingPong(); |
| 143 client.DoCancelAfterBegin(); |
| 144 client.DoCancelAfterFirstResponse(); |
| 145 client.DoTimeoutOnSleepingServer(); |
| 146 client.DoEmptyStream(); |
| 147 client.DoStatusWithMessage(); |
| 148 client.DoCustomMetadata(); |
| 149 // service_account_creds and jwt_token_creds can only run with ssl. |
| 150 if (FLAGS_use_tls) { |
| 151 grpc::string json_key = GetServiceAccountJsonKey(); |
| 152 client.DoJwtTokenCreds(json_key); |
| 153 client.DoOauth2AuthToken(FLAGS_default_service_account, |
| 154 FLAGS_oauth_scope); |
| 155 client.DoPerRpcCreds(json_key); |
| 156 } |
| 157 // compute_engine_creds only runs in GCE. |
| 158 } else { |
| 159 gpr_log( |
| 160 GPR_ERROR, |
| 161 "Unsupported test case %s. Valid options are all|empty_unary|" |
| 162 "large_unary|large_compressed_unary|client_streaming|server_streaming|" |
| 163 "server_compressed_streaming|half_duplex|ping_pong|cancel_after_begin|" |
| 164 "cancel_after_first_response|timeout_on_sleeping_server|empty_stream|" |
| 165 "compute_engine_creds|jwt_token_creds|oauth2_auth_token|per_rpc_creds", |
| 166 "status_code_and_message|custom_metadata", FLAGS_test_case.c_str()); |
| 167 ret = 1; |
| 168 } |
| 169 |
| 170 return ret; |
| 171 } |
OLD | NEW |