Add fuzzing for transform::SingleEntryPoint

BUG=tint:722

Change-Id: I83dfb2cb196f6e80ffb48dc41ff385621a5d629e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49580
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Auto-Submit: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
Ryan Harrison 2021-04-29 20:49:25 +00:00 committed by Commit Bot service account
parent bc5461d731
commit 52456c69c8
6 changed files with 81 additions and 0 deletions

View File

@ -92,6 +92,11 @@ if (build_with_chromium) {
deps = [ ":tint_fuzzer_common" ]
}
fuzzer_test("tint_single_entry_point_fuzzer") {
sources = [ "tint_single_entry_point_fuzzer.cc" ]
deps = [ ":tint_fuzzer_common" ]
}
fuzzer_test("tint_spirv_transform_fuzzer") {
sources = [ "tint_spirv_transform_fuzzer.cc" ]
deps = [ ":tint_fuzzer_common" ]
@ -189,6 +194,7 @@ if (build_with_chromium) {
":tint_first_index_offset_fuzzer",
":tint_inspector_fuzzer",
":tint_renamer_fuzzer",
":tint_single_entry_point_fuzzer",
":tint_spirv_transform_fuzzer",
":tint_wgsl_reader_spv_writer_fuzzer",
]

View File

@ -37,6 +37,7 @@ if (${TINT_BUILD_WGSL_READER} AND ${TINT_BUILD_SPV_WRITER})
add_tint_fuzzer(tint_first_index_offset_fuzzer)
add_tint_fuzzer(tint_inspector_fuzzer)
add_tint_fuzzer(tint_renamer_fuzzer)
add_tint_fuzzer(tint_single_entry_point_fuzzer)
add_tint_fuzzer(tint_spirv_transform_fuzzer)
add_tint_fuzzer(tint_wgsl_reader_spv_writer_fuzzer)
endif()

View File

@ -35,6 +35,11 @@ bool AddPlatformIndependentPasses(Config* config) {
return false;
}
if (!ExtractSingleEntryPointInputs(&config->data, &config->size,
&config->inputs)) {
return 0;
}
config->manager.Add<transform::BoundArrayAccessors>();
config->manager
.Add<transform::EmitVertexPointSize>(); // TODO(tint:753): Remove once
@ -42,6 +47,7 @@ bool AddPlatformIndependentPasses(Config* config) {
config->manager.Add<transform::FirstIndexOffset>();
config->manager.Add<transform::BindingRemapper>();
config->manager.Add<transform::Renamer>();
config->manager.Add<tint::transform::SingleEntryPoint>();
return true;
}

View File

@ -101,6 +101,33 @@ bool ExtractFirstIndexOffsetInputs(const uint8_t** data,
return true;
}
bool ExtractSingleEntryPointInputs(const uint8_t** data,
size_t* size,
tint::transform::DataMap* inputs) {
if ((*size) < sizeof(uint8_t)) {
return false;
}
auto count = *reinterpret_cast<const uint8_t*>(*data);
(*data) += sizeof(uint8_t);
(*size) -= sizeof(uint8_t);
if ((*size) < count) {
return false;
}
auto* c = reinterpret_cast<const char*>(*data);
std::string input(c, c + count);
(*data) += count * sizeof(char);
(*size) -= count * sizeof(char);
transform::SingleEntryPoint::Config cfg(input);
inputs->Add<transform::SingleEntryPoint::Config>(cfg);
return true;
}
CommonFuzzer::CommonFuzzer(InputFormat input, OutputFormat output)
: input_(input),
output_(output),

View File

@ -29,6 +29,10 @@ bool ExtractFirstIndexOffsetInputs(const uint8_t** data,
size_t* size,
tint::transform::DataMap* inputs);
bool ExtractSingleEntryPointInputs(const uint8_t** data,
size_t* size,
tint::transform::DataMap* inputs);
enum class InputFormat { kWGSL, kSpv, kNone };
enum class OutputFormat { kWGSL, kSpv, kHLSL, kMSL, kNone };

View File

@ -0,0 +1,37 @@
// Copyright 2021 The Tint 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 "fuzzers/tint_common_fuzzer.h"
namespace tint {
namespace fuzzers {
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
tint::transform::Manager transform_manager;
tint::transform::DataMap transform_inputs;
if (!ExtractSingleEntryPointInputs(&data, &size, &transform_inputs)) {
return 0;
}
transform_manager.Add<tint::transform::SingleEntryPoint>();
tint::fuzzers::CommonFuzzer fuzzer(InputFormat::kWGSL, OutputFormat::kSpv);
fuzzer.SetTransformManager(&transform_manager, std::move(transform_inputs));
return fuzzer.Run(data, size);
}
} // namespace fuzzers
} // namespace tint