Craig Tiller | ae69ad1 | 2015-08-27 09:06:31 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
Craig Tiller | 6169d5f | 2016-03-31 07:46:18 -0700 | [diff] [blame] | 3 | * Copyright 2015, Google Inc. |
Craig Tiller | ae69ad1 | 2015-08-27 09:06:31 -0700 | [diff] [blame] | 4 | * All rights reserved. |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions are |
| 8 | * met: |
| 9 | * |
| 10 | * * Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * * Redistributions in binary form must reproduce the above |
| 13 | * copyright notice, this list of conditions and the following disclaimer |
| 14 | * in the documentation and/or other materials provided with the |
| 15 | * distribution. |
| 16 | * * Neither the name of Google Inc. nor the names of its |
| 17 | * contributors may be used to endorse or promote products derived from |
| 18 | * this software without specific prior written permission. |
| 19 | * |
| 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | * |
| 32 | */ |
| 33 | |
Craig Tiller | a353e9d | 2016-03-31 10:37:07 -0700 | [diff] [blame] | 34 | #include "src/core/lib/iomgr/endpoint_pair.h" |
Craig Tiller | ae69ad1 | 2015-08-27 09:06:31 -0700 | [diff] [blame] | 35 | #include <grpc/grpc.h> |
| 36 | #include <grpc/support/alloc.h> |
| 37 | #include <grpc/support/log.h> |
| 38 | #include <grpc/support/time.h> |
| 39 | #include <grpc/support/useful.h> |
Vijay Pai | e9ef536 | 2016-02-25 18:10:24 -0800 | [diff] [blame] | 40 | #include "test/core/iomgr/endpoint_tests.h" |
Craig Tiller | 69b093b | 2016-02-25 19:04:07 -0800 | [diff] [blame] | 41 | #include "test/core/util/test_config.h" |
Craig Tiller | ae69ad1 | 2015-08-27 09:06:31 -0700 | [diff] [blame] | 42 | |
Craig Tiller | 69b093b | 2016-02-25 19:04:07 -0800 | [diff] [blame] | 43 | static gpr_mu *g_mu; |
| 44 | static grpc_pollset *g_pollset; |
Craig Tiller | ae69ad1 | 2015-08-27 09:06:31 -0700 | [diff] [blame] | 45 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 46 | static void clean_up(void) {} |
Craig Tiller | ae69ad1 | 2015-08-27 09:06:31 -0700 | [diff] [blame] | 47 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 48 | static grpc_endpoint_test_fixture create_fixture_endpoint_pair( |
| 49 | size_t slice_size) { |
Craig Tiller | f5768a6 | 2015-09-22 10:54:34 -0700 | [diff] [blame] | 50 | grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
Craig Tiller | ae69ad1 | 2015-08-27 09:06:31 -0700 | [diff] [blame] | 51 | grpc_endpoint_test_fixture f; |
Craig Tiller | afcc875 | 2016-10-18 16:10:06 -0700 | [diff] [blame] | 52 | grpc_resource_quota *resource_quota = |
| 53 | grpc_resource_quota_create("endpoint_pair_test"); |
Craig Tiller | d467348 | 2016-09-23 13:50:04 -0700 | [diff] [blame] | 54 | grpc_endpoint_pair p = |
Craig Tiller | 20afa3d | 2016-10-17 14:52:14 -0700 | [diff] [blame] | 55 | grpc_iomgr_create_endpoint_pair("test", resource_quota, slice_size); |
| 56 | grpc_resource_quota_unref(resource_quota); |
Craig Tiller | ae69ad1 | 2015-08-27 09:06:31 -0700 | [diff] [blame] | 57 | |
| 58 | f.client_ep = p.client; |
| 59 | f.server_ep = p.server; |
Craig Tiller | 69b093b | 2016-02-25 19:04:07 -0800 | [diff] [blame] | 60 | grpc_endpoint_add_to_pollset(&exec_ctx, f.client_ep, g_pollset); |
| 61 | grpc_endpoint_add_to_pollset(&exec_ctx, f.server_ep, g_pollset); |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 62 | grpc_exec_ctx_finish(&exec_ctx); |
Craig Tiller | ae69ad1 | 2015-08-27 09:06:31 -0700 | [diff] [blame] | 63 | |
| 64 | return f; |
| 65 | } |
| 66 | |
| 67 | static grpc_endpoint_test_config configs[] = { |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 68 | {"tcp/tcp_socketpair", create_fixture_endpoint_pair, clean_up}, |
Craig Tiller | ae69ad1 | 2015-08-27 09:06:31 -0700 | [diff] [blame] | 69 | }; |
| 70 | |
Craig Tiller | f707d62 | 2016-05-06 14:26:12 -0700 | [diff] [blame] | 71 | static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, |
| 72 | grpc_error *error) { |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 73 | grpc_pollset_destroy(p); |
Craig Tiller | dfff1b8 | 2015-09-21 14:39:57 -0700 | [diff] [blame] | 74 | } |
Craig Tiller | ae69ad1 | 2015-08-27 09:06:31 -0700 | [diff] [blame] | 75 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 76 | int main(int argc, char **argv) { |
Craig Tiller | dfff1b8 | 2015-09-21 14:39:57 -0700 | [diff] [blame] | 77 | grpc_closure destroyed; |
Craig Tiller | f5768a6 | 2015-09-22 10:54:34 -0700 | [diff] [blame] | 78 | grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 79 | grpc_test_init(argc, argv); |
| 80 | grpc_init(); |
Yuchen Zeng | 47de64c | 2017-02-22 19:04:38 -0800 | [diff] [blame] | 81 | g_pollset = gpr_zalloc(grpc_pollset_size()); |
Craig Tiller | 69b093b | 2016-02-25 19:04:07 -0800 | [diff] [blame] | 82 | grpc_pollset_init(g_pollset, &g_mu); |
| 83 | grpc_endpoint_tests(configs[0], g_pollset, g_mu); |
Craig Tiller | d465456 | 2017-01-03 08:45:56 -0800 | [diff] [blame] | 84 | grpc_closure_init(&destroyed, destroy_pollset, g_pollset, |
| 85 | grpc_schedule_on_exec_ctx); |
Craig Tiller | 69b093b | 2016-02-25 19:04:07 -0800 | [diff] [blame] | 86 | grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed); |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 87 | grpc_exec_ctx_finish(&exec_ctx); |
| 88 | grpc_shutdown(); |
Craig Tiller | 69b093b | 2016-02-25 19:04:07 -0800 | [diff] [blame] | 89 | gpr_free(g_pollset); |
Craig Tiller | ae69ad1 | 2015-08-27 09:06:31 -0700 | [diff] [blame] | 90 | |
| 91 | return 0; |
| 92 | } |