blob: 8e81e432e7965c45d44dbbdfdae3db6e1d65a9d7 [file] [log] [blame]
chenwa8fd44a2014-12-10 15:13:55 -08001/*
2 *
Craig Tiller06059952015-02-18 08:34:56 -08003 * Copyright 2015, Google Inc.
chenwa8fd44a2014-12-10 15:13:55 -08004 * 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
chenwa8fd44a2014-12-10 15:13:55 -080034#include <memory>
chenwa8fd44a2014-12-10 15:13:55 -080035
Craig Tillercf133f42015-02-26 14:05:56 -080036#include <unistd.h>
37
chenwa8fd44a2014-12-10 15:13:55 -080038#include <grpc/grpc.h>
39#include <grpc/support/log.h>
Nicolas "Pixel" Nobleba608202015-02-20 02:48:03 +010040#include <gflags/gflags.h>
yang-g8c2be9f2015-08-19 16:28:09 -070041#include <grpc++/channel.h>
chenwa8fd44a2014-12-10 15:13:55 -080042#include <grpc++/client_context.h>
yang-g9e2f90c2015-08-21 15:35:03 -070043
Yang Gaoa4002072015-04-09 23:25:21 -070044#include "test/cpp/interop/client_helper.h"
45#include "test/cpp/interop/interop_client.h"
Yang Gao103837e2015-04-15 15:23:54 -070046#include "test/cpp/util/test_config.h"
chenwa8fd44a2014-12-10 15:13:55 -080047
yang-g035cf092015-09-18 12:11:05 -070048DEFINE_bool(use_tls, false, "Whether to use tls.");
yang-ga006b5f2015-10-07 13:14:35 -070049DEFINE_bool(use_test_ca, false, "False to use SSL roots for google");
chenwa8fd44a2014-12-10 15:13:55 -080050DEFINE_int32(server_port, 0, "Server port.");
chenwebb4e6d2014-12-22 14:41:55 -080051DEFINE_string(server_host, "127.0.0.1", "Server host to connect to");
Julien Boeuf597a4f22015-02-23 15:57:14 -080052DEFINE_string(server_host_override, "foo.test.google.fr",
chenwebb4e6d2014-12-22 14:41:55 -080053 "Override the server host which is sent in HTTP header");
chenwa8fd44a2014-12-10 15:13:55 -080054DEFINE_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 Quintascd37d582015-08-09 15:50:21 -070058 "large_compressed_unary : single request and compressed (large) "
59 "response; "
chenwa8fd44a2014-12-10 15:13:55 -080060 "client_streaming : request streaming with single response; "
61 "server_streaming : single request with response streaming; "
David Garcia Quintascd37d582015-08-09 15:50:21 -070062 "server_compressed_streaming : single request with compressed "
63 "response streaming; "
Yang Gaoc38dda42015-01-26 00:09:23 -080064 "slow_consumer : single request with response; "
chenw69ca59f2014-12-16 14:20:44 -080065 " streaming with slow client consumer; "
Yang Gaoc38dda42015-01-26 00:09:23 -080066 "half_duplex : half-duplex streaming; "
67 "ping_pong : full-duplex streaming; "
Yang Gao68d61572015-04-24 14:42:42 -070068 "cancel_after_begin : cancel stream after starting it; "
69 "cancel_after_first_response: cancel on first response; "
yang-g69563b92015-07-10 15:32:11 -070070 "timeout_on_sleeping_server: deadline exceeds on stream; "
yang-g78bddc62015-09-21 10:32:17 -070071 "empty_stream : bi-di stream with no request/response; "
Yang Gaobd18be22015-01-27 14:29:19 -080072 "compute_engine_creds: large_unary with compute engine auth; "
Yang Gao25770b02015-02-27 15:30:58 -080073 "jwt_token_creds: large_unary with JWT token auth; "
yang-gbe5f0592015-07-13 11:11:50 -070074 "oauth2_auth_token: raw oauth2 access token auth; "
yang-g5bf510b2015-07-14 10:54:29 -070075 "per_rpc_creds: raw oauth2 access token on a single rpc; "
David Garcia Quintas2e1bb1b2015-08-10 14:05:57 -070076 "status_code_and_message: verify status code & message; "
yang-gc10348a2016-02-19 16:05:10 -080077 "custom_metadata: server will echo custom metadata;"
chenwa8fd44a2014-12-10 15:13:55 -080078 "all : all of above.");
Yang Gaoaec1d0b2015-01-27 15:02:14 -080079DEFINE_string(default_service_account, "",
Yang Gaobd18be22015-01-27 14:29:19 -080080 "Email of GCE default service account");
Yang Gaoc38dda42015-01-26 00:09:23 -080081DEFINE_string(service_account_key_file, "",
82 "Path to service account json key file.");
83DEFINE_string(oauth_scope, "", "Scope for OAuth tokens.");
chenwa8fd44a2014-12-10 15:13:55 -080084
Yang Gaoa4002072015-04-09 23:25:21 -070085using grpc::testing::CreateChannelForTestCase;
86using grpc::testing::GetServiceAccountJsonKey;
chenwa8fd44a2014-12-10 15:13:55 -080087
chenwa8fd44a2014-12-10 15:13:55 -080088int main(int argc, char** argv) {
Yang Gao103837e2015-04-15 15:23:54 -070089 grpc::testing::InitTest(&argc, &argv, true);
Abhishek Kumare1c867d2015-08-05 11:04:45 -070090 gpr_log(GPR_INFO, "Testing these cases: %s", FLAGS_test_case.c_str());
Yang Gaoeaccf902015-04-15 14:05:07 -070091 int ret = 0;
Yang Gaoa4002072015-04-09 23:25:21 -070092 grpc::testing::InteropClient client(
93 CreateChannelForTestCase(FLAGS_test_case));
chenwa8fd44a2014-12-10 15:13:55 -080094 if (FLAGS_test_case == "empty_unary") {
Yang Gaoa4002072015-04-09 23:25:21 -070095 client.DoEmpty();
chenwa8fd44a2014-12-10 15:13:55 -080096 } else if (FLAGS_test_case == "large_unary") {
Yang Gaoa4002072015-04-09 23:25:21 -070097 client.DoLargeUnary();
David Garcia Quintascd37d582015-08-09 15:50:21 -070098 } else if (FLAGS_test_case == "large_compressed_unary") {
99 client.DoLargeCompressedUnary();
chenw6edb5472015-01-08 14:04:39 -0800100 } else if (FLAGS_test_case == "client_streaming") {
Yang Gaoa4002072015-04-09 23:25:21 -0700101 client.DoRequestStreaming();
chenw6edb5472015-01-08 14:04:39 -0800102 } else if (FLAGS_test_case == "server_streaming") {
Yang Gaoa4002072015-04-09 23:25:21 -0700103 client.DoResponseStreaming();
David Garcia Quintascd37d582015-08-09 15:50:21 -0700104 } else if (FLAGS_test_case == "server_compressed_streaming") {
105 client.DoResponseCompressedStreaming();
chenw6edb5472015-01-08 14:04:39 -0800106 } else if (FLAGS_test_case == "slow_consumer") {
Yang Gaoa4002072015-04-09 23:25:21 -0700107 client.DoResponseStreamingWithSlowConsumer();
chenw6edb5472015-01-08 14:04:39 -0800108 } else if (FLAGS_test_case == "half_duplex") {
Yang Gaoa4002072015-04-09 23:25:21 -0700109 client.DoHalfDuplex();
chenw6edb5472015-01-08 14:04:39 -0800110 } else if (FLAGS_test_case == "ping_pong") {
Yang Gaoa4002072015-04-09 23:25:21 -0700111 client.DoPingPong();
Yang Gao68d61572015-04-24 14:42:42 -0700112 } 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-g69563b92015-07-10 15:32:11 -0700116 } else if (FLAGS_test_case == "timeout_on_sleeping_server") {
117 client.DoTimeoutOnSleepingServer();
yang-g78bddc62015-09-21 10:32:17 -0700118 } else if (FLAGS_test_case == "empty_stream") {
119 client.DoEmptyStream();
Yang Gaobd18be22015-01-27 14:29:19 -0800120 } else if (FLAGS_test_case == "compute_engine_creds") {
Yang Gaoa4002072015-04-09 23:25:21 -0700121 client.DoComputeEngineCreds(FLAGS_default_service_account,
122 FLAGS_oauth_scope);
Yang Gao25770b02015-02-27 15:30:58 -0800123 } else if (FLAGS_test_case == "jwt_token_creds") {
Yang Gaoa4002072015-04-09 23:25:21 -0700124 grpc::string json_key = GetServiceAccountJsonKey();
125 client.DoJwtTokenCreds(json_key);
yang-gbe5f0592015-07-13 11:11:50 -0700126 } else if (FLAGS_test_case == "oauth2_auth_token") {
yang-g867d0c12015-09-02 14:33:15 -0700127 client.DoOauth2AuthToken(FLAGS_default_service_account, FLAGS_oauth_scope);
yang-g5bf510b2015-07-14 10:54:29 -0700128 } else if (FLAGS_test_case == "per_rpc_creds") {
129 grpc::string json_key = GetServiceAccountJsonKey();
yang-g867d0c12015-09-02 14:33:15 -0700130 client.DoPerRpcCreds(json_key);
Abhishek Kumare1c867d2015-08-05 11:04:45 -0700131 } else if (FLAGS_test_case == "status_code_and_message") {
132 client.DoStatusWithMessage();
yang-gc10348a2016-02-19 16:05:10 -0800133 } else if (FLAGS_test_case == "custom_metadata") {
134 client.DoCustomMetadata();
chenw6edb5472015-01-08 14:04:39 -0800135 } else if (FLAGS_test_case == "all") {
Yang Gaoa4002072015-04-09 23:25:21 -0700136 client.DoEmpty();
137 client.DoLargeUnary();
138 client.DoRequestStreaming();
139 client.DoResponseStreaming();
David Garcia Quintascd37d582015-08-09 15:50:21 -0700140 client.DoResponseCompressedStreaming();
Yang Gaoa4002072015-04-09 23:25:21 -0700141 client.DoHalfDuplex();
142 client.DoPingPong();
Yang Gao68d61572015-04-24 14:42:42 -0700143 client.DoCancelAfterBegin();
144 client.DoCancelAfterFirstResponse();
yang-g69563b92015-07-10 15:32:11 -0700145 client.DoTimeoutOnSleepingServer();
yang-g78bddc62015-09-21 10:32:17 -0700146 client.DoEmptyStream();
Abhishek Kumare1c867d2015-08-05 11:04:45 -0700147 client.DoStatusWithMessage();
yang-gc10348a2016-02-19 16:05:10 -0800148 client.DoCustomMetadata();
Yang Gao25770b02015-02-27 15:30:58 -0800149 // service_account_creds and jwt_token_creds can only run with ssl.
yang-g035cf092015-09-18 12:11:05 -0700150 if (FLAGS_use_tls) {
Yang Gaoa4002072015-04-09 23:25:21 -0700151 grpc::string json_key = GetServiceAccountJsonKey();
Yang Gaoa4002072015-04-09 23:25:21 -0700152 client.DoJwtTokenCreds(json_key);
Craig Tiller71a0f9d2015-09-28 17:22:01 -0700153 client.DoOauth2AuthToken(FLAGS_default_service_account,
154 FLAGS_oauth_scope);
yang-g867d0c12015-09-02 14:33:15 -0700155 client.DoPerRpcCreds(json_key);
Yang Gao3bc377c2015-01-26 10:55:25 -0800156 }
Yang Gaobd18be22015-01-27 14:29:19 -0800157 // compute_engine_creds only runs in GCE.
chenwa8fd44a2014-12-10 15:13:55 -0800158 } else {
159 gpr_log(
160 GPR_ERROR,
161 "Unsupported test case %s. Valid options are all|empty_unary|"
David Garcia Quintascd37d582015-08-09 15:50:21 -0700162 "large_unary|large_compressed_unary|client_streaming|server_streaming|"
163 "server_compressed_streaming|half_duplex|ping_pong|cancel_after_begin|"
yang-g78bddc62015-09-21 10:32:17 -0700164 "cancel_after_first_response|timeout_on_sleeping_server|empty_stream|"
Julien Boeuf421738b2015-08-27 16:34:44 -0700165 "compute_engine_creds|jwt_token_creds|oauth2_auth_token|per_rpc_creds",
yang-gc10348a2016-02-19 16:05:10 -0800166 "status_code_and_message|custom_metadata", FLAGS_test_case.c_str());
Yang Gaoeaccf902015-04-15 14:05:07 -0700167 ret = 1;
chenwa8fd44a2014-12-10 15:13:55 -0800168 }
169
Yang Gaoeaccf902015-04-15 14:05:07 -0700170 return ret;
Craig Tiller190d3602015-02-18 09:23:38 -0800171}