David Garcia Quintas | dd2ebee | 2015-06-23 18:42:17 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
Craig Tiller | 2e19036 | 2016-03-25 14:33:26 -0700 | [diff] [blame] | 3 | * Copyright 2015-2016, Google Inc. |
David Garcia Quintas | dd2ebee | 2015-06-23 18:42:17 -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 | f40df23 | 2016-03-25 13:38:14 -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 | adcb92d | 2016-03-28 10:14:05 -0700 | [diff] [blame] | 44 | #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" |
Craig Tiller | 9533d04 | 2016-03-25 17:11:06 -0700 | [diff] [blame] | 45 | #include "src/core/lib/channel/channel_args.h" |
| 46 | #include "src/core/lib/channel/client_channel.h" |
| 47 | #include "src/core/lib/channel/connected_channel.h" |
| 48 | #include "src/core/lib/channel/http_server_filter.h" |
| 49 | #include "src/core/lib/surface/channel.h" |
| 50 | #include "src/core/lib/surface/server.h" |
David Garcia Quintas | dd2ebee | 2015-06-23 18:42:17 -0700 | [diff] [blame] | 51 | #include "test/core/util/port.h" |
| 52 | #include "test/core/util/test_config.h" |
| 53 | |
| 54 | typedef struct fullstack_compression_fixture_data { |
| 55 | char *localaddr; |
Craig Tiller | 17effab | 2015-08-04 08:19:36 -0700 | [diff] [blame] | 56 | grpc_channel_args *client_args_compression; |
| 57 | grpc_channel_args *server_args_compression; |
David Garcia Quintas | dd2ebee | 2015-06-23 18:42:17 -0700 | [diff] [blame] | 58 | } fullstack_compression_fixture_data; |
| 59 | |
| 60 | static grpc_end2end_test_fixture chttp2_create_fixture_fullstack_compression( |
| 61 | grpc_channel_args *client_args, grpc_channel_args *server_args) { |
| 62 | grpc_end2end_test_fixture f; |
| 63 | int port = grpc_pick_unused_port_or_die(); |
| 64 | fullstack_compression_fixture_data *ffd = |
| 65 | gpr_malloc(sizeof(fullstack_compression_fixture_data)); |
David Garcia Quintas | 4e40336 | 2015-07-01 16:45:34 -0700 | [diff] [blame] | 66 | memset(ffd, 0, sizeof(fullstack_compression_fixture_data)); |
David Garcia Quintas | dd2ebee | 2015-06-23 18:42:17 -0700 | [diff] [blame] | 67 | |
| 68 | gpr_join_host_port(&ffd->localaddr, "localhost", port); |
| 69 | |
David Garcia Quintas | 4e40336 | 2015-07-01 16:45:34 -0700 | [diff] [blame] | 70 | memset(&f, 0, sizeof(f)); |
David Garcia Quintas | dd2ebee | 2015-06-23 18:42:17 -0700 | [diff] [blame] | 71 | f.fixture_data = ffd; |
Nicolas "Pixel" Noble | 9a123df | 2015-07-29 23:45:08 +0200 | [diff] [blame] | 72 | f.cq = grpc_completion_queue_create(NULL); |
David Garcia Quintas | dd2ebee | 2015-06-23 18:42:17 -0700 | [diff] [blame] | 73 | |
| 74 | return f; |
| 75 | } |
| 76 | |
| 77 | void chttp2_init_client_fullstack_compression(grpc_end2end_test_fixture *f, |
Craig Tiller | 17effab | 2015-08-04 08:19:36 -0700 | [diff] [blame] | 78 | grpc_channel_args *client_args) { |
David Garcia Quintas | dd2ebee | 2015-06-23 18:42:17 -0700 | [diff] [blame] | 79 | fullstack_compression_fixture_data *ffd = f->fixture_data; |
David Garcia Quintas | 4e40336 | 2015-07-01 16:45:34 -0700 | [diff] [blame] | 80 | if (ffd->client_args_compression != NULL) { |
| 81 | grpc_channel_args_destroy(ffd->client_args_compression); |
| 82 | } |
David Garcia Quintas | cadbf22 | 2015-07-17 15:33:13 -0700 | [diff] [blame] | 83 | ffd->client_args_compression = grpc_channel_args_set_compression_algorithm( |
| 84 | client_args, GRPC_COMPRESS_GZIP); |
Craig Tiller | 4a4f149 | 2015-07-21 16:32:29 -0700 | [diff] [blame] | 85 | f->client = grpc_insecure_channel_create(ffd->localaddr, |
Nicolas "Pixel" Noble | 9d72b14 | 2015-08-08 01:45:38 +0200 | [diff] [blame] | 86 | ffd->client_args_compression, NULL); |
David Garcia Quintas | dd2ebee | 2015-06-23 18:42:17 -0700 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | void chttp2_init_server_fullstack_compression(grpc_end2end_test_fixture *f, |
Craig Tiller | 17effab | 2015-08-04 08:19:36 -0700 | [diff] [blame] | 90 | grpc_channel_args *server_args) { |
David Garcia Quintas | dd2ebee | 2015-06-23 18:42:17 -0700 | [diff] [blame] | 91 | fullstack_compression_fixture_data *ffd = f->fixture_data; |
David Garcia Quintas | 4e40336 | 2015-07-01 16:45:34 -0700 | [diff] [blame] | 92 | if (ffd->server_args_compression != NULL) { |
| 93 | grpc_channel_args_destroy(ffd->server_args_compression); |
| 94 | } |
David Garcia Quintas | cadbf22 | 2015-07-17 15:33:13 -0700 | [diff] [blame] | 95 | ffd->server_args_compression = grpc_channel_args_set_compression_algorithm( |
| 96 | server_args, GRPC_COMPRESS_GZIP); |
David Garcia Quintas | dd2ebee | 2015-06-23 18:42:17 -0700 | [diff] [blame] | 97 | if (f->server) { |
| 98 | grpc_server_destroy(f->server); |
| 99 | } |
Nicolas "Pixel" Noble | 9a123df | 2015-07-29 23:45:08 +0200 | [diff] [blame] | 100 | f->server = grpc_server_create(ffd->server_args_compression, NULL); |
| 101 | grpc_server_register_completion_queue(f->server, f->cq, NULL); |
Craig Tiller | c5ae3eb | 2015-08-03 10:42:22 -0700 | [diff] [blame] | 102 | GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr)); |
David Garcia Quintas | dd2ebee | 2015-06-23 18:42:17 -0700 | [diff] [blame] | 103 | grpc_server_start(f->server); |
| 104 | } |
| 105 | |
| 106 | void chttp2_tear_down_fullstack_compression(grpc_end2end_test_fixture *f) { |
| 107 | fullstack_compression_fixture_data *ffd = f->fixture_data; |
| 108 | grpc_channel_args_destroy(ffd->client_args_compression); |
| 109 | grpc_channel_args_destroy(ffd->server_args_compression); |
| 110 | gpr_free(ffd->localaddr); |
| 111 | gpr_free(ffd); |
| 112 | } |
| 113 | |
| 114 | /* All test configurations */ |
| 115 | static grpc_end2end_test_config configs[] = { |
| 116 | {"chttp2/fullstack_compression", FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION, |
| 117 | chttp2_create_fixture_fullstack_compression, |
| 118 | chttp2_init_client_fullstack_compression, |
| 119 | chttp2_init_server_fullstack_compression, |
| 120 | chttp2_tear_down_fullstack_compression}, |
| 121 | }; |
| 122 | |
| 123 | int main(int argc, char **argv) { |
| 124 | size_t i; |
| 125 | |
| 126 | grpc_test_init(argc, argv); |
| 127 | grpc_init(); |
| 128 | |
| 129 | for (i = 0; i < sizeof(configs) / sizeof(*configs); i++) { |
Craig Tiller | 0fe5ee7 | 2015-12-22 12:50:36 -0800 | [diff] [blame] | 130 | grpc_end2end_tests(argc, argv, configs[i]); |
David Garcia Quintas | dd2ebee | 2015-06-23 18:42:17 -0700 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | grpc_shutdown(); |
| 134 | |
| 135 | return 0; |
| 136 | } |