blob: 9f6ad980063f35d58388ee8d9fb01c5cc4dd62ba [file] [log] [blame]
nnoble0c475f02014-12-05 15:37:39 -08001/*
2 *
Craig Tiller06059952015-02-18 08:34:56 -08003 * Copyright 2015, Google Inc.
nnoble0c475f02014-12-05 15:37:39 -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
nnoble0c475f02014-12-05 15:37:39 -080038#include "src/core/channel/client_channel.h"
39#include "src/core/channel/connected_channel.h"
40#include "src/core/channel/http_filter.h"
klempnercd45aad2014-12-23 15:53:16 -080041#include "src/core/channel/http_client_filter.h"
nnoble0c475f02014-12-05 15:37:39 -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"
nnoble0c475f02014-12-05 15:37:39 -080045#include "src/core/surface/channel.h"
46#include "src/core/surface/client.h"
47#include "src/core/surface/server.h"
nnoble0c475f02014-12-05 15:37:39 -080048#include "src/core/transport/chttp2_transport.h"
49#include <grpc/support/alloc.h>
50#include <grpc/support/log.h>
51#include <grpc/support/sync.h>
52#include <grpc/support/thd.h>
53#include <grpc/support/useful.h>
54#include "test/core/util/port.h"
55#include "test/core/util/test_config.h"
56
nnoble0c475f02014-12-05 15:37:39 -080057/* chttp2 transport that is immediately available (used for testing
58 connected_channel without a client_channel */
59
60static grpc_transport_setup_result server_setup_transport(
61 void *ts, grpc_transport *transport, grpc_mdctx *mdctx) {
62 grpc_end2end_test_fixture *f = ts;
63 static grpc_channel_filter const *extra_filters[] = {&grpc_http_server_filter,
64 &grpc_http_filter};
65 return grpc_server_setup_transport(f->server, transport, extra_filters,
66 GPR_ARRAY_SIZE(extra_filters), mdctx);
67}
68
69typedef struct {
70 grpc_end2end_test_fixture *f;
71 grpc_channel_args *client_args;
72} sp_client_setup;
73
74static grpc_transport_setup_result client_setup_transport(
75 void *ts, grpc_transport *transport, grpc_mdctx *mdctx) {
76 sp_client_setup *cs = ts;
77
klempnercd45aad2014-12-23 15:53:16 -080078 const grpc_channel_filter *filters[] = {
79 &grpc_client_surface_filter, &grpc_http_client_filter, &grpc_http_filter,
80 &grpc_connected_channel_filter};
nnoble0c475f02014-12-05 15:37:39 -080081 size_t nfilters = sizeof(filters) / sizeof(*filters);
82 grpc_channel *channel = grpc_channel_create_from_filters(
83 filters, nfilters, cs->client_args, mdctx, 1);
84
85 cs->f->client = channel;
86
87 return grpc_connected_channel_bind_transport(
88 grpc_channel_get_channel_stack(channel), transport);
89}
90
nnoble0c475f02014-12-05 15:37:39 -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));
nnoble0c475f02014-12-05 15:37:39 -080094
95 grpc_end2end_test_fixture f;
ctillerc6d61c42014-12-15 14:52:08 -080096 memset(&f, 0, sizeof(f));
nnoble0c475f02014-12-05 15:37:39 -080097 f.fixture_data = sfd;
98 f.client_cq = grpc_completion_queue_create();
99 f.server_cq = grpc_completion_queue_create();
nnoble0c475f02014-12-05 15:37:39 -0800100
ctiller18b49ab2014-12-09 14:39:16 -0800101 *sfd = grpc_iomgr_create_endpoint_pair(1);
nnoble0c475f02014-12-05 15:37:39 -0800102
103 return f;
104}
105
106static void chttp2_init_client_socketpair(grpc_end2end_test_fixture *f,
107 grpc_channel_args *client_args) {
ctiller18b49ab2014-12-09 14:39:16 -0800108 grpc_endpoint_pair *sfd = f->fixture_data;
nnoble0c475f02014-12-05 15:37:39 -0800109 sp_client_setup cs;
110 cs.client_args = client_args;
111 cs.f = f;
nnoble0c475f02014-12-05 15:37:39 -0800112 grpc_create_chttp2_transport(client_setup_transport, &cs, client_args,
ctiller18b49ab2014-12-09 14:39:16 -0800113 sfd->client, NULL, 0, grpc_mdctx_create(), 1);
nnoble0c475f02014-12-05 15:37:39 -0800114 GPR_ASSERT(f->client);
115}
116
117static void chttp2_init_server_socketpair(grpc_end2end_test_fixture *f,
118 grpc_channel_args *server_args) {
ctiller18b49ab2014-12-09 14:39:16 -0800119 grpc_endpoint_pair *sfd = f->fixture_data;
ctillerc6d61c42014-12-15 14:52:08 -0800120 GPR_ASSERT(!f->server);
121 f->server =
122 grpc_server_create_from_filters(f->server_cq, NULL, 0, server_args);
ctiller58393c22015-01-07 14:03:30 -0800123 grpc_server_start(f->server);
ctiller18b49ab2014-12-09 14:39:16 -0800124 grpc_create_chttp2_transport(server_setup_transport, f, server_args,
125 sfd->server, NULL, 0, grpc_mdctx_create(), 0);
nnoble0c475f02014-12-05 15:37:39 -0800126}
127
128static void chttp2_tear_down_socketpair(grpc_end2end_test_fixture *f) {
129 gpr_free(f->fixture_data);
130}
131
132/* All test configurations */
133static grpc_end2end_test_config configs[] = {
Craig Tillerb5dcec52015-01-13 11:13:42 -0800134 {"chttp2/socketpair_one_byte_at_a_time", 0,
135 chttp2_create_fixture_socketpair, chttp2_init_client_socketpair,
Craig Tiller8ad8a412015-02-25 08:36:40 -0800136 chttp2_init_server_socketpair, chttp2_tear_down_socketpair},
137};
nnoble0c475f02014-12-05 15:37:39 -0800138
139int main(int argc, char **argv) {
140 size_t i;
141
142 grpc_test_init(argc, argv);
143 grpc_init();
144
145 for (i = 0; i < sizeof(configs) / sizeof(*configs); i++) {
146 grpc_end2end_tests(configs[i]);
147 }
148
149 grpc_shutdown();
150
151 return 0;
Craig Tiller190d3602015-02-18 09:23:38 -0800152}