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 "test/core/end2end/end2end_tests.h"
20
21 #include <string.h>
22
23 #include <grpc/support/alloc.h>
24 #include <grpc/support/log.h>
25 #include <grpc/support/sync.h>
26
27 #include "src/core/ext/filters/client_channel/client_channel.h"
28 #include "src/core/ext/filters/http/server/http_server_filter.h"
29 #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
30 #include "src/core/lib/channel/connected_channel.h"
31 #include "src/core/lib/gpr/host_port.h"
32 #include "src/core/lib/surface/channel.h"
33 #include "src/core/lib/surface/server.h"
34 #include "test/core/util/port.h"
35 #include "test/core/util/test_config.h"
36
37 typedef struct fullstack_fixture_data {
38 char* localaddr;
39 } fullstack_fixture_data;
40
chttp2_create_fixture_fullstack(grpc_channel_args * client_args,grpc_channel_args * server_args)41 static grpc_end2end_test_fixture chttp2_create_fixture_fullstack(
42 grpc_channel_args* client_args, grpc_channel_args* server_args) {
43 grpc_end2end_test_fixture f;
44 int port = grpc_pick_unused_port_or_die();
45 fullstack_fixture_data* ffd = static_cast<fullstack_fixture_data*>(
46 gpr_malloc(sizeof(fullstack_fixture_data)));
47 memset(&f, 0, sizeof(f));
48
49 gpr_join_host_port(&ffd->localaddr, "localhost", port);
50
51 f.fixture_data = ffd;
52 f.cq = grpc_completion_queue_create_for_next(nullptr);
53 f.shutdown_cq = grpc_completion_queue_create_for_pluck(nullptr);
54
55 return f;
56 }
57
chttp2_init_client_fullstack(grpc_end2end_test_fixture * f,grpc_channel_args * client_args)58 void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f,
59 grpc_channel_args* client_args) {
60 fullstack_fixture_data* ffd =
61 static_cast<fullstack_fixture_data*>(f->fixture_data);
62 f->client =
63 grpc_insecure_channel_create(ffd->localaddr, client_args, nullptr);
64 GPR_ASSERT(f->client);
65 }
66
chttp2_init_server_fullstack(grpc_end2end_test_fixture * f,grpc_channel_args * server_args)67 void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f,
68 grpc_channel_args* server_args) {
69 fullstack_fixture_data* ffd =
70 static_cast<fullstack_fixture_data*>(f->fixture_data);
71 if (f->server) {
72 grpc_server_destroy(f->server);
73 }
74 f->server = grpc_server_create(server_args, nullptr);
75 grpc_server_register_completion_queue(f->server, f->cq, nullptr);
76 GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr));
77 grpc_server_start(f->server);
78 }
79
chttp2_tear_down_fullstack(grpc_end2end_test_fixture * f)80 void chttp2_tear_down_fullstack(grpc_end2end_test_fixture* f) {
81 fullstack_fixture_data* ffd =
82 static_cast<fullstack_fixture_data*>(f->fixture_data);
83 gpr_free(ffd->localaddr);
84 gpr_free(ffd);
85 }
86
87 /* All test configurations */
88 static grpc_end2end_test_config configs[] = {
89 {"chttp2/fullstack",
90 FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION |
91 FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL |
92 FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER,
93 nullptr, chttp2_create_fixture_fullstack, chttp2_init_client_fullstack,
94 chttp2_init_server_fullstack, chttp2_tear_down_fullstack},
95 };
96
main(int argc,char ** argv)97 int main(int argc, char** argv) {
98 size_t i;
99
100 grpc_test_init(argc, argv);
101 grpc_end2end_tests_pre_init();
102 grpc_init();
103
104 for (i = 0; i < sizeof(configs) / sizeof(*configs); i++) {
105 grpc_end2end_tests(argc, argv, configs[i]);
106 }
107
108 grpc_shutdown();
109
110 return 0;
111 }
112