diff options
Diffstat (limited to 'test/core/util')
-rw-r--r-- | test/core/util/BUILD | 58 | ||||
-rwxr-xr-x | test/core/util/fuzzer_one_entry_runner.sh | 33 | ||||
-rw-r--r-- | test/core/util/grpc_fuzzer.bzl | 43 | ||||
-rw-r--r-- | test/core/util/mock_endpoint.c | 10 | ||||
-rw-r--r-- | test/core/util/passthru_endpoint.c | 21 | ||||
-rw-r--r-- | test/core/util/port_server_client.c | 28 | ||||
-rw-r--r-- | test/core/util/test_tcp_server.c | 6 |
7 files changed, 170 insertions, 29 deletions
diff --git a/test/core/util/BUILD b/test/core/util/BUILD new file mode 100644 index 0000000000..e50e595d03 --- /dev/null +++ b/test/core/util/BUILD @@ -0,0 +1,58 @@ + + +cc_library( + name = "gpr_test_util", + srcs = [ + "test_config.c", + "memory_counters.c", + ], + hdrs = [ + "test_config.h", + "memory_counters.h", + ], + deps = ["//:gpr"], + visibility = ["//:__subpackages__"], +) + +cc_library( + name = "grpc_test_util", + srcs = [ + "grpc_profiler.c", + "mock_endpoint.c", + "parse_hexstring.c", + "passthru_endpoint.c", + "port_posix.c", + "port_server_client.c", + "port_windows.c", + "reconnect_server.c", + "slice_splitter.c", + "test_tcp_server.c", + ], + hdrs = [ + "grpc_profiler.h", + "mock_endpoint.h", + "parse_hexstring.h", + "passthru_endpoint.h", + "port.h", + "port_server_client.h", + "reconnect_server.h", + "slice_splitter.h", + "test_tcp_server.h", + ], + deps = [":gpr_test_util", "//:grpc"], + visibility = ["//test:__subpackages__"], + copts = ["-std=c99"], +) + +cc_library( + name = "one_corpus_entry_fuzzer", + srcs = ["one_corpus_entry_fuzzer.c"], + deps = [":gpr_test_util", "//:grpc"], + visibility = ["//test:__subpackages__"], +) + +sh_library( + name = "fuzzer_one_entry_runner", + srcs = ["fuzzer_one_entry_runner.sh"], + visibility = ["//test:__subpackages__"], +) diff --git a/test/core/util/fuzzer_one_entry_runner.sh b/test/core/util/fuzzer_one_entry_runner.sh new file mode 100755 index 0000000000..a0558a9c09 --- /dev/null +++ b/test/core/util/fuzzer_one_entry_runner.sh @@ -0,0 +1,33 @@ +#!/bin/sh + +# Test runner for fuzzer tests from bazel + +# Copyright 2017, 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. +$1 $2 diff --git a/test/core/util/grpc_fuzzer.bzl b/test/core/util/grpc_fuzzer.bzl new file mode 100644 index 0000000000..2f552a9fdb --- /dev/null +++ b/test/core/util/grpc_fuzzer.bzl @@ -0,0 +1,43 @@ +# 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. + +def grpc_fuzzer(name, corpus, srcs = [], deps = [], **kwargs): + native.cc_binary( + name = '%s/one_entry.bin' % name, + srcs = srcs, + deps = deps + ["//test/core/util:one_corpus_entry_fuzzer"], + **kwargs + ) + for entry in native.glob(['%s/*' % corpus]): + native.sh_test( + name = '%s/one_entry/%s' % (name, entry), + data = [':%s/one_entry.bin' % name, entry], + srcs = ['//test/core/util:fuzzer_one_entry_runner'], + args = ['$(location :%s/one_entry.bin)' % name, '$(location %s)' % entry] + ) diff --git a/test/core/util/mock_endpoint.c b/test/core/util/mock_endpoint.c index bf6d85252a..04793bceab 100644 --- a/test/core/util/mock_endpoint.c +++ b/test/core/util/mock_endpoint.c @@ -55,7 +55,7 @@ static void me_read(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep, gpr_mu_lock(&m->mu); if (m->read_buffer.count > 0) { grpc_slice_buffer_swap(&m->read_buffer, slices); - grpc_exec_ctx_sched(exec_ctx, cb, GRPC_ERROR_NONE, NULL); + grpc_closure_sched(exec_ctx, cb, GRPC_ERROR_NONE); } else { m->on_read = cb; m->on_read_out = slices; @@ -69,7 +69,7 @@ static void me_write(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep, for (size_t i = 0; i < slices->count; i++) { m->on_write(slices->slices[i]); } - grpc_exec_ctx_sched(exec_ctx, cb, GRPC_ERROR_NONE, NULL); + grpc_closure_sched(exec_ctx, cb, GRPC_ERROR_NONE); } static void me_add_to_pollset(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep, @@ -82,8 +82,8 @@ static void me_shutdown(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep) { grpc_mock_endpoint *m = (grpc_mock_endpoint *)ep; gpr_mu_lock(&m->mu); if (m->on_read) { - grpc_exec_ctx_sched(exec_ctx, m->on_read, - GRPC_ERROR_CREATE("Endpoint Shutdown"), NULL); + grpc_closure_sched(exec_ctx, m->on_read, + GRPC_ERROR_CREATE("Endpoint Shutdown")); m->on_read = NULL; } gpr_mu_unlock(&m->mu); @@ -144,7 +144,7 @@ void grpc_mock_endpoint_put_read(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep, gpr_mu_lock(&m->mu); if (m->on_read != NULL) { grpc_slice_buffer_add(m->on_read_out, slice); - grpc_exec_ctx_sched(exec_ctx, m->on_read, GRPC_ERROR_NONE, NULL); + grpc_closure_sched(exec_ctx, m->on_read, GRPC_ERROR_NONE); m->on_read = NULL; } else { grpc_slice_buffer_add(&m->read_buffer, slice); diff --git a/test/core/util/passthru_endpoint.c b/test/core/util/passthru_endpoint.c index b3405f02e9..d42ec7f9e8 100644 --- a/test/core/util/passthru_endpoint.c +++ b/test/core/util/passthru_endpoint.c @@ -39,6 +39,8 @@ #include <grpc/support/string_util.h> #include "src/core/lib/iomgr/sockaddr.h" +#include "src/core/lib/slice/slice_internal.h" + typedef struct passthru_endpoint passthru_endpoint; typedef struct { @@ -63,11 +65,10 @@ static void me_read(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep, half *m = (half *)ep; gpr_mu_lock(&m->parent->mu); if (m->parent->shutdown) { - grpc_exec_ctx_sched(exec_ctx, cb, GRPC_ERROR_CREATE("Already shutdown"), - NULL); + grpc_closure_sched(exec_ctx, cb, GRPC_ERROR_CREATE("Already shutdown")); } else if (m->read_buffer.count > 0) { grpc_slice_buffer_swap(&m->read_buffer, slices); - grpc_exec_ctx_sched(exec_ctx, cb, GRPC_ERROR_NONE, NULL); + grpc_closure_sched(exec_ctx, cb, GRPC_ERROR_NONE); } else { m->on_read = cb; m->on_read_out = slices; @@ -91,7 +92,7 @@ static void me_write(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep, for (size_t i = 0; i < slices->count; i++) { grpc_slice_buffer_add(m->on_read_out, grpc_slice_ref(slices->slices[i])); } - grpc_exec_ctx_sched(exec_ctx, m->on_read, GRPC_ERROR_NONE, NULL); + grpc_closure_sched(exec_ctx, m->on_read, GRPC_ERROR_NONE); m->on_read = NULL; } else { for (size_t i = 0; i < slices->count; i++) { @@ -99,7 +100,7 @@ static void me_write(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep, } } gpr_mu_unlock(&m->parent->mu); - grpc_exec_ctx_sched(exec_ctx, cb, error, NULL); + grpc_closure_sched(exec_ctx, cb, error); } static void me_add_to_pollset(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep, @@ -113,14 +114,12 @@ static void me_shutdown(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep) { gpr_mu_lock(&m->parent->mu); m->parent->shutdown = true; if (m->on_read) { - grpc_exec_ctx_sched(exec_ctx, m->on_read, GRPC_ERROR_CREATE("Shutdown"), - NULL); + grpc_closure_sched(exec_ctx, m->on_read, GRPC_ERROR_CREATE("Shutdown")); m->on_read = NULL; } m = other_half(m); if (m->on_read) { - grpc_exec_ctx_sched(exec_ctx, m->on_read, GRPC_ERROR_CREATE("Shutdown"), - NULL); + grpc_closure_sched(exec_ctx, m->on_read, GRPC_ERROR_CREATE("Shutdown")); m->on_read = NULL; } gpr_mu_unlock(&m->parent->mu); @@ -133,8 +132,8 @@ static void me_destroy(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep) { if (0 == --p->halves) { gpr_mu_unlock(&p->mu); gpr_mu_destroy(&p->mu); - grpc_slice_buffer_destroy(&p->client.read_buffer); - grpc_slice_buffer_destroy(&p->server.read_buffer); + grpc_slice_buffer_destroy_internal(exec_ctx, &p->client.read_buffer); + grpc_slice_buffer_destroy_internal(exec_ctx, &p->server.read_buffer); grpc_resource_user_unref(exec_ctx, p->client.resource_user); grpc_resource_user_unref(exec_ctx, p->server.resource_user); gpr_free(p); diff --git a/test/core/util/port_server_client.c b/test/core/util/port_server_client.c index b2342feeb4..4baf63dcd7 100644 --- a/test/core/util/port_server_client.c +++ b/test/core/util/port_server_client.c @@ -92,7 +92,8 @@ void grpc_free_port_using_server(char *server, int port) { grpc_pollset *pollset = gpr_malloc(grpc_pollset_size()); grpc_pollset_init(pollset, &pr.mu); pr.pops = grpc_polling_entity_create_from_pollset(pollset); - shutdown_closure = grpc_closure_create(destroy_pops_and_shutdown, &pr.pops); + shutdown_closure = grpc_closure_create(destroy_pops_and_shutdown, &pr.pops, + grpc_schedule_on_exec_ctx); req.host = server; gpr_asprintf(&path, "/drop/%d", port); @@ -103,8 +104,10 @@ void grpc_free_port_using_server(char *server, int port) { grpc_resource_quota_create("port_server_client/free"); grpc_httpcli_get(&exec_ctx, &context, &pr.pops, resource_quota, &req, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10), - grpc_closure_create(freed_port_from_server, &pr), &rsp); - grpc_resource_quota_internal_unref(&exec_ctx, resource_quota); + grpc_closure_create(freed_port_from_server, &pr, + grpc_schedule_on_exec_ctx), + &rsp); + grpc_resource_quota_unref_internal(&exec_ctx, resource_quota); gpr_mu_lock(pr.mu); while (!pr.done) { grpc_pollset_worker *worker = NULL; @@ -174,9 +177,10 @@ static void got_port_from_server(grpc_exec_ctx *exec_ctx, void *arg, grpc_resource_quota_create("port_server_client/pick_retry"); grpc_httpcli_get(exec_ctx, pr->ctx, &pr->pops, resource_quota, &req, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10), - grpc_closure_create(got_port_from_server, pr), + grpc_closure_create(got_port_from_server, pr, + grpc_schedule_on_exec_ctx), &pr->response); - grpc_resource_quota_internal_unref(exec_ctx, resource_quota); + grpc_resource_quota_unref_internal(exec_ctx, resource_quota); return; } GPR_ASSERT(response); @@ -208,7 +212,8 @@ int grpc_pick_port_using_server(char *server) { grpc_pollset *pollset = gpr_malloc(grpc_pollset_size()); grpc_pollset_init(pollset, &pr.mu); pr.pops = grpc_polling_entity_create_from_pollset(pollset); - shutdown_closure = grpc_closure_create(destroy_pops_and_shutdown, &pr.pops); + shutdown_closure = grpc_closure_create(destroy_pops_and_shutdown, &pr.pops, + grpc_schedule_on_exec_ctx); pr.port = -1; pr.server = server; pr.ctx = &context; @@ -219,11 +224,12 @@ int grpc_pick_port_using_server(char *server) { grpc_httpcli_context_init(&context); grpc_resource_quota *resource_quota = grpc_resource_quota_create("port_server_client/pick"); - grpc_httpcli_get(&exec_ctx, &context, &pr.pops, resource_quota, &req, - GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10), - grpc_closure_create(got_port_from_server, &pr), - &pr.response); - grpc_resource_quota_internal_unref(&exec_ctx, resource_quota); + grpc_httpcli_get( + &exec_ctx, &context, &pr.pops, resource_quota, &req, + GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10), + grpc_closure_create(got_port_from_server, &pr, grpc_schedule_on_exec_ctx), + &pr.response); + grpc_resource_quota_unref_internal(&exec_ctx, resource_quota); grpc_exec_ctx_finish(&exec_ctx); gpr_mu_lock(pr.mu); while (pr.port == -1) { diff --git a/test/core/util/test_tcp_server.c b/test/core/util/test_tcp_server.c index 16df91d968..2338b81ab1 100644 --- a/test/core/util/test_tcp_server.c +++ b/test/core/util/test_tcp_server.c @@ -57,7 +57,8 @@ void test_tcp_server_init(test_tcp_server *server, grpc_tcp_server_cb on_connect, void *user_data) { grpc_init(); server->tcp_server = NULL; - grpc_closure_init(&server->shutdown_complete, on_server_destroyed, server); + grpc_closure_init(&server->shutdown_complete, on_server_destroyed, server, + grpc_schedule_on_exec_ctx); server->shutdown = 0; server->pollset = gpr_malloc(grpc_pollset_size()); grpc_pollset_init(server->pollset, &server->mu); @@ -111,7 +112,8 @@ void test_tcp_server_destroy(test_tcp_server *server) { gpr_timespec shutdown_deadline; grpc_closure do_nothing_cb; grpc_tcp_server_unref(&exec_ctx, server->tcp_server); - grpc_closure_init(&do_nothing_cb, do_nothing, NULL); + grpc_closure_init(&do_nothing_cb, do_nothing, NULL, + grpc_schedule_on_exec_ctx); shutdown_deadline = gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), gpr_time_from_seconds(5, GPR_TIMESPAN)); while (!server->shutdown && |