blob: 072968f7cdc6a6572ae37a838de0f7363b44aafa [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>
chenwa8fd44a2014-12-10 15:13:55 -080041#include <grpc++/channel_interface.h>
42#include <grpc++/client_context.h>
chenwa8fd44a2014-12-10 15:13:55 -080043#include <grpc++/status.h>
44#include <grpc++/stream.h>
Yang Gaoa4002072015-04-09 23:25:21 -070045#include "test/cpp/interop/client_helper.h"
46#include "test/cpp/interop/interop_client.h"
Yang Gao103837e2015-04-15 15:23:54 -070047#include "test/cpp/util/test_config.h"
chenwa8fd44a2014-12-10 15:13:55 -080048
49DEFINE_bool(enable_ssl, false, "Whether to use ssl/tls.");
Yang Gaoc38dda42015-01-26 00:09:23 -080050DEFINE_bool(use_prod_roots, false, "True to use SSL roots for google");
chenwa8fd44a2014-12-10 15:13:55 -080051DEFINE_int32(server_port, 0, "Server port.");
chenwebb4e6d2014-12-22 14:41:55 -080052DEFINE_string(server_host, "127.0.0.1", "Server host to connect to");
Julien Boeuf597a4f22015-02-23 15:57:14 -080053DEFINE_string(server_host_override, "foo.test.google.fr",
chenwebb4e6d2014-12-22 14:41:55 -080054 "Override the server host which is sent in HTTP header");
chenwa8fd44a2014-12-10 15:13:55 -080055DEFINE_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 Gaoc38dda42015-01-26 00:09:23 -080061 "slow_consumer : single request with response; "
chenw69ca59f2014-12-16 14:20:44 -080062 " streaming with slow client consumer; "
Yang Gaoc38dda42015-01-26 00:09:23 -080063 "half_duplex : half-duplex streaming; "
64 "ping_pong : full-duplex streaming; "
65 "service_account_creds : large_unary with service_account auth; "
Yang Gaobd18be22015-01-27 14:29:19 -080066 "compute_engine_creds: large_unary with compute engine auth; "
Yang Gao25770b02015-02-27 15:30:58 -080067 "jwt_token_creds: large_unary with JWT token auth; "
chenwa8fd44a2014-12-10 15:13:55 -080068 "all : all of above.");
Yang Gaoaec1d0b2015-01-27 15:02:14 -080069DEFINE_string(default_service_account, "",
Yang Gaobd18be22015-01-27 14:29:19 -080070 "Email of GCE default service account");
Yang Gaoc38dda42015-01-26 00:09:23 -080071DEFINE_string(service_account_key_file, "",
72 "Path to service account json key file.");
73DEFINE_string(oauth_scope, "", "Scope for OAuth tokens.");
chenwa8fd44a2014-12-10 15:13:55 -080074
Yang Gaoa4002072015-04-09 23:25:21 -070075using grpc::testing::CreateChannelForTestCase;
76using grpc::testing::GetServiceAccountJsonKey;
chenwa8fd44a2014-12-10 15:13:55 -080077
chenwa8fd44a2014-12-10 15:13:55 -080078int main(int argc, char** argv) {
Yang Gao103837e2015-04-15 15:23:54 -070079 grpc::testing::InitTest(&argc, &argv, true);
chenwa8fd44a2014-12-10 15:13:55 -080080
Yang Gaoeaccf902015-04-15 14:05:07 -070081 int ret = 0;
Yang Gaoa4002072015-04-09 23:25:21 -070082 grpc::testing::InteropClient client(
83 CreateChannelForTestCase(FLAGS_test_case));
chenwa8fd44a2014-12-10 15:13:55 -080084 if (FLAGS_test_case == "empty_unary") {
Yang Gaoa4002072015-04-09 23:25:21 -070085 client.DoEmpty();
chenwa8fd44a2014-12-10 15:13:55 -080086 } else if (FLAGS_test_case == "large_unary") {
Yang Gaoa4002072015-04-09 23:25:21 -070087 client.DoLargeUnary();
chenw6edb5472015-01-08 14:04:39 -080088 } else if (FLAGS_test_case == "client_streaming") {
Yang Gaoa4002072015-04-09 23:25:21 -070089 client.DoRequestStreaming();
chenw6edb5472015-01-08 14:04:39 -080090 } else if (FLAGS_test_case == "server_streaming") {
Yang Gaoa4002072015-04-09 23:25:21 -070091 client.DoResponseStreaming();
chenw6edb5472015-01-08 14:04:39 -080092 } else if (FLAGS_test_case == "slow_consumer") {
Yang Gaoa4002072015-04-09 23:25:21 -070093 client.DoResponseStreamingWithSlowConsumer();
chenw6edb5472015-01-08 14:04:39 -080094 } else if (FLAGS_test_case == "half_duplex") {
Yang Gaoa4002072015-04-09 23:25:21 -070095 client.DoHalfDuplex();
chenw6edb5472015-01-08 14:04:39 -080096 } else if (FLAGS_test_case == "ping_pong") {
Yang Gaoa4002072015-04-09 23:25:21 -070097 client.DoPingPong();
Yang Gaoc38dda42015-01-26 00:09:23 -080098 } else if (FLAGS_test_case == "service_account_creds") {
Yang Gaoa4002072015-04-09 23:25:21 -070099 grpc::string json_key = GetServiceAccountJsonKey();
100 client.DoServiceAccountCreds(json_key, FLAGS_oauth_scope);
Yang Gaobd18be22015-01-27 14:29:19 -0800101 } else if (FLAGS_test_case == "compute_engine_creds") {
Yang Gaoa4002072015-04-09 23:25:21 -0700102 client.DoComputeEngineCreds(FLAGS_default_service_account,
103 FLAGS_oauth_scope);
Yang Gao25770b02015-02-27 15:30:58 -0800104 } else if (FLAGS_test_case == "jwt_token_creds") {
Yang Gaoa4002072015-04-09 23:25:21 -0700105 grpc::string json_key = GetServiceAccountJsonKey();
106 client.DoJwtTokenCreds(json_key);
chenw6edb5472015-01-08 14:04:39 -0800107 } else if (FLAGS_test_case == "all") {
Yang Gaoa4002072015-04-09 23:25:21 -0700108 client.DoEmpty();
109 client.DoLargeUnary();
110 client.DoRequestStreaming();
111 client.DoResponseStreaming();
112 client.DoHalfDuplex();
113 client.DoPingPong();
Yang Gao25770b02015-02-27 15:30:58 -0800114 // service_account_creds and jwt_token_creds can only run with ssl.
Yang Gao3bc377c2015-01-26 10:55:25 -0800115 if (FLAGS_enable_ssl) {
Yang Gaoa4002072015-04-09 23:25:21 -0700116 grpc::string json_key = GetServiceAccountJsonKey();
117 client.DoServiceAccountCreds(json_key, FLAGS_oauth_scope);
118 client.DoJwtTokenCreds(json_key);
Yang Gao3bc377c2015-01-26 10:55:25 -0800119 }
Yang Gaobd18be22015-01-27 14:29:19 -0800120 // compute_engine_creds only runs in GCE.
chenwa8fd44a2014-12-10 15:13:55 -0800121 } else {
122 gpr_log(
123 GPR_ERROR,
124 "Unsupported test case %s. Valid options are all|empty_unary|"
Yang Gao3bc377c2015-01-26 10:55:25 -0800125 "large_unary|client_streaming|server_streaming|half_duplex|ping_pong|"
Yang Gao25770b02015-02-27 15:30:58 -0800126 "service_account_creds|compute_engine_creds|jwt_token_creds",
chenwa8fd44a2014-12-10 15:13:55 -0800127 FLAGS_test_case.c_str());
Yang Gaoeaccf902015-04-15 14:05:07 -0700128 ret = 1;
chenwa8fd44a2014-12-10 15:13:55 -0800129 }
130
Yang Gaoeaccf902015-04-15 14:05:07 -0700131 return ret;
Craig Tiller190d3602015-02-18 09:23:38 -0800132}