1 /*
2  *
3  * Copyright 2017 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/inproc/inproc_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 inproc_fixture_data {
38   bool dummy;  // reserved for future expansion. Struct can't be empty
39 } inproc_fixture_data;
40 
inproc_create_fixture(grpc_channel_args * client_args,grpc_channel_args * server_args)41 static grpc_end2end_test_fixture inproc_create_fixture(
42     grpc_channel_args* client_args, grpc_channel_args* server_args) {
43   grpc_end2end_test_fixture f;
44   inproc_fixture_data* ffd = static_cast<inproc_fixture_data*>(
45       gpr_malloc(sizeof(inproc_fixture_data)));
46   memset(&f, 0, sizeof(f));
47 
48   f.fixture_data = ffd;
49   f.cq = grpc_completion_queue_create_for_next(nullptr);
50   f.shutdown_cq = grpc_completion_queue_create_for_pluck(nullptr);
51 
52   return f;
53 }
54 
inproc_init_client(grpc_end2end_test_fixture * f,grpc_channel_args * client_args)55 void inproc_init_client(grpc_end2end_test_fixture* f,
56                         grpc_channel_args* client_args) {
57   f->client = grpc_inproc_channel_create(f->server, client_args, nullptr);
58   GPR_ASSERT(f->client);
59 }
60 
inproc_init_server(grpc_end2end_test_fixture * f,grpc_channel_args * server_args)61 void inproc_init_server(grpc_end2end_test_fixture* f,
62                         grpc_channel_args* server_args) {
63   if (f->server) {
64     grpc_server_destroy(f->server);
65   }
66   f->server = grpc_server_create(server_args, nullptr);
67   grpc_server_register_completion_queue(f->server, f->cq, nullptr);
68   grpc_server_start(f->server);
69 }
70 
inproc_tear_down(grpc_end2end_test_fixture * f)71 void inproc_tear_down(grpc_end2end_test_fixture* f) {
72   inproc_fixture_data* ffd = static_cast<inproc_fixture_data*>(f->fixture_data);
73   gpr_free(ffd);
74 }
75 
76 /* All test configurations */
77 static grpc_end2end_test_config configs[] = {
78     {"inproc", FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER, nullptr,
79      inproc_create_fixture, inproc_init_client, inproc_init_server,
80      inproc_tear_down},
81 };
82 
main(int argc,char ** argv)83 int main(int argc, char** argv) {
84   size_t i;
85 
86   grpc_test_init(argc, argv);
87   grpc_end2end_tests_pre_init();
88   grpc_init();
89 
90   for (i = 0; i < sizeof(configs) / sizeof(*configs); i++) {
91     grpc_end2end_tests(argc, argv, configs[i]);
92   }
93 
94   grpc_shutdown();
95 
96   return 0;
97 }
98