blob: c4dc5b9bc173ce7d81a80b24dea31f8d62c5074a [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
34#include "test/core/end2end/end2end_tests.h"
35
36#include <string.h>
37
Craig Tiller178edfa2016-02-17 20:54:46 -080038#include <grpc/support/alloc.h>
39#include <grpc/support/host_port.h>
40#include <grpc/support/log.h>
41#include <grpc/support/sync.h>
42#include <grpc/support/thd.h>
43#include <grpc/support/useful.h>
Craig Tillerd4c98332016-03-31 13:45:47 -070044#include "src/core/ext/client_config/client_channel.h"
Craig Tilleradcb92d2016-03-28 10:14:05 -070045#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
Craig Tiller9533d042016-03-25 17:11:06 -070046#include "src/core/lib/channel/connected_channel.h"
47#include "src/core/lib/channel/http_server_filter.h"
48#include "src/core/lib/support/env.h"
49#include "src/core/lib/surface/channel.h"
50#include "src/core/lib/surface/server.h"
Craig Tiller178edfa2016-02-17 20:54:46 -080051#include "test/core/util/port.h"
52#include "test/core/util/test_config.h"
Craig Tiller178edfa2016-02-17 20:54:46 -080053
54typedef struct fullstack_fixture_data {
55 char *localaddr;
56} fullstack_fixture_data;
57
58static grpc_end2end_test_fixture chttp2_create_fixture_fullstack(
59 grpc_channel_args *client_args, grpc_channel_args *server_args) {
60 grpc_end2end_test_fixture f;
61 int port = grpc_pick_unused_port_or_die();
62 fullstack_fixture_data *ffd = gpr_malloc(sizeof(fullstack_fixture_data));
63 memset(&f, 0, sizeof(f));
64
65 gpr_join_host_port(&ffd->localaddr, "localhost", port);
66
67 f.fixture_data = ffd;
68 f.cq = grpc_completion_queue_create(NULL);
69
70 return f;
71}
72
73void chttp2_init_client_fullstack(grpc_end2end_test_fixture *f,
74 grpc_channel_args *client_args) {
75 fullstack_fixture_data *ffd = f->fixture_data;
76 f->client = grpc_insecure_channel_create(ffd->localaddr, client_args, NULL);
77 GPR_ASSERT(f->client);
78}
79
80void chttp2_init_server_fullstack(grpc_end2end_test_fixture *f,
81 grpc_channel_args *server_args) {
82 fullstack_fixture_data *ffd = f->fixture_data;
83 if (f->server) {
84 grpc_server_destroy(f->server);
85 }
86 f->server = grpc_server_create(server_args, NULL);
87 grpc_server_register_completion_queue(f->server, f->cq, NULL);
88 GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr));
89 grpc_server_start(f->server);
90}
91
92void chttp2_tear_down_fullstack(grpc_end2end_test_fixture *f) {
93 fullstack_fixture_data *ffd = f->fixture_data;
94 gpr_free(ffd->localaddr);
95 gpr_free(ffd);
96}
97
98/* All test configurations */
99static grpc_end2end_test_config configs[] = {
100 {"chttp2/fullstack", FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION,
101 chttp2_create_fixture_fullstack, chttp2_init_client_fullstack,
102 chttp2_init_server_fullstack, chttp2_tear_down_fullstack},
103};
104
105int main(int argc, char **argv) {
106 size_t i;
107
108 /* force tracing on, with a value to force many
109 code paths in trace.c to be taken */
110 gpr_setenv("GRPC_TRACE", "doesnt-exist,http,all");
111
112#ifdef GPR_POSIX_SOCKET
113 g_fixture_slowdown_factor = isatty(STDOUT_FILENO) ? 10.0 : 1.0;
114#else
115 g_fixture_slowdown_factor = 10.0;
116#endif
117
118 grpc_test_init(argc, argv);
Craig Tiller9e9edbc2016-04-04 10:38:49 -0700119 grpc_end2end_tests_pre_init();
Craig Tiller178edfa2016-02-17 20:54:46 -0800120 grpc_init();
121
Craig Tiller178edfa2016-02-17 20:54:46 -0800122 GPR_ASSERT(0 == grpc_tracer_set_enabled("also-doesnt-exist", 0));
123 GPR_ASSERT(1 == grpc_tracer_set_enabled("http", 1));
124 GPR_ASSERT(1 == grpc_tracer_set_enabled("all", 1));
125
Craig Tiller9498bb12016-03-23 08:13:01 -0700126 for (i = 0; i < sizeof(configs) / sizeof(*configs); i++) {
127 grpc_end2end_tests(argc, argv, configs[i]);
128 }
129
Craig Tiller178edfa2016-02-17 20:54:46 -0800130 grpc_shutdown();
131
132 return 0;
133}