blob: 807fc8e7bc3f29972be93b37bc5c886b78f24316 [file] [log] [blame]
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001/*
2 *
Craig Tiller06059952015-02-18 08:34:56 -08003 * Copyright 2015, Google Inc.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08004 * 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"
ctillerc6d61c42014-12-15 14:52:08 -080035
36#include <string.h>
37
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080038#include "src/core/channel/client_channel.h"
David Garcia Quintas17bb6492015-07-08 15:16:22 -070039#include "src/core/channel/compress_filter.h"
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080040#include "src/core/channel/connected_channel.h"
klempnercd45aad2014-12-23 15:53:16 -080041#include "src/core/channel/http_client_filter.h"
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080042#include "src/core/channel/http_server_filter.h"
ctiller18b49ab2014-12-09 14:39:16 -080043#include "src/core/iomgr/endpoint_pair.h"
44#include "src/core/iomgr/iomgr.h"
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080045#include "src/core/surface/channel.h"
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080046#include "src/core/surface/server.h"
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080047#include "src/core/transport/chttp2_transport.h"
48#include <grpc/support/alloc.h>
49#include <grpc/support/log.h>
50#include <grpc/support/sync.h>
51#include <grpc/support/thd.h>
52#include <grpc/support/useful.h>
53#include "test/core/util/port.h"
54#include "test/core/util/test_config.h"
55
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080056/* chttp2 transport that is immediately available (used for testing
57 connected_channel without a client_channel */
58
Craig Tiller079a11b2015-06-30 10:07:15 -070059static void server_setup_transport(void *ts, grpc_transport *transport,
60 grpc_mdctx *mdctx) {
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080061 grpc_end2end_test_fixture *f = ts;
Craig Tiller06aeea72015-04-23 10:54:45 -070062 static grpc_channel_filter const *extra_filters[] = {
63 &grpc_http_server_filter};
Craig Tilleracf0f072015-06-29 08:24:16 -070064 grpc_server_setup_transport(f->server, transport, extra_filters,
Craig Tiller079a11b2015-06-30 10:07:15 -070065 GPR_ARRAY_SIZE(extra_filters), mdctx,
66 grpc_server_get_channel_args(f->server));
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080067}
68
69typedef struct {
70 grpc_end2end_test_fixture *f;
71 grpc_channel_args *client_args;
72} sp_client_setup;
73
Craig Tiller079a11b2015-06-30 10:07:15 -070074static void client_setup_transport(void *ts, grpc_transport *transport,
75 grpc_mdctx *mdctx) {
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080076 sp_client_setup *cs = ts;
77
Craig Tilleracf0f072015-06-29 08:24:16 -070078 const grpc_channel_filter *filters[] = {&grpc_http_client_filter,
David Garcia Quintas5927aec2015-06-18 17:24:44 -070079 &grpc_compress_filter,
Craig Tiller06aeea72015-04-23 10:54:45 -070080 &grpc_connected_channel_filter};
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080081 size_t nfilters = sizeof(filters) / sizeof(*filters);
82 grpc_channel *channel = grpc_channel_create_from_filters(
Craig Tiller1b22b9d2015-07-20 13:42:22 -070083 "socketpair-target", filters, nfilters, cs->client_args, mdctx, 1);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080084
85 cs->f->client = channel;
86
Craig Tiller079a11b2015-06-30 10:07:15 -070087 grpc_connected_channel_bind_transport(grpc_channel_get_channel_stack(channel),
88 transport);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080089}
90
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080091static grpc_end2end_test_fixture chttp2_create_fixture_socketpair(
92 grpc_channel_args *client_args, grpc_channel_args *server_args) {
ctiller18b49ab2014-12-09 14:39:16 -080093 grpc_endpoint_pair *sfd = gpr_malloc(sizeof(grpc_endpoint_pair));
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080094
95 grpc_end2end_test_fixture f;
ctillerc6d61c42014-12-15 14:52:08 -080096 memset(&f, 0, sizeof(f));
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080097 f.fixture_data = sfd;
Craig Tiller65ad0a72015-05-11 10:38:07 -070098 f.cq = grpc_completion_queue_create();
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080099
Craig Tillerfa275a92015-06-01 13:55:54 -0700100 *sfd = grpc_iomgr_create_endpoint_pair("fixture", 65536);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800101
102 return f;
103}
104
105static void chttp2_init_client_socketpair(grpc_end2end_test_fixture *f,
106 grpc_channel_args *client_args) {
ctiller18b49ab2014-12-09 14:39:16 -0800107 grpc_endpoint_pair *sfd = f->fixture_data;
Craig Tilleracf0f072015-06-29 08:24:16 -0700108 grpc_transport *transport;
109 grpc_mdctx *mdctx = grpc_mdctx_create();
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800110 sp_client_setup cs;
111 cs.client_args = client_args;
112 cs.f = f;
Craig Tiller1dd70262015-07-06 11:45:30 -0700113 transport = grpc_create_chttp2_transport(client_args, sfd->client, mdctx, 1);
Craig Tilleracf0f072015-06-29 08:24:16 -0700114 client_setup_transport(&cs, transport, mdctx);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800115 GPR_ASSERT(f->client);
Craig Tiller1dd70262015-07-06 11:45:30 -0700116 grpc_chttp2_transport_start_reading(transport, NULL, 0);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800117}
118
119static void chttp2_init_server_socketpair(grpc_end2end_test_fixture *f,
120 grpc_channel_args *server_args) {
ctiller18b49ab2014-12-09 14:39:16 -0800121 grpc_endpoint_pair *sfd = f->fixture_data;
Craig Tilleracf0f072015-06-29 08:24:16 -0700122 grpc_mdctx *mdctx = grpc_mdctx_create();
123 grpc_transport *transport;
ctillerc6d61c42014-12-15 14:52:08 -0800124 GPR_ASSERT(!f->server);
Craig Tillerf9e6adf2015-05-06 11:45:59 -0700125 f->server = grpc_server_create_from_filters(NULL, 0, server_args);
Craig Tiller5532ae22015-05-11 10:40:19 -0700126 grpc_server_register_completion_queue(f->server, f->cq);
ctiller58393c22015-01-07 14:03:30 -0800127 grpc_server_start(f->server);
Craig Tiller1dd70262015-07-06 11:45:30 -0700128 transport = grpc_create_chttp2_transport(server_args, sfd->server, mdctx, 0);
Craig Tilleracf0f072015-06-29 08:24:16 -0700129 server_setup_transport(f, transport, mdctx);
Craig Tiller1dd70262015-07-06 11:45:30 -0700130 grpc_chttp2_transport_start_reading(transport, NULL, 0);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800131}
132
133static void chttp2_tear_down_socketpair(grpc_end2end_test_fixture *f) {
134 gpr_free(f->fixture_data);
135}
136
137/* All test configurations */
138static grpc_end2end_test_config configs[] = {
139 {"chttp2/socketpair", 0, chttp2_create_fixture_socketpair,
140 chttp2_init_client_socketpair, chttp2_init_server_socketpair,
Craig Tiller8ad8a412015-02-25 08:36:40 -0800141 chttp2_tear_down_socketpair},
142};
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800143
144int main(int argc, char **argv) {
145 size_t i;
146
147 grpc_test_init(argc, argv);
148 grpc_init();
149
150 for (i = 0; i < sizeof(configs) / sizeof(*configs); i++) {
151 grpc_end2end_tests(configs[i]);
152 }
153
154 grpc_shutdown();
155
156 return 0;
Craig Tiller190d3602015-02-18 09:23:38 -0800157}