blob: 8d8d5e7d6c406cac01c542b2c308d88b29bb9659 [file] [log] [blame]
David Garcia Quintasdd2ebee2015-06-23 18:42:17 -07001/*
2 *
Craig Tiller2e190362016-03-25 14:33:26 -07003 * Copyright 2015-2016, Google Inc.
David Garcia Quintasdd2ebee2015-06-23 18:42:17 -07004 * 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 Tillerf40df232016-03-25 13:38:14 -070038#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 Tilleradcb92d2016-03-28 10:14:05 -070044#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
Craig Tiller9533d042016-03-25 17:11:06 -070045#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 Quintasdd2ebee2015-06-23 18:42:17 -070051#include "test/core/util/port.h"
52#include "test/core/util/test_config.h"
53
54typedef struct fullstack_compression_fixture_data {
55 char *localaddr;
Craig Tiller17effab2015-08-04 08:19:36 -070056 grpc_channel_args *client_args_compression;
57 grpc_channel_args *server_args_compression;
David Garcia Quintasdd2ebee2015-06-23 18:42:17 -070058} fullstack_compression_fixture_data;
59
60static 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 Quintas4e403362015-07-01 16:45:34 -070066 memset(ffd, 0, sizeof(fullstack_compression_fixture_data));
David Garcia Quintasdd2ebee2015-06-23 18:42:17 -070067
68 gpr_join_host_port(&ffd->localaddr, "localhost", port);
69
David Garcia Quintas4e403362015-07-01 16:45:34 -070070 memset(&f, 0, sizeof(f));
David Garcia Quintasdd2ebee2015-06-23 18:42:17 -070071 f.fixture_data = ffd;
Nicolas "Pixel" Noble9a123df2015-07-29 23:45:08 +020072 f.cq = grpc_completion_queue_create(NULL);
David Garcia Quintasdd2ebee2015-06-23 18:42:17 -070073
74 return f;
75}
76
77void chttp2_init_client_fullstack_compression(grpc_end2end_test_fixture *f,
Craig Tiller17effab2015-08-04 08:19:36 -070078 grpc_channel_args *client_args) {
David Garcia Quintasdd2ebee2015-06-23 18:42:17 -070079 fullstack_compression_fixture_data *ffd = f->fixture_data;
David Garcia Quintas4e403362015-07-01 16:45:34 -070080 if (ffd->client_args_compression != NULL) {
81 grpc_channel_args_destroy(ffd->client_args_compression);
82 }
David Garcia Quintascadbf222015-07-17 15:33:13 -070083 ffd->client_args_compression = grpc_channel_args_set_compression_algorithm(
84 client_args, GRPC_COMPRESS_GZIP);
Craig Tiller4a4f1492015-07-21 16:32:29 -070085 f->client = grpc_insecure_channel_create(ffd->localaddr,
Nicolas "Pixel" Noble9d72b142015-08-08 01:45:38 +020086 ffd->client_args_compression, NULL);
David Garcia Quintasdd2ebee2015-06-23 18:42:17 -070087}
88
89void chttp2_init_server_fullstack_compression(grpc_end2end_test_fixture *f,
Craig Tiller17effab2015-08-04 08:19:36 -070090 grpc_channel_args *server_args) {
David Garcia Quintasdd2ebee2015-06-23 18:42:17 -070091 fullstack_compression_fixture_data *ffd = f->fixture_data;
David Garcia Quintas4e403362015-07-01 16:45:34 -070092 if (ffd->server_args_compression != NULL) {
93 grpc_channel_args_destroy(ffd->server_args_compression);
94 }
David Garcia Quintascadbf222015-07-17 15:33:13 -070095 ffd->server_args_compression = grpc_channel_args_set_compression_algorithm(
96 server_args, GRPC_COMPRESS_GZIP);
David Garcia Quintasdd2ebee2015-06-23 18:42:17 -070097 if (f->server) {
98 grpc_server_destroy(f->server);
99 }
Nicolas "Pixel" Noble9a123df2015-07-29 23:45:08 +0200100 f->server = grpc_server_create(ffd->server_args_compression, NULL);
101 grpc_server_register_completion_queue(f->server, f->cq, NULL);
Craig Tillerc5ae3eb2015-08-03 10:42:22 -0700102 GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr));
David Garcia Quintasdd2ebee2015-06-23 18:42:17 -0700103 grpc_server_start(f->server);
104}
105
106void 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 */
115static 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
123int 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 Tiller0fe5ee72015-12-22 12:50:36 -0800130 grpc_end2end_tests(argc, argv, configs[i]);
David Garcia Quintasdd2ebee2015-06-23 18:42:17 -0700131 }
132
133 grpc_shutdown();
134
135 return 0;
136}