chenw | a8fd44a | 2014-12-10 15:13:55 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
Craig Tiller | 0605995 | 2015-02-18 08:34:56 -0800 | [diff] [blame] | 3 | * Copyright 2015, Google Inc. |
chenw | a8fd44a | 2014-12-10 15:13:55 -0800 | [diff] [blame] | 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 | |
chenw | a8fd44a | 2014-12-10 15:13:55 -0800 | [diff] [blame] | 34 | #include <memory> |
chenw | a8fd44a | 2014-12-10 15:13:55 -0800 | [diff] [blame] | 35 | |
Craig Tiller | cf133f4 | 2015-02-26 14:05:56 -0800 | [diff] [blame] | 36 | #include <unistd.h> |
| 37 | |
chenw | a8fd44a | 2014-12-10 15:13:55 -0800 | [diff] [blame] | 38 | #include <grpc/grpc.h> |
| 39 | #include <grpc/support/log.h> |
Nicolas "Pixel" Noble | ba60820 | 2015-02-20 02:48:03 +0100 | [diff] [blame] | 40 | #include <gflags/gflags.h> |
yang-g | 8c2be9f | 2015-08-19 16:28:09 -0700 | [diff] [blame] | 41 | #include <grpc++/channel.h> |
chenw | a8fd44a | 2014-12-10 15:13:55 -0800 | [diff] [blame] | 42 | #include <grpc++/client_context.h> |
yang-g | 9e2f90c | 2015-08-21 15:35:03 -0700 | [diff] [blame] | 43 | |
Yang Gao | a400207 | 2015-04-09 23:25:21 -0700 | [diff] [blame] | 44 | #include "test/cpp/interop/client_helper.h" |
| 45 | #include "test/cpp/interop/interop_client.h" |
Yang Gao | 103837e | 2015-04-15 15:23:54 -0700 | [diff] [blame] | 46 | #include "test/cpp/util/test_config.h" |
chenw | a8fd44a | 2014-12-10 15:13:55 -0800 | [diff] [blame] | 47 | |
yang-g | 035cf09 | 2015-09-18 12:11:05 -0700 | [diff] [blame] | 48 | DEFINE_bool(use_tls, false, "Whether to use tls."); |
yang-g | a006b5f | 2015-10-07 13:14:35 -0700 | [diff] [blame] | 49 | DEFINE_bool(use_test_ca, false, "False to use SSL roots for google"); |
chenw | a8fd44a | 2014-12-10 15:13:55 -0800 | [diff] [blame] | 50 | DEFINE_int32(server_port, 0, "Server port."); |
chenw | ebb4e6d | 2014-12-22 14:41:55 -0800 | [diff] [blame] | 51 | DEFINE_string(server_host, "127.0.0.1", "Server host to connect to"); |
Julien Boeuf | 597a4f2 | 2015-02-23 15:57:14 -0800 | [diff] [blame] | 52 | DEFINE_string(server_host_override, "foo.test.google.fr", |
chenw | ebb4e6d | 2014-12-22 14:41:55 -0800 | [diff] [blame] | 53 | "Override the server host which is sent in HTTP header"); |
chenw | a8fd44a | 2014-12-10 15:13:55 -0800 | [diff] [blame] | 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; " |
David Garcia Quintas | cd37d58 | 2015-08-09 15:50:21 -0700 | [diff] [blame] | 58 | "large_compressed_unary : single request and compressed (large) " |
| 59 | "response; " |
chenw | a8fd44a | 2014-12-10 15:13:55 -0800 | [diff] [blame] | 60 | "client_streaming : request streaming with single response; " |
| 61 | "server_streaming : single request with response streaming; " |
David Garcia Quintas | cd37d58 | 2015-08-09 15:50:21 -0700 | [diff] [blame] | 62 | "server_compressed_streaming : single request with compressed " |
| 63 | "response streaming; " |
Yang Gao | c38dda4 | 2015-01-26 00:09:23 -0800 | [diff] [blame] | 64 | "slow_consumer : single request with response; " |
chenw | 69ca59f | 2014-12-16 14:20:44 -0800 | [diff] [blame] | 65 | " streaming with slow client consumer; " |
Yang Gao | c38dda4 | 2015-01-26 00:09:23 -0800 | [diff] [blame] | 66 | "half_duplex : half-duplex streaming; " |
| 67 | "ping_pong : full-duplex streaming; " |
Yang Gao | 68d6157 | 2015-04-24 14:42:42 -0700 | [diff] [blame] | 68 | "cancel_after_begin : cancel stream after starting it; " |
| 69 | "cancel_after_first_response: cancel on first response; " |
yang-g | 69563b9 | 2015-07-10 15:32:11 -0700 | [diff] [blame] | 70 | "timeout_on_sleeping_server: deadline exceeds on stream; " |
yang-g | 78bddc6 | 2015-09-21 10:32:17 -0700 | [diff] [blame] | 71 | "empty_stream : bi-di stream with no request/response; " |
Yang Gao | bd18be2 | 2015-01-27 14:29:19 -0800 | [diff] [blame] | 72 | "compute_engine_creds: large_unary with compute engine auth; " |
Yang Gao | 25770b0 | 2015-02-27 15:30:58 -0800 | [diff] [blame] | 73 | "jwt_token_creds: large_unary with JWT token auth; " |
yang-g | be5f059 | 2015-07-13 11:11:50 -0700 | [diff] [blame] | 74 | "oauth2_auth_token: raw oauth2 access token auth; " |
yang-g | 5bf510b | 2015-07-14 10:54:29 -0700 | [diff] [blame] | 75 | "per_rpc_creds: raw oauth2 access token on a single rpc; " |
David Garcia Quintas | 2e1bb1b | 2015-08-10 14:05:57 -0700 | [diff] [blame] | 76 | "status_code_and_message: verify status code & message; " |
yang-g | c10348a | 2016-02-19 16:05:10 -0800 | [diff] [blame^] | 77 | "custom_metadata: server will echo custom metadata;" |
chenw | a8fd44a | 2014-12-10 15:13:55 -0800 | [diff] [blame] | 78 | "all : all of above."); |
Yang Gao | aec1d0b | 2015-01-27 15:02:14 -0800 | [diff] [blame] | 79 | DEFINE_string(default_service_account, "", |
Yang Gao | bd18be2 | 2015-01-27 14:29:19 -0800 | [diff] [blame] | 80 | "Email of GCE default service account"); |
Yang Gao | c38dda4 | 2015-01-26 00:09:23 -0800 | [diff] [blame] | 81 | DEFINE_string(service_account_key_file, "", |
| 82 | "Path to service account json key file."); |
| 83 | DEFINE_string(oauth_scope, "", "Scope for OAuth tokens."); |
chenw | a8fd44a | 2014-12-10 15:13:55 -0800 | [diff] [blame] | 84 | |
Yang Gao | a400207 | 2015-04-09 23:25:21 -0700 | [diff] [blame] | 85 | using grpc::testing::CreateChannelForTestCase; |
| 86 | using grpc::testing::GetServiceAccountJsonKey; |
chenw | a8fd44a | 2014-12-10 15:13:55 -0800 | [diff] [blame] | 87 | |
chenw | a8fd44a | 2014-12-10 15:13:55 -0800 | [diff] [blame] | 88 | int main(int argc, char** argv) { |
Yang Gao | 103837e | 2015-04-15 15:23:54 -0700 | [diff] [blame] | 89 | grpc::testing::InitTest(&argc, &argv, true); |
Abhishek Kumar | e1c867d | 2015-08-05 11:04:45 -0700 | [diff] [blame] | 90 | gpr_log(GPR_INFO, "Testing these cases: %s", FLAGS_test_case.c_str()); |
Yang Gao | eaccf90 | 2015-04-15 14:05:07 -0700 | [diff] [blame] | 91 | int ret = 0; |
Yang Gao | a400207 | 2015-04-09 23:25:21 -0700 | [diff] [blame] | 92 | grpc::testing::InteropClient client( |
| 93 | CreateChannelForTestCase(FLAGS_test_case)); |
chenw | a8fd44a | 2014-12-10 15:13:55 -0800 | [diff] [blame] | 94 | if (FLAGS_test_case == "empty_unary") { |
Yang Gao | a400207 | 2015-04-09 23:25:21 -0700 | [diff] [blame] | 95 | client.DoEmpty(); |
chenw | a8fd44a | 2014-12-10 15:13:55 -0800 | [diff] [blame] | 96 | } else if (FLAGS_test_case == "large_unary") { |
Yang Gao | a400207 | 2015-04-09 23:25:21 -0700 | [diff] [blame] | 97 | client.DoLargeUnary(); |
David Garcia Quintas | cd37d58 | 2015-08-09 15:50:21 -0700 | [diff] [blame] | 98 | } else if (FLAGS_test_case == "large_compressed_unary") { |
| 99 | client.DoLargeCompressedUnary(); |
chenw | 6edb547 | 2015-01-08 14:04:39 -0800 | [diff] [blame] | 100 | } else if (FLAGS_test_case == "client_streaming") { |
Yang Gao | a400207 | 2015-04-09 23:25:21 -0700 | [diff] [blame] | 101 | client.DoRequestStreaming(); |
chenw | 6edb547 | 2015-01-08 14:04:39 -0800 | [diff] [blame] | 102 | } else if (FLAGS_test_case == "server_streaming") { |
Yang Gao | a400207 | 2015-04-09 23:25:21 -0700 | [diff] [blame] | 103 | client.DoResponseStreaming(); |
David Garcia Quintas | cd37d58 | 2015-08-09 15:50:21 -0700 | [diff] [blame] | 104 | } else if (FLAGS_test_case == "server_compressed_streaming") { |
| 105 | client.DoResponseCompressedStreaming(); |
chenw | 6edb547 | 2015-01-08 14:04:39 -0800 | [diff] [blame] | 106 | } else if (FLAGS_test_case == "slow_consumer") { |
Yang Gao | a400207 | 2015-04-09 23:25:21 -0700 | [diff] [blame] | 107 | client.DoResponseStreamingWithSlowConsumer(); |
chenw | 6edb547 | 2015-01-08 14:04:39 -0800 | [diff] [blame] | 108 | } else if (FLAGS_test_case == "half_duplex") { |
Yang Gao | a400207 | 2015-04-09 23:25:21 -0700 | [diff] [blame] | 109 | client.DoHalfDuplex(); |
chenw | 6edb547 | 2015-01-08 14:04:39 -0800 | [diff] [blame] | 110 | } else if (FLAGS_test_case == "ping_pong") { |
Yang Gao | a400207 | 2015-04-09 23:25:21 -0700 | [diff] [blame] | 111 | client.DoPingPong(); |
Yang Gao | 68d6157 | 2015-04-24 14:42:42 -0700 | [diff] [blame] | 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(); |
yang-g | 69563b9 | 2015-07-10 15:32:11 -0700 | [diff] [blame] | 116 | } else if (FLAGS_test_case == "timeout_on_sleeping_server") { |
| 117 | client.DoTimeoutOnSleepingServer(); |
yang-g | 78bddc6 | 2015-09-21 10:32:17 -0700 | [diff] [blame] | 118 | } else if (FLAGS_test_case == "empty_stream") { |
| 119 | client.DoEmptyStream(); |
Yang Gao | bd18be2 | 2015-01-27 14:29:19 -0800 | [diff] [blame] | 120 | } else if (FLAGS_test_case == "compute_engine_creds") { |
Yang Gao | a400207 | 2015-04-09 23:25:21 -0700 | [diff] [blame] | 121 | client.DoComputeEngineCreds(FLAGS_default_service_account, |
| 122 | FLAGS_oauth_scope); |
Yang Gao | 25770b0 | 2015-02-27 15:30:58 -0800 | [diff] [blame] | 123 | } else if (FLAGS_test_case == "jwt_token_creds") { |
Yang Gao | a400207 | 2015-04-09 23:25:21 -0700 | [diff] [blame] | 124 | grpc::string json_key = GetServiceAccountJsonKey(); |
| 125 | client.DoJwtTokenCreds(json_key); |
yang-g | be5f059 | 2015-07-13 11:11:50 -0700 | [diff] [blame] | 126 | } else if (FLAGS_test_case == "oauth2_auth_token") { |
yang-g | 867d0c1 | 2015-09-02 14:33:15 -0700 | [diff] [blame] | 127 | client.DoOauth2AuthToken(FLAGS_default_service_account, FLAGS_oauth_scope); |
yang-g | 5bf510b | 2015-07-14 10:54:29 -0700 | [diff] [blame] | 128 | } else if (FLAGS_test_case == "per_rpc_creds") { |
| 129 | grpc::string json_key = GetServiceAccountJsonKey(); |
yang-g | 867d0c1 | 2015-09-02 14:33:15 -0700 | [diff] [blame] | 130 | client.DoPerRpcCreds(json_key); |
Abhishek Kumar | e1c867d | 2015-08-05 11:04:45 -0700 | [diff] [blame] | 131 | } else if (FLAGS_test_case == "status_code_and_message") { |
| 132 | client.DoStatusWithMessage(); |
yang-g | c10348a | 2016-02-19 16:05:10 -0800 | [diff] [blame^] | 133 | } else if (FLAGS_test_case == "custom_metadata") { |
| 134 | client.DoCustomMetadata(); |
chenw | 6edb547 | 2015-01-08 14:04:39 -0800 | [diff] [blame] | 135 | } else if (FLAGS_test_case == "all") { |
Yang Gao | a400207 | 2015-04-09 23:25:21 -0700 | [diff] [blame] | 136 | client.DoEmpty(); |
| 137 | client.DoLargeUnary(); |
| 138 | client.DoRequestStreaming(); |
| 139 | client.DoResponseStreaming(); |
David Garcia Quintas | cd37d58 | 2015-08-09 15:50:21 -0700 | [diff] [blame] | 140 | client.DoResponseCompressedStreaming(); |
Yang Gao | a400207 | 2015-04-09 23:25:21 -0700 | [diff] [blame] | 141 | client.DoHalfDuplex(); |
| 142 | client.DoPingPong(); |
Yang Gao | 68d6157 | 2015-04-24 14:42:42 -0700 | [diff] [blame] | 143 | client.DoCancelAfterBegin(); |
| 144 | client.DoCancelAfterFirstResponse(); |
yang-g | 69563b9 | 2015-07-10 15:32:11 -0700 | [diff] [blame] | 145 | client.DoTimeoutOnSleepingServer(); |
yang-g | 78bddc6 | 2015-09-21 10:32:17 -0700 | [diff] [blame] | 146 | client.DoEmptyStream(); |
Abhishek Kumar | e1c867d | 2015-08-05 11:04:45 -0700 | [diff] [blame] | 147 | client.DoStatusWithMessage(); |
yang-g | c10348a | 2016-02-19 16:05:10 -0800 | [diff] [blame^] | 148 | client.DoCustomMetadata(); |
Yang Gao | 25770b0 | 2015-02-27 15:30:58 -0800 | [diff] [blame] | 149 | // service_account_creds and jwt_token_creds can only run with ssl. |
yang-g | 035cf09 | 2015-09-18 12:11:05 -0700 | [diff] [blame] | 150 | if (FLAGS_use_tls) { |
Yang Gao | a400207 | 2015-04-09 23:25:21 -0700 | [diff] [blame] | 151 | grpc::string json_key = GetServiceAccountJsonKey(); |
Yang Gao | a400207 | 2015-04-09 23:25:21 -0700 | [diff] [blame] | 152 | client.DoJwtTokenCreds(json_key); |
Craig Tiller | 71a0f9d | 2015-09-28 17:22:01 -0700 | [diff] [blame] | 153 | client.DoOauth2AuthToken(FLAGS_default_service_account, |
| 154 | FLAGS_oauth_scope); |
yang-g | 867d0c1 | 2015-09-02 14:33:15 -0700 | [diff] [blame] | 155 | client.DoPerRpcCreds(json_key); |
Yang Gao | 3bc377c | 2015-01-26 10:55:25 -0800 | [diff] [blame] | 156 | } |
Yang Gao | bd18be2 | 2015-01-27 14:29:19 -0800 | [diff] [blame] | 157 | // compute_engine_creds only runs in GCE. |
chenw | a8fd44a | 2014-12-10 15:13:55 -0800 | [diff] [blame] | 158 | } else { |
| 159 | gpr_log( |
| 160 | GPR_ERROR, |
| 161 | "Unsupported test case %s. Valid options are all|empty_unary|" |
David Garcia Quintas | cd37d58 | 2015-08-09 15:50:21 -0700 | [diff] [blame] | 162 | "large_unary|large_compressed_unary|client_streaming|server_streaming|" |
| 163 | "server_compressed_streaming|half_duplex|ping_pong|cancel_after_begin|" |
yang-g | 78bddc6 | 2015-09-21 10:32:17 -0700 | [diff] [blame] | 164 | "cancel_after_first_response|timeout_on_sleeping_server|empty_stream|" |
Julien Boeuf | 421738b | 2015-08-27 16:34:44 -0700 | [diff] [blame] | 165 | "compute_engine_creds|jwt_token_creds|oauth2_auth_token|per_rpc_creds", |
yang-g | c10348a | 2016-02-19 16:05:10 -0800 | [diff] [blame^] | 166 | "status_code_and_message|custom_metadata", FLAGS_test_case.c_str()); |
Yang Gao | eaccf90 | 2015-04-15 14:05:07 -0700 | [diff] [blame] | 167 | ret = 1; |
chenw | a8fd44a | 2014-12-10 15:13:55 -0800 | [diff] [blame] | 168 | } |
| 169 | |
Yang Gao | eaccf90 | 2015-04-15 14:05:07 -0700 | [diff] [blame] | 170 | return ret; |
Craig Tiller | 190d360 | 2015-02-18 09:23:38 -0800 | [diff] [blame] | 171 | } |