mirror of
https://github.com/KhronosGroup/SPIRV-Tools
synced 2024-11-23 04:00:05 +00:00
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:
parent
e323529d99
commit
de9496e9f1
2
BUILD.gn
2
BUILD.gn
@ -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",
|
||||
|
@ -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_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"
|
||||
}
|
||||
|
37
testing/fuzzers/spvtools_opt_legalization_fuzzer.cpp
Normal file
37
testing/fuzzers/spvtools_opt_legalization_fuzzer.cpp
Normal 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;
|
||||
}
|
37
testing/fuzzers/spvtools_opt_size_fuzzer.cpp
Normal file
37
testing/fuzzers/spvtools_opt_size_fuzzer.cpp
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user