Craig Tiller | 9a8df28 | 2016-02-19 09:08:09 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
Craig Tiller | 7a1aab6 | 2016-02-19 13:03:42 -0800 | [diff] [blame] | 3 | * Copyright 2015-2016, Google Inc. |
Craig Tiller | 9a8df28 | 2016-02-19 09:08:09 -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" |
| 35 | |
| 36 | #include <string.h> |
| 37 | |
Craig Tiller | f40df23 | 2016-03-25 13:38:14 -0700 | [diff] [blame] | 38 | #include <grpc/support/alloc.h> |
| 39 | #include <grpc/support/log.h> |
| 40 | #include <grpc/support/sync.h> |
| 41 | #include <grpc/support/thd.h> |
| 42 | #include <grpc/support/useful.h> |
Craig Tiller | 9533d04 | 2016-03-25 17:11:06 -0700 | [diff] [blame] | 43 | #include "src/core/lib/channel/client_channel.h" |
| 44 | #include "src/core/lib/channel/compress_filter.h" |
| 45 | #include "src/core/lib/channel/connected_channel.h" |
| 46 | #include "src/core/lib/channel/http_client_filter.h" |
| 47 | #include "src/core/lib/channel/http_server_filter.h" |
| 48 | #include "src/core/lib/iomgr/endpoint_pair.h" |
| 49 | #include "src/core/lib/iomgr/iomgr.h" |
| 50 | #include "src/core/lib/surface/channel.h" |
| 51 | #include "src/core/lib/surface/server.h" |
| 52 | #include "src/core/lib/transport/chttp2_transport.h" |
Craig Tiller | 9a8df28 | 2016-02-19 09:08:09 -0800 | [diff] [blame] | 53 | #include "test/core/util/port.h" |
| 54 | #include "test/core/util/test_config.h" |
| 55 | |
| 56 | /* chttp2 transport that is immediately available (used for testing |
| 57 | connected_channel without a client_channel */ |
| 58 | |
| 59 | static void server_setup_transport(void *ts, grpc_transport *transport) { |
| 60 | grpc_end2end_test_fixture *f = ts; |
Craig Tiller | 9a8df28 | 2016-02-19 09:08:09 -0800 | [diff] [blame] | 61 | grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
Craig Tiller | de67626 | 2016-02-19 12:28:34 -0800 | [diff] [blame] | 62 | grpc_server_setup_transport(&exec_ctx, f->server, transport, |
Craig Tiller | 9a8df28 | 2016-02-19 09:08:09 -0800 | [diff] [blame] | 63 | grpc_server_get_channel_args(f->server)); |
| 64 | grpc_exec_ctx_finish(&exec_ctx); |
| 65 | } |
| 66 | |
| 67 | typedef struct { |
| 68 | grpc_end2end_test_fixture *f; |
| 69 | grpc_channel_args *client_args; |
| 70 | } sp_client_setup; |
| 71 | |
| 72 | static void client_setup_transport(grpc_exec_ctx *exec_ctx, void *ts, |
| 73 | grpc_transport *transport) { |
| 74 | sp_client_setup *cs = ts; |
| 75 | |
Craig Tiller | d78d164 | 2016-02-21 22:18:51 -0800 | [diff] [blame] | 76 | cs->f->client = |
| 77 | grpc_channel_create(exec_ctx, "socketpair-target", cs->client_args, |
| 78 | GRPC_CLIENT_DIRECT_CHANNEL, transport); |
Craig Tiller | 9a8df28 | 2016-02-19 09:08:09 -0800 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | static grpc_end2end_test_fixture chttp2_create_fixture_socketpair( |
| 82 | grpc_channel_args *client_args, grpc_channel_args *server_args) { |
| 83 | grpc_endpoint_pair *sfd = gpr_malloc(sizeof(grpc_endpoint_pair)); |
| 84 | |
| 85 | grpc_end2end_test_fixture f; |
| 86 | memset(&f, 0, sizeof(f)); |
| 87 | f.fixture_data = sfd; |
| 88 | f.cq = grpc_completion_queue_create(NULL); |
| 89 | |
| 90 | *sfd = grpc_iomgr_create_endpoint_pair("fixture", 65536); |
| 91 | |
| 92 | return f; |
| 93 | } |
| 94 | |
| 95 | static void chttp2_init_client_socketpair(grpc_end2end_test_fixture *f, |
| 96 | grpc_channel_args *client_args) { |
| 97 | grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
| 98 | grpc_endpoint_pair *sfd = f->fixture_data; |
| 99 | grpc_transport *transport; |
| 100 | sp_client_setup cs; |
| 101 | cs.client_args = client_args; |
| 102 | cs.f = f; |
| 103 | transport = |
| 104 | grpc_create_chttp2_transport(&exec_ctx, client_args, sfd->client, 1); |
| 105 | client_setup_transport(&exec_ctx, &cs, transport); |
| 106 | GPR_ASSERT(f->client); |
| 107 | grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL, 0); |
| 108 | grpc_exec_ctx_finish(&exec_ctx); |
| 109 | } |
| 110 | |
| 111 | static void chttp2_init_server_socketpair(grpc_end2end_test_fixture *f, |
| 112 | grpc_channel_args *server_args) { |
| 113 | grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
| 114 | grpc_endpoint_pair *sfd = f->fixture_data; |
| 115 | grpc_transport *transport; |
| 116 | GPR_ASSERT(!f->server); |
Craig Tiller | de67626 | 2016-02-19 12:28:34 -0800 | [diff] [blame] | 117 | f->server = grpc_server_create(server_args, NULL); |
Craig Tiller | 9a8df28 | 2016-02-19 09:08:09 -0800 | [diff] [blame] | 118 | grpc_server_register_completion_queue(f->server, f->cq, NULL); |
| 119 | grpc_server_start(f->server); |
| 120 | transport = |
| 121 | grpc_create_chttp2_transport(&exec_ctx, server_args, sfd->server, 0); |
| 122 | server_setup_transport(f, transport); |
| 123 | grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL, 0); |
| 124 | grpc_exec_ctx_finish(&exec_ctx); |
| 125 | } |
| 126 | |
| 127 | static void chttp2_tear_down_socketpair(grpc_end2end_test_fixture *f) { |
| 128 | gpr_free(f->fixture_data); |
| 129 | } |
| 130 | |
| 131 | /* All test configurations */ |
| 132 | static grpc_end2end_test_config configs[] = { |
| 133 | {"chttp2/socketpair", 0, chttp2_create_fixture_socketpair, |
| 134 | chttp2_init_client_socketpair, chttp2_init_server_socketpair, |
| 135 | chttp2_tear_down_socketpair}, |
| 136 | }; |
| 137 | |
| 138 | int main(int argc, char **argv) { |
| 139 | size_t i; |
| 140 | |
| 141 | grpc_test_init(argc, argv); |
| 142 | grpc_init(); |
| 143 | |
| 144 | for (i = 0; i < sizeof(configs) / sizeof(*configs); i++) { |
| 145 | grpc_end2end_tests(argc, argv, configs[i]); |
| 146 | } |
| 147 | |
| 148 | grpc_shutdown(); |
| 149 | |
| 150 | return 0; |
| 151 | } |