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