Craig Tiller | 17effab | 2015-08-04 08:19:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
Craig Tiller | 6169d5f | 2016-03-31 07:46:18 -0700 | [diff] [blame] | 3 | * Copyright 2015, Google Inc. |
Craig Tiller | 17effab | 2015-08-04 08:19:36 -0700 | [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 | 17effab | 2015-08-04 08:19:36 -0700 | [diff] [blame] | 38 | #include <grpc/support/alloc.h> |
| 39 | #include <grpc/support/host_port.h> |
| 40 | #include <grpc/support/log.h> |
| 41 | #include <grpc/support/sync.h> |
| 42 | #include <grpc/support/thd.h> |
| 43 | #include <grpc/support/useful.h> |
Craig Tiller | d4c9833 | 2016-03-31 13:45:47 -0700 | [diff] [blame] | 44 | #include "src/core/ext/client_config/client_channel.h" |
Craig Tiller | 4a6dad3 | 2016-04-01 13:51:14 -0700 | [diff] [blame] | 45 | #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" |
Craig Tiller | 9533d04 | 2016-03-25 17:11:06 -0700 | [diff] [blame] | 46 | #include "src/core/lib/channel/connected_channel.h" |
| 47 | #include "src/core/lib/channel/http_server_filter.h" |
| 48 | #include "src/core/lib/surface/channel.h" |
| 49 | #include "src/core/lib/surface/server.h" |
Craig Tiller | 17effab | 2015-08-04 08:19:36 -0700 | [diff] [blame] | 50 | #include "test/core/end2end/fixtures/proxy.h" |
| 51 | #include "test/core/util/port.h" |
| 52 | #include "test/core/util/test_config.h" |
| 53 | |
| 54 | typedef struct fullstack_fixture_data { |
| 55 | grpc_end2end_proxy *proxy; |
| 56 | } fullstack_fixture_data; |
| 57 | |
| 58 | static grpc_server *create_proxy_server(const char *port) { |
Nicolas "Pixel" Noble | 9d72b14 | 2015-08-08 01:45:38 +0200 | [diff] [blame] | 59 | grpc_server *s = grpc_server_create(NULL, NULL); |
Craig Tiller | 64f32dc | 2015-08-05 12:53:14 -0700 | [diff] [blame] | 60 | GPR_ASSERT(grpc_server_add_insecure_http2_port(s, port)); |
Craig Tiller | 17effab | 2015-08-04 08:19:36 -0700 | [diff] [blame] | 61 | return s; |
| 62 | } |
| 63 | |
| 64 | static grpc_channel *create_proxy_client(const char *target) { |
Nicolas "Pixel" Noble | 9d72b14 | 2015-08-08 01:45:38 +0200 | [diff] [blame] | 65 | return grpc_insecure_channel_create(target, NULL, NULL); |
Craig Tiller | 17effab | 2015-08-04 08:19:36 -0700 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | static const grpc_end2end_proxy_def proxy_def = {create_proxy_server, |
| 69 | create_proxy_client}; |
| 70 | |
| 71 | static grpc_end2end_test_fixture chttp2_create_fixture_fullstack( |
| 72 | grpc_channel_args *client_args, grpc_channel_args *server_args) { |
| 73 | grpc_end2end_test_fixture f; |
| 74 | fullstack_fixture_data *ffd = gpr_malloc(sizeof(fullstack_fixture_data)); |
| 75 | memset(&f, 0, sizeof(f)); |
| 76 | |
| 77 | ffd->proxy = grpc_end2end_proxy_create(&proxy_def); |
| 78 | |
| 79 | f.fixture_data = ffd; |
Nicolas "Pixel" Noble | 9d72b14 | 2015-08-08 01:45:38 +0200 | [diff] [blame] | 80 | f.cq = grpc_completion_queue_create(NULL); |
Craig Tiller | 17effab | 2015-08-04 08:19:36 -0700 | [diff] [blame] | 81 | |
| 82 | return f; |
| 83 | } |
| 84 | |
| 85 | void chttp2_init_client_fullstack(grpc_end2end_test_fixture *f, |
| 86 | grpc_channel_args *client_args) { |
| 87 | fullstack_fixture_data *ffd = f->fixture_data; |
| 88 | f->client = grpc_insecure_channel_create( |
Nicolas "Pixel" Noble | 9d72b14 | 2015-08-08 01:45:38 +0200 | [diff] [blame] | 89 | grpc_end2end_proxy_get_client_target(ffd->proxy), client_args, NULL); |
Craig Tiller | 17effab | 2015-08-04 08:19:36 -0700 | [diff] [blame] | 90 | GPR_ASSERT(f->client); |
| 91 | } |
| 92 | |
| 93 | void chttp2_init_server_fullstack(grpc_end2end_test_fixture *f, |
| 94 | grpc_channel_args *server_args) { |
| 95 | fullstack_fixture_data *ffd = f->fixture_data; |
| 96 | if (f->server) { |
| 97 | grpc_server_destroy(f->server); |
| 98 | } |
Nicolas "Pixel" Noble | 9d72b14 | 2015-08-08 01:45:38 +0200 | [diff] [blame] | 99 | f->server = grpc_server_create(server_args, NULL); |
| 100 | grpc_server_register_completion_queue(f->server, f->cq, NULL); |
Craig Tiller | 64f32dc | 2015-08-05 12:53:14 -0700 | [diff] [blame] | 101 | GPR_ASSERT(grpc_server_add_insecure_http2_port( |
Craig Tiller | 17effab | 2015-08-04 08:19:36 -0700 | [diff] [blame] | 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 = f->fixture_data; |
| 108 | grpc_end2end_proxy_destroy(ffd->proxy); |
| 109 | gpr_free(ffd); |
| 110 | } |
| 111 | |
| 112 | /* All test configurations */ |
| 113 | static grpc_end2end_test_config configs[] = { |
| 114 | {"chttp2/fullstack+proxy", FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION, |
| 115 | chttp2_create_fixture_fullstack, chttp2_init_client_fullstack, |
| 116 | chttp2_init_server_fullstack, chttp2_tear_down_fullstack}, |
| 117 | }; |
| 118 | |
| 119 | int main(int argc, char **argv) { |
| 120 | size_t i; |
| 121 | |
| 122 | grpc_test_init(argc, argv); |
| 123 | grpc_init(); |
| 124 | |
| 125 | for (i = 0; i < sizeof(configs) / sizeof(*configs); i++) { |
Craig Tiller | 0fe5ee7 | 2015-12-22 12:50:36 -0800 | [diff] [blame] | 126 | grpc_end2end_tests(argc, argv, configs[i]); |
Craig Tiller | 17effab | 2015-08-04 08:19:36 -0700 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | grpc_shutdown(); |
| 130 | |
| 131 | return 0; |
| 132 | } |