Debian Codegraph @

test/core/end2end/fixtures/h2_compress.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 <string>
22
23 #include <grpc/compression.h>
24 #include <grpc/grpc.h>
25 #include <grpc/grpc_security.h>
26 #include <grpc/support/log.h>
27
28 #include "src/core/lib/channel/channel_args.h"
29 #include "src/core/lib/gprpp/host_port.h"
30 #include "src/core/lib/iomgr/exec_ctx.h"
31 #include "test/core/compression/args_utils.h"
32 #include "test/core/end2end/end2end_tests.h"
33 #include "test/core/util/port.h"
34 #include "test/core/util/test_config.h"
35
36 struct fullstack_compression_fixture_data {
37 ~fullstack_compression_fixture_data() {
38 grpc_channel_args_destroy(client_args_compression);
39 grpc_channel_args_destroy(server_args_compression);
40 }
41 std::string localaddr;
42 const grpc_channel_args* client_args_compression = nullptr;
43 const grpc_channel_args* server_args_compression = nullptr;
44 };
45
46 static grpc_end2end_test_fixture chttp2_create_fixture_fullstack_compression(
47 const grpc_channel_args* /*client_args*/,
48 const grpc_channel_args* /*server_args*/) {
49 grpc_end2end_test_fixture f;
50 int port = grpc_pick_unused_port_or_die();
51 fullstack_compression_fixture_data* ffd =
52 new fullstack_compression_fixture_data();
53 ffd->localaddr = grpc_core::JoinHostPort("localhost", port);
54
55 memset(&f, 0, sizeof(f));
56 f.fixture_data = ffd;
57 f.cq = grpc_completion_queue_create_for_next(nullptr);
58
59 return f;
60 }
61
62 void chttp2_init_client_fullstack_compression(
63 grpc_end2end_test_fixture* f, const grpc_channel_args* client_args) {
64 fullstack_compression_fixture_data* ffd =
65 static_cast<fullstack_compression_fixture_data*>(f->fixture_data);
66 if (ffd->client_args_compression != nullptr) {
67 grpc_core::ExecCtx exec_ctx;
68 grpc_channel_args_destroy(ffd->client_args_compression);
69 }
70 ffd->client_args_compression =
71 grpc_channel_args_set_channel_default_compression_algorithm(
72 client_args, GRPC_COMPRESS_GZIP);
73 grpc_channel_credentials* creds = grpc_insecure_credentials_create();
74 f->client = grpc_channel_create(ffd->localaddr.c_str(), creds,
75 ffd->client_args_compression);
76 grpc_channel_credentials_release(creds);
77 }
78
79 void chttp2_init_server_fullstack_compression(
80 grpc_end2end_test_fixture* f, const grpc_channel_args* server_args) {
81 fullstack_compression_fixture_data* ffd =
82 static_cast<fullstack_compression_fixture_data*>(f->fixture_data);
83 if (ffd->server_args_compression != nullptr) {
84 grpc_core::ExecCtx exec_ctx;
85 grpc_channel_args_destroy(ffd->server_args_compression);
86 }
87 ffd->server_args_compression =
88 grpc_channel_args_set_channel_default_compression_algorithm(
89 server_args, GRPC_COMPRESS_GZIP);
90 if (f->server) {
91 grpc_server_destroy(f->server);
92 }
93 f->server = grpc_server_create(ffd->server_args_compression, nullptr);
94 grpc_server_register_completion_queue(f->server, f->cq, nullptr);
95 grpc_server_credentials* server_creds =
96 grpc_insecure_server_credentials_create();
97 GPR_ASSERT(grpc_server_add_http2_port(f->server, ffd->localaddr.c_str(),
98 server_creds));
99 grpc_server_credentials_release(server_creds);
100 grpc_server_start(f->server);
101 }
102
103 void chttp2_tear_down_fullstack_compression(grpc_end2end_test_fixture* f) {
104 grpc_core::ExecCtx exec_ctx;
105 fullstack_compression_fixture_data* ffd =
106 static_cast<fullstack_compression_fixture_data*>(f->fixture_data);
107 delete ffd;
108 }
109
110 /* All test configurations */
111 static grpc_end2end_test_config configs[] = {
112 {"chttp2/fullstack_compression",
113 FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION |
114 FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL |
115 FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER,
116 nullptr, chttp2_create_fixture_fullstack_compression,
117 chttp2_init_client_fullstack_compression,
118 chttp2_init_server_fullstack_compression,
119 chttp2_tear_down_fullstack_compression},
120 };
121
122 int main(int argc, char** argv) {
123 size_t i;
124
125 grpc::testing::TestEnvironment env(&argc, argv);
126 grpc_end2end_tests_pre_init();
127 grpc_init();
128
129 for (i = 0; i < sizeof(configs) / sizeof(*configs); i++) {
130 grpc_end2end_tests(argc, argv, configs[i]);
131 }
132
133 grpc_shutdown();
134
135 return 0;
136 }