3 * Copyright 2015 gRPC authors.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 #include "src/core/lib/iomgr/port.h"
21 #include "test/core/end2end/end2end_tests.h"
24 #ifdef GRPC_POSIX_SOCKET
28 #include <grpc/support/alloc.h>
29 #include <grpc/support/log.h>
30 #include <grpc/support/sync.h>
32 #include "src/core/ext/filters/client_channel/client_channel.h"
33 #include "src/core/ext/filters/http/server/http_server_filter.h"
34 #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
35 #include "src/core/lib/channel/connected_channel.h"
36 #include "src/core/lib/gpr/env.h"
37 #include "src/core/lib/gpr/host_port.h"
38 #include "src/core/lib/surface/channel.h"
39 #include "src/core/lib/surface/server.h"
40 #include "test/core/util/port.h"
41 #include "test/core/util/test_config.h"
43 typedef struct fullstack_fixture_data {
45 } fullstack_fixture_data;
47 static grpc_end2end_test_fixture chttp2_create_fixture_fullstack(
48 grpc_channel_args* client_args, grpc_channel_args* server_args) {
49 grpc_end2end_test_fixture f;
50 int port = grpc_pick_unused_port_or_die();
51 fullstack_fixture_data* ffd = static_cast<fullstack_fixture_data*>(
52 gpr_malloc(sizeof(fullstack_fixture_data)));
53 memset(&f, 0, sizeof(f));
55 gpr_join_host_port(&ffd->localaddr, "localhost", port);
58 f.cq = grpc_completion_queue_create_for_next(nullptr);
59 f.shutdown_cq = grpc_completion_queue_create_for_pluck(nullptr);
64 void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f,
65 grpc_channel_args* client_args) {
66 fullstack_fixture_data* ffd =
67 static_cast<fullstack_fixture_data*>(f->fixture_data);
69 grpc_insecure_channel_create(ffd->localaddr, client_args, nullptr);
70 GPR_ASSERT(f->client);
73 void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f,
74 grpc_channel_args* server_args) {
75 fullstack_fixture_data* ffd =
76 static_cast<fullstack_fixture_data*>(f->fixture_data);
78 grpc_server_destroy(f->server);
80 f->server = grpc_server_create(server_args, nullptr);
81 grpc_server_register_completion_queue(f->server, f->cq, nullptr);
82 GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr));
83 grpc_server_start(f->server);
86 void chttp2_tear_down_fullstack(grpc_end2end_test_fixture* f) {
87 fullstack_fixture_data* ffd =
88 static_cast<fullstack_fixture_data*>(f->fixture_data);
89 gpr_free(ffd->localaddr);
93 /* All test configurations */
94 static grpc_end2end_test_config configs[] = {
96 FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION |
97 FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL |
98 FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER,
99 nullptr, chttp2_create_fixture_fullstack, chttp2_init_client_fullstack,
100 chttp2_init_server_fullstack, chttp2_tear_down_fullstack},
103 int main(int argc, char** argv) {
106 /* force tracing on, with a value to force many
107 code paths in trace.c to be taken */
108 gpr_setenv("GRPC_TRACE", "doesnt-exist,http,all");
110 #ifdef GRPC_POSIX_SOCKET
111 g_fixture_slowdown_factor = isatty(STDOUT_FILENO) ? 10 : 1;
113 g_fixture_slowdown_factor = 10;
117 /* on Windows, writing logs to stderr is very slow
118 when stderr is redirected to a disk file.
119 The "trace" tests fixtures generates large amount
120 of logs, so setting a buffer for stderr prevents certain
121 test cases from timing out. */
122 setvbuf(stderr, NULL, _IOLBF, 1024);
125 grpc::testing::TestEnvironment env(argc, argv);
126 grpc_end2end_tests_pre_init();
129 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));
133 for (i = 0; i < sizeof(configs) / sizeof(*configs); i++) {
134 grpc_end2end_tests(argc, argv, configs[i]);