David Garcia Quintas | 824363d | 2016-07-13 23:09:34 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright 2016, 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 <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> |
| 44 | #include "src/core/ext/client_config/client_channel.h" |
| 45 | #include "src/core/ext/load_reporting/load_reporting.h" |
| 46 | #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" |
| 47 | #include "src/core/lib/channel/channel_args.h" |
| 48 | #include "src/core/lib/channel/connected_channel.h" |
| 49 | #include "src/core/lib/channel/http_server_filter.h" |
| 50 | #include "src/core/lib/surface/channel.h" |
| 51 | #include "src/core/lib/surface/server.h" |
| 52 | #include "test/core/util/port.h" |
| 53 | #include "test/core/util/test_config.h" |
| 54 | |
| 55 | typedef struct load_reporting_fixture_data { |
| 56 | char *localaddr; |
| 57 | } load_reporting_fixture_data; |
| 58 | |
| 59 | static grpc_end2end_test_fixture chttp2_create_fixture_load_reporting( |
| 60 | grpc_channel_args *client_args, grpc_channel_args *server_args) { |
| 61 | grpc_end2end_test_fixture f; |
| 62 | int port = grpc_pick_unused_port_or_die(); |
| 63 | load_reporting_fixture_data *ffd = |
| 64 | gpr_malloc(sizeof(load_reporting_fixture_data)); |
| 65 | memset(&f, 0, sizeof(f)); |
| 66 | |
| 67 | gpr_join_host_port(&ffd->localaddr, "localhost", port); |
| 68 | |
| 69 | f.fixture_data = ffd; |
| 70 | f.cq = grpc_completion_queue_create(NULL); |
| 71 | |
| 72 | return f; |
| 73 | } |
| 74 | |
| 75 | void chttp2_init_client_load_reporting(grpc_end2end_test_fixture *f, |
| 76 | grpc_channel_args *client_args) { |
| 77 | load_reporting_fixture_data *ffd = f->fixture_data; |
| 78 | f->client = grpc_insecure_channel_create(ffd->localaddr, client_args, NULL); |
| 79 | GPR_ASSERT(f->client); |
| 80 | } |
| 81 | |
| 82 | void chttp2_init_server_load_reporting(grpc_end2end_test_fixture *f, |
| 83 | grpc_channel_args *server_args) { |
| 84 | load_reporting_fixture_data *ffd = f->fixture_data; |
| 85 | grpc_arg arg = grpc_load_reporting_enable_arg(); |
| 86 | if (f->server) { |
| 87 | grpc_server_destroy(f->server); |
| 88 | } |
| 89 | server_args = grpc_channel_args_copy_and_add(server_args, &arg, 1); |
| 90 | f->server = grpc_server_create(server_args, NULL); |
| 91 | grpc_channel_args_destroy(server_args); |
| 92 | grpc_server_register_completion_queue(f->server, f->cq, NULL); |
| 93 | GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr)); |
| 94 | grpc_server_start(f->server); |
| 95 | } |
| 96 | |
| 97 | void chttp2_tear_down_load_reporting(grpc_end2end_test_fixture *f) { |
| 98 | load_reporting_fixture_data *ffd = f->fixture_data; |
| 99 | gpr_free(ffd->localaddr); |
| 100 | gpr_free(ffd); |
| 101 | } |
| 102 | |
| 103 | /* All test configurations */ |
| 104 | static grpc_end2end_test_config configs[] = { |
| 105 | {"chttp2/fullstack+load_reporting", |
| 106 | FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION, |
| 107 | chttp2_create_fixture_load_reporting, chttp2_init_client_load_reporting, |
| 108 | chttp2_init_server_load_reporting, chttp2_tear_down_load_reporting}, |
| 109 | }; |
| 110 | |
| 111 | int main(int argc, char **argv) { |
| 112 | size_t i; |
| 113 | |
| 114 | grpc_test_init(argc, argv); |
| 115 | grpc_end2end_tests_pre_init(); |
| 116 | grpc_init(); |
| 117 | |
| 118 | for (i = 0; i < sizeof(configs) / sizeof(*configs); i++) { |
| 119 | grpc_end2end_tests(argc, argv, configs[i]); |
| 120 | } |
| 121 | |
| 122 | grpc_shutdown(); |
| 123 | |
| 124 | return 0; |
| 125 | } |