Debian Codegraph @

test/core/end2end/fixtures/h2_full+trace.cc

raw
1 /*
2 *
3 * Copyright 2015 gRPC authors.
4 *
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
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
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.
16 *
17 */
18
19 #include <grpc/impl/codegen/port_platform.h>
20
21 #include <string.h>
22
23 #include <grpc/grpc.h>
24
25 #include "src/core/lib/iomgr/port.h" // IWYU pragma: keep
26
27 #ifdef GRPC_POSIX_SOCKET
28 #include <unistd.h>
29 #endif
30
31 #include <string>
32
33 #include <grpc/grpc_security.h>
34 #include <grpc/support/log.h>
35
36 #include "src/core/lib/debug/trace.h"
37 #include "src/core/lib/gprpp/global_config_generic.h"
38 #include "src/core/lib/gprpp/host_port.h"
39 #include "src/core/lib/iomgr/port.h"
40 #include "test/core/end2end/end2end_tests.h"
41 #include "test/core/util/port.h"
42 #include "test/core/util/test_config.h"
43
44 struct fullstack_fixture_data {
45 std::string localaddr;
46 };
47
48 static grpc_end2end_test_fixture chttp2_create_fixture_fullstack(
49 const grpc_channel_args* /*client_args*/,
50 const grpc_channel_args* /*server_args*/) {
51 grpc_end2end_test_fixture f;
52 int port = grpc_pick_unused_port_or_die();
53 fullstack_fixture_data* ffd = new fullstack_fixture_data();
54 memset(&f, 0, sizeof(f));
55
56 ffd->localaddr = grpc_core::JoinHostPort("localhost", port);
57
58 f.fixture_data = ffd;
59 f.cq = grpc_completion_queue_create_for_next(nullptr);
60
61 return f;
62 }
63
64 void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f,
65 const grpc_channel_args* client_args) {
66 fullstack_fixture_data* ffd =
67 static_cast<fullstack_fixture_data*>(f->fixture_data);
68 grpc_channel_credentials* creds = grpc_insecure_credentials_create();
69 f->client = grpc_channel_create(ffd->localaddr.c_str(), creds, client_args);
70 grpc_channel_credentials_release(creds);
71 GPR_ASSERT(f->client);
72 }
73
74 void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f,
75 const grpc_channel_args* server_args) {
76 fullstack_fixture_data* ffd =
77 static_cast<fullstack_fixture_data*>(f->fixture_data);
78 if (f->server) {
79 grpc_server_destroy(f->server);
80 }
81 f->server = grpc_server_create(server_args, nullptr);
82 grpc_server_register_completion_queue(f->server, f->cq, nullptr);
83 grpc_server_credentials* server_creds =
84 grpc_insecure_server_credentials_create();
85 GPR_ASSERT(grpc_server_add_http2_port(f->server, ffd->localaddr.c_str(),
86 server_creds));
87 grpc_server_credentials_release(server_creds);
88 grpc_server_start(f->server);
89 }
90
91 void chttp2_tear_down_fullstack(grpc_end2end_test_fixture* f) {
92 fullstack_fixture_data* ffd =
93 static_cast<fullstack_fixture_data*>(f->fixture_data);
94 delete ffd;
95 }
96
97 /* All test configurations */
98 static grpc_end2end_test_config configs[] = {
99 {"chttp2/fullstack",
100 FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION |
101 FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL |
102 FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER,
103 nullptr, chttp2_create_fixture_fullstack, chttp2_init_client_fullstack,
104 chttp2_init_server_fullstack, chttp2_tear_down_fullstack},
105 };
106
107 int main(int argc, char** argv) {
108 size_t i;
109
110 /* force tracing on, with a value to force many
111 code paths in trace.c to be taken */
112 GPR_GLOBAL_CONFIG_SET(grpc_trace, "doesnt-exist,http,all");
113
114 #ifdef GRPC_POSIX_SOCKET
115 g_fixture_slowdown_factor = isatty(STDOUT_FILENO) ? 10 : 1;
116 #else
117 g_fixture_slowdown_factor = 10;
118 #endif
119
120 #ifdef GPR_WINDOWS
121 /* on Windows, writing logs to stderr is very slow
122 when stderr is redirected to a disk file.
123 The "trace" tests fixtures generates large amount
124 of logs, so setting a buffer for stderr prevents certain
125 test cases from timing out. */
126 setvbuf(stderr, NULL, _IOLBF, 1024);
127 #endif
128
129 grpc::testing::TestEnvironment env(&argc, argv);
130 grpc_end2end_tests_pre_init();
131 grpc_init();
132
133 GPR_ASSERT(0 == grpc_tracer_set_enabled("also-doesnt-exist", 0));
134 GPR_ASSERT(1 == grpc_tracer_set_enabled("http", 1));
135 GPR_ASSERT(1 == grpc_tracer_set_enabled("all", 1));
136
137 for (i = 0; i < sizeof(configs) / sizeof(*configs); i++) {
138 grpc_end2end_tests(argc, argv, configs[i]);
139 }
140
141 grpc_shutdown();
142
143 return 0;
144 }