diff options
author | dan sinclair <dj2@everburning.com> | 2018-08-02 14:36:43 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-02 14:36:43 -0400 |
commit | de9496e9f1b9d74c117fb4c4552ef0f5d74b8cbd (patch) | |
tree | 3a1532fc729302c92adf5b5ef378369ec841a8f1 | |
parent | e323529d99213aa83db2d5989f99f419b99e7c58 (diff) |
Add more fuzzers for Optimizer. (#1788)
This Cl adds the legalization and size fuzzers for the optimizer. The
main optimizer is renamed to the performance optimizer.
-rw-r--r-- | BUILD.gn | 2 | ||||
-rw-r--r-- | testing/fuzzers/BUILD.gn | 40 | ||||
-rw-r--r-- | testing/fuzzers/spvtools_opt_legalization_fuzzer.cpp | 37 | ||||
-rw-r--r-- | testing/fuzzers/spvtools_opt_performance_fuzzer.cpp (renamed from testing/fuzzers/spvtools_opt_fuzzer.cpp) | 0 | ||||
-rw-r--r-- | testing/fuzzers/spvtools_opt_size_fuzzer.cpp | 37 |
5 files changed, 111 insertions, 5 deletions
@@ -414,6 +414,8 @@ static_library("spvtools_opt") { "source/opt/cfg.h", "source/opt/cfg_cleanup_pass.cpp", "source/opt/cfg_cleanup_pass.h", + "source/opt/combine_access_chains.cpp", + "source/opt/combine_access_chains.h", "source/opt/common_uniform_elim_pass.cpp", "source/opt/common_uniform_elim_pass.h", "source/opt/compact_ids_pass.cpp", diff --git a/testing/fuzzers/BUILD.gn b/testing/fuzzers/BUILD.gn index 718e8f6c..df8291a5 100644 --- a/testing/fuzzers/BUILD.gn +++ b/testing/fuzzers/BUILD.gn @@ -33,8 +33,10 @@ if (!build_with_chromium || use_fuzzing_engine) { testonly = true deps = [ - ":spvtools_opt_fuzzer", ":spvtools_val_fuzzer", + ":spvtools_opt_legalization_fuzzer", + ":spvtools_opt_performance_fuzzer", + ":spvtools_opt_size_fuzzer", ] } } @@ -60,9 +62,21 @@ template("spvtools_fuzzer") { } } -spvtools_fuzzer("spvtools_opt_fuzzer_src") { +spvtools_fuzzer("spvtools_opt_performance_fuzzer_src") { sources = [ - "spvtools_opt_fuzzer.cpp", + "spvtools_opt_performance_fuzzer.cpp", + ] +} + +spvtools_fuzzer("spvtools_opt_legalization_fuzzer_src") { + sources = [ + "spvtools_opt_legalization_fuzzer.cpp", + ] +} + +spvtools_fuzzer("spvtools_opt_size_fuzzer_src") { + sources = [ + "spvtools_opt_size_fuzzer.cpp", ] } @@ -73,10 +87,26 @@ spvtools_fuzzer("spvtools_val_fuzzer_src") { } if (!build_with_chromium || use_fuzzing_engine) { - fuzzer_test("spvtools_opt_fuzzer") { + fuzzer_test("spvtools_opt_performance_fuzzer") { + sources = [] + deps = [ + ":spvtools_opt_performance_fuzzer_src", + ] + seed_corpus = "corpora/spv" + } + + fuzzer_test("spvtools_opt_legalization_fuzzer") { + sources = [] + deps = [ + ":spvtools_opt_legalization_fuzzer_src", + ] + seed_corpus = "corpora/spv" + } + + fuzzer_test("spvtools_opt_size_fuzzer") { sources = [] deps = [ - ":spvtools_opt_fuzzer_src", + ":spvtools_opt_size_fuzzer_src", ] seed_corpus = "corpora/spv" } diff --git a/testing/fuzzers/spvtools_opt_legalization_fuzzer.cpp b/testing/fuzzers/spvtools_opt_legalization_fuzzer.cpp new file mode 100644 index 00000000..f37dcc84 --- /dev/null +++ b/testing/fuzzers/spvtools_opt_legalization_fuzzer.cpp @@ -0,0 +1,37 @@ +// Copyright (c) 2018 Google Inc. +// +// 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 <cstdint> + +#include "spirv-tools/optimizer.hpp" + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { + spvtools::Optimizer optimizer(SPV_ENV_UNIVERSAL_1_3); + optimizer.SetMessageConsumer([](spv_message_level_t, const char*, + const spv_position_t&, const char*) {}); + + std::vector<uint32_t> input; + input.resize(size >> 2); + + size_t count = 0; + for (size_t i = 0; (i + 3) < size; i += 4) { + input[count++] = data[i] | (data[i + 1] << 8) | (data[i + 2] << 16) | + (data[i + 3]) << 24; + } + + optimizer.RegisterLegalizationPasses(); + optimizer.Run(input.data(), input.size(), &input); + + return 0; +} diff --git a/testing/fuzzers/spvtools_opt_fuzzer.cpp b/testing/fuzzers/spvtools_opt_performance_fuzzer.cpp index 7f94febc..7f94febc 100644 --- a/testing/fuzzers/spvtools_opt_fuzzer.cpp +++ b/testing/fuzzers/spvtools_opt_performance_fuzzer.cpp diff --git a/testing/fuzzers/spvtools_opt_size_fuzzer.cpp b/testing/fuzzers/spvtools_opt_size_fuzzer.cpp new file mode 100644 index 00000000..1f06a71f --- /dev/null +++ b/testing/fuzzers/spvtools_opt_size_fuzzer.cpp @@ -0,0 +1,37 @@ +// Copyright (c) 2018 Google Inc. +// +// 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 <cstdint> + +#include "spirv-tools/optimizer.hpp" + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { + spvtools::Optimizer optimizer(SPV_ENV_UNIVERSAL_1_3); + optimizer.SetMessageConsumer([](spv_message_level_t, const char*, + const spv_position_t&, const char*) {}); + + std::vector<uint32_t> input; + input.resize(size >> 2); + + size_t count = 0; + for (size_t i = 0; (i + 3) < size; i += 4) { + input[count++] = data[i] | (data[i + 1] << 8) | (data[i + 2] << 16) | + (data[i + 3]) << 24; + } + + optimizer.RegisterSizePasses(); + optimizer.Run(input.data(), input.size(), &input); + + return 0; +} |