blob: 4b98ef257e5ab1a8a479d08063b1e35268c9d25b [file] [log] [blame]
Craig Tillerae69ad12015-08-27 09:06:31 -07001/*
2 *
Craig Tiller6169d5f2016-03-31 07:46:18 -07003 * Copyright 2015, Google Inc.
Craig Tillerae69ad12015-08-27 09:06:31 -07004 * 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 Tillera353e9d2016-03-31 10:37:07 -070034#include "src/core/lib/iomgr/endpoint_pair.h"
Craig Tillerae69ad12015-08-27 09:06:31 -070035#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 Paie9ef5362016-02-25 18:10:24 -080040#include "test/core/iomgr/endpoint_tests.h"
Craig Tiller69b093b2016-02-25 19:04:07 -080041#include "test/core/util/test_config.h"
Craig Tillerae69ad12015-08-27 09:06:31 -070042
Craig Tiller69b093b2016-02-25 19:04:07 -080043static gpr_mu *g_mu;
44static grpc_pollset *g_pollset;
Craig Tillerae69ad12015-08-27 09:06:31 -070045
Craig Tillera82950e2015-09-22 12:33:20 -070046static void clean_up(void) {}
Craig Tillerae69ad12015-08-27 09:06:31 -070047
Craig Tillera82950e2015-09-22 12:33:20 -070048static grpc_endpoint_test_fixture create_fixture_endpoint_pair(
49 size_t slice_size) {
Craig Tillerf5768a62015-09-22 10:54:34 -070050 grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
Craig Tillerae69ad12015-08-27 09:06:31 -070051 grpc_endpoint_test_fixture f;
Craig Tillerafcc8752016-10-18 16:10:06 -070052 grpc_resource_quota *resource_quota =
53 grpc_resource_quota_create("endpoint_pair_test");
Craig Tillerd4673482016-09-23 13:50:04 -070054 grpc_endpoint_pair p =
Craig Tiller20afa3d2016-10-17 14:52:14 -070055 grpc_iomgr_create_endpoint_pair("test", resource_quota, slice_size);
56 grpc_resource_quota_unref(resource_quota);
Craig Tillerae69ad12015-08-27 09:06:31 -070057
58 f.client_ep = p.client;
59 f.server_ep = p.server;
Craig Tiller69b093b2016-02-25 19:04:07 -080060 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 Tillera82950e2015-09-22 12:33:20 -070062 grpc_exec_ctx_finish(&exec_ctx);
Craig Tillerae69ad12015-08-27 09:06:31 -070063
64 return f;
65}
66
67static grpc_endpoint_test_config configs[] = {
Craig Tillera82950e2015-09-22 12:33:20 -070068 {"tcp/tcp_socketpair", create_fixture_endpoint_pair, clean_up},
Craig Tillerae69ad12015-08-27 09:06:31 -070069};
70
Craig Tillerf707d622016-05-06 14:26:12 -070071static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p,
72 grpc_error *error) {
Craig Tillera82950e2015-09-22 12:33:20 -070073 grpc_pollset_destroy(p);
Craig Tillerdfff1b82015-09-21 14:39:57 -070074}
Craig Tillerae69ad12015-08-27 09:06:31 -070075
Craig Tillera82950e2015-09-22 12:33:20 -070076int main(int argc, char **argv) {
Craig Tillerdfff1b82015-09-21 14:39:57 -070077 grpc_closure destroyed;
Craig Tillerf5768a62015-09-22 10:54:34 -070078 grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
Craig Tillera82950e2015-09-22 12:33:20 -070079 grpc_test_init(argc, argv);
80 grpc_init();
Yuchen Zeng47de64c2017-02-22 19:04:38 -080081 g_pollset = gpr_zalloc(grpc_pollset_size());
Craig Tiller69b093b2016-02-25 19:04:07 -080082 grpc_pollset_init(g_pollset, &g_mu);
83 grpc_endpoint_tests(configs[0], g_pollset, g_mu);
Craig Tillerd4654562017-01-03 08:45:56 -080084 grpc_closure_init(&destroyed, destroy_pollset, g_pollset,
85 grpc_schedule_on_exec_ctx);
Craig Tiller69b093b2016-02-25 19:04:07 -080086 grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed);
Craig Tillera82950e2015-09-22 12:33:20 -070087 grpc_exec_ctx_finish(&exec_ctx);
88 grpc_shutdown();
Craig Tiller69b093b2016-02-25 19:04:07 -080089 gpr_free(g_pollset);
Craig Tillerae69ad12015-08-27 09:06:31 -070090
91 return 0;
92}