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.
This commit is contained in:
dan sinclair 2018-08-02 14:36:43 -04:00 committed by GitHub
parent e323529d99
commit de9496e9f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 111 additions and 5 deletions

View File

@ -414,6 +414,8 @@ static_library("spvtools_opt") {
"source/opt/cfg.h", "source/opt/cfg.h",
"source/opt/cfg_cleanup_pass.cpp", "source/opt/cfg_cleanup_pass.cpp",
"source/opt/cfg_cleanup_pass.h", "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.cpp",
"source/opt/common_uniform_elim_pass.h", "source/opt/common_uniform_elim_pass.h",
"source/opt/compact_ids_pass.cpp", "source/opt/compact_ids_pass.cpp",

View File

@ -33,8 +33,10 @@ if (!build_with_chromium || use_fuzzing_engine) {
testonly = true testonly = true
deps = [ deps = [
":spvtools_opt_fuzzer",
":spvtools_val_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 = [ 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) { if (!build_with_chromium || use_fuzzing_engine) {
fuzzer_test("spvtools_opt_fuzzer") { fuzzer_test("spvtools_opt_performance_fuzzer") {
sources = [] sources = []
deps = [ deps = [
":spvtools_opt_fuzzer_src", ":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_size_fuzzer_src",
] ]
seed_corpus = "corpora/spv" seed_corpus = "corpora/spv"
} }

View File

@ -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;
}

View File

@ -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;
}