Add robustness pass to reader writer fuzzers

BUG=chromium:1255257,tint:1208

Change-Id: Ia5daeff8d839cbb7810bbbc12feab21039d0b681
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/66060
Auto-Submit: Ryan Harrison <rharrison@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Alastair Donaldson <afdx@google.com>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
This commit is contained in:
Ryan Harrison 2021-10-12 14:41:20 +00:00 committed by Tint LUCI CQ
parent ce90ac52f4
commit 37a666d91c
11 changed files with 82 additions and 16 deletions

View File

@ -71,6 +71,7 @@ if (build_with_chromium) {
"random_generator.h",
"tint_common_fuzzer.cc",
"tint_common_fuzzer.h",
"tint_reader_writer_fuzzer.h",
"transform_builder.h",
]
}
@ -85,6 +86,7 @@ if (build_with_chromium) {
"fuzzer_init.h",
]
}
if (tint_build_wgsl_reader) {
fuzzer_test("tint_wgsl_reader_fuzzer") {
sources = [ "tint_wgsl_reader_fuzzer.cc" ]

View File

@ -24,6 +24,7 @@ function(add_tint_fuzzer NAME)
random_generator.h
tint_common_fuzzer.cc
tint_common_fuzzer.h
tint_reader_writer_fuzzer.h
transform_builder.h
)
target_link_libraries(${NAME} libtint-fuzz)

View File

@ -0,0 +1,55 @@
// 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.
#ifndef FUZZERS_TINT_READER_WRITER_FUZZER_H_
#define FUZZERS_TINT_READER_WRITER_FUZZER_H_
#include <memory>
#include "fuzzers/tint_common_fuzzer.h"
#include "fuzzers/transform_builder.h"
namespace tint {
namespace fuzzers {
class ReaderWriterFuzzer : public CommonFuzzer {
public:
explicit ReaderWriterFuzzer(InputFormat input, OutputFormat output)
: CommonFuzzer(input, output) {}
~ReaderWriterFuzzer() {}
void SetTransformManager(transform::Manager* tm, transform::DataMap* inputs) {
tm_set_ = true;
CommonFuzzer::SetTransformManager(tm, inputs);
}
int Run(const uint8_t* data, size_t size) {
if (!tm_set_) {
tb_ = std::make_unique<TransformBuilder>(data, size);
tb_->AddTransform<tint::transform::Robustness>();
SetTransformManager(tb_->manager(), tb_->data_map());
}
return CommonFuzzer::Run(data, size);
}
private:
bool tm_set_ = false;
std::unique_ptr<TransformBuilder> tb_;
};
} // namespace fuzzers
} // namespace tint
#endif // FUZZERS_TINT_READER_WRITER_FUZZER_H_

View File

@ -15,13 +15,14 @@
#include <vector>
#include "fuzzers/fuzzer_init.h"
#include "fuzzers/tint_common_fuzzer.h"
#include "fuzzers/tint_reader_writer_fuzzer.h"
namespace tint {
namespace fuzzers {
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
tint::fuzzers::CommonFuzzer fuzzer(InputFormat::kSpv, OutputFormat::kHLSL);
tint::fuzzers::ReaderWriterFuzzer fuzzer(InputFormat::kSpv,
OutputFormat::kHLSL);
fuzzer.SetDumpInput(GetCliParams().dump_input);
return fuzzer.Run(data, size);
}

View File

@ -15,7 +15,7 @@
#include <vector>
#include "fuzzers/fuzzer_init.h"
#include "fuzzers/tint_common_fuzzer.h"
#include "fuzzers/tint_reader_writer_fuzzer.h"
namespace tint {
namespace fuzzers {
@ -24,7 +24,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
DataBuilder b(data, size);
writer::msl::Options options;
GenerateMslOptions(&b, &options);
tint::fuzzers::CommonFuzzer fuzzer(InputFormat::kSpv, OutputFormat::kMSL);
tint::fuzzers::ReaderWriterFuzzer fuzzer(InputFormat::kSpv,
OutputFormat::kMSL);
fuzzer.SetOptionsMsl(options);
fuzzer.SetDumpInput(GetCliParams().dump_input);
return fuzzer.Run(data, size);

View File

@ -15,7 +15,7 @@
#include <vector>
#include "fuzzers/fuzzer_init.h"
#include "fuzzers/tint_common_fuzzer.h"
#include "fuzzers/tint_reader_writer_fuzzer.h"
namespace tint {
namespace fuzzers {
@ -24,7 +24,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
DataBuilder b(data, size);
writer::spirv::Options options;
GenerateSpirvOptions(&b, &options);
tint::fuzzers::CommonFuzzer fuzzer(InputFormat::kSpv, OutputFormat::kSpv);
tint::fuzzers::ReaderWriterFuzzer fuzzer(InputFormat::kSpv,
OutputFormat::kSpv);
fuzzer.SetOptionsSpirv(options);
fuzzer.SetDumpInput(GetCliParams().dump_input);
return fuzzer.Run(data, size);

View File

@ -15,13 +15,14 @@
#include <vector>
#include "fuzzers/fuzzer_init.h"
#include "fuzzers/tint_common_fuzzer.h"
#include "fuzzers/tint_reader_writer_fuzzer.h"
namespace tint {
namespace fuzzers {
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
tint::fuzzers::CommonFuzzer fuzzer(InputFormat::kSpv, OutputFormat::kWGSL);
tint::fuzzers::ReaderWriterFuzzer fuzzer(InputFormat::kSpv,
OutputFormat::kWGSL);
fuzzer.SetDumpInput(GetCliParams().dump_input);
return fuzzer.Run(data, size);
}

View File

@ -15,13 +15,14 @@
#include <string>
#include "fuzzers/fuzzer_init.h"
#include "fuzzers/tint_common_fuzzer.h"
#include "fuzzers/tint_reader_writer_fuzzer.h"
namespace tint {
namespace fuzzers {
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
tint::fuzzers::CommonFuzzer fuzzer(InputFormat::kWGSL, OutputFormat::kHLSL);
tint::fuzzers::ReaderWriterFuzzer fuzzer(InputFormat::kWGSL,
OutputFormat::kHLSL);
fuzzer.SetDumpInput(GetCliParams().dump_input);
return fuzzer.Run(data, size);
}

View File

@ -15,7 +15,7 @@
#include <string>
#include "fuzzers/fuzzer_init.h"
#include "fuzzers/tint_common_fuzzer.h"
#include "fuzzers/tint_reader_writer_fuzzer.h"
namespace tint {
namespace fuzzers {
@ -24,7 +24,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
DataBuilder b(data, size);
writer::msl::Options options;
GenerateMslOptions(&b, &options);
tint::fuzzers::CommonFuzzer fuzzer(InputFormat::kWGSL, OutputFormat::kMSL);
tint::fuzzers::ReaderWriterFuzzer fuzzer(InputFormat::kWGSL,
OutputFormat::kMSL);
fuzzer.SetOptionsMsl(options);
fuzzer.SetDumpInput(GetCliParams().dump_input);
return fuzzer.Run(data, size);

View File

@ -15,7 +15,7 @@
#include <string>
#include "fuzzers/fuzzer_init.h"
#include "fuzzers/tint_common_fuzzer.h"
#include "fuzzers/tint_reader_writer_fuzzer.h"
namespace tint {
namespace fuzzers {
@ -24,7 +24,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
DataBuilder b(data, size);
writer::spirv::Options options;
GenerateSpirvOptions(&b, &options);
tint::fuzzers::CommonFuzzer fuzzer(InputFormat::kWGSL, OutputFormat::kSpv);
tint::fuzzers::ReaderWriterFuzzer fuzzer(InputFormat::kWGSL,
OutputFormat::kSpv);
fuzzer.SetOptionsSpirv(options);
fuzzer.SetDumpInput(GetCliParams().dump_input);
return fuzzer.Run(data, size);

View File

@ -15,13 +15,14 @@
#include <string>
#include "fuzzers/fuzzer_init.h"
#include "fuzzers/tint_common_fuzzer.h"
#include "fuzzers/tint_reader_writer_fuzzer.h"
namespace tint {
namespace fuzzers {
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
tint::fuzzers::CommonFuzzer fuzzer(InputFormat::kWGSL, OutputFormat::kWGSL);
tint::fuzzers::ReaderWriterFuzzer fuzzer(InputFormat::kWGSL,
OutputFormat::kWGSL);
fuzzer.SetDumpInput(GetCliParams().dump_input);
return fuzzer.Run(data, size);
}