From ef8ef3b8f3c6226de34d311de8ec9918dfcc6ba9 Mon Sep 17 00:00:00 2001 From: Sree Kuchibhotla Date: Fri, 9 Dec 2016 23:03:33 -0800 Subject: [PATCH 1/8] Tests for pollset_set. --- Makefile | 36 ++ build.yaml | 14 + test/core/iomgr/pollset_set_test.c | 472 +++++++++++++++++++++++ tools/run_tests/sources_and_headers.json | 17 + tools/run_tests/tests.json | 18 + 5 files changed, 557 insertions(+) create mode 100644 test/core/iomgr/pollset_set_test.c diff --git a/Makefile b/Makefile index 3a228b4414fb2..3f4430da9ad4c 100644 --- a/Makefile +++ b/Makefile @@ -1023,6 +1023,7 @@ no_server_test: $(BINDIR)/$(CONFIG)/no_server_test percent_decode_fuzzer: $(BINDIR)/$(CONFIG)/percent_decode_fuzzer percent_encode_fuzzer: $(BINDIR)/$(CONFIG)/percent_encode_fuzzer percent_encoding_test: $(BINDIR)/$(CONFIG)/percent_encoding_test +pollset_set_test: $(BINDIR)/$(CONFIG)/pollset_set_test resolve_address_test: $(BINDIR)/$(CONFIG)/resolve_address_test resource_quota_test: $(BINDIR)/$(CONFIG)/resource_quota_test secure_channel_create_test: $(BINDIR)/$(CONFIG)/secure_channel_create_test @@ -1354,6 +1355,7 @@ buildtests_c: privatelibs_c \ $(BINDIR)/$(CONFIG)/murmur_hash_test \ $(BINDIR)/$(CONFIG)/no_server_test \ $(BINDIR)/$(CONFIG)/percent_encoding_test \ + $(BINDIR)/$(CONFIG)/pollset_set_test \ $(BINDIR)/$(CONFIG)/resolve_address_test \ $(BINDIR)/$(CONFIG)/resource_quota_test \ $(BINDIR)/$(CONFIG)/secure_channel_create_test \ @@ -1749,6 +1751,8 @@ test_c: buildtests_c $(Q) $(BINDIR)/$(CONFIG)/no_server_test || ( echo test no_server_test failed ; exit 1 ) $(E) "[RUN] Testing percent_encoding_test" $(Q) $(BINDIR)/$(CONFIG)/percent_encoding_test || ( echo test percent_encoding_test failed ; exit 1 ) + $(E) "[RUN] Testing pollset_set_test" + $(Q) $(BINDIR)/$(CONFIG)/pollset_set_test || ( echo test pollset_set_test failed ; exit 1 ) $(E) "[RUN] Testing resolve_address_test" $(Q) $(BINDIR)/$(CONFIG)/resolve_address_test || ( echo test resolve_address_test failed ; exit 1 ) $(E) "[RUN] Testing resource_quota_test" @@ -10603,6 +10607,38 @@ endif endif +POLLSET_SET_TEST_SRC = \ + test/core/iomgr/pollset_set_test.c \ + +POLLSET_SET_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(POLLSET_SET_TEST_SRC)))) +ifeq ($(NO_SECURE),true) + +# You can't build secure targets if you don't have OpenSSL. + +$(BINDIR)/$(CONFIG)/pollset_set_test: openssl_dep_error + +else + + + +$(BINDIR)/$(CONFIG)/pollset_set_test: $(POLLSET_SET_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a + $(E) "[LD] Linking $@" + $(Q) mkdir -p `dirname $@` + $(Q) $(LD) $(LDFLAGS) $(POLLSET_SET_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBS) $(LDLIBS_SECURE) -o $(BINDIR)/$(CONFIG)/pollset_set_test + +endif + +$(OBJDIR)/$(CONFIG)/test/core/iomgr/pollset_set_test.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a + +deps_pollset_set_test: $(POLLSET_SET_TEST_OBJS:.o=.dep) + +ifneq ($(NO_SECURE),true) +ifneq ($(NO_DEPS),true) +-include $(POLLSET_SET_TEST_OBJS:.o=.dep) +endif +endif + + RESOLVE_ADDRESS_TEST_SRC = \ test/core/iomgr/resolve_address_test.c \ diff --git a/build.yaml b/build.yaml index 2555abce0c663..ef2dde591e7c1 100644 --- a/build.yaml +++ b/build.yaml @@ -2429,6 +2429,20 @@ targets: - grpc - gpr_test_util - gpr +- name: pollset_set_test + build: test + language: c + src: + - test/core/iomgr/pollset_set_test.c + deps: + - grpc_test_util + - grpc + - gpr_test_util + - gpr + exclude_iomgrs: + - uv + platforms: + - linux - name: resolve_address_test build: test language: c diff --git a/test/core/iomgr/pollset_set_test.c b/test/core/iomgr/pollset_set_test.c new file mode 100644 index 0000000000000..af971c0784ef5 --- /dev/null +++ b/test/core/iomgr/pollset_set_test.c @@ -0,0 +1,472 @@ +/* + * + * Copyright 2016, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#include "src/core/lib/iomgr/port.h" + +/* This test only relevant on linux systems */ +#ifdef GRPC_POSIX_SOCKET +#include "src/core/lib/iomgr/ev_posix.h" + +#include +#include +#include + +#include +#include + +#include "src/core/lib/iomgr/iomgr.h" +#include "test/core/util/test_config.h" + +/******************************************************************************* + * test_pollset_set + */ + +typedef struct test_pollset_set { grpc_pollset_set *pss; } test_pollset_set; + +void init_test_pollset_sets(test_pollset_set pollset_sets[], int num_pss) { + int i; + for (i = 0; i < num_pss; i++) { + pollset_sets[i].pss = grpc_pollset_set_create(); + } +} + +void cleanup_test_pollset_sets(test_pollset_set pollset_sets[], int num_pss) { + int i; + for (i = 0; i < num_pss; i++) { + grpc_pollset_set_destroy(pollset_sets[i].pss); + pollset_sets[i].pss = NULL; + } +} + +/******************************************************************************* + * test_pollset + */ + +typedef struct test_pollset { + grpc_pollset *ps; + gpr_mu *mu; +} test_pollset; + +static void init_test_pollsets(test_pollset pollsets[], int num_pollsets) { + int i; + for (i = 0; i < num_pollsets; i++) { + pollsets[i].ps = gpr_malloc(grpc_pollset_size()); + grpc_pollset_init(pollsets[i].ps, &pollsets[i].mu); + } +} + +static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, + grpc_error *error) { + grpc_pollset_destroy(p); +} + +static void cleanup_test_pollsets(grpc_exec_ctx *exec_ctx, + test_pollset pollsets[], int num_pollsets) { + grpc_closure destroyed; + int i; + + for (i = 0; i < num_pollsets; i++) { + grpc_closure_init(&destroyed, destroy_pollset, pollsets[i].ps); + grpc_pollset_shutdown(exec_ctx, pollsets[i].ps, &destroyed); + + grpc_exec_ctx_flush(exec_ctx); + gpr_free(pollsets[i].ps); + pollsets[i].ps = NULL; + } +} + +/******************************************************************************* + * test_fd + */ + +typedef struct test_fd { + grpc_fd *fd; + grpc_wakeup_fd wakeup_fd; + + bool is_on_readable_called; /* Is on_readable closure is called ? */ + grpc_closure on_readable; /* Closure to call when this fd is readable */ +} test_fd; + +void on_readable(grpc_exec_ctx *exec_ctx, void *tfd, grpc_error *error) { + ((test_fd *)tfd)->is_on_readable_called = true; +} + +static void reset_test_fd(grpc_exec_ctx *exec_ctx, test_fd *tfd) { + tfd->is_on_readable_called = false; + + grpc_closure_init(&tfd->on_readable, on_readable, tfd); + grpc_fd_notify_on_read(exec_ctx, tfd->fd, &tfd->on_readable); +} + +static void init_test_fds(grpc_exec_ctx *exec_ctx, test_fd tfds[], + int num_fds) { + int i; + + for (i = 0; i < num_fds; i++) { + GPR_ASSERT(GRPC_ERROR_NONE == grpc_wakeup_fd_init(&tfds[i].wakeup_fd)); + tfds[i].fd = grpc_fd_create(GRPC_WAKEUP_FD_GET_READ_FD(&tfds[i].wakeup_fd), + "test_fd"); + reset_test_fd(exec_ctx, &tfds[i]); + } +} + +static void cleanup_test_fds(grpc_exec_ctx *exec_ctx, test_fd *tfds, + int num_fds) { + int release_fd; + int i; + + for (i = 0; i < num_fds; i++) { + grpc_fd_shutdown(exec_ctx, tfds[i].fd); + grpc_exec_ctx_flush(exec_ctx); + + /* grpc_fd_orphan frees the memory allocated for grpc_fd. Normally it also + * calls close() on the underlying fd. In our case, we are using + * grpc_wakeup_fd and we would like to destroy it ourselves (by calling + * grpc_wakeup_fd_destroy). To prevent grpc_fd from calling close() on the + * underlying fd, call it with a non-NULL 'release_fd' parameter */ + grpc_fd_orphan(exec_ctx, tfds[i].fd, NULL, &release_fd, "test_fd_cleanup"); + grpc_exec_ctx_flush(exec_ctx); + + grpc_wakeup_fd_destroy(&tfds[i].wakeup_fd); + } +} + +static void make_test_fds_readable(test_fd tfds[], int num_fds) { + int i; + for (i = 0; i < num_fds; i++) { + GPR_ASSERT(GRPC_ERROR_NONE == grpc_wakeup_fd_wakeup(&tfds[i].wakeup_fd)); + } +} + +static void verify_readable_and_reset(grpc_exec_ctx *exec_ctx, test_fd tfds[], + int num_fds) { + int i; + for (i = 0; i < num_fds; i++) { + /* Verify that the on_readable callback was called */ + GPR_ASSERT(tfds[i].is_on_readable_called); + + /* Reset the tfd[i] structure */ + GPR_ASSERT(GRPC_ERROR_NONE == + grpc_wakeup_fd_consume_wakeup(&tfds[i].wakeup_fd)); + reset_test_fd(exec_ctx, &tfds[i]); + } +} + +/******************************************************************************* + * Main tests + */ + +/* Test some typical scenarios in pollset_set */ +static void pollset_set_test_basic() { + /* We construct the following structure for this test: + * + * +---> FD0 (Added before PSS1, PS1 and PS2 are added to PSS0) + * | + * +---> FD5 (Added after PSS1, PS1 and PS2 are added to PSS0) + * | + * | + * | +---> FD1 (Added before PSS1 is added to PSS0) + * | | + * | +---> FD6 (Added after PSS1 is added to PSS0) + * | | + * +---> PSS1--+ +--> FD2 (Added before PS0 is added to PSS1) + * | | | + * | +---> PS0---+ + * | | + * PSS0---+ +--> FD7 (Added after PS0 is added to PSS1) + * | + * | + * | +---> FD3 (Added before PS1 is added to PSS0) + * | | + * +---> PS1---+ + * | | + * | +---> FD8 (Added after PS1 added to PSS0) + * | + * | + * | +---> FD4 (Added before PS2 is added to PSS0) + * | | + * +---> PS2---+ + * | + * +---> FD9 (Added after PS2 is added to PSS0) + */ + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + int i; + grpc_pollset_worker *worker; + gpr_timespec deadline; + + test_fd tfds[10]; + test_pollset pollsets[3]; + test_pollset_set pollset_sets[2]; + int num_fds = sizeof(tfds) / sizeof(tfds[0]); + int num_ps = sizeof(pollsets) / sizeof(pollsets[0]); + int num_pss = sizeof(pollset_sets) / sizeof(pollset_sets[0]); + + init_test_fds(&exec_ctx, tfds, num_fds); + init_test_pollsets(pollsets, num_ps); + init_test_pollset_sets(pollset_sets, num_pss); + + /* Construct the pollset_set/pollset/fd tree (see diagram above) */ + + grpc_pollset_set_add_fd(&exec_ctx, pollset_sets[0].pss, tfds[0].fd); + grpc_pollset_set_add_fd(&exec_ctx, pollset_sets[1].pss, tfds[1].fd); + + grpc_pollset_add_fd(&exec_ctx, pollsets[0].ps, tfds[2].fd); + grpc_pollset_add_fd(&exec_ctx, pollsets[1].ps, tfds[3].fd); + grpc_pollset_add_fd(&exec_ctx, pollsets[2].ps, tfds[4].fd); + + grpc_pollset_set_add_pollset_set(&exec_ctx, pollset_sets[0].pss, + pollset_sets[1].pss); + + grpc_pollset_set_add_pollset(&exec_ctx, pollset_sets[1].pss, pollsets[0].ps); + grpc_pollset_set_add_pollset(&exec_ctx, pollset_sets[0].pss, pollsets[1].ps); + grpc_pollset_set_add_pollset(&exec_ctx, pollset_sets[0].pss, pollsets[2].ps); + + grpc_pollset_set_add_fd(&exec_ctx, pollset_sets[0].pss, tfds[5].fd); + grpc_pollset_set_add_fd(&exec_ctx, pollset_sets[1].pss, tfds[6].fd); + + grpc_pollset_add_fd(&exec_ctx, pollsets[0].ps, tfds[7].fd); + grpc_pollset_add_fd(&exec_ctx, pollsets[1].ps, tfds[8].fd); + grpc_pollset_add_fd(&exec_ctx, pollsets[2].ps, tfds[9].fd); + + grpc_exec_ctx_flush(&exec_ctx); + + /* Test that if any FD in the above structure is readable, it is observable by + * doing grpc_pollset_work on any pollset + * + * For every pollset, do the following: + * - (Ensure that all FDs are in reset state) + * - Make all FDs readable + * - Call grpc_pollset_work() on the pollset + * - Flush the exec_ctx + * - Verify that on_readable call back was called for all FDs (and + * reset the FDs) + * */ + for (i = 0; i < num_ps; i++) { + make_test_fds_readable(tfds, num_fds); + + gpr_mu_lock(pollsets[i].mu); + deadline = GRPC_TIMEOUT_MILLIS_TO_DEADLINE(2); + GPR_ASSERT(GRPC_ERROR_NONE == + grpc_pollset_work(&exec_ctx, pollsets[i].ps, &worker, + gpr_now(GPR_CLOCK_MONOTONIC), deadline)); + gpr_mu_unlock(pollsets[i].mu); + + grpc_exec_ctx_flush(&exec_ctx); + + verify_readable_and_reset(&exec_ctx, tfds, num_fds); + grpc_exec_ctx_flush(&exec_ctx); + } + + /* Test tear down */ + grpc_pollset_set_del_fd(&exec_ctx, pollset_sets[0].pss, tfds[0].fd); + grpc_pollset_set_del_fd(&exec_ctx, pollset_sets[0].pss, tfds[5].fd); + grpc_pollset_set_del_fd(&exec_ctx, pollset_sets[1].pss, tfds[1].fd); + grpc_pollset_set_del_fd(&exec_ctx, pollset_sets[1].pss, tfds[6].fd); + grpc_exec_ctx_flush(&exec_ctx); + + grpc_pollset_set_del_pollset(&exec_ctx, pollset_sets[1].pss, pollsets[0].ps); + grpc_pollset_set_del_pollset(&exec_ctx, pollset_sets[0].pss, pollsets[1].ps); + grpc_pollset_set_del_pollset(&exec_ctx, pollset_sets[0].pss, pollsets[2].ps); + + grpc_pollset_set_del_pollset_set(&exec_ctx, pollset_sets[0].pss, + pollset_sets[1].pss); + grpc_exec_ctx_flush(&exec_ctx); + + cleanup_test_fds(&exec_ctx, tfds, num_fds); + cleanup_test_pollsets(&exec_ctx, pollsets, num_ps); + cleanup_test_pollset_sets(pollset_sets, num_pss); + grpc_exec_ctx_finish(&exec_ctx); +} + +/* Same FD added multiple times to the pollset_set tree */ +void pollset_set_test_dup_fds() { + /* We construct the following structure for this test: + * + * +---> FD0 + * | + * | + * PSS0---+ + * | +---> FD0 (also under PSS0) + * | | + * +---> PSS1--+ +--> FD1 (also under PSS1) + * | | + * +---> PS ---+ + * | | + * | +--> FD2 + * +---> FD1 + */ + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_pollset_worker *worker; + gpr_timespec deadline; + + test_fd tfds[3]; + test_pollset pollset; + test_pollset_set pollset_sets[2]; + int num_fds = sizeof(tfds) / sizeof(tfds[0]); + int num_ps = 1; + int num_pss = sizeof(pollset_sets) / sizeof(pollset_sets[0]); + + init_test_fds(&exec_ctx, tfds, num_fds); + init_test_pollsets(&pollset, num_ps); + init_test_pollset_sets(pollset_sets, num_pss); + + /* Construct the structure */ + grpc_pollset_set_add_fd(&exec_ctx, pollset_sets[0].pss, tfds[0].fd); + grpc_pollset_set_add_fd(&exec_ctx, pollset_sets[1].pss, tfds[0].fd); + grpc_pollset_set_add_fd(&exec_ctx, pollset_sets[1].pss, tfds[1].fd); + + grpc_pollset_add_fd(&exec_ctx, pollset.ps, tfds[1].fd); + grpc_pollset_add_fd(&exec_ctx, pollset.ps, tfds[2].fd); + + grpc_pollset_set_add_pollset(&exec_ctx, pollset_sets[1].pss, pollset.ps); + grpc_pollset_set_add_pollset_set(&exec_ctx, pollset_sets[0].pss, + pollset_sets[1].pss); + + /* Test. Make all FDs readable and make sure that can be observed by doing a + * grpc_pollset_work on the pollset 'PS' */ + make_test_fds_readable(tfds, num_fds); + + gpr_mu_lock(pollset.mu); + deadline = GRPC_TIMEOUT_MILLIS_TO_DEADLINE(2); + GPR_ASSERT(GRPC_ERROR_NONE == + grpc_pollset_work(&exec_ctx, pollset.ps, &worker, + gpr_now(GPR_CLOCK_MONOTONIC), deadline)); + gpr_mu_unlock(pollset.mu); + grpc_exec_ctx_flush(&exec_ctx); + + verify_readable_and_reset(&exec_ctx, tfds, num_fds); + grpc_exec_ctx_flush(&exec_ctx); + + /* Tear down */ + grpc_pollset_set_del_fd(&exec_ctx, pollset_sets[0].pss, tfds[0].fd); + grpc_pollset_set_del_fd(&exec_ctx, pollset_sets[1].pss, tfds[0].fd); + grpc_pollset_set_del_fd(&exec_ctx, pollset_sets[1].pss, tfds[1].fd); + + grpc_pollset_set_del_pollset(&exec_ctx, pollset_sets[1].pss, pollset.ps); + grpc_pollset_set_del_pollset_set(&exec_ctx, pollset_sets[0].pss, + pollset_sets[1].pss); + grpc_exec_ctx_flush(&exec_ctx); + + cleanup_test_fds(&exec_ctx, tfds, num_fds); + cleanup_test_pollsets(&exec_ctx, &pollset, num_ps); + cleanup_test_pollset_sets(pollset_sets, num_pss); + grpc_exec_ctx_finish(&exec_ctx); +} + +/* Pollset_set with an empty pollset */ +void pollset_set_test_empty_pollset() { + /* We construct the following structure for this test: + * + * +---> PS0 (EMPTY) + * | + * +---> FD0 + * | + * PSS0---+ + * | +---> FD1 + * | | + * +---> PS1--+ + * | + * +---> FD2 + */ + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_pollset_worker *worker; + gpr_timespec deadline; + + test_fd tfds[3]; + test_pollset pollsets[2]; + test_pollset_set pollset_set; + int num_fds = sizeof(tfds) / sizeof(tfds[0]); + int num_ps = sizeof(pollsets) / sizeof(pollsets[0]); + int num_pss = 1; + + init_test_fds(&exec_ctx, tfds, num_fds); + init_test_pollsets(pollsets, num_ps); + init_test_pollset_sets(&pollset_set, num_pss); + + /* Construct the structure */ + grpc_pollset_set_add_fd(&exec_ctx, pollset_set.pss, tfds[0].fd); + grpc_pollset_add_fd(&exec_ctx, pollsets[1].ps, tfds[1].fd); + grpc_pollset_add_fd(&exec_ctx, pollsets[1].ps, tfds[2].fd); + + grpc_pollset_set_add_pollset(&exec_ctx, pollset_set.pss, pollsets[0].ps); + grpc_pollset_set_add_pollset(&exec_ctx, pollset_set.pss, pollsets[1].ps); + + /* Test. Make all FDs readable and make sure that can be observed by doing + * grpc_pollset_work on the empty pollset 'PS0' */ + make_test_fds_readable(tfds, num_fds); + + gpr_mu_lock(pollsets[0].mu); + deadline = GRPC_TIMEOUT_MILLIS_TO_DEADLINE(2); + GPR_ASSERT(GRPC_ERROR_NONE == + grpc_pollset_work(&exec_ctx, pollsets[0].ps, &worker, + gpr_now(GPR_CLOCK_MONOTONIC), deadline)); + gpr_mu_unlock(pollsets[0].mu); + grpc_exec_ctx_flush(&exec_ctx); + + verify_readable_and_reset(&exec_ctx, tfds, num_fds); + grpc_exec_ctx_flush(&exec_ctx); + + /* Tear down */ + grpc_pollset_set_del_fd(&exec_ctx, pollset_set.pss, tfds[0].fd); + grpc_pollset_set_del_pollset(&exec_ctx, pollset_set.pss, pollsets[0].ps); + grpc_pollset_set_del_pollset(&exec_ctx, pollset_set.pss, pollsets[1].ps); + grpc_exec_ctx_flush(&exec_ctx); + + cleanup_test_fds(&exec_ctx, tfds, num_fds); + cleanup_test_pollsets(&exec_ctx, pollsets, num_ps); + cleanup_test_pollset_sets(&pollset_set, num_pss); + grpc_exec_ctx_finish(&exec_ctx); +} + +int main(int argc, char **argv) { + const char *poll_strategy = NULL; + grpc_test_init(argc, argv); + grpc_iomgr_init(); + + poll_strategy = grpc_get_poll_strategy_name(); + if (poll_strategy != NULL && strcmp(poll_strategy, "epoll") == 0) { + pollset_set_test_basic(); + pollset_set_test_dup_fds(); + pollset_set_test_empty_pollset(); + } else { + gpr_log(GPR_INFO, + "Skipping the test. The test is only relevant for 'epoll' " + "strategy. and the current strategy is: '%s'", + poll_strategy); + } + + grpc_iomgr_shutdown(); + return 0; +} +#else /* defined(GRPC_LINUX_EPOLL) */ +int main(int argc, char **argv) { return 0; } +#endif /* !defined(GRPC_LINUX_EPOLL) */ diff --git a/tools/run_tests/sources_and_headers.json b/tools/run_tests/sources_and_headers.json index 9dd5a1c85f0be..3e61487ac657c 100644 --- a/tools/run_tests/sources_and_headers.json +++ b/tools/run_tests/sources_and_headers.json @@ -1676,6 +1676,23 @@ "third_party": false, "type": "target" }, + { + "deps": [ + "gpr", + "gpr_test_util", + "grpc", + "grpc_test_util" + ], + "headers": [], + "is_filegroup": false, + "language": "c", + "name": "pollset_set_test", + "src": [ + "test/core/iomgr/pollset_set_test.c" + ], + "third_party": false, + "type": "target" + }, { "deps": [ "gpr", diff --git a/tools/run_tests/tests.json b/tools/run_tests/tests.json index 8d1e9b4568395..d96fa41922420 100644 --- a/tools/run_tests/tests.json +++ b/tools/run_tests/tests.json @@ -1697,6 +1697,24 @@ "windows" ] }, + { + "args": [], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "gtest": false, + "language": "c", + "name": "pollset_set_test", + "platforms": [ + "linux" + ] + }, { "args": [], "ci_platforms": [ From 0542d11ea8ab3ffde3458fbf7daf7a2af93b19fa Mon Sep 17 00:00:00 2001 From: Sree Kuchibhotla Date: Mon, 9 Jan 2017 15:07:11 -0800 Subject: [PATCH 2/8] Re-ran generate_projects.sh --- tools/doxygen/Doxyfile.c++ | 42 +++++++++++----------- tools/doxygen/Doxyfile.c++.internal | 40 ++++++++++----------- tools/doxygen/Doxyfile.core | 38 ++++++++++---------- tools/doxygen/Doxyfile.core.internal | 54 ++++++++++++++-------------- 4 files changed, 87 insertions(+), 87 deletions(-) diff --git a/tools/doxygen/Doxyfile.c++ b/tools/doxygen/Doxyfile.c++ index 2c16f6f24a024..bb620f6b4a076 100644 --- a/tools/doxygen/Doxyfile.c++ +++ b/tools/doxygen/Doxyfile.c++ @@ -848,34 +848,34 @@ include/grpc/impl/codegen/sync.h \ include/grpc/impl/codegen/sync_generic.h \ include/grpc/impl/codegen/sync_posix.h \ include/grpc/impl/codegen/sync_windows.h \ +doc/command_line_tool.md \ +doc/statuscodes.md \ +doc/interop-test-descriptions.md \ doc/fail_fast.md \ +doc/server-reflection.md \ +doc/c-style-guide.md \ +doc/load-balancing.md \ +doc/compression_cookbook.md \ +doc/connectivity-semantics-and-api.md \ +doc/PROTOCOL-HTTP2.md \ +doc/health-checking.md \ +doc/binary-logging.md \ +doc/stress_test_framework.md \ +doc/negative-http2-interop-test-descriptions.md \ doc/compression.md \ +doc/server_reflection_tutorial.md \ +doc/cpp-style-guide.md \ doc/environment_variables.md \ -doc/stress_test_framework.md \ doc/PROTOCOL-WEB.md \ -doc/cpp-style-guide.md \ -doc/http-grpc-status-mapping.md \ -doc/wait-for-ready.md \ -doc/command_line_tool.md \ -doc/c-style-guide.md \ -doc/server_reflection_tutorial.md \ -doc/health-checking.md \ -doc/connection-backoff-interop-test-description.md \ -doc/epoll-polling-engine.md \ doc/naming.md \ -doc/binary-logging.md \ -doc/connectivity-semantics-and-api.md \ +doc/epoll-polling-engine.md \ doc/connection-backoff.md \ -doc/compression_cookbook.md \ -doc/PROTOCOL-HTTP2.md \ -doc/load-balancing.md \ -doc/negative-http2-interop-test-descriptions.md \ -doc/server-reflection.md \ -doc/interop-test-descriptions.md \ -doc/statuscodes.md \ +doc/connection-backoff-interop-test-description.md \ doc/g_stands_for.md \ -doc/cpp/perf_notes.md \ -doc/cpp/pending_api_cleanups.md +doc/http-grpc-status-mapping.md \ +doc/wait-for-ready.md \ +doc/cpp/pending_api_cleanups.md \ +doc/cpp/perf_notes.md # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal index 89915d7b08e1e..a8dd34820daa5 100644 --- a/tools/doxygen/Doxyfile.c++.internal +++ b/tools/doxygen/Doxyfile.c++.internal @@ -894,34 +894,34 @@ src/cpp/util/status.cc \ src/cpp/util/string_ref.cc \ src/cpp/util/time_cc.cc \ src/cpp/codegen/codegen_init.cc \ +doc/command_line_tool.md \ +doc/statuscodes.md \ +doc/interop-test-descriptions.md \ doc/fail_fast.md \ +doc/server-reflection.md \ +doc/c-style-guide.md \ +doc/load-balancing.md \ +doc/compression_cookbook.md \ +doc/connectivity-semantics-and-api.md \ +doc/PROTOCOL-HTTP2.md \ +doc/health-checking.md \ +doc/binary-logging.md \ +doc/stress_test_framework.md \ +doc/negative-http2-interop-test-descriptions.md \ doc/compression.md \ +doc/server_reflection_tutorial.md \ +doc/cpp-style-guide.md \ doc/environment_variables.md \ -doc/stress_test_framework.md \ doc/PROTOCOL-WEB.md \ -doc/cpp-style-guide.md \ -doc/http-grpc-status-mapping.md \ -doc/wait-for-ready.md \ -doc/command_line_tool.md \ -doc/c-style-guide.md \ -doc/server_reflection_tutorial.md \ -doc/health-checking.md \ -doc/connection-backoff-interop-test-description.md \ -doc/epoll-polling-engine.md \ doc/naming.md \ -doc/binary-logging.md \ -doc/connectivity-semantics-and-api.md \ +doc/epoll-polling-engine.md \ doc/connection-backoff.md \ -doc/compression_cookbook.md \ -doc/PROTOCOL-HTTP2.md \ -doc/load-balancing.md \ -doc/negative-http2-interop-test-descriptions.md \ -doc/server-reflection.md \ -doc/interop-test-descriptions.md \ -doc/statuscodes.md \ +doc/connection-backoff-interop-test-description.md \ doc/g_stands_for.md \ -doc/cpp/perf_notes.md \ +doc/http-grpc-status-mapping.md \ +doc/wait-for-ready.md \ doc/cpp/pending_api_cleanups.md \ +doc/cpp/perf_notes.md \ src/cpp/README.md # This tag can be used to specify the character encoding of the source files diff --git a/tools/doxygen/Doxyfile.core b/tools/doxygen/Doxyfile.core index e7fc1dbc5739b..562f3fdc2ee6e 100644 --- a/tools/doxygen/Doxyfile.core +++ b/tools/doxygen/Doxyfile.core @@ -826,32 +826,32 @@ include/grpc/impl/codegen/sync.h \ include/grpc/impl/codegen/sync_generic.h \ include/grpc/impl/codegen/sync_posix.h \ include/grpc/impl/codegen/sync_windows.h \ +doc/command_line_tool.md \ +doc/statuscodes.md \ +doc/interop-test-descriptions.md \ doc/fail_fast.md \ +doc/server-reflection.md \ +doc/c-style-guide.md \ +doc/load-balancing.md \ +doc/compression_cookbook.md \ +doc/connectivity-semantics-and-api.md \ +doc/PROTOCOL-HTTP2.md \ +doc/health-checking.md \ +doc/binary-logging.md \ +doc/stress_test_framework.md \ +doc/negative-http2-interop-test-descriptions.md \ doc/compression.md \ +doc/server_reflection_tutorial.md \ +doc/cpp-style-guide.md \ doc/environment_variables.md \ -doc/stress_test_framework.md \ doc/PROTOCOL-WEB.md \ -doc/cpp-style-guide.md \ -doc/http-grpc-status-mapping.md \ -doc/wait-for-ready.md \ -doc/command_line_tool.md \ -doc/c-style-guide.md \ -doc/server_reflection_tutorial.md \ -doc/health-checking.md \ -doc/connection-backoff-interop-test-description.md \ -doc/epoll-polling-engine.md \ doc/naming.md \ -doc/binary-logging.md \ -doc/connectivity-semantics-and-api.md \ +doc/epoll-polling-engine.md \ doc/connection-backoff.md \ -doc/compression_cookbook.md \ -doc/PROTOCOL-HTTP2.md \ -doc/load-balancing.md \ -doc/negative-http2-interop-test-descriptions.md \ -doc/server-reflection.md \ -doc/interop-test-descriptions.md \ -doc/statuscodes.md \ +doc/connection-backoff-interop-test-description.md \ doc/g_stands_for.md \ +doc/http-grpc-status-mapping.md \ +doc/wait-for-ready.md \ doc/core/pending_api_cleanups.md # This tag can be used to specify the character encoding of the source files diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index 8b60152009bea..7b647d2ed8d44 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -1281,52 +1281,52 @@ src/core/lib/support/tmpfile_msys.c \ src/core/lib/support/tmpfile_posix.c \ src/core/lib/support/tmpfile_windows.c \ src/core/lib/support/wrap_memcpy.c \ +doc/command_line_tool.md \ +doc/statuscodes.md \ +doc/interop-test-descriptions.md \ doc/fail_fast.md \ +doc/server-reflection.md \ +doc/c-style-guide.md \ +doc/load-balancing.md \ +doc/compression_cookbook.md \ +doc/connectivity-semantics-and-api.md \ +doc/PROTOCOL-HTTP2.md \ +doc/health-checking.md \ +doc/binary-logging.md \ +doc/stress_test_framework.md \ +doc/negative-http2-interop-test-descriptions.md \ doc/compression.md \ +doc/server_reflection_tutorial.md \ +doc/cpp-style-guide.md \ doc/environment_variables.md \ -doc/stress_test_framework.md \ doc/PROTOCOL-WEB.md \ -doc/cpp-style-guide.md \ -doc/http-grpc-status-mapping.md \ -doc/wait-for-ready.md \ -doc/command_line_tool.md \ -doc/c-style-guide.md \ -doc/server_reflection_tutorial.md \ -doc/health-checking.md \ -doc/connection-backoff-interop-test-description.md \ -doc/epoll-polling-engine.md \ doc/naming.md \ -doc/binary-logging.md \ -doc/connectivity-semantics-and-api.md \ +doc/epoll-polling-engine.md \ doc/connection-backoff.md \ -doc/compression_cookbook.md \ -doc/PROTOCOL-HTTP2.md \ -doc/load-balancing.md \ -doc/negative-http2-interop-test-descriptions.md \ -doc/server-reflection.md \ -doc/interop-test-descriptions.md \ -doc/statuscodes.md \ +doc/connection-backoff-interop-test-description.md \ doc/g_stands_for.md \ +doc/http-grpc-status-mapping.md \ +doc/wait-for-ready.md \ doc/core/pending_api_cleanups.md \ src/core/README.md \ src/core/ext/README.md \ src/core/ext/transport/README.md \ src/core/ext/transport/chttp2/README.md \ -src/core/ext/transport/chttp2/client/secure/README.md \ -src/core/ext/transport/chttp2/client/insecure/README.md \ src/core/ext/transport/chttp2/transport/README.md \ -src/core/ext/transport/chttp2/server/secure/README.md \ src/core/ext/transport/chttp2/server/insecure/README.md \ +src/core/ext/transport/chttp2/server/secure/README.md \ +src/core/ext/transport/chttp2/client/insecure/README.md \ +src/core/ext/transport/chttp2/client/secure/README.md \ +src/core/ext/census/README.md \ +src/core/ext/census/gen/README.md \ src/core/ext/client_channel/README.md \ src/core/ext/resolver/README.md \ -src/core/ext/resolver/sockaddr/README.md \ src/core/ext/resolver/dns/native/README.md \ -src/core/ext/census/README.md \ -src/core/ext/census/gen/README.md \ +src/core/ext/resolver/sockaddr/README.md \ src/core/lib/README.md \ -src/core/lib/tsi/README.md \ -src/core/lib/channel/README.md \ src/core/lib/transport/README.md \ +src/core/lib/channel/README.md \ +src/core/lib/tsi/README.md \ src/core/lib/iomgr/README.md \ src/core/lib/surface/README.md From 645e30a9311af1721bd8b02b533953c2c38d8263 Mon Sep 17 00:00:00 2001 From: Sree Kuchibhotla Date: Fri, 20 Jan 2017 10:59:15 -0800 Subject: [PATCH 3/8] Fix compilation errors after latest merge with master --- test/core/iomgr/pollset_set_test.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/test/core/iomgr/pollset_set_test.c b/test/core/iomgr/pollset_set_test.c index af971c0784ef5..335e3662e6df4 100644 --- a/test/core/iomgr/pollset_set_test.c +++ b/test/core/iomgr/pollset_set_test.c @@ -95,7 +95,8 @@ static void cleanup_test_pollsets(grpc_exec_ctx *exec_ctx, int i; for (i = 0; i < num_pollsets; i++) { - grpc_closure_init(&destroyed, destroy_pollset, pollsets[i].ps); + grpc_closure_init(&destroyed, destroy_pollset, pollsets[i].ps, + grpc_schedule_on_exec_ctx); grpc_pollset_shutdown(exec_ctx, pollsets[i].ps, &destroyed); grpc_exec_ctx_flush(exec_ctx); @@ -123,7 +124,8 @@ void on_readable(grpc_exec_ctx *exec_ctx, void *tfd, grpc_error *error) { static void reset_test_fd(grpc_exec_ctx *exec_ctx, test_fd *tfd) { tfd->is_on_readable_called = false; - grpc_closure_init(&tfd->on_readable, on_readable, tfd); + grpc_closure_init(&tfd->on_readable, on_readable, tfd, + grpc_schedule_on_exec_ctx); grpc_fd_notify_on_read(exec_ctx, tfd->fd, &tfd->on_readable); } @@ -449,6 +451,7 @@ void pollset_set_test_empty_pollset() { int main(int argc, char **argv) { const char *poll_strategy = NULL; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_test_init(argc, argv); grpc_iomgr_init(); @@ -464,7 +467,8 @@ int main(int argc, char **argv) { poll_strategy); } - grpc_iomgr_shutdown(); + grpc_iomgr_shutdown(&exec_ctx); + grpc_exec_ctx_finish(&exec_ctx); return 0; } #else /* defined(GRPC_LINUX_EPOLL) */ From 7e87c3292927e2c4fa0a0adeaf614cdd0cc4710b Mon Sep 17 00:00:00 2001 From: Sree Kuchibhotla Date: Mon, 23 Jan 2017 14:11:23 -0800 Subject: [PATCH 4/8] generate_projects.sh --- CMakeLists.txt | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2ca0b805429b4..c10773fc02a36 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6919,6 +6919,30 @@ target_link_libraries(percent_encoding_test endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) +add_executable(pollset_set_test + test/core/iomgr/pollset_set_test.c +) + +target_include_directories(pollset_set_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(pollset_set_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + add_executable(resolve_address_test test/core/iomgr/resolve_address_test.c ) From 113267be684063fd4e8db5e83954d6ba1d520b53 Mon Sep 17 00:00:00 2001 From: Sree Kuchibhotla Date: Wed, 25 Jan 2017 14:37:19 -0800 Subject: [PATCH 5/8] Address code review comments --- test/core/iomgr/pollset_set_test.c | 53 +++++++++++------------------- 1 file changed, 20 insertions(+), 33 deletions(-) diff --git a/test/core/iomgr/pollset_set_test.c b/test/core/iomgr/pollset_set_test.c index 335e3662e6df4..e0675bd9d2c0b 100644 --- a/test/core/iomgr/pollset_set_test.c +++ b/test/core/iomgr/pollset_set_test.c @@ -32,9 +32,8 @@ */ #include "src/core/lib/iomgr/port.h" -/* This test only relevant on linux systems */ -#ifdef GRPC_POSIX_SOCKET -#include "src/core/lib/iomgr/ev_posix.h" +/* This test only relevant on linux systems where epoll is available */ +#ifdef GRPC_LINUX_EPOLL #include #include @@ -43,6 +42,7 @@ #include #include +#include "src/core/lib/iomgr/ev_posix.h" #include "src/core/lib/iomgr/iomgr.h" #include "test/core/util/test_config.h" @@ -52,16 +52,14 @@ typedef struct test_pollset_set { grpc_pollset_set *pss; } test_pollset_set; -void init_test_pollset_sets(test_pollset_set pollset_sets[], int num_pss) { - int i; - for (i = 0; i < num_pss; i++) { +void init_test_pollset_sets(test_pollset_set *pollset_sets, int num_pss) { + for (int i = 0; i < num_pss; i++) { pollset_sets[i].pss = grpc_pollset_set_create(); } } -void cleanup_test_pollset_sets(test_pollset_set pollset_sets[], int num_pss) { - int i; - for (i = 0; i < num_pss; i++) { +void cleanup_test_pollset_sets(test_pollset_set *pollset_sets, int num_pss) { + for (int i = 0; i < num_pss; i++) { grpc_pollset_set_destroy(pollset_sets[i].pss); pollset_sets[i].pss = NULL; } @@ -76,9 +74,8 @@ typedef struct test_pollset { gpr_mu *mu; } test_pollset; -static void init_test_pollsets(test_pollset pollsets[], int num_pollsets) { - int i; - for (i = 0; i < num_pollsets; i++) { +static void init_test_pollsets(test_pollset *pollsets, int num_pollsets) { + for (int i = 0; i < num_pollsets; i++) { pollsets[i].ps = gpr_malloc(grpc_pollset_size()); grpc_pollset_init(pollsets[i].ps, &pollsets[i].mu); } @@ -90,11 +87,9 @@ static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, } static void cleanup_test_pollsets(grpc_exec_ctx *exec_ctx, - test_pollset pollsets[], int num_pollsets) { + test_pollset *pollsets, int num_pollsets) { grpc_closure destroyed; - int i; - - for (i = 0; i < num_pollsets; i++) { + for (int i = 0; i < num_pollsets; i++) { grpc_closure_init(&destroyed, destroy_pollset, pollsets[i].ps, grpc_schedule_on_exec_ctx); grpc_pollset_shutdown(exec_ctx, pollsets[i].ps, &destroyed); @@ -129,11 +124,8 @@ static void reset_test_fd(grpc_exec_ctx *exec_ctx, test_fd *tfd) { grpc_fd_notify_on_read(exec_ctx, tfd->fd, &tfd->on_readable); } -static void init_test_fds(grpc_exec_ctx *exec_ctx, test_fd tfds[], - int num_fds) { - int i; - - for (i = 0; i < num_fds; i++) { +static void init_test_fds(grpc_exec_ctx *exec_ctx, test_fd *tfds, int num_fds) { + for (int i = 0; i < num_fds; i++) { GPR_ASSERT(GRPC_ERROR_NONE == grpc_wakeup_fd_init(&tfds[i].wakeup_fd)); tfds[i].fd = grpc_fd_create(GRPC_WAKEUP_FD_GET_READ_FD(&tfds[i].wakeup_fd), "test_fd"); @@ -144,9 +136,8 @@ static void init_test_fds(grpc_exec_ctx *exec_ctx, test_fd tfds[], static void cleanup_test_fds(grpc_exec_ctx *exec_ctx, test_fd *tfds, int num_fds) { int release_fd; - int i; - for (i = 0; i < num_fds; i++) { + for (int i = 0; i < num_fds; i++) { grpc_fd_shutdown(exec_ctx, tfds[i].fd); grpc_exec_ctx_flush(exec_ctx); @@ -162,17 +153,15 @@ static void cleanup_test_fds(grpc_exec_ctx *exec_ctx, test_fd *tfds, } } -static void make_test_fds_readable(test_fd tfds[], int num_fds) { - int i; - for (i = 0; i < num_fds; i++) { +static void make_test_fds_readable(test_fd *tfds, int num_fds) { + for (int i = 0; i < num_fds; i++) { GPR_ASSERT(GRPC_ERROR_NONE == grpc_wakeup_fd_wakeup(&tfds[i].wakeup_fd)); } } -static void verify_readable_and_reset(grpc_exec_ctx *exec_ctx, test_fd tfds[], +static void verify_readable_and_reset(grpc_exec_ctx *exec_ctx, test_fd *tfds, int num_fds) { - int i; - for (i = 0; i < num_fds; i++) { + for (int i = 0; i < num_fds; i++) { /* Verify that the on_readable callback was called */ GPR_ASSERT(tfds[i].is_on_readable_called); @@ -221,7 +210,6 @@ static void pollset_set_test_basic() { * +---> FD9 (Added after PS2 is added to PSS0) */ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - int i; grpc_pollset_worker *worker; gpr_timespec deadline; @@ -272,7 +260,7 @@ static void pollset_set_test_basic() { * - Verify that on_readable call back was called for all FDs (and * reset the FDs) * */ - for (i = 0; i < num_ps; i++) { + for (int i = 0; i < num_ps; i++) { make_test_fds_readable(tfds, num_fds); gpr_mu_lock(pollsets[i].mu); @@ -450,12 +438,11 @@ void pollset_set_test_empty_pollset() { } int main(int argc, char **argv) { - const char *poll_strategy = NULL; + const char *poll_strategy = grpc_get_poll_strategy_name(); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_test_init(argc, argv); grpc_iomgr_init(); - poll_strategy = grpc_get_poll_strategy_name(); if (poll_strategy != NULL && strcmp(poll_strategy, "epoll") == 0) { pollset_set_test_basic(); pollset_set_test_dup_fds(); From 9930e4b39486b3eb62609c67b87d7bc80f63e50d Mon Sep 17 00:00:00 2001 From: Sree Kuchibhotla Date: Wed, 25 Jan 2017 14:48:20 -0800 Subject: [PATCH 6/8] Code review comments --- test/core/iomgr/pollset_set_test.c | 38 +++++++++++++++++------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/test/core/iomgr/pollset_set_test.c b/test/core/iomgr/pollset_set_test.c index e0675bd9d2c0b..3e8dcb4f9c90e 100644 --- a/test/core/iomgr/pollset_set_test.c +++ b/test/core/iomgr/pollset_set_test.c @@ -41,6 +41,7 @@ #include #include +#include #include "src/core/lib/iomgr/ev_posix.h" #include "src/core/lib/iomgr/iomgr.h" @@ -52,13 +53,14 @@ typedef struct test_pollset_set { grpc_pollset_set *pss; } test_pollset_set; -void init_test_pollset_sets(test_pollset_set *pollset_sets, int num_pss) { +void init_test_pollset_sets(test_pollset_set *pollset_sets, const int num_pss) { for (int i = 0; i < num_pss; i++) { pollset_sets[i].pss = grpc_pollset_set_create(); } } -void cleanup_test_pollset_sets(test_pollset_set *pollset_sets, int num_pss) { +void cleanup_test_pollset_sets(test_pollset_set *pollset_sets, + const int num_pss) { for (int i = 0; i < num_pss; i++) { grpc_pollset_set_destroy(pollset_sets[i].pss); pollset_sets[i].pss = NULL; @@ -74,7 +76,7 @@ typedef struct test_pollset { gpr_mu *mu; } test_pollset; -static void init_test_pollsets(test_pollset *pollsets, int num_pollsets) { +static void init_test_pollsets(test_pollset *pollsets, const int num_pollsets) { for (int i = 0; i < num_pollsets; i++) { pollsets[i].ps = gpr_malloc(grpc_pollset_size()); grpc_pollset_init(pollsets[i].ps, &pollsets[i].mu); @@ -87,7 +89,8 @@ static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, } static void cleanup_test_pollsets(grpc_exec_ctx *exec_ctx, - test_pollset *pollsets, int num_pollsets) { + test_pollset *pollsets, + const int num_pollsets) { grpc_closure destroyed; for (int i = 0; i < num_pollsets; i++) { grpc_closure_init(&destroyed, destroy_pollset, pollsets[i].ps, @@ -124,7 +127,8 @@ static void reset_test_fd(grpc_exec_ctx *exec_ctx, test_fd *tfd) { grpc_fd_notify_on_read(exec_ctx, tfd->fd, &tfd->on_readable); } -static void init_test_fds(grpc_exec_ctx *exec_ctx, test_fd *tfds, int num_fds) { +static void init_test_fds(grpc_exec_ctx *exec_ctx, test_fd *tfds, + const int num_fds) { for (int i = 0; i < num_fds; i++) { GPR_ASSERT(GRPC_ERROR_NONE == grpc_wakeup_fd_init(&tfds[i].wakeup_fd)); tfds[i].fd = grpc_fd_create(GRPC_WAKEUP_FD_GET_READ_FD(&tfds[i].wakeup_fd), @@ -134,7 +138,7 @@ static void init_test_fds(grpc_exec_ctx *exec_ctx, test_fd *tfds, int num_fds) { } static void cleanup_test_fds(grpc_exec_ctx *exec_ctx, test_fd *tfds, - int num_fds) { + const int num_fds) { int release_fd; for (int i = 0; i < num_fds; i++) { @@ -153,14 +157,14 @@ static void cleanup_test_fds(grpc_exec_ctx *exec_ctx, test_fd *tfds, } } -static void make_test_fds_readable(test_fd *tfds, int num_fds) { +static void make_test_fds_readable(test_fd *tfds, const int num_fds) { for (int i = 0; i < num_fds; i++) { GPR_ASSERT(GRPC_ERROR_NONE == grpc_wakeup_fd_wakeup(&tfds[i].wakeup_fd)); } } static void verify_readable_and_reset(grpc_exec_ctx *exec_ctx, test_fd *tfds, - int num_fds) { + const int num_fds) { for (int i = 0; i < num_fds; i++) { /* Verify that the on_readable callback was called */ GPR_ASSERT(tfds[i].is_on_readable_called); @@ -216,9 +220,9 @@ static void pollset_set_test_basic() { test_fd tfds[10]; test_pollset pollsets[3]; test_pollset_set pollset_sets[2]; - int num_fds = sizeof(tfds) / sizeof(tfds[0]); - int num_ps = sizeof(pollsets) / sizeof(pollsets[0]); - int num_pss = sizeof(pollset_sets) / sizeof(pollset_sets[0]); + const int num_fds = GPR_ARRAY_SIZE(tfds); + const int num_ps = GPR_ARRAY_SIZE(pollsets); + const int num_pss = GPR_ARRAY_SIZE(pollset_sets); init_test_fds(&exec_ctx, tfds, num_fds); init_test_pollsets(pollsets, num_ps); @@ -321,9 +325,9 @@ void pollset_set_test_dup_fds() { test_fd tfds[3]; test_pollset pollset; test_pollset_set pollset_sets[2]; - int num_fds = sizeof(tfds) / sizeof(tfds[0]); - int num_ps = 1; - int num_pss = sizeof(pollset_sets) / sizeof(pollset_sets[0]); + const int num_fds = GPR_ARRAY_SIZE(tfds); + const int num_ps = 1; + const int num_pss = GPR_ARRAY_SIZE(pollset_sets); init_test_fds(&exec_ctx, tfds, num_fds); init_test_pollsets(&pollset, num_ps); @@ -394,9 +398,9 @@ void pollset_set_test_empty_pollset() { test_fd tfds[3]; test_pollset pollsets[2]; test_pollset_set pollset_set; - int num_fds = sizeof(tfds) / sizeof(tfds[0]); - int num_ps = sizeof(pollsets) / sizeof(pollsets[0]); - int num_pss = 1; + const int num_fds = GPR_ARRAY_SIZE(tfds); + const int num_ps = GPR_ARRAY_SIZE(pollsets); + const int num_pss = 1; init_test_fds(&exec_ctx, tfds, num_fds); init_test_pollsets(pollsets, num_ps); From 608982d1fc1cf84e2907e948ac4b9cba75d3e782 Mon Sep 17 00:00:00 2001 From: Sree Kuchibhotla Date: Mon, 30 Jan 2017 10:45:39 -0800 Subject: [PATCH 7/8] fix grpc_fd_shutdown invocation after latest merge --- test/core/iomgr/pollset_set_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/core/iomgr/pollset_set_test.c b/test/core/iomgr/pollset_set_test.c index 3e8dcb4f9c90e..f1a56ecafb975 100644 --- a/test/core/iomgr/pollset_set_test.c +++ b/test/core/iomgr/pollset_set_test.c @@ -142,7 +142,7 @@ static void cleanup_test_fds(grpc_exec_ctx *exec_ctx, test_fd *tfds, int release_fd; for (int i = 0; i < num_fds; i++) { - grpc_fd_shutdown(exec_ctx, tfds[i].fd); + grpc_fd_shutdown(exec_ctx, tfds[i].fd, GRPC_ERROR_CREATE("fd cleanup")); grpc_exec_ctx_flush(exec_ctx); /* grpc_fd_orphan frees the memory allocated for grpc_fd. Normally it also From 5862f76bd14be059b1ffcd27d72548adede7e7b3 Mon Sep 17 00:00:00 2001 From: Sree Kuchibhotla Date: Wed, 1 Feb 2017 17:00:13 -0800 Subject: [PATCH 8/8] GRPC_TIMEOUT_MILLIS_TO_DEADLINE now renamed to grpc_timeout_milliseconds_to_deadline --- test/core/iomgr/pollset_set_test.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/core/iomgr/pollset_set_test.c b/test/core/iomgr/pollset_set_test.c index f1a56ecafb975..40fa858602097 100644 --- a/test/core/iomgr/pollset_set_test.c +++ b/test/core/iomgr/pollset_set_test.c @@ -268,7 +268,7 @@ static void pollset_set_test_basic() { make_test_fds_readable(tfds, num_fds); gpr_mu_lock(pollsets[i].mu); - deadline = GRPC_TIMEOUT_MILLIS_TO_DEADLINE(2); + deadline = grpc_timeout_milliseconds_to_deadline(2); GPR_ASSERT(GRPC_ERROR_NONE == grpc_pollset_work(&exec_ctx, pollsets[i].ps, &worker, gpr_now(GPR_CLOCK_MONOTONIC), deadline)); @@ -350,7 +350,7 @@ void pollset_set_test_dup_fds() { make_test_fds_readable(tfds, num_fds); gpr_mu_lock(pollset.mu); - deadline = GRPC_TIMEOUT_MILLIS_TO_DEADLINE(2); + deadline = grpc_timeout_milliseconds_to_deadline(2); GPR_ASSERT(GRPC_ERROR_NONE == grpc_pollset_work(&exec_ctx, pollset.ps, &worker, gpr_now(GPR_CLOCK_MONOTONIC), deadline)); @@ -419,7 +419,7 @@ void pollset_set_test_empty_pollset() { make_test_fds_readable(tfds, num_fds); gpr_mu_lock(pollsets[0].mu); - deadline = GRPC_TIMEOUT_MILLIS_TO_DEADLINE(2); + deadline = grpc_timeout_milliseconds_to_deadline(2); GPR_ASSERT(GRPC_ERROR_NONE == grpc_pollset_work(&exec_ctx, pollsets[0].ps, &worker, gpr_now(GPR_CLOCK_MONOTONIC), deadline));