fuzzers: Switch fuzzers to new generator API

Remove sanitizer transform fuzzers, as these will no longer be
publicly visible. We should fuzz the generator options instead.

Change-Id: If8f2c70f505bdaecd62a2f53a6586c3b84bd1c33
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/57760
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
James Price 2021-07-12 21:07:41 +00:00 committed by Tint LUCI CQ
parent aa48b1ad8d
commit 54d1ee6f11
8 changed files with 44 additions and 151 deletions

View File

@ -91,11 +91,6 @@ if (build_with_chromium) {
deps = [ ":tint_fuzzer_common" ] deps = [ ":tint_fuzzer_common" ]
} }
fuzzer_test("tint_spirv_transform_fuzzer") {
sources = [ "tint_spirv_transform_fuzzer.cc" ]
deps = [ ":tint_fuzzer_common" ]
}
fuzzer_test("tint_vertex_pulling_fuzzer") { fuzzer_test("tint_vertex_pulling_fuzzer") {
sources = [ "tint_vertex_pulling_fuzzer.cc" ] sources = [ "tint_vertex_pulling_fuzzer.cc" ]
deps = [ ":tint_fuzzer_common" ] deps = [ ":tint_fuzzer_common" ]
@ -108,11 +103,6 @@ if (build_with_chromium) {
} }
if (tint_build_wgsl_reader && tint_build_hlsl_writer) { if (tint_build_wgsl_reader && tint_build_hlsl_writer) {
fuzzer_test("tint_hlsl_transform_fuzzer") {
sources = [ "tint_hlsl_transform_fuzzer.cc" ]
deps = [ ":tint_fuzzer_common" ]
}
fuzzer_test("tint_wgsl_reader_hlsl_writer_fuzzer") { fuzzer_test("tint_wgsl_reader_hlsl_writer_fuzzer") {
sources = [ "tint_wgsl_reader_hlsl_writer_fuzzer.cc" ] sources = [ "tint_wgsl_reader_hlsl_writer_fuzzer.cc" ]
deps = [ ":tint_fuzzer_common" ] deps = [ ":tint_fuzzer_common" ]
@ -120,11 +110,6 @@ if (build_with_chromium) {
} }
if (tint_build_wgsl_reader && tint_build_msl_writer) { if (tint_build_wgsl_reader && tint_build_msl_writer) {
fuzzer_test("tint_msl_transform_fuzzer") {
sources = [ "tint_msl_transform_fuzzer.cc" ]
deps = [ ":tint_fuzzer_common" ]
}
fuzzer_test("tint_wgsl_reader_msl_writer_fuzzer") { fuzzer_test("tint_wgsl_reader_msl_writer_fuzzer") {
sources = [ "tint_wgsl_reader_msl_writer_fuzzer.cc" ] sources = [ "tint_wgsl_reader_msl_writer_fuzzer.cc" ]
deps = [ ":tint_fuzzer_common" ] deps = [ ":tint_fuzzer_common" ]
@ -192,20 +177,17 @@ if (build_with_chromium) {
":tint_inspector_fuzzer", ":tint_inspector_fuzzer",
":tint_renamer_fuzzer", ":tint_renamer_fuzzer",
":tint_single_entry_point_fuzzer", ":tint_single_entry_point_fuzzer",
":tint_spirv_transform_fuzzer",
":tint_vertex_pulling_fuzzer", ":tint_vertex_pulling_fuzzer",
":tint_wgsl_reader_spv_writer_fuzzer", ":tint_wgsl_reader_spv_writer_fuzzer",
] ]
} }
if (tint_build_wgsl_reader && tint_build_hlsl_writer) { if (tint_build_wgsl_reader && tint_build_hlsl_writer) {
deps += [ deps += [
":tint_hlsl_transform_fuzzer",
":tint_wgsl_reader_hlsl_writer_fuzzer", ":tint_wgsl_reader_hlsl_writer_fuzzer",
] ]
} }
if (tint_build_wgsl_reader && tint_build_msl_writer) { if (tint_build_wgsl_reader && tint_build_msl_writer) {
deps += [ deps += [
":tint_msl_transform_fuzzer",
":tint_wgsl_reader_msl_writer_fuzzer", ":tint_wgsl_reader_msl_writer_fuzzer",
] ]
} }

View File

@ -37,19 +37,16 @@ if (${TINT_BUILD_WGSL_READER} AND ${TINT_BUILD_SPV_WRITER})
add_tint_fuzzer(tint_renamer_fuzzer) add_tint_fuzzer(tint_renamer_fuzzer)
add_tint_fuzzer(tint_robustness_fuzzer) add_tint_fuzzer(tint_robustness_fuzzer)
add_tint_fuzzer(tint_single_entry_point_fuzzer) add_tint_fuzzer(tint_single_entry_point_fuzzer)
add_tint_fuzzer(tint_spirv_transform_fuzzer)
add_tint_fuzzer(tint_vertex_pulling_fuzzer) add_tint_fuzzer(tint_vertex_pulling_fuzzer)
add_tint_fuzzer(tint_wgsl_reader_spv_writer_fuzzer) add_tint_fuzzer(tint_wgsl_reader_spv_writer_fuzzer)
endif() endif()
if (${TINT_BUILD_WGSL_READER} AND ${TINT_BUILD_HLSL_WRITER}) if (${TINT_BUILD_WGSL_READER} AND ${TINT_BUILD_HLSL_WRITER})
add_tint_fuzzer(tint_wgsl_reader_hlsl_writer_fuzzer) add_tint_fuzzer(tint_wgsl_reader_hlsl_writer_fuzzer)
add_tint_fuzzer(tint_hlsl_transform_fuzzer)
endif() endif()
if (${TINT_BUILD_WGSL_READER} AND ${TINT_BUILD_MSL_WRITER}) if (${TINT_BUILD_WGSL_READER} AND ${TINT_BUILD_MSL_WRITER})
add_tint_fuzzer(tint_wgsl_reader_msl_writer_fuzzer) add_tint_fuzzer(tint_wgsl_reader_msl_writer_fuzzer)
add_tint_fuzzer(tint_msl_transform_fuzzer)
endif() endif()
if (${TINT_BUILD_SPV_READER}) if (${TINT_BUILD_SPV_READER})

View File

@ -62,8 +62,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
return 0; return 0;
} }
config.manager.Add<transform::Hlsl>();
fuzzers::CommonFuzzer fuzzer(InputFormat::kWGSL, OutputFormat::kHLSL); fuzzers::CommonFuzzer fuzzer(InputFormat::kWGSL, OutputFormat::kHLSL);
fuzzer.SetTransformManager(&config.manager, std::move(config.inputs)); fuzzer.SetTransformManager(&config.manager, std::move(config.inputs));
@ -79,8 +77,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
return 0; return 0;
} }
config.manager.Add<transform::Msl>();
fuzzers::CommonFuzzer fuzzer(InputFormat::kWGSL, OutputFormat::kMSL); fuzzers::CommonFuzzer fuzzer(InputFormat::kWGSL, OutputFormat::kMSL);
fuzzer.SetTransformManager(&config.manager, std::move(config.inputs)); fuzzer.SetTransformManager(&config.manager, std::move(config.inputs));
@ -95,8 +91,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
return 0; return 0;
} }
config.manager.Add<transform::Spirv>();
fuzzers::CommonFuzzer fuzzer(InputFormat::kWGSL, OutputFormat::kSpv); fuzzers::CommonFuzzer fuzzer(InputFormat::kWGSL, OutputFormat::kSpv);
fuzzer.SetTransformManager(&config.manager, std::move(config.inputs)); fuzzer.SetTransformManager(&config.manager, std::move(config.inputs));

View File

@ -92,10 +92,11 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
// original source so that reformatting doesn't impact the final wgsl // original source so that reformatting doesn't impact the final wgsl
// comparison. // comparison.
std::string src_wgsl; std::string src_wgsl;
tint::writer::wgsl::Options wgsl_options;
{ {
tint::writer::wgsl::Generator src_gen(&src); auto result = tint::writer::wgsl::Generate(&src, wgsl_options);
ASSERT_TRUE(src_gen.Generate()); ASSERT_TRUE(result.success);
src_wgsl = src_gen.result(); src_wgsl = result.wgsl;
// Move the src program to a temporary that'll be dropped, so that the src // Move the src program to a temporary that'll be dropped, so that the src
// program is released before we attempt to print the dst program. This // program is released before we attempt to print the dst program. This
@ -106,9 +107,9 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
} }
// Print the dst program, check it matches the original source // Print the dst program, check it matches the original source
tint::writer::wgsl::Generator dst_gen(&dst); auto result = tint::writer::wgsl::Generate(&dst, wgsl_options);
ASSERT_TRUE(dst_gen.Generate()); ASSERT_TRUE(result.success);
auto dst_wgsl = dst_gen.result(); auto dst_wgsl = result.wgsl;
ASSERT_EQ(src_wgsl, dst_wgsl); ASSERT_EQ(src_wgsl, dst_wgsl);
return 0; return 0;

View File

@ -321,45 +321,57 @@ int CommonFuzzer::Run(const uint8_t* data, size_t size) {
} }
switch (output_) { switch (output_) {
case OutputFormat::kWGSL: case OutputFormat::kWGSL: {
#if TINT_BUILD_WGSL_WRITER #if TINT_BUILD_WGSL_WRITER
writer_ = std::make_unique<writer::wgsl::Generator>(&program); writer::wgsl::Options options;
#endif // TINT_BUILD_WGSL_WRITER auto result = writer::wgsl::Generate(&program, options);
break; if (!result.success) {
case OutputFormat::kSpv:
#if TINT_BUILD_SPV_WRITER
writer_ = std::make_unique<writer::spirv::Generator>(&program);
#endif // TINT_BUILD_SPV_WRITER
break;
case OutputFormat::kHLSL:
#if TINT_BUILD_HLSL_WRITER
writer_ = std::make_unique<writer::hlsl::Generator>(&program);
#endif // TINT_BUILD_HLSL_WRITER
break;
case OutputFormat::kMSL:
#if TINT_BUILD_MSL_WRITER
writer_ = std::make_unique<writer::msl::Generator>(&program);
#endif // TINT_BUILD_MSL_WRITER
break;
case OutputFormat::kNone:
break;
}
if (writer_) {
if (!writer_->Generate()) {
errors_ = writer_->error(); errors_ = writer_->error();
return 0; return 0;
} }
#endif // TINT_BUILD_WGSL_WRITER
break;
}
case OutputFormat::kSpv: {
#if TINT_BUILD_SPV_WRITER #if TINT_BUILD_SPV_WRITER
if (output_ == OutputFormat::kSpv && writer::spirv::Options options;
!SPIRVToolsValidationCheck( auto result = writer::spirv::Generate(&program, options);
program, if (!result.success) {
static_cast<writer::spirv::Generator*>(writer_.get())->result())) { errors_ = writer_->error();
return 0;
}
if (!SPIRVToolsValidationCheck(program, result.spirv)) {
FatalError(program.Diagnostics(), FatalError(program.Diagnostics(),
"Fuzzing detected invalid spirv being emitted by Tint"); "Fuzzing detected invalid spirv being emitted by Tint");
} }
#endif // TINT_BUILD_SPV_WRITER #endif // TINT_BUILD_SPV_WRITER
break;
}
case OutputFormat::kHLSL: {
#if TINT_BUILD_HLSL_WRITER
writer::hlsl::Options options;
auto result = writer::hlsl::Generate(&program, options);
if (!result.success) {
errors_ = writer_->error();
return 0;
}
#endif // TINT_BUILD_HLSL_WRITER
break;
}
case OutputFormat::kMSL: {
#if TINT_BUILD_MSL_WRITER
writer::msl::Options options;
auto result = writer::msl::Generate(&program, options);
if (!result.success) {
errors_ = writer_->error();
return 0;
}
#endif // TINT_BUILD_MSL_WRITER
break;
}
case OutputFormat::kNone:
break;
} }
return 0; return 0;

View File

@ -1,31 +0,0 @@
// 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) {
transform::Manager transform_manager;
transform_manager.Add<transform::Hlsl>();
fuzzers::CommonFuzzer fuzzer(InputFormat::kWGSL, OutputFormat::kHLSL);
fuzzer.SetTransformManager(&transform_manager, {});
return fuzzer.Run(data, size);
}
} // namespace fuzzers
} // namespace tint

View File

@ -1,31 +0,0 @@
// 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) {
transform::Manager transform_manager;
transform_manager.Add<transform::Msl>();
fuzzers::CommonFuzzer fuzzer(InputFormat::kWGSL, OutputFormat::kMSL);
fuzzer.SetTransformManager(&transform_manager, {});
return fuzzer.Run(data, size);
}
} // namespace fuzzers
} // namespace tint

View File

@ -1,31 +0,0 @@
// 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) {
transform::Manager transform_manager;
transform_manager.Add<transform::Spirv>();
fuzzers::CommonFuzzer fuzzer(InputFormat::kWGSL, OutputFormat::kSpv);
fuzzer.SetTransformManager(&transform_manager, {});
return fuzzer.Run(data, size);
}
} // namespace fuzzers
} // namespace tint