blob: 6a504c6a9ca7f841ba3d2d770fa609c964f332a2 [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 Tiller9a8df282016-02-19 09:08:09 -080038#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 Tiller9533d042016-03-25 17:11:06 -070043#include "src/core/lib/channel/client_channel.h"
44#include "src/core/lib/channel/compress_filter.h"
45#include "src/core/lib/channel/connected_channel.h"
46#include "src/core/lib/channel/http_client_filter.h"
47#include "src/core/lib/channel/http_server_filter.h"
48#include "src/core/lib/iomgr/endpoint_pair.h"
49#include "src/core/lib/iomgr/iomgr.h"
50#include "src/core/lib/surface/channel.h"
51#include "src/core/lib/surface/server.h"
52#include "src/core/lib/transport/chttp2_transport.h"
Craig Tiller9a8df282016-02-19 09:08:09 -080053#include "test/core/util/port.h"
54#include "test/core/util/test_config.h"
55
56/* chttp2 transport that is immediately available (used for testing
57 connected_channel without a client_channel */
58
59static void server_setup_transport(void *ts, grpc_transport *transport) {
60 grpc_end2end_test_fixture *f = ts;
Craig Tiller9a8df282016-02-19 09:08:09 -080061 grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
Craig Tillerde676262016-02-19 12:28:34 -080062 grpc_server_setup_transport(&exec_ctx, f->server, transport,
Craig Tiller9a8df282016-02-19 09:08:09 -080063 grpc_server_get_channel_args(f->server));
64 grpc_exec_ctx_finish(&exec_ctx);
65}
66
67typedef struct {
68 grpc_end2end_test_fixture *f;
69 grpc_channel_args *client_args;
70} sp_client_setup;
71
72static void client_setup_transport(grpc_exec_ctx *exec_ctx, void *ts,
73 grpc_transport *transport) {
74 sp_client_setup *cs = ts;
75
Craig Tillerd78d1642016-02-21 22:18:51 -080076 cs->f->client =
77 grpc_channel_create(exec_ctx, "socketpair-target", cs->client_args,
78 GRPC_CLIENT_DIRECT_CHANNEL, transport);
Craig Tiller9a8df282016-02-19 09:08:09 -080079}
80
81static grpc_end2end_test_fixture chttp2_create_fixture_socketpair(
82 grpc_channel_args *client_args, grpc_channel_args *server_args) {
83 grpc_endpoint_pair *sfd = gpr_malloc(sizeof(grpc_endpoint_pair));
84
85 grpc_end2end_test_fixture f;
86 memset(&f, 0, sizeof(f));
87 f.fixture_data = sfd;
88 f.cq = grpc_completion_queue_create(NULL);
89
90 *sfd = grpc_iomgr_create_endpoint_pair("fixture", 1);
91
92 return f;
93}
94
95static void chttp2_init_client_socketpair(grpc_end2end_test_fixture *f,
96 grpc_channel_args *client_args) {
97 grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
98 grpc_endpoint_pair *sfd = f->fixture_data;
99 grpc_transport *transport;
100 sp_client_setup cs;
101 cs.client_args = client_args;
102 cs.f = f;
103 transport =
104 grpc_create_chttp2_transport(&exec_ctx, client_args, sfd->client, 1);
105 client_setup_transport(&exec_ctx, &cs, transport);
106 GPR_ASSERT(f->client);
107 grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL, 0);
108 grpc_exec_ctx_finish(&exec_ctx);
109}
110
111static void chttp2_init_server_socketpair(grpc_end2end_test_fixture *f,
112 grpc_channel_args *server_args) {
113 grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
114 grpc_endpoint_pair *sfd = f->fixture_data;
115 grpc_transport *transport;
116 GPR_ASSERT(!f->server);
Craig Tillerde676262016-02-19 12:28:34 -0800117 f->server = grpc_server_create(server_args, NULL);
Craig Tiller9a8df282016-02-19 09:08:09 -0800118 grpc_server_register_completion_queue(f->server, f->cq, NULL);
119 grpc_server_start(f->server);
120 transport =
121 grpc_create_chttp2_transport(&exec_ctx, server_args, sfd->server, 0);
122 server_setup_transport(f, transport);
123 grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL, 0);
124 grpc_exec_ctx_finish(&exec_ctx);
125}
126
127static void chttp2_tear_down_socketpair(grpc_end2end_test_fixture *f) {
128 gpr_free(f->fixture_data);
129}
130
131/* All test configurations */
132static grpc_end2end_test_config configs[] = {
133 {"chttp2/socketpair_one_byte_at_a_time", 0,
134 chttp2_create_fixture_socketpair, chttp2_init_client_socketpair,
135 chttp2_init_server_socketpair, chttp2_tear_down_socketpair},
136};
137
138int main(int argc, char **argv) {
139 size_t i;
140
141 grpc_test_init(argc, argv);
142 grpc_init();
143
144 for (i = 0; i < sizeof(configs) / sizeof(*configs); i++) {
145 grpc_end2end_tests(argc, argv, configs[i]);
146 }
147
148 grpc_shutdown();
149
150 return 0;
151}