Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
Craig Tiller | 0605995 | 2015-02-18 08:34:56 -0800 | [diff] [blame] | 3 | * Copyright 2015, Google Inc. |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 4 | * All rights reserved. |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions are |
| 8 | * met: |
| 9 | * |
| 10 | * * Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * * Redistributions in binary form must reproduce the above |
| 13 | * copyright notice, this list of conditions and the following disclaimer |
| 14 | * in the documentation and/or other materials provided with the |
| 15 | * distribution. |
| 16 | * * Neither the name of Google Inc. nor the names of its |
| 17 | * contributors may be used to endorse or promote products derived from |
| 18 | * this software without specific prior written permission. |
| 19 | * |
| 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | * |
| 32 | */ |
| 33 | |
| 34 | #include "test/core/end2end/end2end_tests.h" |
ctiller | c6d61c4 | 2014-12-15 14:52:08 -0800 | [diff] [blame] | 35 | |
| 36 | #include <string.h> |
| 37 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 38 | #include "src/core/channel/client_channel.h" |
| 39 | #include "src/core/channel/connected_channel.h" |
klempner | cd45aad | 2014-12-23 15:53:16 -0800 | [diff] [blame] | 40 | #include "src/core/channel/http_client_filter.h" |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 41 | #include "src/core/channel/http_server_filter.h" |
ctiller | 18b49ab | 2014-12-09 14:39:16 -0800 | [diff] [blame] | 42 | #include "src/core/iomgr/endpoint_pair.h" |
| 43 | #include "src/core/iomgr/iomgr.h" |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 44 | #include "src/core/surface/channel.h" |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 45 | #include "src/core/surface/server.h" |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 46 | #include "src/core/transport/chttp2_transport.h" |
| 47 | #include <grpc/support/alloc.h> |
| 48 | #include <grpc/support/log.h> |
| 49 | #include <grpc/support/sync.h> |
| 50 | #include <grpc/support/thd.h> |
| 51 | #include <grpc/support/useful.h> |
| 52 | #include "test/core/util/port.h" |
| 53 | #include "test/core/util/test_config.h" |
| 54 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 55 | /* chttp2 transport that is immediately available (used for testing |
| 56 | connected_channel without a client_channel */ |
| 57 | |
Craig Tiller | 079a11b | 2015-06-30 10:07:15 -0700 | [diff] [blame] | 58 | static void server_setup_transport(void *ts, grpc_transport *transport, |
| 59 | grpc_mdctx *mdctx) { |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 60 | grpc_end2end_test_fixture *f = ts; |
Craig Tiller | 06aeea7 | 2015-04-23 10:54:45 -0700 | [diff] [blame] | 61 | static grpc_channel_filter const *extra_filters[] = { |
| 62 | &grpc_http_server_filter}; |
Craig Tiller | acf0f07 | 2015-06-29 08:24:16 -0700 | [diff] [blame] | 63 | grpc_server_setup_transport(f->server, transport, extra_filters, |
Craig Tiller | 079a11b | 2015-06-30 10:07:15 -0700 | [diff] [blame] | 64 | GPR_ARRAY_SIZE(extra_filters), mdctx, |
| 65 | grpc_server_get_channel_args(f->server)); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | typedef struct { |
| 69 | grpc_end2end_test_fixture *f; |
| 70 | grpc_channel_args *client_args; |
| 71 | } sp_client_setup; |
| 72 | |
Craig Tiller | 079a11b | 2015-06-30 10:07:15 -0700 | [diff] [blame] | 73 | static void client_setup_transport(void *ts, grpc_transport *transport, |
| 74 | grpc_mdctx *mdctx) { |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 75 | sp_client_setup *cs = ts; |
| 76 | |
Craig Tiller | acf0f07 | 2015-06-29 08:24:16 -0700 | [diff] [blame] | 77 | const grpc_channel_filter *filters[] = {&grpc_http_client_filter, |
Craig Tiller | 06aeea7 | 2015-04-23 10:54:45 -0700 | [diff] [blame] | 78 | &grpc_connected_channel_filter}; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 79 | size_t nfilters = sizeof(filters) / sizeof(*filters); |
| 80 | grpc_channel *channel = grpc_channel_create_from_filters( |
| 81 | filters, nfilters, cs->client_args, mdctx, 1); |
| 82 | |
| 83 | cs->f->client = channel; |
| 84 | |
Craig Tiller | 079a11b | 2015-06-30 10:07:15 -0700 | [diff] [blame] | 85 | grpc_connected_channel_bind_transport(grpc_channel_get_channel_stack(channel), |
| 86 | transport); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 87 | } |
| 88 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 89 | static grpc_end2end_test_fixture chttp2_create_fixture_socketpair( |
| 90 | grpc_channel_args *client_args, grpc_channel_args *server_args) { |
ctiller | 18b49ab | 2014-12-09 14:39:16 -0800 | [diff] [blame] | 91 | grpc_endpoint_pair *sfd = gpr_malloc(sizeof(grpc_endpoint_pair)); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 92 | |
| 93 | grpc_end2end_test_fixture f; |
ctiller | c6d61c4 | 2014-12-15 14:52:08 -0800 | [diff] [blame] | 94 | memset(&f, 0, sizeof(f)); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 95 | f.fixture_data = sfd; |
Craig Tiller | 65ad0a7 | 2015-05-11 10:38:07 -0700 | [diff] [blame] | 96 | f.cq = grpc_completion_queue_create(); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 97 | |
Craig Tiller | fa275a9 | 2015-06-01 13:55:54 -0700 | [diff] [blame] | 98 | *sfd = grpc_iomgr_create_endpoint_pair("fixture", 65536); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 99 | |
| 100 | return f; |
| 101 | } |
| 102 | |
| 103 | static void chttp2_init_client_socketpair(grpc_end2end_test_fixture *f, |
| 104 | grpc_channel_args *client_args) { |
ctiller | 18b49ab | 2014-12-09 14:39:16 -0800 | [diff] [blame] | 105 | grpc_endpoint_pair *sfd = f->fixture_data; |
Craig Tiller | acf0f07 | 2015-06-29 08:24:16 -0700 | [diff] [blame] | 106 | grpc_transport *transport; |
| 107 | grpc_mdctx *mdctx = grpc_mdctx_create(); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 108 | sp_client_setup cs; |
| 109 | cs.client_args = client_args; |
| 110 | cs.f = f; |
Craig Tiller | 1dd7026 | 2015-07-06 11:45:30 -0700 | [diff] [blame^] | 111 | transport = grpc_create_chttp2_transport(client_args, sfd->client, mdctx, 1); |
Craig Tiller | acf0f07 | 2015-06-29 08:24:16 -0700 | [diff] [blame] | 112 | client_setup_transport(&cs, transport, mdctx); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 113 | GPR_ASSERT(f->client); |
Craig Tiller | 1dd7026 | 2015-07-06 11:45:30 -0700 | [diff] [blame^] | 114 | grpc_chttp2_transport_start_reading(transport, NULL, 0); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | static void chttp2_init_server_socketpair(grpc_end2end_test_fixture *f, |
| 118 | grpc_channel_args *server_args) { |
ctiller | 18b49ab | 2014-12-09 14:39:16 -0800 | [diff] [blame] | 119 | grpc_endpoint_pair *sfd = f->fixture_data; |
Craig Tiller | acf0f07 | 2015-06-29 08:24:16 -0700 | [diff] [blame] | 120 | grpc_mdctx *mdctx = grpc_mdctx_create(); |
| 121 | grpc_transport *transport; |
ctiller | c6d61c4 | 2014-12-15 14:52:08 -0800 | [diff] [blame] | 122 | GPR_ASSERT(!f->server); |
Craig Tiller | f9e6adf | 2015-05-06 11:45:59 -0700 | [diff] [blame] | 123 | f->server = grpc_server_create_from_filters(NULL, 0, server_args); |
Craig Tiller | 5532ae2 | 2015-05-11 10:40:19 -0700 | [diff] [blame] | 124 | grpc_server_register_completion_queue(f->server, f->cq); |
ctiller | 58393c2 | 2015-01-07 14:03:30 -0800 | [diff] [blame] | 125 | grpc_server_start(f->server); |
Craig Tiller | 1dd7026 | 2015-07-06 11:45:30 -0700 | [diff] [blame^] | 126 | transport = grpc_create_chttp2_transport(server_args, sfd->server, mdctx, 0); |
Craig Tiller | acf0f07 | 2015-06-29 08:24:16 -0700 | [diff] [blame] | 127 | server_setup_transport(f, transport, mdctx); |
Craig Tiller | 1dd7026 | 2015-07-06 11:45:30 -0700 | [diff] [blame^] | 128 | grpc_chttp2_transport_start_reading(transport, NULL, 0); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | static void chttp2_tear_down_socketpair(grpc_end2end_test_fixture *f) { |
| 132 | gpr_free(f->fixture_data); |
| 133 | } |
| 134 | |
| 135 | /* All test configurations */ |
| 136 | static grpc_end2end_test_config configs[] = { |
| 137 | {"chttp2/socketpair", 0, chttp2_create_fixture_socketpair, |
| 138 | chttp2_init_client_socketpair, chttp2_init_server_socketpair, |
Craig Tiller | 8ad8a41 | 2015-02-25 08:36:40 -0800 | [diff] [blame] | 139 | chttp2_tear_down_socketpair}, |
| 140 | }; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 141 | |
| 142 | int main(int argc, char **argv) { |
| 143 | size_t i; |
| 144 | |
| 145 | grpc_test_init(argc, argv); |
| 146 | grpc_init(); |
| 147 | |
| 148 | for (i = 0; i < sizeof(configs) / sizeof(*configs); i++) { |
| 149 | grpc_end2end_tests(configs[i]); |
| 150 | } |
| 151 | |
| 152 | grpc_shutdown(); |
| 153 | |
| 154 | return 0; |
Craig Tiller | 190d360 | 2015-02-18 09:23:38 -0800 | [diff] [blame] | 155 | } |