Add fuzzers for various emission paths
BUG=tint:58,tint:59,tint:194,tint:195 Change-Id: Ibca5efbcd608489dcb7c6c45a5fcf596b97165dc Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/36901 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: dan sinclair <dsinclair@chromium.org> Auto-Submit: Ryan Harrison <rharrison@chromium.org>
This commit is contained in:
parent
766e31d507
commit
39545b7e7c
88
BUILD.gn
88
BUILD.gn
|
@ -1324,6 +1324,50 @@ if (build_with_chromium) {
|
|||
}
|
||||
}
|
||||
|
||||
if (tint_build_wgsl_reader && tint_build_wgsl_writer) {
|
||||
fuzzer_test("tint_wgsl_reader_wgsl_writer_fuzzer") {
|
||||
sources = [ "fuzzers/tint_wgsl_reader_wgsl_writer_fuzzer.cc" ]
|
||||
deps = [
|
||||
":libtint_wgsl_reader_src",
|
||||
":libtint_wgsl_writer_src",
|
||||
":tint_fuzzer_common",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
if (tint_build_wgsl_reader && tint_build_spv_writer) {
|
||||
fuzzer_test("tint_wgsl_reader_spv_writer_fuzzer") {
|
||||
sources = [ "fuzzers/tint_wgsl_reader_spv_writer_fuzzer.cc" ]
|
||||
deps = [
|
||||
":libtint_spv_writer_src",
|
||||
":libtint_wgsl_reader_src",
|
||||
":tint_fuzzer_common",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
if (tint_build_wgsl_reader && tint_build_hlsl_writer) {
|
||||
fuzzer_test("tint_wgsl_reader_hlsl_writer_fuzzer") {
|
||||
sources = [ "fuzzers/tint_wgsl_reader_hlsl_writer_fuzzer.cc" ]
|
||||
deps = [
|
||||
":libtint_hlsl_writer_src",
|
||||
":libtint_wgsl_reader_src",
|
||||
":tint_fuzzer_common",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
if (tint_build_wgsl_reader && tint_build_msl_writer) {
|
||||
fuzzer_test("tint_wgsl_reader_msl_writer_fuzzer") {
|
||||
sources = [ "fuzzers/tint_wgsl_reader_msl_writer_fuzzer.cc" ]
|
||||
deps = [
|
||||
":libtint_msl_writer_src",
|
||||
":libtint_wgsl_reader_src",
|
||||
":tint_fuzzer_common",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
if (tint_build_spv_reader) {
|
||||
fuzzer_test("tint_spv_reader_fuzzer") {
|
||||
sources = [ "fuzzers/tint_spv_reader_fuzzer.cc" ]
|
||||
|
@ -1334,6 +1378,50 @@ if (build_with_chromium) {
|
|||
}
|
||||
}
|
||||
|
||||
if (tint_build_spv_reader && tint_build_wgsl_writer) {
|
||||
fuzzer_test("tint_spv_reader_wgsl_writer_fuzzer") {
|
||||
sources = [ "fuzzers/tint_spv_reader_wgsl_writer_fuzzer.cc" ]
|
||||
deps = [
|
||||
":libtint_spv_reader_src",
|
||||
":libtint_wgsl_writer_src",
|
||||
":tint_fuzzer_common",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
if (tint_build_spv_reader && tint_build_spv_writer) {
|
||||
fuzzer_test("tint_spv_reader_spv_writer_fuzzer") {
|
||||
sources = [ "fuzzers/tint_spv_reader_spv_writer_fuzzer.cc" ]
|
||||
deps = [
|
||||
":libtint_spv_reader_src",
|
||||
":libtint_spv_writer_src",
|
||||
":tint_fuzzer_common",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
if (tint_build_spv_reader && tint_build_hlsl_writer) {
|
||||
fuzzer_test("tint_spv_reader_hlsl_writer_fuzzer") {
|
||||
sources = [ "fuzzers/tint_spv_reader_hlsl_writer_fuzzer.cc" ]
|
||||
deps = [
|
||||
":libtint_hlsl_writer_src",
|
||||
":libtint_spv_reader_src",
|
||||
":tint_fuzzer_common",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
if (tint_build_spv_reader && tint_build_msl_writer) {
|
||||
fuzzer_test("tint_spv_reader_msl_writer_fuzzer") {
|
||||
sources = [ "fuzzers/tint_spv_reader_msl_writer_fuzzer.cc" ]
|
||||
deps = [
|
||||
":libtint_msl_writer_src",
|
||||
":libtint_spv_reader_src",
|
||||
":tint_fuzzer_common",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
if (tint_build_wgsl_reader && tint_build_wgsl_writer) {
|
||||
fuzzer_test("tint_ast_clone_fuzzer") {
|
||||
sources = [ "fuzzers/tint_ast_clone_fuzzer.cc" ]
|
||||
|
|
|
@ -21,14 +21,47 @@ function(add_tint_fuzzer NAME)
|
|||
target_compile_options(${NAME} PRIVATE -Wno-missing-prototypes)
|
||||
endfunction()
|
||||
|
||||
if (${TINT_BUILD_WGSL_READER})
|
||||
if ({$TINT_BUILD_WGSL_READER})
|
||||
add_tint_fuzzer(tint_wgsl_reader_fuzzer)
|
||||
endif()
|
||||
|
||||
if ({$TINT_BUILD_WGSL_READER} AND ${TINT_BUILD_WGSL_WRITER})
|
||||
add_tint_fuzzer(tint_wgsl_reader_wgsl_writer_fuzzer)
|
||||
endif()
|
||||
|
||||
if ({$TINT_BUILD_WGSL_READER} AND ${TINT_BUILD_SPV_WRITER})
|
||||
add_tint_fuzzer(tint_wgsl_reader_spv_writer_fuzzer)
|
||||
endif()
|
||||
|
||||
if ({$TINT_BUILD_WGSL_READER} AND ${TINT_BUILD_HLSL_WRITER})
|
||||
add_tint_fuzzer(tint_wgsl_reader_hlsl_writer_fuzzer)
|
||||
endif()
|
||||
|
||||
if ({$TINT_BUILD_WGSL_READER} AND ${TINT_BUILD_MSL_WRITER})
|
||||
add_tint_fuzzer(tint_wgsl_reader_msl_writer_fuzzer)
|
||||
endif()
|
||||
|
||||
if (${TINT_BUILD_SPV_READER})
|
||||
add_tint_fuzzer(tint_spv_reader_fuzzer)
|
||||
endif()
|
||||
|
||||
if (${TINT_BUILD_SPV_READER} AND ${TINT_BUILD_WGSL_WRITER})
|
||||
add_tint_fuzzer(tint_spv_reader_wgsl_writer_fuzzer)
|
||||
endif()
|
||||
|
||||
if (${TINT_BUILD_SPV_READER} AND ${TINT_BUILD_SPV_WRITER})
|
||||
add_tint_fuzzer(tint_spv_reader_spv_writer_fuzzer)
|
||||
endif()
|
||||
|
||||
if (${TINT_BUILD_SPV_READER} AND ${TINT_BUILD_HLSL_WRITER})
|
||||
add_tint_fuzzer(tint_spv_reader_hlsl_writer_fuzzer)
|
||||
endif()
|
||||
|
||||
if (${TINT_BUILD_SPV_READER} AND ${TINT_BUILD_MSL_WRITER})
|
||||
add_tint_fuzzer(tint_spv_reader_msl_writer_fuzzer)
|
||||
endif()
|
||||
|
||||
|
||||
if (${TINT_BUILD_WGSL_READER} AND ${TINT_BUILD_WGSL_WRITER})
|
||||
add_tint_fuzzer(tint_ast_clone_fuzzer)
|
||||
endif()
|
||||
|
|
|
@ -16,12 +16,14 @@
|
|||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace tint {
|
||||
namespace fuzzers {
|
||||
|
||||
CommonFuzzer::CommonFuzzer(InputFormat input) : input_(input) {}
|
||||
CommonFuzzer::CommonFuzzer(InputFormat input, OutputFormat output)
|
||||
: input_(input), output_(output) {}
|
||||
CommonFuzzer::~CommonFuzzer() = default;
|
||||
|
||||
int CommonFuzzer::Run(const uint8_t* data, size_t size) {
|
||||
|
@ -58,8 +60,62 @@ int CommonFuzzer::Run(const uint8_t* data, size_t size) {
|
|||
break;
|
||||
}
|
||||
|
||||
if (parser) {
|
||||
parser->Parse();
|
||||
if (!parser) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!parser->Parse()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (output_ == OutputFormat::kNone) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto mod = parser->module();
|
||||
if (!mod.IsValid()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
tint::TypeDeterminer td(&mod);
|
||||
if (!td.Determine()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
tint::Validator v;
|
||||
if (!v.Validate(&mod)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::unique_ptr<tint::writer::Writer> writer;
|
||||
|
||||
switch (output_) {
|
||||
case OutputFormat::kWGSL:
|
||||
#if TINT_BUILD_WGSL_WRITER
|
||||
writer = std::make_unique<tint::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));
|
||||
#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));
|
||||
#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));
|
||||
#endif // TINT_BUILD_MSL_WRITER
|
||||
break;
|
||||
case OutputFormat::kNone:
|
||||
break;
|
||||
}
|
||||
|
||||
if (writer) {
|
||||
writer->Generate();
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -22,15 +22,18 @@ namespace fuzzers {
|
|||
|
||||
enum class InputFormat { kWGSL, kSpv, kNone };
|
||||
|
||||
enum class OutputFormat { kWGSL, kSpv, kHLSL, kMSL, kNone };
|
||||
|
||||
class CommonFuzzer {
|
||||
public:
|
||||
explicit CommonFuzzer(InputFormat input);
|
||||
explicit CommonFuzzer(InputFormat input, OutputFormat output);
|
||||
~CommonFuzzer();
|
||||
|
||||
int Run(const uint8_t* data, size_t size);
|
||||
|
||||
private:
|
||||
InputFormat input_;
|
||||
OutputFormat output_;
|
||||
};
|
||||
|
||||
} // namespace fuzzers
|
||||
|
|
|
@ -16,7 +16,13 @@
|
|||
|
||||
#include "fuzzers/tint_common_fuzzer.h"
|
||||
|
||||
namespace tint {
|
||||
namespace fuzzers {
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||
tint::fuzzers::CommonFuzzer fuzzer(tint::fuzzers::InputFormat::kSpv);
|
||||
tint::fuzzers::CommonFuzzer fuzzer(InputFormat::kSpv, OutputFormat::kNone);
|
||||
return fuzzer.Run(data, size);
|
||||
}
|
||||
|
||||
} // namespace fuzzers
|
||||
} // namespace tint
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
// 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 <vector>
|
||||
|
||||
#include "fuzzers/tint_common_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);
|
||||
return fuzzer.Run(data, size);
|
||||
}
|
||||
|
||||
} // namespace fuzzers
|
||||
} // namespace tint
|
|
@ -0,0 +1,28 @@
|
|||
// 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 <vector>
|
||||
|
||||
#include "fuzzers/tint_common_fuzzer.h"
|
||||
|
||||
namespace tint {
|
||||
namespace fuzzers {
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||
tint::fuzzers::CommonFuzzer fuzzer(InputFormat::kSpv, OutputFormat::kMSL);
|
||||
return fuzzer.Run(data, size);
|
||||
}
|
||||
|
||||
} // namespace fuzzers
|
||||
} // namespace tint
|
|
@ -0,0 +1,28 @@
|
|||
// 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 <vector>
|
||||
|
||||
#include "fuzzers/tint_common_fuzzer.h"
|
||||
|
||||
namespace tint {
|
||||
namespace fuzzers {
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||
tint::fuzzers::CommonFuzzer fuzzer(InputFormat::kSpv, OutputFormat::kSpv);
|
||||
return fuzzer.Run(data, size);
|
||||
}
|
||||
|
||||
} // namespace fuzzers
|
||||
} // namespace tint
|
|
@ -0,0 +1,28 @@
|
|||
// 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 <vector>
|
||||
|
||||
#include "fuzzers/tint_common_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);
|
||||
return fuzzer.Run(data, size);
|
||||
}
|
||||
|
||||
} // namespace fuzzers
|
||||
} // namespace tint
|
|
@ -16,7 +16,13 @@
|
|||
|
||||
#include "fuzzers/tint_common_fuzzer.h"
|
||||
|
||||
namespace tint {
|
||||
namespace fuzzers {
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||
tint::fuzzers::CommonFuzzer fuzzer(tint::fuzzers::InputFormat::kWGSL);
|
||||
tint::fuzzers::CommonFuzzer fuzzer(InputFormat::kWGSL, OutputFormat::kNone);
|
||||
return fuzzer.Run(data, size);
|
||||
}
|
||||
|
||||
} // namespace fuzzers
|
||||
} // namespace tint
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
// 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 <string>
|
||||
|
||||
#include "fuzzers/tint_common_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);
|
||||
return fuzzer.Run(data, size);
|
||||
}
|
||||
|
||||
} // namespace fuzzers
|
||||
} // namespace tint
|
|
@ -0,0 +1,28 @@
|
|||
// 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 <string>
|
||||
|
||||
#include "fuzzers/tint_common_fuzzer.h"
|
||||
|
||||
namespace tint {
|
||||
namespace fuzzers {
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||
tint::fuzzers::CommonFuzzer fuzzer(InputFormat::kWGSL, OutputFormat::kMSL);
|
||||
return fuzzer.Run(data, size);
|
||||
}
|
||||
|
||||
} // namespace fuzzers
|
||||
} // namespace tint
|
|
@ -0,0 +1,28 @@
|
|||
// 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 <string>
|
||||
|
||||
#include "fuzzers/tint_common_fuzzer.h"
|
||||
|
||||
namespace tint {
|
||||
namespace fuzzers {
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||
tint::fuzzers::CommonFuzzer fuzzer(InputFormat::kWGSL, OutputFormat::kSpv);
|
||||
return fuzzer.Run(data, size);
|
||||
}
|
||||
|
||||
} // namespace fuzzers
|
||||
} // namespace tint
|
|
@ -0,0 +1,28 @@
|
|||
// 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 <string>
|
||||
|
||||
#include "fuzzers/tint_common_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);
|
||||
return fuzzer.Run(data, size);
|
||||
}
|
||||
|
||||
} // namespace fuzzers
|
||||
} // namespace tint
|
Loading…
Reference in New Issue