Line data Source code
1 : /*
2 : *
3 : * Copyright 2015, 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 4 : DEFINE_bool(use_tls, false, "Whether to use tls.");
49 4 : DEFINE_bool(use_test_ca, false, "False to use SSL roots for google");
50 4 : DEFINE_int32(server_port, 0, "Server port.");
51 4 : DEFINE_string(server_host, "127.0.0.1", "Server host to connect to");
52 4 : DEFINE_string(server_host_override, "foo.test.google.fr",
53 : "Override the server host which is sent in HTTP header");
54 4 : 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 : "all : all of above.");
78 4 : DEFINE_string(default_service_account, "",
79 : "Email of GCE default service account");
80 4 : DEFINE_string(service_account_key_file, "",
81 : "Path to service account json key file.");
82 4 : DEFINE_string(oauth_scope, "", "Scope for OAuth tokens.");
83 :
84 : using grpc::testing::CreateChannelForTestCase;
85 : using grpc::testing::GetServiceAccountJsonKey;
86 :
87 4 : int main(int argc, char** argv) {
88 4 : grpc::testing::InitTest(&argc, &argv, true);
89 4 : gpr_log(GPR_INFO, "Testing these cases: %s", FLAGS_test_case.c_str());
90 4 : int ret = 0;
91 : grpc::testing::InteropClient client(
92 4 : CreateChannelForTestCase(FLAGS_test_case));
93 4 : if (FLAGS_test_case == "empty_unary") {
94 0 : client.DoEmpty();
95 4 : } else if (FLAGS_test_case == "large_unary") {
96 4 : client.DoLargeUnary();
97 0 : } else if (FLAGS_test_case == "large_compressed_unary") {
98 0 : client.DoLargeCompressedUnary();
99 0 : } else if (FLAGS_test_case == "client_streaming") {
100 0 : client.DoRequestStreaming();
101 0 : } else if (FLAGS_test_case == "server_streaming") {
102 0 : client.DoResponseStreaming();
103 0 : } else if (FLAGS_test_case == "server_compressed_streaming") {
104 0 : client.DoResponseCompressedStreaming();
105 0 : } else if (FLAGS_test_case == "slow_consumer") {
106 0 : client.DoResponseStreamingWithSlowConsumer();
107 0 : } else if (FLAGS_test_case == "half_duplex") {
108 0 : client.DoHalfDuplex();
109 0 : } else if (FLAGS_test_case == "ping_pong") {
110 0 : client.DoPingPong();
111 0 : } else if (FLAGS_test_case == "cancel_after_begin") {
112 0 : client.DoCancelAfterBegin();
113 0 : } else if (FLAGS_test_case == "cancel_after_first_response") {
114 0 : client.DoCancelAfterFirstResponse();
115 0 : } else if (FLAGS_test_case == "timeout_on_sleeping_server") {
116 0 : client.DoTimeoutOnSleepingServer();
117 0 : } else if (FLAGS_test_case == "empty_stream") {
118 0 : client.DoEmptyStream();
119 0 : } else if (FLAGS_test_case == "compute_engine_creds") {
120 : client.DoComputeEngineCreds(FLAGS_default_service_account,
121 0 : FLAGS_oauth_scope);
122 0 : } else if (FLAGS_test_case == "jwt_token_creds") {
123 0 : grpc::string json_key = GetServiceAccountJsonKey();
124 0 : client.DoJwtTokenCreds(json_key);
125 0 : } else if (FLAGS_test_case == "oauth2_auth_token") {
126 0 : client.DoOauth2AuthToken(FLAGS_default_service_account, FLAGS_oauth_scope);
127 0 : } else if (FLAGS_test_case == "per_rpc_creds") {
128 0 : grpc::string json_key = GetServiceAccountJsonKey();
129 0 : client.DoPerRpcCreds(json_key);
130 0 : } else if (FLAGS_test_case == "status_code_and_message") {
131 0 : client.DoStatusWithMessage();
132 0 : } else if (FLAGS_test_case == "all") {
133 0 : client.DoEmpty();
134 0 : client.DoLargeUnary();
135 0 : client.DoRequestStreaming();
136 0 : client.DoResponseStreaming();
137 0 : client.DoResponseCompressedStreaming();
138 0 : client.DoHalfDuplex();
139 0 : client.DoPingPong();
140 0 : client.DoCancelAfterBegin();
141 0 : client.DoCancelAfterFirstResponse();
142 0 : client.DoTimeoutOnSleepingServer();
143 0 : client.DoEmptyStream();
144 0 : client.DoStatusWithMessage();
145 : // service_account_creds and jwt_token_creds can only run with ssl.
146 0 : if (FLAGS_use_tls) {
147 0 : grpc::string json_key = GetServiceAccountJsonKey();
148 0 : client.DoJwtTokenCreds(json_key);
149 : client.DoOauth2AuthToken(FLAGS_default_service_account,
150 0 : FLAGS_oauth_scope);
151 0 : client.DoPerRpcCreds(json_key);
152 : }
153 : // compute_engine_creds only runs in GCE.
154 : } else {
155 : gpr_log(
156 : GPR_ERROR,
157 : "Unsupported test case %s. Valid options are all|empty_unary|"
158 : "large_unary|large_compressed_unary|client_streaming|server_streaming|"
159 : "server_compressed_streaming|half_duplex|ping_pong|cancel_after_begin|"
160 : "cancel_after_first_response|timeout_on_sleeping_server|empty_stream|"
161 : "compute_engine_creds|jwt_token_creds|oauth2_auth_token|per_rpc_creds",
162 0 : FLAGS_test_case.c_str());
163 0 : ret = 1;
164 : }
165 :
166 4 : return ret;
167 12 : }
|