blob: 5fc8b325831076fd63ea86336826fea31b4fea09 [file] [log] [blame]
Craig Tiller9a8df282016-02-19 09:08:09 -08001/*
2 *
Craig Tiller7a1aab62016-02-19 13:03:42 -08003 * Copyright 2015-2016, Google Inc.
Craig Tiller9a8df282016-02-19 09:08:09 -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"
35
36#include <string.h>
37
Craig Tillerf40df232016-03-25 13:38:14 -070038#include <grpc/support/alloc.h>
39#include <grpc/support/log.h>
40#include <grpc/support/sync.h>
41#include <grpc/support/thd.h>
42#include <grpc/support/useful.h>
Craig Tilleradcb92d2016-03-28 10:14:05 -070043#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
Craig Tiller9533d042016-03-25 17:11:06 -070044#include "src/core/lib/channel/client_channel.h"
45#include "src/core/lib/channel/compress_filter.h"
46#include "src/core/lib/channel/connected_channel.h"
47#include "src/core/lib/channel/http_client_filter.h"
48#include "src/core/lib/channel/http_server_filter.h"
49#include "src/core/lib/iomgr/endpoint_pair.h"
50#include "src/core/lib/iomgr/iomgr.h"
51#include "src/core/lib/support/env.h"
52#include "src/core/lib/surface/channel.h"
53#include "src/core/lib/surface/server.h"
Craig Tiller9a8df282016-02-19 09:08:09 -080054#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
60static void server_setup_transport(void *ts, grpc_transport *transport) {
61 grpc_end2end_test_fixture *f = ts;
Craig Tiller9a8df282016-02-19 09:08:09 -080062 grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
Craig Tillerd78d1642016-02-21 22:18:51 -080063 grpc_server_setup_transport(&exec_ctx, f->server, transport,
Craig Tiller9a8df282016-02-19 09:08:09 -080064 grpc_server_get_channel_args(f->server));
65 grpc_exec_ctx_finish(&exec_ctx);
66}
67
68typedef struct {
69 grpc_end2end_test_fixture *f;
70 grpc_channel_args *client_args;
71} sp_client_setup;
72
73static void client_setup_transport(grpc_exec_ctx *exec_ctx, void *ts,
74 grpc_transport *transport) {
75 sp_client_setup *cs = ts;
76
Craig Tillerd78d1642016-02-21 22:18:51 -080077 cs->f->client =
78 grpc_channel_create(exec_ctx, "socketpair-target", cs->client_args,
79 GRPC_CLIENT_DIRECT_CHANNEL, transport);
Craig Tiller9a8df282016-02-19 09:08:09 -080080}
81
82static grpc_end2end_test_fixture chttp2_create_fixture_socketpair(
83 grpc_channel_args *client_args, grpc_channel_args *server_args) {
84 grpc_endpoint_pair *sfd = gpr_malloc(sizeof(grpc_endpoint_pair));
85
86 grpc_end2end_test_fixture f;
87 memset(&f, 0, sizeof(f));
88 f.fixture_data = sfd;
89 f.cq = grpc_completion_queue_create(NULL);
90
91 *sfd = grpc_iomgr_create_endpoint_pair("fixture", 65536);
92
93 return f;
94}
95
96static void chttp2_init_client_socketpair(grpc_end2end_test_fixture *f,
97 grpc_channel_args *client_args) {
98 grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
99 grpc_endpoint_pair *sfd = f->fixture_data;
100 grpc_transport *transport;
101 sp_client_setup cs;
102 cs.client_args = client_args;
103 cs.f = f;
104 transport =
105 grpc_create_chttp2_transport(&exec_ctx, client_args, sfd->client, 1);
106 client_setup_transport(&exec_ctx, &cs, transport);
107 GPR_ASSERT(f->client);
108 grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL, 0);
109 grpc_exec_ctx_finish(&exec_ctx);
110}
111
112static void chttp2_init_server_socketpair(grpc_end2end_test_fixture *f,
113 grpc_channel_args *server_args) {
114 grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
115 grpc_endpoint_pair *sfd = f->fixture_data;
116 grpc_transport *transport;
117 GPR_ASSERT(!f->server);
Craig Tillerde676262016-02-19 12:28:34 -0800118 f->server = grpc_server_create(server_args, NULL);
Craig Tiller9a8df282016-02-19 09:08:09 -0800119 grpc_server_register_completion_queue(f->server, f->cq, NULL);
120 grpc_server_start(f->server);
121 transport =
122 grpc_create_chttp2_transport(&exec_ctx, server_args, sfd->server, 0);
123 server_setup_transport(f, transport);
124 grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL, 0);
125 grpc_exec_ctx_finish(&exec_ctx);
126}
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[] = {
134 {"chttp2/socketpair", 0, chttp2_create_fixture_socketpair,
135 chttp2_init_client_socketpair, chttp2_init_server_socketpair,
136 chttp2_tear_down_socketpair},
137};
138
139int main(int argc, char **argv) {
140 size_t i;
141 grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
142
143 /* force tracing on, with a value to force many
144 code paths in trace.c to be taken */
145 gpr_setenv("GRPC_TRACE", "doesnt-exist,http,all");
146#ifdef GPR_POSIX_SOCKET
147 g_fixture_slowdown_factor = isatty(STDOUT_FILENO) ? 10.0 : 1.0;
148#else
149 g_fixture_slowdown_factor = 10.0;
150#endif
151
152 grpc_test_init(argc, argv);
153 grpc_init();
154 grpc_exec_ctx_finish(&exec_ctx);
155
156 GPR_ASSERT(0 == grpc_tracer_set_enabled("also-doesnt-exist", 0));
157 GPR_ASSERT(1 == grpc_tracer_set_enabled("http", 1));
158 GPR_ASSERT(1 == grpc_tracer_set_enabled("all", 1));
159
160 for (i = 0; i < sizeof(configs) / sizeof(*configs); i++) {
161 grpc_end2end_tests(argc, argv, configs[i]);
162 }
163
164 grpc_shutdown();
165
166 return 0;
167}