endpoint_pair_test.cc 2.3 KB

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