Robbie Shade | 4b70e03 | 2015-07-10 15:44:33 -0400 | [diff] [blame] | 1 | /* |
| 2 | * |
Craig Tiller | 6169d5f | 2016-03-31 07:46:18 -0700 | [diff] [blame] | 3 | * Copyright 2015, Google Inc. |
Robbie Shade | 4b70e03 | 2015-07-10 15:44:33 -0400 | [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 | 9533d04 | 2016-03-25 17:11:06 -0700 | [diff] [blame] | 34 | #include "src/core/lib/iomgr/udp_server.h" |
Robbie Shade | 4b70e03 | 2015-07-10 15:44:33 -0400 | [diff] [blame] | 35 | |
Robbie Shade | 4b70e03 | 2015-07-10 15:44:33 -0400 | [diff] [blame] | 36 | #include <netinet/in.h> |
| 37 | #include <string.h> |
Craig Tiller | f40df23 | 2016-03-25 13:38:14 -0700 | [diff] [blame] | 38 | #include <sys/socket.h> |
Robbie Shade | 4b70e03 | 2015-07-10 15:44:33 -0400 | [diff] [blame] | 39 | #include <unistd.h> |
| 40 | |
Craig Tiller | fe01b58 | 2016-05-11 08:05:59 -0700 | [diff] [blame] | 41 | #include <grpc/grpc.h> |
| 42 | #include <grpc/support/alloc.h> |
Robbie Shade | 4b70e03 | 2015-07-10 15:44:33 -0400 | [diff] [blame] | 43 | #include <grpc/support/log.h> |
| 44 | #include <grpc/support/sync.h> |
| 45 | #include <grpc/support/time.h> |
Robbie Shade | 4b70e03 | 2015-07-10 15:44:33 -0400 | [diff] [blame] | 46 | |
Craig Tiller | d9a60bb | 2016-03-28 23:13:19 -0700 | [diff] [blame] | 47 | #include "src/core/lib/iomgr/ev_posix.h" |
| 48 | #include "src/core/lib/iomgr/iomgr.h" |
Craig Tiller | c227815 | 2016-03-21 08:59:54 -0700 | [diff] [blame] | 49 | #include "test/core/util/test_config.h" |
Robbie Shade | 4b70e03 | 2015-07-10 15:44:33 -0400 | [diff] [blame] | 50 | |
| 51 | #define LOG_TEST(x) gpr_log(GPR_INFO, "%s", #x) |
| 52 | |
Craig Tiller | 3ab2fe0 | 2016-04-11 20:11:18 -0700 | [diff] [blame] | 53 | static grpc_pollset *g_pollset; |
Nicolas "Pixel" Noble | b9012fc | 2016-03-14 23:19:04 +0100 | [diff] [blame] | 54 | static gpr_mu *g_mu; |
Robbie Shade | 4b70e03 | 2015-07-10 15:44:33 -0400 | [diff] [blame] | 55 | static int g_number_of_reads = 0; |
Robbie Shade | 2b10767 | 2015-08-04 19:55:42 -0400 | [diff] [blame] | 56 | static int g_number_of_bytes_read = 0; |
Robbie Shade | 9aa6f40 | 2016-05-12 13:28:04 -0400 | [diff] [blame] | 57 | static int g_number_of_orphan_calls = 0; |
Robbie Shade | 4b70e03 | 2015-07-10 15:44:33 -0400 | [diff] [blame] | 58 | |
Robbie Shade | c6787b2 | 2015-10-07 10:13:53 -0400 | [diff] [blame] | 59 | static void on_read(grpc_exec_ctx *exec_ctx, grpc_fd *emfd, |
| 60 | grpc_server *server) { |
Robbie Shade | 2b10767 | 2015-08-04 19:55:42 -0400 | [diff] [blame] | 61 | char read_buffer[512]; |
Craig Tiller | f96dfc3 | 2015-09-10 14:43:18 -0700 | [diff] [blame] | 62 | ssize_t byte_count; |
Robbie Shade | 2b10767 | 2015-08-04 19:55:42 -0400 | [diff] [blame] | 63 | |
Nicolas "Pixel" Noble | b9012fc | 2016-03-14 23:19:04 +0100 | [diff] [blame] | 64 | gpr_mu_lock(g_mu); |
Craig Tiller | 3ab2fe0 | 2016-04-11 20:11:18 -0700 | [diff] [blame] | 65 | byte_count = |
| 66 | recv(grpc_fd_wrapped_fd(emfd), read_buffer, sizeof(read_buffer), 0); |
Robbie Shade | 2b10767 | 2015-08-04 19:55:42 -0400 | [diff] [blame] | 67 | |
Robbie Shade | 4b70e03 | 2015-07-10 15:44:33 -0400 | [diff] [blame] | 68 | g_number_of_reads++; |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 69 | g_number_of_bytes_read += (int)byte_count; |
Robbie Shade | 2b10767 | 2015-08-04 19:55:42 -0400 | [diff] [blame] | 70 | |
Nicolas "Pixel" Noble | cede774 | 2016-07-19 01:52:36 +0200 | [diff] [blame] | 71 | GPR_ASSERT( |
| 72 | GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, NULL))); |
Nicolas "Pixel" Noble | b9012fc | 2016-03-14 23:19:04 +0100 | [diff] [blame] | 73 | gpr_mu_unlock(g_mu); |
Robbie Shade | 4b70e03 | 2015-07-10 15:44:33 -0400 | [diff] [blame] | 74 | } |
| 75 | |
Robbie Shade | 9aa6f40 | 2016-05-12 13:28:04 -0400 | [diff] [blame] | 76 | static void on_fd_orphaned(grpc_fd *emfd) { |
| 77 | gpr_log(GPR_INFO, "gRPC FD about to be orphaned: %d", |
| 78 | grpc_fd_wrapped_fd(emfd)); |
| 79 | g_number_of_orphan_calls++; |
| 80 | } |
| 81 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 82 | static void test_no_op(void) { |
Craig Tiller | b8b1a46 | 2015-09-22 12:50:03 -0700 | [diff] [blame] | 83 | grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 84 | grpc_udp_server *s = grpc_udp_server_create(); |
Craig Tiller | b8b1a46 | 2015-09-22 12:50:03 -0700 | [diff] [blame] | 85 | grpc_udp_server_destroy(&exec_ctx, s, NULL); |
| 86 | grpc_exec_ctx_finish(&exec_ctx); |
Robbie Shade | 4b70e03 | 2015-07-10 15:44:33 -0400 | [diff] [blame] | 87 | } |
| 88 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 89 | static void test_no_op_with_start(void) { |
Craig Tiller | f5768a6 | 2015-09-22 10:54:34 -0700 | [diff] [blame] | 90 | grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 91 | grpc_udp_server *s = grpc_udp_server_create(); |
| 92 | LOG_TEST("test_no_op_with_start"); |
Robbie Shade | 147fe70 | 2015-09-25 15:04:40 -0400 | [diff] [blame] | 93 | grpc_udp_server_start(&exec_ctx, s, NULL, 0, NULL); |
Craig Tiller | b8b1a46 | 2015-09-22 12:50:03 -0700 | [diff] [blame] | 94 | grpc_udp_server_destroy(&exec_ctx, s, NULL); |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 95 | grpc_exec_ctx_finish(&exec_ctx); |
Robbie Shade | 4b70e03 | 2015-07-10 15:44:33 -0400 | [diff] [blame] | 96 | } |
| 97 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 98 | static void test_no_op_with_port(void) { |
Robbie Shade | 9aa6f40 | 2016-05-12 13:28:04 -0400 | [diff] [blame] | 99 | g_number_of_orphan_calls = 0; |
Craig Tiller | b8b1a46 | 2015-09-22 12:50:03 -0700 | [diff] [blame] | 100 | grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
Robbie Shade | 4b70e03 | 2015-07-10 15:44:33 -0400 | [diff] [blame] | 101 | struct sockaddr_in addr; |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 102 | grpc_udp_server *s = grpc_udp_server_create(); |
| 103 | LOG_TEST("test_no_op_with_port"); |
Robbie Shade | 4b70e03 | 2015-07-10 15:44:33 -0400 | [diff] [blame] | 104 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 105 | memset(&addr, 0, sizeof(addr)); |
Robbie Shade | 4b70e03 | 2015-07-10 15:44:33 -0400 | [diff] [blame] | 106 | addr.sin_family = AF_INET; |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 107 | GPR_ASSERT(grpc_udp_server_add_port(s, (struct sockaddr *)&addr, sizeof(addr), |
Robbie Shade | 9aa6f40 | 2016-05-12 13:28:04 -0400 | [diff] [blame] | 108 | on_read, on_fd_orphaned)); |
Robbie Shade | 4b70e03 | 2015-07-10 15:44:33 -0400 | [diff] [blame] | 109 | |
Craig Tiller | b8b1a46 | 2015-09-22 12:50:03 -0700 | [diff] [blame] | 110 | grpc_udp_server_destroy(&exec_ctx, s, NULL); |
| 111 | grpc_exec_ctx_finish(&exec_ctx); |
Robbie Shade | 9aa6f40 | 2016-05-12 13:28:04 -0400 | [diff] [blame] | 112 | |
Robbie Shade | 006314a | 2016-05-13 10:35:02 -0400 | [diff] [blame] | 113 | /* The server had a single FD, which should have been orphaned. */ |
Robbie Shade | 9aa6f40 | 2016-05-12 13:28:04 -0400 | [diff] [blame] | 114 | GPR_ASSERT(g_number_of_orphan_calls == 1); |
Robbie Shade | 4b70e03 | 2015-07-10 15:44:33 -0400 | [diff] [blame] | 115 | } |
| 116 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 117 | static void test_no_op_with_port_and_start(void) { |
Robbie Shade | 9aa6f40 | 2016-05-12 13:28:04 -0400 | [diff] [blame] | 118 | g_number_of_orphan_calls = 0; |
Craig Tiller | f5768a6 | 2015-09-22 10:54:34 -0700 | [diff] [blame] | 119 | grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
Robbie Shade | 4b70e03 | 2015-07-10 15:44:33 -0400 | [diff] [blame] | 120 | struct sockaddr_in addr; |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 121 | grpc_udp_server *s = grpc_udp_server_create(); |
| 122 | LOG_TEST("test_no_op_with_port_and_start"); |
Robbie Shade | 4b70e03 | 2015-07-10 15:44:33 -0400 | [diff] [blame] | 123 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 124 | memset(&addr, 0, sizeof(addr)); |
Robbie Shade | 4b70e03 | 2015-07-10 15:44:33 -0400 | [diff] [blame] | 125 | addr.sin_family = AF_INET; |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 126 | GPR_ASSERT(grpc_udp_server_add_port(s, (struct sockaddr *)&addr, sizeof(addr), |
Robbie Shade | 9aa6f40 | 2016-05-12 13:28:04 -0400 | [diff] [blame] | 127 | on_read, on_fd_orphaned)); |
Robbie Shade | 4b70e03 | 2015-07-10 15:44:33 -0400 | [diff] [blame] | 128 | |
Robbie Shade | 147fe70 | 2015-09-25 15:04:40 -0400 | [diff] [blame] | 129 | grpc_udp_server_start(&exec_ctx, s, NULL, 0, NULL); |
Robbie Shade | 4b70e03 | 2015-07-10 15:44:33 -0400 | [diff] [blame] | 130 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 131 | grpc_udp_server_destroy(&exec_ctx, s, NULL); |
| 132 | grpc_exec_ctx_finish(&exec_ctx); |
Robbie Shade | 9aa6f40 | 2016-05-12 13:28:04 -0400 | [diff] [blame] | 133 | |
Robbie Shade | 006314a | 2016-05-13 10:35:02 -0400 | [diff] [blame] | 134 | /* The server had a single FD, which should have been orphaned. */ |
Robbie Shade | 9aa6f40 | 2016-05-12 13:28:04 -0400 | [diff] [blame] | 135 | GPR_ASSERT(g_number_of_orphan_calls == 1); |
Robbie Shade | 4b70e03 | 2015-07-10 15:44:33 -0400 | [diff] [blame] | 136 | } |
| 137 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 138 | static void test_receive(int number_of_clients) { |
Craig Tiller | f5768a6 | 2015-09-22 10:54:34 -0700 | [diff] [blame] | 139 | grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
Robbie Shade | 4b70e03 | 2015-07-10 15:44:33 -0400 | [diff] [blame] | 140 | struct sockaddr_storage addr; |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 141 | socklen_t addr_len = sizeof(addr); |
Robbie Shade | aeb386c | 2015-08-04 19:20:41 -0400 | [diff] [blame] | 142 | int clifd, svrfd; |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 143 | grpc_udp_server *s = grpc_udp_server_create(); |
Robbie Shade | 4b70e03 | 2015-07-10 15:44:33 -0400 | [diff] [blame] | 144 | int i; |
| 145 | int number_of_reads_before; |
| 146 | gpr_timespec deadline; |
| 147 | grpc_pollset *pollsets[1]; |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 148 | LOG_TEST("test_receive"); |
| 149 | gpr_log(GPR_INFO, "clients=%d", number_of_clients); |
Robbie Shade | 2b10767 | 2015-08-04 19:55:42 -0400 | [diff] [blame] | 150 | |
| 151 | g_number_of_bytes_read = 0; |
Robbie Shade | 9aa6f40 | 2016-05-12 13:28:04 -0400 | [diff] [blame] | 152 | g_number_of_orphan_calls = 0; |
Robbie Shade | 4b70e03 | 2015-07-10 15:44:33 -0400 | [diff] [blame] | 153 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 154 | memset(&addr, 0, sizeof(addr)); |
Robbie Shade | 4b70e03 | 2015-07-10 15:44:33 -0400 | [diff] [blame] | 155 | addr.ss_family = AF_INET; |
Robbie Shade | 9aa6f40 | 2016-05-12 13:28:04 -0400 | [diff] [blame] | 156 | GPR_ASSERT(grpc_udp_server_add_port(s, (struct sockaddr *)&addr, addr_len, |
| 157 | on_read, on_fd_orphaned)); |
Robbie Shade | 1cef6dc | 2015-07-15 14:16:48 -0400 | [diff] [blame] | 158 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 159 | svrfd = grpc_udp_server_get_fd(s, 0); |
| 160 | GPR_ASSERT(svrfd >= 0); |
| 161 | GPR_ASSERT(getsockname(svrfd, (struct sockaddr *)&addr, &addr_len) == 0); |
| 162 | GPR_ASSERT(addr_len <= sizeof(addr)); |
Robbie Shade | aeb386c | 2015-08-04 19:20:41 -0400 | [diff] [blame] | 163 | |
Craig Tiller | 3ab2fe0 | 2016-04-11 20:11:18 -0700 | [diff] [blame] | 164 | pollsets[0] = g_pollset; |
Robbie Shade | 147fe70 | 2015-09-25 15:04:40 -0400 | [diff] [blame] | 165 | grpc_udp_server_start(&exec_ctx, s, pollsets, 1, NULL); |
Robbie Shade | 4b70e03 | 2015-07-10 15:44:33 -0400 | [diff] [blame] | 166 | |
Nicolas "Pixel" Noble | b9012fc | 2016-03-14 23:19:04 +0100 | [diff] [blame] | 167 | gpr_mu_lock(g_mu); |
Robbie Shade | 1cef6dc | 2015-07-15 14:16:48 -0400 | [diff] [blame] | 168 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 169 | for (i = 0; i < number_of_clients; i++) { |
| 170 | deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10); |
Robbie Shade | 4b70e03 | 2015-07-10 15:44:33 -0400 | [diff] [blame] | 171 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 172 | number_of_reads_before = g_number_of_reads; |
| 173 | /* Create a socket, send a packet to the UDP server. */ |
| 174 | clifd = socket(addr.ss_family, SOCK_DGRAM, 0); |
| 175 | GPR_ASSERT(clifd >= 0); |
| 176 | GPR_ASSERT(connect(clifd, (struct sockaddr *)&addr, addr_len) == 0); |
| 177 | GPR_ASSERT(5 == write(clifd, "hello", 5)); |
| 178 | while (g_number_of_reads == number_of_reads_before && |
| 179 | gpr_time_cmp(deadline, gpr_now(deadline.clock_type)) > 0) { |
Nicolas "Pixel" Noble | b9012fc | 2016-03-14 23:19:04 +0100 | [diff] [blame] | 180 | grpc_pollset_worker *worker = NULL; |
Nicolas "Pixel" Noble | cede774 | 2016-07-19 01:52:36 +0200 | [diff] [blame] | 181 | GPR_ASSERT(GRPC_LOG_IF_ERROR( |
| 182 | "pollset_work", |
| 183 | grpc_pollset_work(&exec_ctx, g_pollset, &worker, |
| 184 | gpr_now(GPR_CLOCK_MONOTONIC), deadline))); |
Nicolas "Pixel" Noble | b9012fc | 2016-03-14 23:19:04 +0100 | [diff] [blame] | 185 | gpr_mu_unlock(g_mu); |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 186 | grpc_exec_ctx_finish(&exec_ctx); |
Nicolas "Pixel" Noble | b9012fc | 2016-03-14 23:19:04 +0100 | [diff] [blame] | 187 | gpr_mu_lock(g_mu); |
Robbie Shade | 4b70e03 | 2015-07-10 15:44:33 -0400 | [diff] [blame] | 188 | } |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 189 | GPR_ASSERT(g_number_of_reads == number_of_reads_before + 1); |
| 190 | close(clifd); |
| 191 | } |
| 192 | GPR_ASSERT(g_number_of_bytes_read == 5 * number_of_clients); |
Robbie Shade | 4b70e03 | 2015-07-10 15:44:33 -0400 | [diff] [blame] | 193 | |
Nicolas "Pixel" Noble | b9012fc | 2016-03-14 23:19:04 +0100 | [diff] [blame] | 194 | gpr_mu_unlock(g_mu); |
Robbie Shade | 1cef6dc | 2015-07-15 14:16:48 -0400 | [diff] [blame] | 195 | |
Craig Tiller | b8b1a46 | 2015-09-22 12:50:03 -0700 | [diff] [blame] | 196 | grpc_udp_server_destroy(&exec_ctx, s, NULL); |
| 197 | grpc_exec_ctx_finish(&exec_ctx); |
Robbie Shade | 9aa6f40 | 2016-05-12 13:28:04 -0400 | [diff] [blame] | 198 | |
Robbie Shade | 006314a | 2016-05-13 10:35:02 -0400 | [diff] [blame] | 199 | /* The server had a single FD, which should have been orphaned. */ |
| 200 | GPR_ASSERT(g_number_of_orphan_calls == 1); |
Robbie Shade | 4b70e03 | 2015-07-10 15:44:33 -0400 | [diff] [blame] | 201 | } |
| 202 | |
Nicolas "Pixel" Noble | cede774 | 2016-07-19 01:52:36 +0200 | [diff] [blame] | 203 | static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, |
| 204 | grpc_error *error) { |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 205 | grpc_pollset_destroy(p); |
Craig Tiller | 294d0ec | 2015-09-21 14:59:45 -0700 | [diff] [blame] | 206 | } |
Robbie Shade | 4b70e03 | 2015-07-10 15:44:33 -0400 | [diff] [blame] | 207 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 208 | int main(int argc, char **argv) { |
Craig Tiller | 294d0ec | 2015-09-21 14:59:45 -0700 | [diff] [blame] | 209 | grpc_closure destroyed; |
Craig Tiller | f5768a6 | 2015-09-22 10:54:34 -0700 | [diff] [blame] | 210 | grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 211 | grpc_test_init(argc, argv); |
Nicolas "Pixel" Noble | b9012fc | 2016-03-14 23:19:04 +0100 | [diff] [blame] | 212 | grpc_init(); |
Craig Tiller | 3ab2fe0 | 2016-04-11 20:11:18 -0700 | [diff] [blame] | 213 | g_pollset = gpr_malloc(grpc_pollset_size()); |
| 214 | grpc_pollset_init(g_pollset, &g_mu); |
Robbie Shade | 4b70e03 | 2015-07-10 15:44:33 -0400 | [diff] [blame] | 215 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 216 | test_no_op(); |
| 217 | test_no_op_with_start(); |
| 218 | test_no_op_with_port(); |
| 219 | test_no_op_with_port_and_start(); |
| 220 | test_receive(1); |
| 221 | test_receive(10); |
Robbie Shade | 4b70e03 | 2015-07-10 15:44:33 -0400 | [diff] [blame] | 222 | |
Craig Tiller | 3ab2fe0 | 2016-04-11 20:11:18 -0700 | [diff] [blame] | 223 | grpc_closure_init(&destroyed, destroy_pollset, g_pollset); |
| 224 | grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed); |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 225 | grpc_exec_ctx_finish(&exec_ctx); |
Craig Tiller | 3ab2fe0 | 2016-04-11 20:11:18 -0700 | [diff] [blame] | 226 | gpr_free(g_pollset); |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 227 | grpc_iomgr_shutdown(); |
Robbie Shade | 4b70e03 | 2015-07-10 15:44:33 -0400 | [diff] [blame] | 228 | return 0; |
| 229 | } |