Line data Source code
1 : /*
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"
42 : #include "src/core/channel/compress_filter.h"
43 : #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"
47 : #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 :
60 148 : static void server_setup_transport(void *ts, grpc_transport *transport,
61 : grpc_mdctx *mdctx) {
62 148 : grpc_end2end_test_fixture *f = ts;
63 : static grpc_channel_filter const *extra_filters[] = {
64 : &grpc_http_server_filter};
65 148 : grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
66 148 : grpc_server_setup_transport(&exec_ctx, f->server, transport, extra_filters,
67 : GPR_ARRAY_SIZE(extra_filters), mdctx,
68 : grpc_server_get_channel_args(f->server));
69 148 : grpc_exec_ctx_finish(&exec_ctx);
70 148 : }
71 :
72 : typedef struct {
73 : grpc_end2end_test_fixture *f;
74 : grpc_channel_args *client_args;
75 : } sp_client_setup;
76 :
77 148 : static void client_setup_transport(grpc_exec_ctx *exec_ctx, void *ts,
78 : grpc_transport *transport,
79 : grpc_mdctx *mdctx) {
80 148 : sp_client_setup *cs = ts;
81 :
82 148 : const grpc_channel_filter *filters[] = {&grpc_http_client_filter,
83 : &grpc_compress_filter,
84 : &grpc_connected_channel_filter};
85 148 : size_t nfilters = sizeof(filters) / sizeof(*filters);
86 148 : grpc_channel *channel =
87 : grpc_channel_create_from_filters(exec_ctx, "socketpair-target", filters,
88 148 : nfilters, cs->client_args, mdctx, 1);
89 :
90 148 : cs->f->client = channel;
91 :
92 148 : grpc_connected_channel_bind_transport(grpc_channel_get_channel_stack(channel),
93 : transport);
94 148 : }
95 :
96 148 : static grpc_end2end_test_fixture chttp2_create_fixture_socketpair(
97 : grpc_channel_args *client_args, grpc_channel_args *server_args) {
98 148 : grpc_endpoint_pair *sfd = gpr_malloc(sizeof(grpc_endpoint_pair));
99 :
100 : grpc_end2end_test_fixture f;
101 148 : memset(&f, 0, sizeof(f));
102 148 : f.fixture_data = sfd;
103 148 : f.cq = grpc_completion_queue_create(NULL);
104 :
105 148 : *sfd = grpc_iomgr_create_endpoint_pair("fixture", 65536);
106 :
107 148 : return f;
108 : }
109 :
110 148 : static void chttp2_init_client_socketpair(grpc_end2end_test_fixture *f,
111 : grpc_channel_args *client_args) {
112 148 : grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
113 148 : grpc_endpoint_pair *sfd = f->fixture_data;
114 : grpc_transport *transport;
115 148 : grpc_mdctx *mdctx = grpc_mdctx_create();
116 : sp_client_setup cs;
117 148 : cs.client_args = client_args;
118 148 : cs.f = f;
119 148 : transport = grpc_create_chttp2_transport(&exec_ctx, client_args, sfd->client,
120 : mdctx, 1);
121 148 : client_setup_transport(&exec_ctx, &cs, transport, mdctx);
122 148 : GPR_ASSERT(f->client);
123 148 : grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL, 0);
124 148 : grpc_exec_ctx_finish(&exec_ctx);
125 148 : }
126 :
127 148 : static void chttp2_init_server_socketpair(grpc_end2end_test_fixture *f,
128 : grpc_channel_args *server_args) {
129 148 : grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
130 148 : grpc_endpoint_pair *sfd = f->fixture_data;
131 148 : grpc_mdctx *mdctx = grpc_mdctx_create();
132 : grpc_transport *transport;
133 148 : GPR_ASSERT(!f->server);
134 148 : f->server = grpc_server_create_from_filters(NULL, 0, server_args);
135 148 : grpc_server_register_completion_queue(f->server, f->cq, NULL);
136 148 : grpc_server_start(f->server);
137 148 : transport = grpc_create_chttp2_transport(&exec_ctx, server_args, sfd->server,
138 : mdctx, 0);
139 148 : server_setup_transport(f, transport, mdctx);
140 148 : grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL, 0);
141 148 : grpc_exec_ctx_finish(&exec_ctx);
142 148 : }
143 :
144 148 : static void chttp2_tear_down_socketpair(grpc_end2end_test_fixture *f) {
145 148 : gpr_free(f->fixture_data);
146 148 : }
147 :
148 : /* All test configurations */
149 : static grpc_end2end_test_config configs[] = {
150 : {"chttp2/socketpair", 0, chttp2_create_fixture_socketpair,
151 : chttp2_init_client_socketpair, chttp2_init_server_socketpair,
152 : chttp2_tear_down_socketpair},
153 : };
154 :
155 57 : int main(int argc, char **argv) {
156 : size_t i;
157 57 : grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
158 :
159 : /* force tracing on, with a value to force many
160 : code paths in trace.c to be taken */
161 57 : gpr_setenv("GRPC_TRACE", "doesnt-exist,http,all");
162 : #ifdef GPR_POSIX_SOCKET
163 57 : g_fixture_slowdown_factor = isatty(STDOUT_FILENO) ? 10.0 : 1.0;
164 : #else
165 : g_fixture_slowdown_factor = 10.0;
166 : #endif
167 :
168 57 : grpc_test_init(argc, argv);
169 57 : grpc_init();
170 57 : grpc_exec_ctx_finish(&exec_ctx);
171 :
172 57 : GPR_ASSERT(0 == grpc_tracer_set_enabled("also-doesnt-exist", 0));
173 57 : GPR_ASSERT(1 == grpc_tracer_set_enabled("http", 1));
174 57 : GPR_ASSERT(1 == grpc_tracer_set_enabled("all", 1));
175 :
176 114 : for (i = 0; i < sizeof(configs) / sizeof(*configs); i++) {
177 57 : grpc_end2end_tests(configs[i]);
178 : }
179 :
180 57 : grpc_shutdown();
181 :
182 57 : return 0;
183 : }
|