Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 3 | * Copyright 2015 gRPC authors. |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 4 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 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 |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 8 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 10 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 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. |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 16 | * |
| 17 | */ |
| 18 | |
| 19 | #include "test/core/end2end/end2end_tests.h" |
| 20 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 21 | #include <string.h> |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 22 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 23 | #include <grpc/support/alloc.h> |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 24 | #include <grpc/support/log.h> |
| 25 | #include <grpc/support/sync.h> |
Vijay Pai | d4d0a30 | 2018-01-25 13:24:03 -0800 | [diff] [blame] | 26 | |
Craig Tiller | 9eb0fde | 2017-03-31 16:59:30 -0700 | [diff] [blame] | 27 | #include "src/core/ext/filters/client_channel/client_channel.h" |
Craig Tiller | e3593d9 | 2017-04-03 14:51:02 -0700 | [diff] [blame] | 28 | #include "src/core/ext/filters/http/server/http_server_filter.h" |
Craig Tiller | adcb92d | 2016-03-28 10:14:05 -0700 | [diff] [blame] | 29 | #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" |
Craig Tiller | 9533d04 | 2016-03-25 17:11:06 -0700 | [diff] [blame] | 30 | #include "src/core/lib/channel/connected_channel.h" |
Vijay Pai | ae376bf | 2018-01-25 22:54:02 -0800 | [diff] [blame] | 31 | #include "src/core/lib/gpr/host_port.h" |
Craig Tiller | 9533d04 | 2016-03-25 17:11:06 -0700 | [diff] [blame] | 32 | #include "src/core/lib/surface/channel.h" |
| 33 | #include "src/core/lib/surface/server.h" |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 34 | #include "test/core/util/port.h" |
| 35 | #include "test/core/util/test_config.h" |
| 36 | |
| 37 | typedef struct fullstack_fixture_data { |
Craig Tiller | baa14a9 | 2017-11-03 09:09:36 -0700 | [diff] [blame] | 38 | char* localaddr; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 39 | } fullstack_fixture_data; |
| 40 | |
| 41 | static grpc_end2end_test_fixture chttp2_create_fixture_fullstack( |
Craig Tiller | baa14a9 | 2017-11-03 09:09:36 -0700 | [diff] [blame] | 42 | grpc_channel_args* client_args, grpc_channel_args* server_args) { |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 43 | grpc_end2end_test_fixture f; |
| 44 | int port = grpc_pick_unused_port_or_die(); |
Yash Tibrewal | 40422d5 | 2017-11-06 14:39:17 -0800 | [diff] [blame] | 45 | fullstack_fixture_data* ffd = static_cast<fullstack_fixture_data*>( |
Yash Tibrewal | 34a57d0 | 2017-10-23 15:33:21 -0700 | [diff] [blame] | 46 | gpr_malloc(sizeof(fullstack_fixture_data))); |
ctiller | c6d61c4 | 2014-12-15 14:52:08 -0800 | [diff] [blame] | 47 | memset(&f, 0, sizeof(f)); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 48 | |
| 49 | gpr_join_host_port(&ffd->localaddr, "localhost", port); |
| 50 | |
| 51 | f.fixture_data = ffd; |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 52 | f.cq = grpc_completion_queue_create_for_next(nullptr); |
| 53 | f.shutdown_cq = grpc_completion_queue_create_for_pluck(nullptr); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 54 | |
| 55 | return f; |
| 56 | } |
| 57 | |
Craig Tiller | baa14a9 | 2017-11-03 09:09:36 -0700 | [diff] [blame] | 58 | void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f, |
| 59 | grpc_channel_args* client_args) { |
Yash Tibrewal | 40422d5 | 2017-11-06 14:39:17 -0800 | [diff] [blame] | 60 | fullstack_fixture_data* ffd = |
| 61 | static_cast<fullstack_fixture_data*>(f->fixture_data); |
Craig Tiller | be98d24 | 2017-11-10 15:26:57 -0800 | [diff] [blame] | 62 | f->client = |
| 63 | grpc_insecure_channel_create(ffd->localaddr, client_args, nullptr); |
Craig Tiller | eb3b12e | 2015-06-26 14:42:49 -0700 | [diff] [blame] | 64 | GPR_ASSERT(f->client); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 65 | } |
| 66 | |
Craig Tiller | baa14a9 | 2017-11-03 09:09:36 -0700 | [diff] [blame] | 67 | void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f, |
| 68 | grpc_channel_args* server_args) { |
Yash Tibrewal | 40422d5 | 2017-11-06 14:39:17 -0800 | [diff] [blame] | 69 | fullstack_fixture_data* ffd = |
| 70 | static_cast<fullstack_fixture_data*>(f->fixture_data); |
ctiller | c6d61c4 | 2014-12-15 14:52:08 -0800 | [diff] [blame] | 71 | if (f->server) { |
| 72 | grpc_server_destroy(f->server); |
| 73 | } |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 74 | f->server = grpc_server_create(server_args, nullptr); |
| 75 | grpc_server_register_completion_queue(f->server, f->cq, nullptr); |
Craig Tiller | c5ae3eb | 2015-08-03 10:42:22 -0700 | [diff] [blame] | 76 | GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr)); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 77 | grpc_server_start(f->server); |
| 78 | } |
| 79 | |
Craig Tiller | baa14a9 | 2017-11-03 09:09:36 -0700 | [diff] [blame] | 80 | void chttp2_tear_down_fullstack(grpc_end2end_test_fixture* f) { |
Yash Tibrewal | 40422d5 | 2017-11-06 14:39:17 -0800 | [diff] [blame] | 81 | fullstack_fixture_data* ffd = |
| 82 | static_cast<fullstack_fixture_data*>(f->fixture_data); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 83 | gpr_free(ffd->localaddr); |
| 84 | gpr_free(ffd); |
| 85 | } |
| 86 | |
| 87 | /* All test configurations */ |
| 88 | static grpc_end2end_test_config configs[] = { |
Craig Tiller | baa14a9 | 2017-11-03 09:09:36 -0700 | [diff] [blame] | 89 | {"chttp2/fullstack", |
| 90 | FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION | |
| 91 | FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL | |
| 92 | FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER, |
David Garcia Quintas | 0287924 | 2018-03-23 18:14:12 -0700 | [diff] [blame^] | 93 | nullptr, chttp2_create_fixture_fullstack, chttp2_init_client_fullstack, |
Craig Tiller | 8ad8a41 | 2015-02-25 08:36:40 -0800 | [diff] [blame] | 94 | chttp2_init_server_fullstack, chttp2_tear_down_fullstack}, |
| 95 | }; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 96 | |
Craig Tiller | baa14a9 | 2017-11-03 09:09:36 -0700 | [diff] [blame] | 97 | int main(int argc, char** argv) { |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 98 | size_t i; |
| 99 | |
| 100 | grpc_test_init(argc, argv); |
Craig Tiller | 9e9edbc | 2016-04-04 10:38:49 -0700 | [diff] [blame] | 101 | grpc_end2end_tests_pre_init(); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 102 | grpc_init(); |
| 103 | |
| 104 | for (i = 0; i < sizeof(configs) / sizeof(*configs); i++) { |
Craig Tiller | 0fe5ee7 | 2015-12-22 12:50:36 -0800 | [diff] [blame] | 105 | grpc_end2end_tests(argc, argv, configs[i]); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | grpc_shutdown(); |
| 109 | |
| 110 | return 0; |
Craig Tiller | 190d360 | 2015-02-18 09:23:38 -0800 | [diff] [blame] | 111 | } |