blob: 511c8b1a46a4753c747cf54d84854c4301426e08 [file] [log] [blame]
Craig Tillereadd9a32015-05-18 14:52:12 -07001/*
2 *
3 * Copyright 2015, 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 "src/core/channel/client_channel.h"
39#include "src/core/channel/connected_channel.h"
40#include "src/core/channel/http_client_filter.h"
41#include "src/core/channel/http_server_filter.h"
David Garcia Quintas5927aec2015-06-18 17:24:44 -070042#include "src/core/channel/compress_filter.h"
Craig Tillereadd9a32015-05-18 14:52:12 -070043#include "src/core/iomgr/endpoint_pair.h"
44#include "src/core/iomgr/iomgr.h"
45#include "src/core/support/env.h"
46#include "src/core/surface/channel.h"
Craig Tillereadd9a32015-05-18 14:52:12 -070047#include "src/core/surface/server.h"
48#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
57/* chttp2 transport that is immediately available (used for testing
58 connected_channel without a client_channel */
59
Craig Tillerb2b42612015-11-20 12:02:17 -080060static void server_setup_transport(void *ts, grpc_transport *transport) {
Craig Tillereadd9a32015-05-18 14:52:12 -070061 grpc_end2end_test_fixture *f = ts;
62 static grpc_channel_filter const *extra_filters[] = {
Craig Tillera82950e2015-09-22 12:33:20 -070063 &grpc_http_server_filter};
Craig Tillerf5768a62015-09-22 10:54:34 -070064 grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
Craig Tillera82950e2015-09-22 12:33:20 -070065 grpc_server_setup_transport(&exec_ctx, f->server, transport, extra_filters,
Craig Tillerb2b42612015-11-20 12:02:17 -080066 GPR_ARRAY_SIZE(extra_filters),
Craig Tillera82950e2015-09-22 12:33:20 -070067 grpc_server_get_channel_args(f->server));
68 grpc_exec_ctx_finish(&exec_ctx);
Craig Tillereadd9a32015-05-18 14:52:12 -070069}
70
Craig Tillera82950e2015-09-22 12:33:20 -070071typedef struct {
Craig Tillereadd9a32015-05-18 14:52:12 -070072 grpc_end2end_test_fixture *f;
73 grpc_channel_args *client_args;
74} sp_client_setup;
75
Craig Tillera82950e2015-09-22 12:33:20 -070076static void client_setup_transport(grpc_exec_ctx *exec_ctx, void *ts,
Craig Tillerb2b42612015-11-20 12:02:17 -080077 grpc_transport *transport) {
Craig Tillereadd9a32015-05-18 14:52:12 -070078 sp_client_setup *cs = ts;
79
Craig Tillera82950e2015-09-22 12:33:20 -070080 const grpc_channel_filter *filters[] = {&grpc_http_client_filter,
81 &grpc_compress_filter,
82 &grpc_connected_channel_filter};
83 size_t nfilters = sizeof(filters) / sizeof(*filters);
Craig Tillerb2b42612015-11-20 12:02:17 -080084 grpc_channel *channel = grpc_channel_create_from_filters(
85 exec_ctx, "socketpair-target", filters, nfilters, cs->client_args, 1);
Craig Tillereadd9a32015-05-18 14:52:12 -070086
87 cs->f->client = channel;
88
Craig Tillera82950e2015-09-22 12:33:20 -070089 grpc_connected_channel_bind_transport(grpc_channel_get_channel_stack(channel),
90 transport);
Craig Tillereadd9a32015-05-18 14:52:12 -070091}
92
Craig Tillera82950e2015-09-22 12:33:20 -070093static grpc_end2end_test_fixture chttp2_create_fixture_socketpair(
94 grpc_channel_args *client_args, grpc_channel_args *server_args) {
95 grpc_endpoint_pair *sfd = gpr_malloc(sizeof(grpc_endpoint_pair));
Craig Tillereadd9a32015-05-18 14:52:12 -070096
97 grpc_end2end_test_fixture f;
Craig Tillera82950e2015-09-22 12:33:20 -070098 memset(&f, 0, sizeof(f));
Craig Tillereadd9a32015-05-18 14:52:12 -070099 f.fixture_data = sfd;
Craig Tillera82950e2015-09-22 12:33:20 -0700100 f.cq = grpc_completion_queue_create(NULL);
Craig Tillereadd9a32015-05-18 14:52:12 -0700101
Craig Tillera82950e2015-09-22 12:33:20 -0700102 *sfd = grpc_iomgr_create_endpoint_pair("fixture", 65536);
Craig Tillereadd9a32015-05-18 14:52:12 -0700103
104 return f;
105}
106
Craig Tillera82950e2015-09-22 12:33:20 -0700107static void chttp2_init_client_socketpair(grpc_end2end_test_fixture *f,
108 grpc_channel_args *client_args) {
Craig Tillerf5768a62015-09-22 10:54:34 -0700109 grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
Craig Tillereadd9a32015-05-18 14:52:12 -0700110 grpc_endpoint_pair *sfd = f->fixture_data;
Craig Tilleracf0f072015-06-29 08:24:16 -0700111 grpc_transport *transport;
Craig Tillereadd9a32015-05-18 14:52:12 -0700112 sp_client_setup cs;
113 cs.client_args = client_args;
114 cs.f = f;
Craig Tillerb2b42612015-11-20 12:02:17 -0800115 transport =
116 grpc_create_chttp2_transport(&exec_ctx, client_args, sfd->client, 1);
117 client_setup_transport(&exec_ctx, &cs, transport);
Craig Tillera82950e2015-09-22 12:33:20 -0700118 GPR_ASSERT(f->client);
119 grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL, 0);
120 grpc_exec_ctx_finish(&exec_ctx);
Craig Tillereadd9a32015-05-18 14:52:12 -0700121}
122
Craig Tillera82950e2015-09-22 12:33:20 -0700123static void chttp2_init_server_socketpair(grpc_end2end_test_fixture *f,
124 grpc_channel_args *server_args) {
Craig Tillerf5768a62015-09-22 10:54:34 -0700125 grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
Craig Tillereadd9a32015-05-18 14:52:12 -0700126 grpc_endpoint_pair *sfd = f->fixture_data;
Craig Tilleracf0f072015-06-29 08:24:16 -0700127 grpc_transport *transport;
Craig Tillera82950e2015-09-22 12:33:20 -0700128 GPR_ASSERT(!f->server);
129 f->server = grpc_server_create_from_filters(NULL, 0, server_args);
130 grpc_server_register_completion_queue(f->server, f->cq, NULL);
131 grpc_server_start(f->server);
Craig Tillerb2b42612015-11-20 12:02:17 -0800132 transport =
133 grpc_create_chttp2_transport(&exec_ctx, server_args, sfd->server, 0);
134 server_setup_transport(f, transport);
Craig Tillera82950e2015-09-22 12:33:20 -0700135 grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL, 0);
136 grpc_exec_ctx_finish(&exec_ctx);
Craig Tillereadd9a32015-05-18 14:52:12 -0700137}
138
Craig Tillera82950e2015-09-22 12:33:20 -0700139static void chttp2_tear_down_socketpair(grpc_end2end_test_fixture *f) {
140 gpr_free(f->fixture_data);
Craig Tillereadd9a32015-05-18 14:52:12 -0700141}
142
143/* All test configurations */
144static grpc_end2end_test_config configs[] = {
Craig Tillera82950e2015-09-22 12:33:20 -0700145 {"chttp2/socketpair", 0, chttp2_create_fixture_socketpair,
146 chttp2_init_client_socketpair, chttp2_init_server_socketpair,
147 chttp2_tear_down_socketpair},
Craig Tillereadd9a32015-05-18 14:52:12 -0700148};
149
Craig Tillera82950e2015-09-22 12:33:20 -0700150int main(int argc, char **argv) {
Craig Tillereadd9a32015-05-18 14:52:12 -0700151 size_t i;
Craig Tillerf5768a62015-09-22 10:54:34 -0700152 grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
Craig Tillereadd9a32015-05-18 14:52:12 -0700153
154 /* force tracing on, with a value to force many
155 code paths in trace.c to be taken */
Craig Tillera82950e2015-09-22 12:33:20 -0700156 gpr_setenv("GRPC_TRACE", "doesnt-exist,http,all");
Craig Tiller2d91b5d2015-08-07 07:39:27 -0700157#ifdef GPR_POSIX_SOCKET
Craig Tillera82950e2015-09-22 12:33:20 -0700158 g_fixture_slowdown_factor = isatty(STDOUT_FILENO) ? 10.0 : 1.0;
Craig Tiller2d91b5d2015-08-07 07:39:27 -0700159#else
Craig Tiller7b9ed352015-08-04 08:55:12 -0700160 g_fixture_slowdown_factor = 10.0;
Craig Tiller2d91b5d2015-08-07 07:39:27 -0700161#endif
Craig Tillereadd9a32015-05-18 14:52:12 -0700162
Craig Tillera82950e2015-09-22 12:33:20 -0700163 grpc_test_init(argc, argv);
164 grpc_init();
165 grpc_exec_ctx_finish(&exec_ctx);
Craig Tillereadd9a32015-05-18 14:52:12 -0700166
Craig Tillera82950e2015-09-22 12:33:20 -0700167 GPR_ASSERT(0 == grpc_tracer_set_enabled("also-doesnt-exist", 0));
168 GPR_ASSERT(1 == grpc_tracer_set_enabled("http", 1));
169 GPR_ASSERT(1 == grpc_tracer_set_enabled("all", 1));
Craig Tilleraf7abf92015-06-03 17:18:58 -0700170
Craig Tillera82950e2015-09-22 12:33:20 -0700171 for (i = 0; i < sizeof(configs) / sizeof(*configs); i++) {
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800172 grpc_end2end_tests(argc, argv, configs[i]);
Craig Tillera82950e2015-09-22 12:33:20 -0700173 }
Craig Tillereadd9a32015-05-18 14:52:12 -0700174
Craig Tillera82950e2015-09-22 12:33:20 -0700175 grpc_shutdown();
Craig Tillereadd9a32015-05-18 14:52:12 -0700176
177 return 0;
178}