Add fuzzing for transform::CalculateArrayLength

BUG=tint:722

Change-Id: Ide83964646f303c03a9cc780f3828f1816baa288
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49380
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Auto-Submit: Ryan Harrison <rharrison@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
Ryan Harrison 2021-04-28 17:57:23 +00:00 committed by Commit Bot service account
parent b5c908f700
commit be303e9265
5 changed files with 47 additions and 8 deletions

View File

@ -76,6 +76,11 @@ if (build_with_chromium) {
deps = [ ":tint_fuzzer_common" ]
}
fuzzer_test("tint_calculate_array_length_fuzzer") {
sources = [ "tint_calculate_array_length_fuzzer.cc" ]
deps = [ ":tint_fuzzer_common" ]
}
fuzzer_test("tint_emit_vertex_point_size_fuzzer") {
sources = [ "tint_emit_vertex_point_size_fuzzer.cc" ]
deps = [ ":tint_fuzzer_common" ]
@ -163,6 +168,7 @@ if (build_with_chromium) {
":tint_all_transforms_fuzzer",
":tint_binding_remapper_fuzzer",
":tint_bound_array_accessors_fuzzer",
":tint_calculate_array_length_fuzzer",
":tint_emit_vertex_point_size_fuzzer",
":tint_first_index_offset_fuzzer",
":tint_inspector_fuzzer",

View File

@ -33,6 +33,7 @@ if (${TINT_BUILD_WGSL_READER} AND ${TINT_BUILD_SPV_WRITER})
add_tint_fuzzer(tint_all_transforms_fuzzer)
add_tint_fuzzer(tint_binding_remapper_fuzzer)
add_tint_fuzzer(tint_bound_array_accessors_fuzzer)
add_tint_fuzzer(tint_calculate_array_length_fuzzer)
add_tint_fuzzer(tint_emit_vertex_point_size_fuzzer)
add_tint_fuzzer(tint_first_index_offset_fuzzer)
add_tint_fuzzer(tint_inspector_fuzzer)

View File

@ -18,9 +18,8 @@ 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;
transform::Manager transform_manager;
transform::DataMap transform_inputs;
if (!ExtractFirstIndexOffsetInputs(&data, &size, &transform_inputs)) {
return 0;
@ -30,12 +29,13 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
return 0;
}
transform_manager.Add<tint::transform::BoundArrayAccessors>();
transform_manager.Add<tint::transform::EmitVertexPointSize>();
transform_manager.Add<tint::transform::FirstIndexOffset>();
transform_manager.Add<tint::transform::BindingRemapper>();
transform_manager.Add<transform::BoundArrayAccessors>();
transform_manager.Add<transform::EmitVertexPointSize>();
transform_manager.Add<transform::FirstIndexOffset>();
transform_manager.Add<transform::BindingRemapper>();
transform_manager.Add<transform::CalculateArrayLength>();
tint::fuzzers::CommonFuzzer fuzzer(InputFormat::kWGSL, OutputFormat::kSpv);
fuzzers::CommonFuzzer fuzzer(InputFormat::kWGSL, OutputFormat::kSpv);
fuzzer.SetTransformManager(&transform_manager, std::move(transform_inputs));
return fuzzer.Run(data, size);

View File

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

View File

@ -26,6 +26,7 @@
#include "src/sem/type_manager.h"
#include "src/transform/binding_remapper.h"
#include "src/transform/bound_array_accessors.h"
#include "src/transform/calculate_array_length.h"
#include "src/transform/emit_vertex_point_size.h"
#include "src/transform/first_index_offset.h"
#include "src/transform/manager.h"