Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
Craig Tiller | 6169d5f | 2016-03-31 07:46:18 -0700 | [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" |
| 35 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 36 | #include <string.h> |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 37 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [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 | 9eb0fde | 2017-03-31 16:59:30 -0700 | [diff] [blame^] | 44 | #include "src/core/ext/filters/client_channel/client_channel.h" |
Craig Tiller | adcb92d | 2016-03-28 10:14:05 -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" |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 50 | #include "test/core/util/port.h" |
| 51 | #include "test/core/util/test_config.h" |
| 52 | |
| 53 | typedef struct fullstack_fixture_data { |
| 54 | char *localaddr; |
| 55 | } fullstack_fixture_data; |
| 56 | |
| 57 | static grpc_end2end_test_fixture chttp2_create_fixture_fullstack( |
| 58 | grpc_channel_args *client_args, grpc_channel_args *server_args) { |
| 59 | grpc_end2end_test_fixture f; |
| 60 | int port = grpc_pick_unused_port_or_die(); |
| 61 | fullstack_fixture_data *ffd = gpr_malloc(sizeof(fullstack_fixture_data)); |
ctiller | c6d61c4 | 2014-12-15 14:52:08 -0800 | [diff] [blame] | 62 | memset(&f, 0, sizeof(f)); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 63 | |
| 64 | gpr_join_host_port(&ffd->localaddr, "localhost", port); |
| 65 | |
| 66 | f.fixture_data = ffd; |
Nicolas "Pixel" Noble | 9a123df | 2015-07-29 23:45:08 +0200 | [diff] [blame] | 67 | f.cq = grpc_completion_queue_create(NULL); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 68 | |
| 69 | return f; |
| 70 | } |
| 71 | |
| 72 | void chttp2_init_client_fullstack(grpc_end2end_test_fixture *f, |
Mark D. Roth | e127a39 | 2016-10-27 08:27:15 -0700 | [diff] [blame] | 73 | grpc_channel_args *client_args) { |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 74 | fullstack_fixture_data *ffd = f->fixture_data; |
Nicolas "Pixel" Noble | 9d72b14 | 2015-08-08 01:45:38 +0200 | [diff] [blame] | 75 | f->client = grpc_insecure_channel_create(ffd->localaddr, client_args, NULL); |
Craig Tiller | eb3b12e | 2015-06-26 14:42:49 -0700 | [diff] [blame] | 76 | GPR_ASSERT(f->client); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | void chttp2_init_server_fullstack(grpc_end2end_test_fixture *f, |
| 80 | grpc_channel_args *server_args) { |
| 81 | fullstack_fixture_data *ffd = f->fixture_data; |
ctiller | c6d61c4 | 2014-12-15 14:52:08 -0800 | [diff] [blame] | 82 | if (f->server) { |
| 83 | grpc_server_destroy(f->server); |
| 84 | } |
Nicolas "Pixel" Noble | 9a123df | 2015-07-29 23:45:08 +0200 | [diff] [blame] | 85 | f->server = grpc_server_create(server_args, NULL); |
| 86 | grpc_server_register_completion_queue(f->server, f->cq, NULL); |
Craig Tiller | c5ae3eb | 2015-08-03 10:42:22 -0700 | [diff] [blame] | 87 | GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr)); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 88 | grpc_server_start(f->server); |
| 89 | } |
| 90 | |
| 91 | void chttp2_tear_down_fullstack(grpc_end2end_test_fixture *f) { |
| 92 | fullstack_fixture_data *ffd = f->fixture_data; |
| 93 | gpr_free(ffd->localaddr); |
| 94 | gpr_free(ffd); |
| 95 | } |
| 96 | |
| 97 | /* All test configurations */ |
| 98 | static grpc_end2end_test_config configs[] = { |
Muxi Yan | ed2be64 | 2016-10-13 14:04:39 -0700 | [diff] [blame] | 99 | {"chttp2/fullstack", FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION | |
Muxi Yan | 4be8afc | 2016-11-07 10:25:55 -0800 | [diff] [blame] | 100 | FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL | |
Muxi Yan | ed2be64 | 2016-10-13 14:04:39 -0700 | [diff] [blame] | 101 | FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER, |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 102 | chttp2_create_fixture_fullstack, chttp2_init_client_fullstack, |
Craig Tiller | 8ad8a41 | 2015-02-25 08:36:40 -0800 | [diff] [blame] | 103 | chttp2_init_server_fullstack, chttp2_tear_down_fullstack}, |
| 104 | }; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 105 | |
| 106 | int main(int argc, char **argv) { |
| 107 | size_t i; |
| 108 | |
| 109 | grpc_test_init(argc, argv); |
Craig Tiller | 9e9edbc | 2016-04-04 10:38:49 -0700 | [diff] [blame] | 110 | grpc_end2end_tests_pre_init(); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 111 | grpc_init(); |
| 112 | |
| 113 | for (i = 0; i < sizeof(configs) / sizeof(*configs); i++) { |
Craig Tiller | 0fe5ee7 | 2015-12-22 12:50:36 -0800 | [diff] [blame] | 114 | grpc_end2end_tests(argc, argv, configs[i]); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | grpc_shutdown(); |
| 118 | |
| 119 | return 0; |
Craig Tiller | 190d360 | 2015-02-18 09:23:38 -0800 | [diff] [blame] | 120 | } |