blob: 9dbb27fc4b882ac006b0812cbb7fffc44f510d1e [file] [log] [blame]
Craig Tiller178edfa2016-02-17 20:54:46 -08001/*
2 *
Craig Tiller6169d5f2016-03-31 07:46:18 -07003 * Copyright 2015, Google Inc.
Craig Tiller178edfa2016-02-17 20:54:46 -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
murgatroid99aa9c5782016-10-10 12:16:13 -070034#include "src/core/lib/iomgr/port.h"
35
Craig Tiller178edfa2016-02-17 20:54:46 -080036#include "test/core/end2end/end2end_tests.h"
37
38#include <string.h>
murgatroid99aa9c5782016-10-10 12:16:13 -070039#ifdef GRPC_POSIX_SOCKET
40#include <unistd.h>
41#endif
Craig Tiller178edfa2016-02-17 20:54:46 -080042
Craig Tiller178edfa2016-02-17 20:54:46 -080043#include <grpc/support/alloc.h>
44#include <grpc/support/host_port.h>
45#include <grpc/support/log.h>
46#include <grpc/support/sync.h>
47#include <grpc/support/thd.h>
48#include <grpc/support/useful.h>
Craig Tiller9eb0fde2017-03-31 16:59:30 -070049#include "src/core/ext/filters/client_channel/client_channel.h"
Craig Tilleradcb92d2016-03-28 10:14:05 -070050#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
Craig Tiller9533d042016-03-25 17:11:06 -070051#include "src/core/lib/channel/connected_channel.h"
52#include "src/core/lib/channel/http_server_filter.h"
53#include "src/core/lib/support/env.h"
54#include "src/core/lib/surface/channel.h"
55#include "src/core/lib/surface/server.h"
Craig Tiller178edfa2016-02-17 20:54:46 -080056#include "test/core/util/port.h"
57#include "test/core/util/test_config.h"
Craig Tiller178edfa2016-02-17 20:54:46 -080058
59typedef struct fullstack_fixture_data {
60 char *localaddr;
61} fullstack_fixture_data;
62
63static grpc_end2end_test_fixture chttp2_create_fixture_fullstack(
64 grpc_channel_args *client_args, grpc_channel_args *server_args) {
65 grpc_end2end_test_fixture f;
66 int port = grpc_pick_unused_port_or_die();
67 fullstack_fixture_data *ffd = gpr_malloc(sizeof(fullstack_fixture_data));
68 memset(&f, 0, sizeof(f));
69
70 gpr_join_host_port(&ffd->localaddr, "localhost", port);
71
72 f.fixture_data = ffd;
73 f.cq = grpc_completion_queue_create(NULL);
74
75 return f;
76}
77
78void chttp2_init_client_fullstack(grpc_end2end_test_fixture *f,
Mark D. Rothe127a392016-10-27 08:27:15 -070079 grpc_channel_args *client_args) {
Craig Tiller178edfa2016-02-17 20:54:46 -080080 fullstack_fixture_data *ffd = f->fixture_data;
81 f->client = grpc_insecure_channel_create(ffd->localaddr, client_args, NULL);
82 GPR_ASSERT(f->client);
83}
84
85void chttp2_init_server_fullstack(grpc_end2end_test_fixture *f,
86 grpc_channel_args *server_args) {
87 fullstack_fixture_data *ffd = f->fixture_data;
88 if (f->server) {
89 grpc_server_destroy(f->server);
90 }
91 f->server = grpc_server_create(server_args, NULL);
92 grpc_server_register_completion_queue(f->server, f->cq, NULL);
93 GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr));
94 grpc_server_start(f->server);
95}
96
97void chttp2_tear_down_fullstack(grpc_end2end_test_fixture *f) {
98 fullstack_fixture_data *ffd = f->fixture_data;
99 gpr_free(ffd->localaddr);
100 gpr_free(ffd);
101}
102
103/* All test configurations */
104static grpc_end2end_test_config configs[] = {
Muxi Yaned2be642016-10-13 14:04:39 -0700105 {"chttp2/fullstack", FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION |
Muxi Yan4be8afc2016-11-07 10:25:55 -0800106 FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL |
Muxi Yaned2be642016-10-13 14:04:39 -0700107 FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER,
Craig Tiller178edfa2016-02-17 20:54:46 -0800108 chttp2_create_fixture_fullstack, chttp2_init_client_fullstack,
109 chttp2_init_server_fullstack, chttp2_tear_down_fullstack},
110};
111
112int main(int argc, char **argv) {
113 size_t i;
114
115 /* force tracing on, with a value to force many
116 code paths in trace.c to be taken */
117 gpr_setenv("GRPC_TRACE", "doesnt-exist,http,all");
118
murgatroid99623dd4f2016-08-08 17:31:27 -0700119#ifdef GRPC_POSIX_SOCKET
Robbie Shadeca7effc2017-01-17 09:14:29 -0500120 g_fixture_slowdown_factor = isatty(STDOUT_FILENO) ? 10 : 1;
Craig Tiller178edfa2016-02-17 20:54:46 -0800121#else
Robbie Shadeca7effc2017-01-17 09:14:29 -0500122 g_fixture_slowdown_factor = 10;
Craig Tiller178edfa2016-02-17 20:54:46 -0800123#endif
124
125 grpc_test_init(argc, argv);
Craig Tiller9e9edbc2016-04-04 10:38:49 -0700126 grpc_end2end_tests_pre_init();
Craig Tiller178edfa2016-02-17 20:54:46 -0800127 grpc_init();
128
Craig Tiller178edfa2016-02-17 20:54:46 -0800129 GPR_ASSERT(0 == grpc_tracer_set_enabled("also-doesnt-exist", 0));
130 GPR_ASSERT(1 == grpc_tracer_set_enabled("http", 1));
131 GPR_ASSERT(1 == grpc_tracer_set_enabled("all", 1));
132
Craig Tiller9498bb12016-03-23 08:13:01 -0700133 for (i = 0; i < sizeof(configs) / sizeof(*configs); i++) {
134 grpc_end2end_tests(argc, argv, configs[i]);
135 }
136
Craig Tiller178edfa2016-02-17 20:54:46 -0800137 grpc_shutdown();
138
139 return 0;
140}