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