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/gpr/host_port.h" 33 #include "src/core/lib/surface/channel.h" 34 #include "src/core/lib/surface/server.h" 35 #include "test/core/util/port.h" 36 #include "test/core/util/test_config.h" 37 38 typedef struct fullstack_compression_fixture_data { 39 char* localaddr; 40 grpc_channel_args* client_args_compression; 41 grpc_channel_args* server_args_compression; 42 } fullstack_compression_fixture_data; 43 44 static grpc_end2end_test_fixture chttp2_create_fixture_fullstack_compression( 45 grpc_channel_args* client_args, grpc_channel_args* server_args) { 46 grpc_end2end_test_fixture f; 47 int port = grpc_pick_unused_port_or_die(); 48 fullstack_compression_fixture_data* ffd = 49 static_cast<fullstack_compression_fixture_data*>( 50 gpr_malloc(sizeof(fullstack_compression_fixture_data))); 51 memset(ffd, 0, sizeof(fullstack_compression_fixture_data)); 52 53 gpr_join_host_port(&ffd->localaddr, "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 f.shutdown_cq = grpc_completion_queue_create_for_pluck(nullptr); 59 60 return f; 61 } 62 63 void chttp2_init_client_fullstack_compression(grpc_end2end_test_fixture* f, 64 grpc_channel_args* client_args) { 65 fullstack_compression_fixture_data* ffd = 66 static_cast<fullstack_compression_fixture_data*>(f->fixture_data); 67 if (ffd->client_args_compression != nullptr) { 68 grpc_core::ExecCtx exec_ctx; 69 grpc_channel_args_destroy(ffd->client_args_compression); 70 } 71 ffd->client_args_compression = grpc_channel_args_set_compression_algorithm( 72 client_args, GRPC_COMPRESS_GZIP); 73 f->client = grpc_insecure_channel_create( 74 ffd->localaddr, ffd->client_args_compression, nullptr); 75 } 76 77 void chttp2_init_server_fullstack_compression(grpc_end2end_test_fixture* f, 78 grpc_channel_args* server_args) { 79 fullstack_compression_fixture_data* ffd = 80 static_cast<fullstack_compression_fixture_data*>(f->fixture_data); 81 if (ffd->server_args_compression != nullptr) { 82 grpc_core::ExecCtx exec_ctx; 83 grpc_channel_args_destroy(ffd->server_args_compression); 84 } 85 ffd->server_args_compression = grpc_channel_args_set_compression_algorithm( 86 server_args, GRPC_COMPRESS_GZIP); 87 if (f->server) { 88 grpc_server_destroy(f->server); 89 } 90 f->server = grpc_server_create(ffd->server_args_compression, nullptr); 91 grpc_server_register_completion_queue(f->server, f->cq, nullptr); 92 GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr)); 93 grpc_server_start(f->server); 94 } 95 96 void chttp2_tear_down_fullstack_compression(grpc_end2end_test_fixture* f) { 97 grpc_core::ExecCtx exec_ctx; 98 fullstack_compression_fixture_data* ffd = 99 static_cast<fullstack_compression_fixture_data*>(f->fixture_data); 100 grpc_channel_args_destroy(ffd->client_args_compression); 101 grpc_channel_args_destroy(ffd->server_args_compression); 102 gpr_free(ffd->localaddr); 103 gpr_free(ffd); 104 } 105 106 /* All test configurations */ 107 static grpc_end2end_test_config configs[] = { 108 {"chttp2/fullstack_compression", 109 FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION | 110 FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL | 111 FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER, 112 nullptr, chttp2_create_fixture_fullstack_compression, 113 chttp2_init_client_fullstack_compression, 114 chttp2_init_server_fullstack_compression, 115 chttp2_tear_down_fullstack_compression}, 116 }; 117 118 int main(int argc, char** argv) { 119 size_t i; 120 121 grpc_test_init(argc, argv); 122 grpc_end2end_tests_pre_init(); 123 grpc_init(); 124 125 for (i = 0; i < sizeof(configs) / sizeof(*configs); i++) { 126 grpc_end2end_tests(argc, argv, configs[i]); 127 } 128 129 grpc_shutdown(); 130 131 return 0; 132 } 133