h2_proxy.cc
Go to the documentation of this file.
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_security.h>
22 #include <grpc/support/alloc.h>
23 #include <grpc/support/log.h>
24 #include <grpc/support/sync.h>
25 
34 #include "test/core/util/port.h"
36 
37 typedef struct fullstack_fixture_data {
40 
41 static grpc_server* create_proxy_server(const char* port,
42  const grpc_channel_args* server_args) {
43  grpc_server* s = grpc_server_create(server_args, nullptr);
44  grpc_server_credentials* server_creds =
46  GPR_ASSERT(grpc_server_add_http2_port(s, port, server_creds));
47  grpc_server_credentials_release(server_creds);
48  return s;
49 }
50 
52  const grpc_channel_args* client_args) {
54  grpc_channel* channel = grpc_channel_create(target, creds, client_args);
56  return channel;
57 }
58 
61 
63  const grpc_channel_args* client_args,
64  const grpc_channel_args* server_args) {
68  memset(&f, 0, sizeof(f));
69 
70  ffd->proxy = grpc_end2end_proxy_create(&proxy_def, client_args, server_args);
71 
72  f.fixture_data = ffd;
74 
75  return f;
76 }
77 
79  const grpc_channel_args* client_args) {
81  static_cast<fullstack_fixture_data*>(f->fixture_data);
83  f->client = grpc_channel_create(
84  grpc_end2end_proxy_get_client_target(ffd->proxy), creds, client_args);
86  GPR_ASSERT(f->client);
87 }
88 
90  const grpc_channel_args* server_args) {
92  static_cast<fullstack_fixture_data*>(f->fixture_data);
93  if (f->server) {
94  grpc_server_destroy(f->server);
95  }
96  f->server = grpc_server_create(server_args, nullptr);
97  grpc_server_register_completion_queue(f->server, f->cq, nullptr);
98  grpc_server_credentials* server_creds =
101  f->server, grpc_end2end_proxy_get_server_port(ffd->proxy), server_creds));
102  grpc_server_credentials_release(server_creds);
103  grpc_server_start(f->server);
104 }
105 
108  static_cast<fullstack_fixture_data*>(f->fixture_data);
110  gpr_free(ffd);
111 }
112 
113 /* All test configurations */
115  {"chttp2/fullstack+proxy",
122 };
123 
124 int main(int argc, char** argv) {
125  size_t i;
126 
127  grpc::testing::TestEnvironment env(&argc, argv);
129  grpc_init();
130 
131  for (i = 0; i < sizeof(configs) / sizeof(*configs); i++) {
132  grpc_end2end_tests(argc, argv, configs[i]);
133  }
134 
135  grpc_shutdown();
136 
137  return 0;
138 }
proxy_def
static const grpc_end2end_proxy_def proxy_def
Definition: h2_proxy.cc:59
FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER
#define FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER
Definition: end2end_tests.h:38
log.h
port.h
generate.env
env
Definition: generate.py:37
memset
return memset(p, 0, total)
grpc_end2end_tests_pre_init
void grpc_end2end_tests_pre_init(void)
Definition: end2end_tests.cc:221
chttp2_create_fixture_fullstack
static grpc_end2end_test_fixture chttp2_create_fixture_fullstack(const grpc_channel_args *client_args, const grpc_channel_args *server_args)
Definition: h2_proxy.cc:62
grpc_end2end_proxy_def
Definition: proxy.h:28
string.h
fullstack_fixture_data
struct fullstack_fixture_data fullstack_fixture_data
gpr_free
GPRAPI void gpr_free(void *ptr)
Definition: alloc.cc:51
client_channel.h
grpc_server_create
GRPCAPI grpc_server * grpc_server_create(const grpc_channel_args *args, void *reserved)
Definition: src/core/lib/surface/server.cc:1456
gpr_malloc
GPRAPI void * gpr_malloc(size_t size)
Definition: alloc.cc:29
grpc_server_register_completion_queue
GRPCAPI void grpc_server_register_completion_queue(grpc_server *server, grpc_completion_queue *cq, void *reserved)
Definition: src/core/lib/surface/server.cc:1466
grpc_security.h
grpc_end2end_test_config
Definition: end2end_tests.h:53
grpc_end2end_proxy_get_server_port
const char * grpc_end2end_proxy_get_server_port(grpc_end2end_proxy *proxy)
Definition: proxy.cc:466
grpc_channel_args
Definition: grpc_types.h:132
grpc_end2end_test_fixture
Definition: end2end_tests.h:46
grpc_insecure_server_credentials_create
GRPCAPI grpc_server_credentials * grpc_insecure_server_credentials_create()
Definition: core/lib/security/credentials/insecure/insecure_credentials.cc:71
FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION
#define FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION
Definition: end2end_tests.h:28
grpc_end2end_proxy_create
grpc_end2end_proxy * grpc_end2end_proxy_create(const grpc_end2end_proxy_def *def, const grpc_channel_args *client_args, const grpc_channel_args *server_args)
Definition: proxy.cc:87
fullstack_fixture_data::proxy
grpc_end2end_http_proxy * proxy
Definition: h2_http_proxy.cc:46
channel
wrapped_grpc_channel * channel
Definition: src/php/ext/grpc/call.h:33
autogen_x86imm.f
f
Definition: autogen_x86imm.py:9
GPR_ASSERT
#define GPR_ASSERT(x)
Definition: include/grpc/impl/codegen/log.h:94
grpc_server_credentials_release
GRPCAPI void grpc_server_credentials_release(grpc_server_credentials *creds)
Definition: credentials.cc:95
FEATURE_MASK_SUPPORTS_REQUEST_PROXYING
#define FEATURE_MASK_SUPPORTS_REQUEST_PROXYING
Definition: end2end_tests.h:36
grpc_server_add_http2_port
GRPCAPI int grpc_server_add_http2_port(grpc_server *server, const char *addr, grpc_server_credentials *creds)
Definition: chttp2_server.cc:1029
chttp2_tear_down_fullstack
void chttp2_tear_down_fullstack(grpc_end2end_test_fixture *f)
Definition: h2_proxy.cc:106
grpc_insecure_credentials_create
GRPCAPI grpc_channel_credentials * grpc_insecure_credentials_create()
Definition: core/lib/security/credentials/insecure/insecure_credentials.cc:64
configs
static grpc_end2end_test_config configs[]
Definition: h2_proxy.cc:114
grpc_server
struct grpc_server grpc_server
Definition: grpc_types.h:65
grpc_server_destroy
GRPCAPI void grpc_server_destroy(grpc_server *server)
Definition: src/core/lib/surface/server.cc:1519
create_proxy_server
static grpc_server * create_proxy_server(const char *port, const grpc_channel_args *server_args)
Definition: h2_proxy.cc:41
end2end_tests.h
grpc_end2end_proxy
Definition: proxy.cc:34
tests.unit._exit_scenarios.port
port
Definition: _exit_scenarios.py:179
proxy.h
test_config.h
grpc_channel_credentials_release
GRPCAPI void grpc_channel_credentials_release(grpc_channel_credentials *creds)
Definition: credentials.cc:36
grpc_end2end_tests
void grpc_end2end_tests(int argc, char **argv, grpc_end2end_test_config config)
Definition: end2end_tests.cc:321
grpc_server_credentials
Definition: src/core/lib/security/credentials/credentials.h:259
grpc_channel_create
GRPCAPI grpc_channel * grpc_channel_create(const char *target, grpc_channel_credentials *creds, const grpc_channel_args *args)
Definition: chttp2_connector.cc:366
http_server_filter.h
main
int main(int argc, char **argv)
Definition: h2_proxy.cc:124
alloc.h
grpc::testing::TestEnvironment
Definition: test/core/util/test_config.h:54
chttp2_transport.h
server.h
grpc_channel
struct grpc_channel grpc_channel
Definition: grpc_types.h:62
fullstack_fixture_data::proxy
grpc_end2end_proxy * proxy
Definition: h2_proxy.cc:38
grpc_end2end_proxy_get_client_target
const char * grpc_end2end_proxy_get_client_target(grpc_end2end_proxy *proxy)
Definition: proxy.cc:462
grpc_end2end_proxy_destroy
void grpc_end2end_proxy_destroy(grpc_end2end_proxy *proxy)
Definition: proxy.cc:139
grpc_completion_queue_create_for_next
GRPCAPI grpc_completion_queue * grpc_completion_queue_create_for_next(void *reserved)
Definition: completion_queue_factory.cc:62
connected_channel.h
fullstack_fixture_data
Definition: h2_census.cc:38
grpc_init
GRPCAPI void grpc_init(void)
Definition: init.cc:146
grpc_server_start
GRPCAPI void grpc_server_start(grpc_server *server)
Definition: src/core/lib/surface/server.cc:1497
chttp2_init_server_fullstack
void chttp2_init_server_fullstack(grpc_end2end_test_fixture *f, const grpc_channel_args *server_args)
Definition: h2_proxy.cc:89
sync.h
chttp2_init_client_fullstack
void chttp2_init_client_fullstack(grpc_end2end_test_fixture *f, const grpc_channel_args *client_args)
Definition: h2_proxy.cc:78
grpc_shutdown
GRPCAPI void grpc_shutdown(void)
Definition: init.cc:209
setup.target
target
Definition: third_party/bloaty/third_party/protobuf/python/setup.py:179
grpc_channel_credentials
Definition: src/core/lib/security/credentials/credentials.h:96
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL
#define FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL
Definition: end2end_tests.h:37
create_proxy_client
static grpc_channel * create_proxy_client(const char *target, const grpc_channel_args *client_args)
Definition: h2_proxy.cc:51
channel.h


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:00:10