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/connected_channel.h" 31 #include "src/core/lib/gpr/host_port.h" 32 #include "src/core/lib/surface/channel.h" 33 #include "src/core/lib/surface/server.h" 34 #include "test/core/end2end/fixtures/proxy.h" 35 #include "test/core/util/port.h" 36 #include "test/core/util/test_config.h" 37 38 typedef struct fullstack_fixture_data { 39 grpc_end2end_proxy* proxy; 40 } fullstack_fixture_data; 41 42 static grpc_server* create_proxy_server(const char* port, 43 grpc_channel_args* server_args) { 44 grpc_server* s = grpc_server_create(server_args, nullptr); 45 GPR_ASSERT(grpc_server_add_insecure_http2_port(s, port)); 46 return s; 47 } 48 49 static grpc_channel* create_proxy_client(const char* target, 50 grpc_channel_args* client_args) { 51 // Disable retries in proxy client. 52 grpc_arg arg; 53 arg.type = GRPC_ARG_INTEGER; 54 arg.key = const_cast<char*>(GRPC_ARG_ENABLE_RETRIES); 55 arg.value.integer = 0; 56 grpc_channel_args* new_args = 57 grpc_channel_args_copy_and_add(client_args, &arg, 1); 58 grpc_channel* channel = 59 grpc_insecure_channel_create(target, new_args, nullptr); 60 grpc_channel_args_destroy(new_args); 61 return channel; 62 } 63 64 static const grpc_end2end_proxy_def proxy_def = {create_proxy_server, 65 create_proxy_client}; 66 67 static grpc_end2end_test_fixture chttp2_create_fixture_fullstack( 68 grpc_channel_args* client_args, grpc_channel_args* server_args) { 69 grpc_end2end_test_fixture f; 70 fullstack_fixture_data* ffd = static_cast<fullstack_fixture_data*>( 71 gpr_malloc(sizeof(fullstack_fixture_data))); 72 memset(&f, 0, sizeof(f)); 73 74 ffd->proxy = grpc_end2end_proxy_create(&proxy_def, client_args, server_args); 75 76 f.fixture_data = ffd; 77 f.cq = grpc_completion_queue_create_for_next(nullptr); 78 f.shutdown_cq = grpc_completion_queue_create_for_pluck(nullptr); 79 80 return f; 81 } 82 83 void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f, 84 grpc_channel_args* client_args) { 85 fullstack_fixture_data* ffd = 86 static_cast<fullstack_fixture_data*>(f->fixture_data); 87 f->client = grpc_insecure_channel_create( 88 grpc_end2end_proxy_get_client_target(ffd->proxy), client_args, nullptr); 89 GPR_ASSERT(f->client); 90 } 91 92 void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f, 93 grpc_channel_args* server_args) { 94 fullstack_fixture_data* ffd = 95 static_cast<fullstack_fixture_data*>(f->fixture_data); 96 if (f->server) { 97 grpc_server_destroy(f->server); 98 } 99 f->server = grpc_server_create(server_args, nullptr); 100 grpc_server_register_completion_queue(f->server, f->cq, nullptr); 101 GPR_ASSERT(grpc_server_add_insecure_http2_port( 102 f->server, grpc_end2end_proxy_get_server_port(ffd->proxy))); 103 grpc_server_start(f->server); 104 } 105 106 void chttp2_tear_down_fullstack(grpc_end2end_test_fixture* f) { 107 fullstack_fixture_data* ffd = 108 static_cast<fullstack_fixture_data*>(f->fixture_data); 109 grpc_end2end_proxy_destroy(ffd->proxy); 110 gpr_free(ffd); 111 } 112 113 /* All test configurations */ 114 static grpc_end2end_test_config configs[] = { 115 {"chttp2/fullstack+proxy", 116 FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION | 117 FEATURE_MASK_SUPPORTS_REQUEST_PROXYING | 118 FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL | 119 FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER, 120 nullptr, chttp2_create_fixture_fullstack, chttp2_init_client_fullstack, 121 chttp2_init_server_fullstack, chttp2_tear_down_fullstack}, 122 }; 123 124 int main(int argc, char** argv) { 125 size_t i; 126 127 grpc_test_init(argc, argv); 128 grpc_end2end_tests_pre_init(); 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 } 139