Craig Tiller | eadd9a3 | 2015-05-18 14:52:12 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright 2015, Google Inc. |
| 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" |
| 35 | |
| 36 | #include <string.h> |
| 37 | |
| 38 | #include "src/core/channel/client_channel.h" |
| 39 | #include "src/core/channel/connected_channel.h" |
| 40 | #include "src/core/channel/http_client_filter.h" |
| 41 | #include "src/core/channel/http_server_filter.h" |
David Garcia Quintas | 5927aec | 2015-06-18 17:24:44 -0700 | [diff] [blame] | 42 | #include "src/core/channel/compress_filter.h" |
Craig Tiller | eadd9a3 | 2015-05-18 14:52:12 -0700 | [diff] [blame] | 43 | #include "src/core/iomgr/endpoint_pair.h" |
| 44 | #include "src/core/iomgr/iomgr.h" |
| 45 | #include "src/core/support/env.h" |
| 46 | #include "src/core/surface/channel.h" |
Craig Tiller | eadd9a3 | 2015-05-18 14:52:12 -0700 | [diff] [blame] | 47 | #include "src/core/surface/server.h" |
| 48 | #include "src/core/transport/chttp2_transport.h" |
| 49 | #include <grpc/support/alloc.h> |
| 50 | #include <grpc/support/log.h> |
| 51 | #include <grpc/support/sync.h> |
| 52 | #include <grpc/support/thd.h> |
| 53 | #include <grpc/support/useful.h> |
| 54 | #include "test/core/util/port.h" |
| 55 | #include "test/core/util/test_config.h" |
| 56 | |
| 57 | /* chttp2 transport that is immediately available (used for testing |
| 58 | connected_channel without a client_channel */ |
| 59 | |
Craig Tiller | 079a11b | 2015-06-30 10:07:15 -0700 | [diff] [blame] | 60 | static void server_setup_transport(void *ts, grpc_transport *transport, |
| 61 | grpc_mdctx *mdctx) { |
Craig Tiller | eadd9a3 | 2015-05-18 14:52:12 -0700 | [diff] [blame] | 62 | grpc_end2end_test_fixture *f = ts; |
| 63 | static grpc_channel_filter const *extra_filters[] = { |
| 64 | &grpc_http_server_filter}; |
Craig Tiller | acf0f07 | 2015-06-29 08:24:16 -0700 | [diff] [blame] | 65 | grpc_server_setup_transport(f->server, transport, extra_filters, |
Craig Tiller | 079a11b | 2015-06-30 10:07:15 -0700 | [diff] [blame] | 66 | GPR_ARRAY_SIZE(extra_filters), mdctx, |
| 67 | grpc_server_get_channel_args(f->server)); |
Craig Tiller | eadd9a3 | 2015-05-18 14:52:12 -0700 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | typedef struct { |
| 71 | grpc_end2end_test_fixture *f; |
| 72 | grpc_channel_args *client_args; |
| 73 | } sp_client_setup; |
| 74 | |
Craig Tiller | 079a11b | 2015-06-30 10:07:15 -0700 | [diff] [blame] | 75 | static void client_setup_transport(void *ts, grpc_transport *transport, |
| 76 | grpc_mdctx *mdctx) { |
Craig Tiller | eadd9a3 | 2015-05-18 14:52:12 -0700 | [diff] [blame] | 77 | sp_client_setup *cs = ts; |
| 78 | |
Craig Tiller | acf0f07 | 2015-06-29 08:24:16 -0700 | [diff] [blame] | 79 | const grpc_channel_filter *filters[] = {&grpc_http_client_filter, |
David Garcia Quintas | 5927aec | 2015-06-18 17:24:44 -0700 | [diff] [blame] | 80 | &grpc_compress_filter, |
Craig Tiller | eadd9a3 | 2015-05-18 14:52:12 -0700 | [diff] [blame] | 81 | &grpc_connected_channel_filter}; |
| 82 | size_t nfilters = sizeof(filters) / sizeof(*filters); |
| 83 | grpc_channel *channel = grpc_channel_create_from_filters( |
Craig Tiller | 1b22b9d | 2015-07-20 13:42:22 -0700 | [diff] [blame] | 84 | "socketpair-target", filters, nfilters, cs->client_args, mdctx, 1); |
Craig Tiller | eadd9a3 | 2015-05-18 14:52:12 -0700 | [diff] [blame] | 85 | |
| 86 | cs->f->client = channel; |
| 87 | |
Craig Tiller | 079a11b | 2015-06-30 10:07:15 -0700 | [diff] [blame] | 88 | grpc_connected_channel_bind_transport(grpc_channel_get_channel_stack(channel), |
| 89 | transport); |
Craig Tiller | eadd9a3 | 2015-05-18 14:52:12 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | static grpc_end2end_test_fixture chttp2_create_fixture_socketpair( |
| 93 | grpc_channel_args *client_args, grpc_channel_args *server_args) { |
| 94 | grpc_endpoint_pair *sfd = gpr_malloc(sizeof(grpc_endpoint_pair)); |
| 95 | |
| 96 | grpc_end2end_test_fixture f; |
| 97 | memset(&f, 0, sizeof(f)); |
| 98 | f.fixture_data = sfd; |
Craig Tiller | 24d1156 | 2015-05-19 23:36:19 -0700 | [diff] [blame] | 99 | f.cq = grpc_completion_queue_create(); |
Craig Tiller | eadd9a3 | 2015-05-18 14:52:12 -0700 | [diff] [blame] | 100 | |
Craig Tiller | fa275a9 | 2015-06-01 13:55:54 -0700 | [diff] [blame] | 101 | *sfd = grpc_iomgr_create_endpoint_pair("fixture", 65536); |
Craig Tiller | eadd9a3 | 2015-05-18 14:52:12 -0700 | [diff] [blame] | 102 | |
| 103 | return f; |
| 104 | } |
| 105 | |
| 106 | static void chttp2_init_client_socketpair(grpc_end2end_test_fixture *f, |
| 107 | grpc_channel_args *client_args) { |
| 108 | grpc_endpoint_pair *sfd = f->fixture_data; |
Craig Tiller | acf0f07 | 2015-06-29 08:24:16 -0700 | [diff] [blame] | 109 | grpc_transport *transport; |
| 110 | grpc_mdctx *mdctx = grpc_mdctx_create(); |
Craig Tiller | eadd9a3 | 2015-05-18 14:52:12 -0700 | [diff] [blame] | 111 | sp_client_setup cs; |
| 112 | cs.client_args = client_args; |
| 113 | cs.f = f; |
Craig Tiller | 1dd7026 | 2015-07-06 11:45:30 -0700 | [diff] [blame] | 114 | transport = grpc_create_chttp2_transport(client_args, sfd->client, mdctx, 1); |
Craig Tiller | acf0f07 | 2015-06-29 08:24:16 -0700 | [diff] [blame] | 115 | client_setup_transport(&cs, transport, mdctx); |
Craig Tiller | eadd9a3 | 2015-05-18 14:52:12 -0700 | [diff] [blame] | 116 | GPR_ASSERT(f->client); |
Craig Tiller | 1dd7026 | 2015-07-06 11:45:30 -0700 | [diff] [blame] | 117 | grpc_chttp2_transport_start_reading(transport, NULL, 0); |
Craig Tiller | eadd9a3 | 2015-05-18 14:52:12 -0700 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | static void chttp2_init_server_socketpair(grpc_end2end_test_fixture *f, |
| 121 | grpc_channel_args *server_args) { |
| 122 | grpc_endpoint_pair *sfd = f->fixture_data; |
Craig Tiller | acf0f07 | 2015-06-29 08:24:16 -0700 | [diff] [blame] | 123 | grpc_mdctx *mdctx = grpc_mdctx_create(); |
| 124 | grpc_transport *transport; |
Craig Tiller | eadd9a3 | 2015-05-18 14:52:12 -0700 | [diff] [blame] | 125 | GPR_ASSERT(!f->server); |
| 126 | f->server = grpc_server_create_from_filters(NULL, 0, server_args); |
Craig Tiller | 24d1156 | 2015-05-19 23:36:19 -0700 | [diff] [blame] | 127 | grpc_server_register_completion_queue(f->server, f->cq); |
Craig Tiller | eadd9a3 | 2015-05-18 14:52:12 -0700 | [diff] [blame] | 128 | grpc_server_start(f->server); |
Craig Tiller | 1dd7026 | 2015-07-06 11:45:30 -0700 | [diff] [blame] | 129 | transport = grpc_create_chttp2_transport(server_args, sfd->server, mdctx, 0); |
Craig Tiller | acf0f07 | 2015-06-29 08:24:16 -0700 | [diff] [blame] | 130 | server_setup_transport(f, transport, mdctx); |
Craig Tiller | 1dd7026 | 2015-07-06 11:45:30 -0700 | [diff] [blame] | 131 | grpc_chttp2_transport_start_reading(transport, NULL, 0); |
Craig Tiller | eadd9a3 | 2015-05-18 14:52:12 -0700 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | static void chttp2_tear_down_socketpair(grpc_end2end_test_fixture *f) { |
| 135 | gpr_free(f->fixture_data); |
| 136 | } |
| 137 | |
| 138 | /* All test configurations */ |
| 139 | static grpc_end2end_test_config configs[] = { |
| 140 | {"chttp2/socketpair", 0, chttp2_create_fixture_socketpair, |
| 141 | chttp2_init_client_socketpair, chttp2_init_server_socketpair, |
| 142 | chttp2_tear_down_socketpair}, |
| 143 | }; |
| 144 | |
| 145 | int main(int argc, char **argv) { |
| 146 | size_t i; |
| 147 | |
| 148 | /* force tracing on, with a value to force many |
| 149 | code paths in trace.c to be taken */ |
| 150 | gpr_setenv("GRPC_TRACE", "doesnt-exist,http,all"); |
| 151 | |
| 152 | grpc_test_init(argc, argv); |
| 153 | grpc_init(); |
| 154 | |
Craig Tiller | af7abf9 | 2015-06-03 17:18:58 -0700 | [diff] [blame] | 155 | GPR_ASSERT(0 == grpc_tracer_set_enabled("also-doesnt-exist", 0)); |
| 156 | GPR_ASSERT(1 == grpc_tracer_set_enabled("http", 1)); |
| 157 | GPR_ASSERT(1 == grpc_tracer_set_enabled("all", 1)); |
| 158 | |
Craig Tiller | eadd9a3 | 2015-05-18 14:52:12 -0700 | [diff] [blame] | 159 | for (i = 0; i < sizeof(configs) / sizeof(*configs); i++) { |
| 160 | grpc_end2end_tests(configs[i]); |
| 161 | } |
| 162 | |
| 163 | grpc_shutdown(); |
| 164 | |
| 165 | return 0; |
| 166 | } |