Add fuzzer for Inspector
BUG=tint:445 Change-Id: Ic342c7e83827bcc57bfd134dec92b03cb9708a70 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/37540 Auto-Submit: Ryan Harrison <rharrison@chromium.org> Reviewed-by: dan sinclair <dsinclair@chromium.org> Commit-Queue: Ryan Harrison <rharrison@chromium.org>
This commit is contained in:
parent
f813959302
commit
1870a48d5f
5
BUILD.gn
5
BUILD.gn
|
@ -1366,6 +1366,11 @@ if (build_with_chromium) {
|
|||
sources = [ "fuzzers/tint_first_index_offset_fuzzer.cc" ]
|
||||
deps = [ ":tint_fuzzer_common" ]
|
||||
}
|
||||
|
||||
fuzzer_test("tint_inspector_fuzzer") {
|
||||
sources = [ "fuzzers/tint_inspector_fuzzer.cc" ]
|
||||
deps = [ ":tint_fuzzer_common" ]
|
||||
}
|
||||
}
|
||||
|
||||
if (tint_build_wgsl_reader && tint_build_hlsl_writer) {
|
||||
|
|
|
@ -34,6 +34,7 @@ if ({$TINT_BUILD_WGSL_READER} AND ${TINT_BUILD_SPV_WRITER})
|
|||
add_tint_fuzzer(tint_bound_array_accessors_fuzzer)
|
||||
add_tint_fuzzer(tint_emit_vertex_point_size_fuzzer)
|
||||
add_tint_fuzzer(tint_first_index_offset_fuzzer)
|
||||
add_tint_fuzzer(tint_inspector_fuzzer)
|
||||
add_tint_fuzzer(tint_wgsl_reader_spv_writer_fuzzer)
|
||||
endif()
|
||||
|
||||
|
|
|
@ -23,13 +23,13 @@ namespace tint {
|
|||
namespace fuzzers {
|
||||
|
||||
CommonFuzzer::CommonFuzzer(InputFormat input, OutputFormat output)
|
||||
: input_(input), output_(output) {}
|
||||
: input_(input), output_(output), inspector_enabled_(false) {}
|
||||
CommonFuzzer::~CommonFuzzer() = default;
|
||||
|
||||
int CommonFuzzer::Run(const uint8_t* data, size_t size) {
|
||||
std::unique_ptr<tint::reader::Reader> parser;
|
||||
std::unique_ptr<reader::Reader> parser;
|
||||
#if TINT_BUILD_WGSL_READER
|
||||
std::unique_ptr<tint::Source::File> file;
|
||||
std::unique_ptr<Source::File> file;
|
||||
#endif // TINT_BUILD_WGSL_READER
|
||||
|
||||
switch (input_) {
|
||||
|
@ -38,8 +38,8 @@ int CommonFuzzer::Run(const uint8_t* data, size_t size) {
|
|||
{
|
||||
std::string str(reinterpret_cast<const char*>(data), size);
|
||||
|
||||
file = std::make_unique<tint::Source::File>("test.wgsl", str);
|
||||
parser = std::make_unique<tint::reader::wgsl::Parser>(file.get());
|
||||
file = std::make_unique<Source::File>("test.wgsl", str);
|
||||
parser = std::make_unique<reader::wgsl::Parser>(file.get());
|
||||
}
|
||||
#endif // TINT_BUILD_WGSL_READER
|
||||
break;
|
||||
|
@ -51,7 +51,7 @@ int CommonFuzzer::Run(const uint8_t* data, size_t size) {
|
|||
std::vector<uint32_t> input(u32Data, u32Data + sizeInU32);
|
||||
|
||||
if (input.size() != 0) {
|
||||
parser = std::make_unique<tint::reader::spirv::Parser>(input);
|
||||
parser = std::make_unique<reader::spirv::Parser>(input);
|
||||
}
|
||||
}
|
||||
#endif // TINT_BUILD_WGSL_READER
|
||||
|
@ -77,16 +77,78 @@ int CommonFuzzer::Run(const uint8_t* data, size_t size) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
tint::TypeDeterminer td(&mod);
|
||||
TypeDeterminer td(&mod);
|
||||
if (!td.Determine()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
tint::Validator v;
|
||||
Validator v;
|
||||
if (!v.Validate(&mod)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (inspector_enabled_) {
|
||||
inspector::Inspector inspector(mod);
|
||||
|
||||
auto entry_points = inspector.GetEntryPoints();
|
||||
if (inspector.has_error()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (auto& ep : entry_points) {
|
||||
auto remapped_name = inspector.GetRemappedNameForEntryPoint(ep.name);
|
||||
if (inspector.has_error()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto constant_ids = inspector.GetConstantIDs();
|
||||
if (inspector.has_error()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto uniform_bindings =
|
||||
inspector.GetUniformBufferResourceBindings(ep.name);
|
||||
if (inspector.has_error()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto storage_bindings =
|
||||
inspector.GetStorageBufferResourceBindings(ep.name);
|
||||
if (inspector.has_error()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto readonly_bindings =
|
||||
inspector.GetReadOnlyStorageBufferResourceBindings(ep.name);
|
||||
if (inspector.has_error()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto sampler_bindings = inspector.GetSamplerResourceBindings(ep.name);
|
||||
if (inspector.has_error()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto comparison_sampler_bindings =
|
||||
inspector.GetComparisonSamplerResourceBindings(ep.name);
|
||||
if (inspector.has_error()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto sampled_texture_bindings =
|
||||
inspector.GetSampledTextureResourceBindings(ep.name);
|
||||
if (inspector.has_error()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto multisampled_texture_bindings =
|
||||
inspector.GetMultisampledTextureResourceBindings(ep.name);
|
||||
if (inspector.has_error()) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (transform_manager_) {
|
||||
auto out = transform_manager_->Run(&mod);
|
||||
if (out.diagnostics.contains_errors()) {
|
||||
|
@ -96,27 +158,27 @@ int CommonFuzzer::Run(const uint8_t* data, size_t size) {
|
|||
mod = std::move(out.module);
|
||||
}
|
||||
|
||||
std::unique_ptr<tint::writer::Writer> writer;
|
||||
std::unique_ptr<writer::Writer> writer;
|
||||
|
||||
switch (output_) {
|
||||
case OutputFormat::kWGSL:
|
||||
#if TINT_BUILD_WGSL_WRITER
|
||||
writer = std::make_unique<tint::writer::wgsl::Generator>(std::move(mod));
|
||||
writer = std::make_unique<writer::wgsl::Generator>(std::move(mod));
|
||||
#endif // TINT_BUILD_WGSL_WRITER
|
||||
break;
|
||||
case OutputFormat::kSpv:
|
||||
#if TINT_BUILD_SPV_WRITER
|
||||
writer = std::make_unique<tint::writer::spirv::Generator>(std::move(mod));
|
||||
writer = std::make_unique<writer::spirv::Generator>(std::move(mod));
|
||||
#endif // TINT_BUILD_SPV_WRITER
|
||||
break;
|
||||
case OutputFormat::kHLSL:
|
||||
#if TINT_BUILD_HLSL_WRITER
|
||||
writer = std::make_unique<tint::writer::hlsl::Generator>(std::move(mod));
|
||||
writer = std::make_unique<writer::hlsl::Generator>(std::move(mod));
|
||||
#endif // TINT_BUILD_HLSL_WRITER
|
||||
break;
|
||||
case OutputFormat::kMSL:
|
||||
#if TINT_BUILD_MSL_WRITER
|
||||
writer = std::make_unique<tint::writer::msl::Generator>(std::move(mod));
|
||||
writer = std::make_unique<writer::msl::Generator>(std::move(mod));
|
||||
#endif // TINT_BUILD_MSL_WRITER
|
||||
break;
|
||||
case OutputFormat::kNone:
|
||||
|
|
|
@ -30,6 +30,7 @@ class CommonFuzzer {
|
|||
~CommonFuzzer();
|
||||
|
||||
void SetTransformManager(transform::Manager* tm) { transform_manager_ = tm; }
|
||||
void EnableInspector() { inspector_enabled_ = true; }
|
||||
|
||||
int Run(const uint8_t* data, size_t size);
|
||||
|
||||
|
@ -37,6 +38,7 @@ class CommonFuzzer {
|
|||
InputFormat input_;
|
||||
OutputFormat output_;
|
||||
transform::Manager* transform_manager_;
|
||||
bool inspector_enabled_;
|
||||
};
|
||||
|
||||
} // namespace fuzzers
|
||||
|
|
Loading…
Reference in New Issue