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> |
chenw | a8fd44a | 2014-12-10 15:13:55 -0800 | [diff] [blame] | 41 | #include <grpc++/channel_interface.h> |
| 42 | #include <grpc++/client_context.h> |
chenw | a8fd44a | 2014-12-10 15:13:55 -0800 | [diff] [blame] | 43 | #include <grpc++/status.h> |
| 44 | #include <grpc++/stream.h> |
Yang Gao | a400207 | 2015-04-09 23:25:21 -0700 | [diff] [blame] | 45 | #include "test/cpp/interop/client_helper.h" |
| 46 | #include "test/cpp/interop/interop_client.h" |
Yang Gao | 103837e | 2015-04-15 15:23:54 -0700 | [diff] [blame] | 47 | #include "test/cpp/util/test_config.h" |
chenw | a8fd44a | 2014-12-10 15:13:55 -0800 | [diff] [blame] | 48 | |
| 49 | DEFINE_bool(enable_ssl, false, "Whether to use ssl/tls."); |
Yang Gao | c38dda4 | 2015-01-26 00:09:23 -0800 | [diff] [blame] | 50 | DEFINE_bool(use_prod_roots, false, "True to use SSL roots for google"); |
chenw | a8fd44a | 2014-12-10 15:13:55 -0800 | [diff] [blame] | 51 | DEFINE_int32(server_port, 0, "Server port."); |
chenw | ebb4e6d | 2014-12-22 14:41:55 -0800 | [diff] [blame] | 52 | 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] | 53 | DEFINE_string(server_host_override, "foo.test.google.fr", |
chenw | ebb4e6d | 2014-12-22 14:41:55 -0800 | [diff] [blame] | 54 | "Override the server host which is sent in HTTP header"); |
chenw | a8fd44a | 2014-12-10 15:13:55 -0800 | [diff] [blame] | 55 | DEFINE_string(test_case, "large_unary", |
| 56 | "Configure different test cases. Valid options are: " |
| 57 | "empty_unary : empty (zero bytes) request and response; " |
| 58 | "large_unary : single request and (large) response; " |
| 59 | "client_streaming : request streaming with single response; " |
| 60 | "server_streaming : single request with response streaming; " |
Yang Gao | c38dda4 | 2015-01-26 00:09:23 -0800 | [diff] [blame] | 61 | "slow_consumer : single request with response; " |
chenw | 69ca59f | 2014-12-16 14:20:44 -0800 | [diff] [blame] | 62 | " streaming with slow client consumer; " |
Yang Gao | c38dda4 | 2015-01-26 00:09:23 -0800 | [diff] [blame] | 63 | "half_duplex : half-duplex streaming; " |
| 64 | "ping_pong : full-duplex streaming; " |
| 65 | "service_account_creds : large_unary with service_account auth; " |
Yang Gao | bd18be2 | 2015-01-27 14:29:19 -0800 | [diff] [blame] | 66 | "compute_engine_creds: large_unary with compute engine auth; " |
Yang Gao | 25770b0 | 2015-02-27 15:30:58 -0800 | [diff] [blame] | 67 | "jwt_token_creds: large_unary with JWT token auth; " |
chenw | a8fd44a | 2014-12-10 15:13:55 -0800 | [diff] [blame] | 68 | "all : all of above."); |
Yang Gao | aec1d0b | 2015-01-27 15:02:14 -0800 | [diff] [blame] | 69 | DEFINE_string(default_service_account, "", |
Yang Gao | bd18be2 | 2015-01-27 14:29:19 -0800 | [diff] [blame] | 70 | "Email of GCE default service account"); |
Yang Gao | c38dda4 | 2015-01-26 00:09:23 -0800 | [diff] [blame] | 71 | DEFINE_string(service_account_key_file, "", |
| 72 | "Path to service account json key file."); |
| 73 | DEFINE_string(oauth_scope, "", "Scope for OAuth tokens."); |
chenw | a8fd44a | 2014-12-10 15:13:55 -0800 | [diff] [blame] | 74 | |
Yang Gao | a400207 | 2015-04-09 23:25:21 -0700 | [diff] [blame] | 75 | using grpc::testing::CreateChannelForTestCase; |
| 76 | using grpc::testing::GetServiceAccountJsonKey; |
chenw | a8fd44a | 2014-12-10 15:13:55 -0800 | [diff] [blame] | 77 | |
chenw | a8fd44a | 2014-12-10 15:13:55 -0800 | [diff] [blame] | 78 | int main(int argc, char** argv) { |
Yang Gao | 103837e | 2015-04-15 15:23:54 -0700 | [diff] [blame] | 79 | grpc::testing::InitTest(&argc, &argv, true); |
chenw | a8fd44a | 2014-12-10 15:13:55 -0800 | [diff] [blame] | 80 | |
Yang Gao | eaccf90 | 2015-04-15 14:05:07 -0700 | [diff] [blame] | 81 | int ret = 0; |
Yang Gao | a400207 | 2015-04-09 23:25:21 -0700 | [diff] [blame] | 82 | grpc::testing::InteropClient client( |
| 83 | CreateChannelForTestCase(FLAGS_test_case)); |
chenw | a8fd44a | 2014-12-10 15:13:55 -0800 | [diff] [blame] | 84 | if (FLAGS_test_case == "empty_unary") { |
Yang Gao | a400207 | 2015-04-09 23:25:21 -0700 | [diff] [blame] | 85 | client.DoEmpty(); |
chenw | a8fd44a | 2014-12-10 15:13:55 -0800 | [diff] [blame] | 86 | } else if (FLAGS_test_case == "large_unary") { |
Yang Gao | a400207 | 2015-04-09 23:25:21 -0700 | [diff] [blame] | 87 | client.DoLargeUnary(); |
chenw | 6edb547 | 2015-01-08 14:04:39 -0800 | [diff] [blame] | 88 | } else if (FLAGS_test_case == "client_streaming") { |
Yang Gao | a400207 | 2015-04-09 23:25:21 -0700 | [diff] [blame] | 89 | client.DoRequestStreaming(); |
chenw | 6edb547 | 2015-01-08 14:04:39 -0800 | [diff] [blame] | 90 | } else if (FLAGS_test_case == "server_streaming") { |
Yang Gao | a400207 | 2015-04-09 23:25:21 -0700 | [diff] [blame] | 91 | client.DoResponseStreaming(); |
chenw | 6edb547 | 2015-01-08 14:04:39 -0800 | [diff] [blame] | 92 | } else if (FLAGS_test_case == "slow_consumer") { |
Yang Gao | a400207 | 2015-04-09 23:25:21 -0700 | [diff] [blame] | 93 | client.DoResponseStreamingWithSlowConsumer(); |
chenw | 6edb547 | 2015-01-08 14:04:39 -0800 | [diff] [blame] | 94 | } else if (FLAGS_test_case == "half_duplex") { |
Yang Gao | a400207 | 2015-04-09 23:25:21 -0700 | [diff] [blame] | 95 | client.DoHalfDuplex(); |
chenw | 6edb547 | 2015-01-08 14:04:39 -0800 | [diff] [blame] | 96 | } else if (FLAGS_test_case == "ping_pong") { |
Yang Gao | a400207 | 2015-04-09 23:25:21 -0700 | [diff] [blame] | 97 | client.DoPingPong(); |
Yang Gao | c38dda4 | 2015-01-26 00:09:23 -0800 | [diff] [blame] | 98 | } else if (FLAGS_test_case == "service_account_creds") { |
Yang Gao | a400207 | 2015-04-09 23:25:21 -0700 | [diff] [blame] | 99 | grpc::string json_key = GetServiceAccountJsonKey(); |
| 100 | client.DoServiceAccountCreds(json_key, FLAGS_oauth_scope); |
Yang Gao | bd18be2 | 2015-01-27 14:29:19 -0800 | [diff] [blame] | 101 | } else if (FLAGS_test_case == "compute_engine_creds") { |
Yang Gao | a400207 | 2015-04-09 23:25:21 -0700 | [diff] [blame] | 102 | client.DoComputeEngineCreds(FLAGS_default_service_account, |
| 103 | FLAGS_oauth_scope); |
Yang Gao | 25770b0 | 2015-02-27 15:30:58 -0800 | [diff] [blame] | 104 | } else if (FLAGS_test_case == "jwt_token_creds") { |
Yang Gao | a400207 | 2015-04-09 23:25:21 -0700 | [diff] [blame] | 105 | grpc::string json_key = GetServiceAccountJsonKey(); |
| 106 | client.DoJwtTokenCreds(json_key); |
chenw | 6edb547 | 2015-01-08 14:04:39 -0800 | [diff] [blame] | 107 | } else if (FLAGS_test_case == "all") { |
Yang Gao | a400207 | 2015-04-09 23:25:21 -0700 | [diff] [blame] | 108 | client.DoEmpty(); |
| 109 | client.DoLargeUnary(); |
| 110 | client.DoRequestStreaming(); |
| 111 | client.DoResponseStreaming(); |
| 112 | client.DoHalfDuplex(); |
| 113 | client.DoPingPong(); |
Yang Gao | 25770b0 | 2015-02-27 15:30:58 -0800 | [diff] [blame] | 114 | // service_account_creds and jwt_token_creds can only run with ssl. |
Yang Gao | 3bc377c | 2015-01-26 10:55:25 -0800 | [diff] [blame] | 115 | if (FLAGS_enable_ssl) { |
Yang Gao | a400207 | 2015-04-09 23:25:21 -0700 | [diff] [blame] | 116 | grpc::string json_key = GetServiceAccountJsonKey(); |
| 117 | client.DoServiceAccountCreds(json_key, FLAGS_oauth_scope); |
| 118 | client.DoJwtTokenCreds(json_key); |
Yang Gao | 3bc377c | 2015-01-26 10:55:25 -0800 | [diff] [blame] | 119 | } |
Yang Gao | bd18be2 | 2015-01-27 14:29:19 -0800 | [diff] [blame] | 120 | // compute_engine_creds only runs in GCE. |
chenw | a8fd44a | 2014-12-10 15:13:55 -0800 | [diff] [blame] | 121 | } else { |
| 122 | gpr_log( |
| 123 | GPR_ERROR, |
| 124 | "Unsupported test case %s. Valid options are all|empty_unary|" |
Yang Gao | 3bc377c | 2015-01-26 10:55:25 -0800 | [diff] [blame] | 125 | "large_unary|client_streaming|server_streaming|half_duplex|ping_pong|" |
Yang Gao | 25770b0 | 2015-02-27 15:30:58 -0800 | [diff] [blame] | 126 | "service_account_creds|compute_engine_creds|jwt_token_creds", |
chenw | a8fd44a | 2014-12-10 15:13:55 -0800 | [diff] [blame] | 127 | FLAGS_test_case.c_str()); |
Yang Gao | eaccf90 | 2015-04-15 14:05:07 -0700 | [diff] [blame] | 128 | ret = 1; |
chenw | a8fd44a | 2014-12-10 15:13:55 -0800 | [diff] [blame] | 129 | } |
| 130 | |
Yang Gao | eaccf90 | 2015-04-15 14:05:07 -0700 | [diff] [blame] | 131 | return ret; |
Craig Tiller | 190d360 | 2015-02-18 09:23:38 -0800 | [diff] [blame] | 132 | } |