blob: 9f0d0f38b3bd76146b01e3672e41e3598d623b31 [file] [log] [blame]
David Klempner7f3ed1e2015-01-16 15:35:56 -08001/*
2 *
3 * Copyright 2015, Google Inc.
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
34#include "src/core/iomgr/pollset_kick.h"
35
36#include <grpc/support/log.h>
37#include "test/core/util/test_config.h"
38
39static void test_allocation() {
40 grpc_pollset_kick_state state;
41 grpc_pollset_kick_init(&state);
42 grpc_pollset_kick_destroy(&state);
43}
44
45static void test_non_kick() {
46 grpc_pollset_kick_state state;
47 int fd;
48
49 grpc_pollset_kick_init(&state);
50 fd = grpc_pollset_kick_pre_poll(&state);
51 GPR_ASSERT(fd >= 0);
52
53 grpc_pollset_kick_post_poll(&state);
54 grpc_pollset_kick_destroy(&state);
55}
56
57static void test_basic_kick() {
58 /* Kicked during poll */
59 grpc_pollset_kick_state state;
60 int fd;
61 grpc_pollset_kick_init(&state);
62
63 fd = grpc_pollset_kick_pre_poll(&state);
64 GPR_ASSERT(fd >= 0);
65
66 grpc_pollset_kick_kick(&state);
67
68 /* Now hypothetically we polled and found that we were kicked */
69 grpc_pollset_kick_consume(&state);
70
71 grpc_pollset_kick_post_poll(&state);
72
73 grpc_pollset_kick_destroy(&state);
74}
75
76static void test_non_poll_kick() {
77 /* Kick before entering poll */
78 grpc_pollset_kick_state state;
79 int fd;
80
81 grpc_pollset_kick_init(&state);
82
83 grpc_pollset_kick_kick(&state);
84 fd = grpc_pollset_kick_pre_poll(&state);
85 GPR_ASSERT(fd < 0);
86 grpc_pollset_kick_destroy(&state);
87}
88
89int main(int argc, char **argv) {
90 grpc_test_init(argc, argv);
91
92 grpc_pollset_kick_global_init();
93
94 test_allocation();
95 test_basic_kick();
96 test_non_poll_kick();
97 test_non_kick();
98
99 grpc_pollset_kick_global_destroy();
100 return 0;
101}