Debian Codegraph @

test/core/end2end/fixtures/h2_full+pipe.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 <string>
20
21 #include <grpc/grpc.h>
22
23 #include "src/core/lib/iomgr/port.h"
24
25 // This test requires posix wakeup fds
26 #ifdef GRPC_POSIX_WAKEUP_FD
27
28 #include <string.h>
29
30 #include <grpc/grpc_security.h>
31 #include <grpc/support/log.h>
32
33 #include "src/core/lib/gprpp/host_port.h"
34 #include "src/core/lib/iomgr/wakeup_fd_posix.h"
35 #include "test/core/end2end/end2end_tests.h"
36 #include "test/core/util/port.h"
37 #include "test/core/util/test_config.h"
38
39 struct fullstack_fixture_data {
40 std::string localaddr;
41 };
42
43 static grpc_end2end_test_fixture chttp2_create_fixture_fullstack(
44 const grpc_channel_args* /*client_args*/,
45 const grpc_channel_args* /*server_args*/) {
46 grpc_end2end_test_fixture f;
47 int port = grpc_pick_unused_port_or_die();
48 fullstack_fixture_data* ffd = new fullstack_fixture_data();
49 memset(&f, 0, sizeof(f));
50
51 ffd->localaddr = grpc_core::JoinHostPort("localhost", port);
52
53 f.fixture_data = ffd;
54 f.cq = grpc_completion_queue_create_for_next(nullptr);
55
56 return f;
57 }
58
59 void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f,
60 const grpc_channel_args* client_args) {
61 fullstack_fixture_data* ffd =
62 static_cast<fullstack_fixture_data*>(f->fixture_data);
63 grpc_channel_credentials* creds = grpc_insecure_credentials_create();
64 f->client = grpc_channel_create(ffd->localaddr.c_str(), creds, client_args);
65 grpc_channel_credentials_release(creds);
66 GPR_ASSERT(f->client);
67 }
68
69 void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f,
70 const grpc_channel_args* server_args) {
71 fullstack_fixture_data* ffd =
72 static_cast<fullstack_fixture_data*>(f->fixture_data);
73 if (f->server) {
74 grpc_server_destroy(f->server);
75 }
76 f->server = grpc_server_create(server_args, nullptr);
77 grpc_server_register_completion_queue(f->server, f->cq, nullptr);
78 grpc_server_credentials* server_creds =
79 grpc_insecure_server_credentials_create();
80 GPR_ASSERT(grpc_server_add_http2_port(f->server, ffd->localaddr.c_str(),
81 server_creds));
82 grpc_server_credentials_release(server_creds);
83 grpc_server_start(f->server);
84 }
85
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 delete ffd;
90 }
91
92 /* All test configurations */
93 static grpc_end2end_test_config configs[] = {
94 {"chttp2/fullstack",
95 FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION |
96 FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL |
97 FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER,
98 nullptr, chttp2_create_fixture_fullstack, chttp2_init_client_fullstack,
99 chttp2_init_server_fullstack, chttp2_tear_down_fullstack},
100 };
101
102 int main(int argc, char** argv) {
103 size_t i;
104
105 grpc_allow_specialized_wakeup_fd = 0;
106
107 grpc::testing::TestEnvironment env(&argc, argv);
108 grpc_end2end_tests_pre_init();
109 grpc_init();
110
111 for (i = 0; i < sizeof(configs) / sizeof(*configs); i++) {
112 grpc_end2end_tests(argc, argv, configs[i]);
113 }
114
115 grpc_shutdown();
116
117 return 0;
118 }
119
120 #else /* GRPC_POSIX_WAKEUP_FD */
121
122 int main(int argc, char** argv) { return 1; }
123
124 #endif /* GRPC_POSIX_WAKEUP_FD */