Debian Codegraph @

test/core/end2end/fixtures/h2_proxy.cc

raw
1 /*
2 *
3 * Copyright 2015 gRPC authors.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 */
18
19 #include <string.h>
20
21 #include <grpc/grpc.h>
22 #include <grpc/grpc_security.h>
23 #include <grpc/support/alloc.h>
24 #include <grpc/support/log.h>
25
26 #include "test/core/end2end/end2end_tests.h"
27 #include "test/core/end2end/fixtures/proxy.h"
28 #include "test/core/util/test_config.h"
29
30 typedef struct fullstack_fixture_data {
31 grpc_end2end_proxy* proxy;
32 } fullstack_fixture_data;
33
34 static grpc_server* create_proxy_server(const char* port,
35 const grpc_channel_args* server_args) {
36 grpc_server* s = grpc_server_create(server_args, nullptr);
37 grpc_server_credentials* server_creds =
38 grpc_insecure_server_credentials_create();
39 GPR_ASSERT(grpc_server_add_http2_port(s, port, server_creds));
40 grpc_server_credentials_release(server_creds);
41 return s;
42 }
43
44 static grpc_channel* create_proxy_client(const char* target,
45 const grpc_channel_args* client_args) {
46 grpc_channel_credentials* creds = grpc_insecure_credentials_create();
47 grpc_channel* channel = grpc_channel_create(target, creds, client_args);
48 grpc_channel_credentials_release(creds);
49 return channel;
50 }
51
52 static const grpc_end2end_proxy_def proxy_def = {create_proxy_server,
53 create_proxy_client};
54
55 static grpc_end2end_test_fixture chttp2_create_fixture_fullstack(
56 const grpc_channel_args* client_args,
57 const grpc_channel_args* server_args) {
58 grpc_end2end_test_fixture f;
59 fullstack_fixture_data* ffd = static_cast<fullstack_fixture_data*>(
60 gpr_malloc(sizeof(fullstack_fixture_data)));
61 memset(&f, 0, sizeof(f));
62
63 ffd->proxy = grpc_end2end_proxy_create(&proxy_def, client_args, server_args);
64
65 f.fixture_data = ffd;
66 f.cq = grpc_completion_queue_create_for_next(nullptr);
67
68 return f;
69 }
70
71 void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f,
72 const grpc_channel_args* client_args) {
73 fullstack_fixture_data* ffd =
74 static_cast<fullstack_fixture_data*>(f->fixture_data);
75 grpc_channel_credentials* creds = grpc_insecure_credentials_create();
76 f->client = grpc_channel_create(
77 grpc_end2end_proxy_get_client_target(ffd->proxy), creds, client_args);
78 grpc_channel_credentials_release(creds);
79 GPR_ASSERT(f->client);
80 }
81
82 void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f,
83 const grpc_channel_args* server_args) {
84 fullstack_fixture_data* ffd =
85 static_cast<fullstack_fixture_data*>(f->fixture_data);
86 if (f->server) {
87 grpc_server_destroy(f->server);
88 }
89 f->server = grpc_server_create(server_args, nullptr);
90 grpc_server_register_completion_queue(f->server, f->cq, nullptr);
91 grpc_server_credentials* server_creds =
92 grpc_insecure_server_credentials_create();
93 GPR_ASSERT(grpc_server_add_http2_port(
94 f->server, grpc_end2end_proxy_get_server_port(ffd->proxy), server_creds));
95 grpc_server_credentials_release(server_creds);
96 grpc_server_start(f->server);
97 }
98
99 void chttp2_tear_down_fullstack(grpc_end2end_test_fixture* f) {
100 fullstack_fixture_data* ffd =
101 static_cast<fullstack_fixture_data*>(f->fixture_data);
102 grpc_end2end_proxy_destroy(ffd->proxy);
103 gpr_free(ffd);
104 }
105
106 /* All test configurations */
107 static grpc_end2end_test_config configs[] = {
108 {"chttp2/fullstack+proxy",
109 FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION |
110 FEATURE_MASK_SUPPORTS_REQUEST_PROXYING |
111 FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL |
112 FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER,
113 nullptr, chttp2_create_fixture_fullstack, chttp2_init_client_fullstack,
114 chttp2_init_server_fullstack, chttp2_tear_down_fullstack},
115 };
116
117 int main(int argc, char** argv) {
118 size_t i;
119
120 grpc::testing::TestEnvironment env(&argc, argv);
121 grpc_end2end_tests_pre_init();
122 grpc_init();
123
124 for (i = 0; i < sizeof(configs) / sizeof(*configs); i++) {
125 grpc_end2end_tests(argc, argv, configs[i]);
126 }
127
128 grpc_shutdown();
129
130 return 0;
131 }