From 2c357bc62e795affe6a9278193b579960aaf56ec Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 29 Sep 2017 11:10:14 -0700 Subject: Moving to allow fuzzer test to run entire corpora under bazel --- test/core/util/BUILD | 8 +- test/core/util/fuzzer_corpus_test.cc | 139 +++++++++++++++++++++++++++++++ test/core/util/grpc_fuzzer.bzl | 20 ++--- test/core/util/one_corpus_entry_fuzzer.c | 39 --------- 4 files changed, 154 insertions(+), 52 deletions(-) create mode 100644 test/core/util/fuzzer_corpus_test.cc delete mode 100644 test/core/util/one_corpus_entry_fuzzer.c diff --git a/test/core/util/BUILD b/test/core/util/BUILD index 10eefe159a..abb50a0c99 100644 --- a/test/core/util/BUILD +++ b/test/core/util/BUILD @@ -89,12 +89,16 @@ grpc_cc_library( ) grpc_cc_library( - name = "one_corpus_entry_fuzzer", - srcs = ["one_corpus_entry_fuzzer.c"], + name = "fuzzer_corpus_test", + srcs = ["fuzzer_corpus_test.cc"], deps = [ ":gpr_test_util", "//:grpc", ], + external_deps = [ + "gtest", + "gflags", + ], ) sh_library( diff --git a/test/core/util/fuzzer_corpus_test.cc b/test/core/util/fuzzer_corpus_test.cc new file mode 100644 index 0000000000..75c6846cd7 --- /dev/null +++ b/test/core/util/fuzzer_corpus_test.cc @@ -0,0 +1,139 @@ +/* + * + * Copyright 2016 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include +#include +#include +#include +#include +#include + +#include "src/core/lib/iomgr/load_file.h" +#include "test/core/util/test_config.h" + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size); +extern "C" bool squelch; +extern "C" bool leak_check; + +DEFINE_string(file, "", "Use this file as test data"); +DEFINE_string(directory, "", "Use this directory as test data"); + +class FuzzerCorpusTest : public ::testing::TestWithParam {}; + +TEST_P(FuzzerCorpusTest, RunOneExample) { + grpc_slice buffer; + squelch = false; + leak_check = false; + GPR_ASSERT(GRPC_LOG_IF_ERROR("load_file", + grpc_load_file(GetParam().c_str(), 0, &buffer))); + LLVMFuzzerTestOneInput(GRPC_SLICE_START_PTR(buffer), + GRPC_SLICE_LENGTH(buffer)); + grpc_slice_unref(buffer); +} + +class ExampleGenerator + : public ::testing::internal::ParamGeneratorInterface { + public: + virtual ::testing::internal::ParamIteratorInterface* Begin() + const; + virtual ::testing::internal::ParamIteratorInterface* End() const; + + private: + void Materialize() const { + if (examples_.empty()) { + if (!FLAGS_file.empty()) examples_.push_back(FLAGS_file); + if (!FLAGS_directory.empty()) { + DIR* dp; + struct dirent* ep; + dp = opendir("./"); + + if (dp != NULL) { + while ((ep = readdir(dp)) != nullptr) examples_.push_back(ep->d_name); + + (void)closedir(dp); + } else { + perror("Couldn't open the directory"); + abort(); + } + } + } + } + + mutable std::vector examples_; +}; + +class ExampleIterator + : public ::testing::internal::ParamIteratorInterface { + public: + ExampleIterator(const ExampleGenerator& base_, + std::vector::const_iterator begin) + : base_(base_), begin_(begin), current_(begin), current_string_(NULL) {} + + ~ExampleIterator() { delete current_string_; } + virtual const ExampleGenerator* BaseGenerator() const { return &base_; } + + virtual void Advance() { + current_++; + delete current_string_; + current_string_ = NULL; + } + virtual ExampleIterator* Clone() const { return new ExampleIterator(*this); } + virtual const std::string* Current() const; + + virtual bool Equals(const ParamIteratorInterface& other) const { + return &base_ == other.BaseGenerator() && + current_ == dynamic_cast(&other)->current_; + } + + private: + ExampleIterator(const ExampleIterator& other) + : base_(other.base_), + begin_(other.begin_), + current_(other.current_), + current_string_(NULL) {} + + const ExampleGenerator& base_; + const std::vector::const_iterator begin_; + std::vector::const_iterator current_; + mutable const std::string* current_string_; +}; + +::testing::internal::ParamIteratorInterface* +ExampleGenerator::Begin() const { + Materialize(); + return new ExampleIterator(*this, examples_.begin()); +} + +::testing::internal::ParamIteratorInterface* +ExampleGenerator::End() const { + Materialize(); + return new ExampleIterator(*this, examples_.end()); +} + +INSTANTIATE_TEST_CASE_P( + CorpusExamples, FuzzerCorpusTest, + ::testing::internal::ParamGenerator(new ExampleGenerator)); + +int main(int argc, char** argv) { + grpc_test_init(argc, argv); + ::testing::InitGoogleTest(&argc, argv); + + return RUN_ALL_TESTS(); +} diff --git a/test/core/util/grpc_fuzzer.bzl b/test/core/util/grpc_fuzzer.bzl index 41f6cdc8ba..55b6f1c1a5 100644 --- a/test/core/util/grpc_fuzzer.bzl +++ b/test/core/util/grpc_fuzzer.bzl @@ -12,19 +12,17 @@ # See the License for the specific language governing permissions and # limitations under the License. -load("//bazel:grpc_build_system.bzl", "grpc_cc_binary") +load("//bazel:grpc_build_system.bzl", "grpc_cc_test") def grpc_fuzzer(name, corpus, srcs = [], deps = [], **kwargs): - grpc_cc_binary( - name = '%s/one_entry.bin' % name, + grpc_cc_test( + name = name, srcs = srcs, - deps = deps + ["//test/core/util:one_corpus_entry_fuzzer"], + deps = deps + ["//test/core/util:fuzzer_corpus_test"], + data = [corpus], + args = ['--directory', '$(location %s)' % corpus], + external_deps = [ + 'gtest', + ], **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/one_corpus_entry_fuzzer.c b/test/core/util/one_corpus_entry_fuzzer.c deleted file mode 100644 index 42467390f2..0000000000 --- a/test/core/util/one_corpus_entry_fuzzer.c +++ /dev/null @@ -1,39 +0,0 @@ -/* - * - * Copyright 2016 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include -#include "src/core/lib/iomgr/load_file.h" - -extern int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size); - -extern bool squelch; -extern bool leak_check; - -int main(int argc, char **argv) { - grpc_slice buffer; - squelch = false; - leak_check = false; - GPR_ASSERT( - GRPC_LOG_IF_ERROR("load_file", grpc_load_file(argv[1], 0, &buffer))); - LLVMFuzzerTestOneInput(GRPC_SLICE_START_PTR(buffer), - GRPC_SLICE_LENGTH(buffer)); - grpc_slice_unref(buffer); - return 0; -} -- cgit v1.2.3 From d75d90f055a664fb60a0b33954c6db06d2ceed57 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 3 Oct 2017 09:58:21 -0700 Subject: Make this work --- test/core/util/fuzzer_corpus_test.cc | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/test/core/util/fuzzer_corpus_test.cc b/test/core/util/fuzzer_corpus_test.cc index 75c6846cd7..a5e99a1bac 100644 --- a/test/core/util/fuzzer_corpus_test.cc +++ b/test/core/util/fuzzer_corpus_test.cc @@ -38,6 +38,7 @@ DEFINE_string(directory, "", "Use this directory as test data"); class FuzzerCorpusTest : public ::testing::TestWithParam {}; TEST_P(FuzzerCorpusTest, RunOneExample) { + gpr_log(GPR_DEBUG, "Example file: %s", GetParam().c_str()); grpc_slice buffer; squelch = false; leak_check = false; @@ -62,10 +63,14 @@ class ExampleGenerator if (!FLAGS_directory.empty()) { DIR* dp; struct dirent* ep; - dp = opendir("./"); + dp = opendir(FLAGS_directory.c_str()); if (dp != NULL) { - while ((ep = readdir(dp)) != nullptr) examples_.push_back(ep->d_name); + while ((ep = readdir(dp)) != nullptr) { + if (ep->d_type == DT_REG) { + examples_.push_back(FLAGS_directory + "/" + ep->d_name); + } + } (void)closedir(dp); } else { @@ -84,18 +89,13 @@ class ExampleIterator public: ExampleIterator(const ExampleGenerator& base_, std::vector::const_iterator begin) - : base_(base_), begin_(begin), current_(begin), current_string_(NULL) {} + : base_(base_), begin_(begin), current_(begin) {} - ~ExampleIterator() { delete current_string_; } virtual const ExampleGenerator* BaseGenerator() const { return &base_; } - virtual void Advance() { - current_++; - delete current_string_; - current_string_ = NULL; - } + virtual void Advance() { current_++; } virtual ExampleIterator* Clone() const { return new ExampleIterator(*this); } - virtual const std::string* Current() const; + virtual const std::string* Current() const { return &*current_; } virtual bool Equals(const ParamIteratorInterface& other) const { return &base_ == other.BaseGenerator() && @@ -104,15 +104,11 @@ class ExampleIterator private: ExampleIterator(const ExampleIterator& other) - : base_(other.base_), - begin_(other.begin_), - current_(other.current_), - current_string_(NULL) {} + : base_(other.base_), begin_(other.begin_), current_(other.current_) {} const ExampleGenerator& base_; const std::vector::const_iterator begin_; std::vector::const_iterator current_; - mutable const std::string* current_string_; }; ::testing::internal::ParamIteratorInterface* @@ -133,6 +129,7 @@ INSTANTIATE_TEST_CASE_P( int main(int argc, char** argv) { grpc_test_init(argc, argv); + ::gflags::ParseCommandLineFlags(&argc, &argv, true); ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); -- cgit v1.2.3 From b44a7bf8c3d8390c78c56b6aff7bd30a2da5289f Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 3 Oct 2017 14:35:38 -0700 Subject: Revert deleted file --- test/core/util/one_corpus_entry_fuzzer.c | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 test/core/util/one_corpus_entry_fuzzer.c diff --git a/test/core/util/one_corpus_entry_fuzzer.c b/test/core/util/one_corpus_entry_fuzzer.c new file mode 100644 index 0000000000..42467390f2 --- /dev/null +++ b/test/core/util/one_corpus_entry_fuzzer.c @@ -0,0 +1,39 @@ +/* + * + * Copyright 2016 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include +#include "src/core/lib/iomgr/load_file.h" + +extern int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size); + +extern bool squelch; +extern bool leak_check; + +int main(int argc, char **argv) { + grpc_slice buffer; + squelch = false; + leak_check = false; + GPR_ASSERT( + GRPC_LOG_IF_ERROR("load_file", grpc_load_file(argv[1], 0, &buffer))); + LLVMFuzzerTestOneInput(GRPC_SLICE_START_PTR(buffer), + GRPC_SLICE_LENGTH(buffer)); + grpc_slice_unref(buffer); + return 0; +} -- cgit v1.2.3 From d3568c0a206b6c4b7529176e181f04c6624b1295 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 3 Oct 2017 15:49:33 -0700 Subject: Fixes --- test/core/slice/BUILD | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/test/core/slice/BUILD b/test/core/slice/BUILD index f86a3a6082..ad2308a4d6 100644 --- a/test/core/slice/BUILD +++ b/test/core/slice/BUILD @@ -20,11 +20,23 @@ licenses(["notice"]) # Apache v2 load("//test/core/util:grpc_fuzzer.bzl", "grpc_fuzzer") +grpc_fuzzer( + name = "percent_encode_fuzzer", + srcs = ["percent_encode_fuzzer.c"], + language = "C", + corpus = "percent_encode_corpus", + deps = [ + "//:gpr", + "//:grpc", + "//test/core/util:grpc_test_util", + ], +) + grpc_fuzzer( name = "percent_decode_fuzzer", srcs = ["percent_decode_fuzzer.c"], language = "C", - corpus = "response_corpus", + corpus = "percent_decode_corpus", deps = [ "//:gpr", "//:grpc", -- cgit v1.2.3 From 663f50c658b6f13dedac5541f8a0789257225a69 Mon Sep 17 00:00:00 2001 From: Juanli Shen Date: Thu, 5 Oct 2017 14:36:13 -0700 Subject: Cancel fallback timer in glb_shutdown() --- src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc index d8e314d1f9..773ae29e41 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc @@ -1010,6 +1010,10 @@ static void glb_shutdown_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol) { grpc_timer_cancel(exec_ctx, &glb_policy->lb_call_retry_timer); glb_policy->retry_timer_active = false; } + if (glb_policy->fallback_timer_active) { + grpc_timer_cancel(exec_ctx, &glb_policy->lb_fallback_timer); + glb_policy->fallback_timer_active = false; + } pending_pick *pp = glb_policy->pending_picks; glb_policy->pending_picks = NULL; -- cgit v1.2.3