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 "src/core/lib/iomgr/endpoint_pair.h"
20 #include <grpc/grpc.h>
21 #include <grpc/support/alloc.h>
22 #include <grpc/support/log.h>
23 #include <grpc/support/time.h>
24
25 #include "src/core/lib/gpr/useful.h"
26 #include "test/core/iomgr/endpoint_tests.h"
27 #include "test/core/util/test_config.h"
28
29 static gpr_mu* g_mu;
30 static grpc_pollset* g_pollset;
31
clean_up(void)32 static void clean_up(void) {}
33
create_fixture_endpoint_pair(size_t slice_size)34 static grpc_endpoint_test_fixture create_fixture_endpoint_pair(
35 size_t slice_size) {
36 grpc_core::ExecCtx exec_ctx;
37 grpc_endpoint_test_fixture f;
38 grpc_arg a[1];
39 a[0].key = const_cast<char*>(GRPC_ARG_TCP_READ_CHUNK_SIZE);
40 a[0].type = GRPC_ARG_INTEGER;
41 a[0].value.integer = static_cast<int>(slice_size);
42 grpc_channel_args args = {GPR_ARRAY_SIZE(a), a};
43 grpc_endpoint_pair p = grpc_iomgr_create_endpoint_pair("test", &args);
44
45 f.client_ep = p.client;
46 f.server_ep = p.server;
47 grpc_endpoint_add_to_pollset(f.client_ep, g_pollset);
48 grpc_endpoint_add_to_pollset(f.server_ep, g_pollset);
49
50 return f;
51 }
52
53 static grpc_endpoint_test_config configs[] = {
54 {"tcp/tcp_socketpair", create_fixture_endpoint_pair, clean_up},
55 };
56
destroy_pollset(void * p,grpc_error * error)57 static void destroy_pollset(void* p, grpc_error* error) {
58 grpc_pollset_destroy(static_cast<grpc_pollset*>(p));
59 }
60
main(int argc,char ** argv)61 int main(int argc, char** argv) {
62 grpc_closure destroyed;
63 grpc_test_init(argc, argv);
64 grpc_init();
65 {
66 grpc_core::ExecCtx exec_ctx;
67 g_pollset = static_cast<grpc_pollset*>(gpr_zalloc(grpc_pollset_size()));
68 grpc_pollset_init(g_pollset, &g_mu);
69 grpc_endpoint_tests(configs[0], g_pollset, g_mu);
70 GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset,
71 grpc_schedule_on_exec_ctx);
72 grpc_pollset_shutdown(g_pollset, &destroyed);
73 }
74 grpc_shutdown();
75 gpr_free(g_pollset);
76
77 return 0;
78 }
79