2021-01-12 16:23:48 +00:00
|
|
|
// 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 {
|
|
|
|
|
2021-04-29 20:03:35 +00:00
|
|
|
struct Config {
|
2021-05-06 15:43:33 +00:00
|
|
|
Config(const uint8_t* data, size_t size) : reader(data, size) {}
|
|
|
|
Reader reader;
|
2021-04-29 20:03:35 +00:00
|
|
|
transform::Manager manager;
|
|
|
|
transform::DataMap inputs;
|
|
|
|
};
|
2021-04-27 17:24:47 +00:00
|
|
|
|
2021-04-29 20:03:35 +00:00
|
|
|
bool AddPlatformIndependentPasses(Config* config) {
|
2021-05-06 15:43:33 +00:00
|
|
|
ExtractFirstIndexOffsetInputs(&config->reader, &config->inputs);
|
|
|
|
ExtractBindingRemapperInputs(&config->reader, &config->inputs);
|
|
|
|
ExtractSingleEntryPointInputs(&config->reader, &config->inputs);
|
|
|
|
ExtractVertexPullingInputs(&config->reader, &config->inputs);
|
2021-04-29 20:49:25 +00:00
|
|
|
|
2021-06-30 13:23:36 +00:00
|
|
|
config->manager.Add<transform::Robustness>();
|
2021-04-29 20:03:35 +00:00
|
|
|
config->manager.Add<transform::FirstIndexOffset>();
|
|
|
|
config->manager.Add<transform::BindingRemapper>();
|
2021-04-29 20:43:45 +00:00
|
|
|
config->manager.Add<transform::Renamer>();
|
2021-04-29 20:49:25 +00:00
|
|
|
config->manager.Add<tint::transform::SingleEntryPoint>();
|
2021-05-06 15:43:33 +00:00
|
|
|
config->manager.Add<tint::transform::VertexPulling>();
|
2021-04-29 20:03:35 +00:00
|
|
|
|
2021-05-06 15:43:33 +00:00
|
|
|
return !config->reader.failed();
|
2021-04-29 20:03:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
|
|
|
{
|
2021-05-06 15:43:33 +00:00
|
|
|
Config config(data, size);
|
2021-04-29 20:03:35 +00:00
|
|
|
|
|
|
|
if (!AddPlatformIndependentPasses(&config)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
fuzzers::CommonFuzzer fuzzer(InputFormat::kWGSL, OutputFormat::kSpv);
|
|
|
|
fuzzer.SetTransformManager(&(config.manager), std::move(config.inputs));
|
2021-01-12 16:23:48 +00:00
|
|
|
|
2021-05-06 15:43:33 +00:00
|
|
|
fuzzer.Run(config.reader.data(), config.reader.size());
|
2021-04-29 20:03:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if TINT_BUILD_HLSL_WRITER
|
|
|
|
{
|
2021-05-06 15:43:33 +00:00
|
|
|
Config config(data, size);
|
2021-04-29 20:03:35 +00:00
|
|
|
|
|
|
|
if (!AddPlatformIndependentPasses(&config)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
config.manager.Add<transform::Hlsl>();
|
|
|
|
|
|
|
|
fuzzers::CommonFuzzer fuzzer(InputFormat::kWGSL, OutputFormat::kHLSL);
|
|
|
|
fuzzer.SetTransformManager(&config.manager, std::move(config.inputs));
|
|
|
|
|
2021-05-06 15:43:33 +00:00
|
|
|
fuzzer.Run(config.reader.data(), config.reader.size());
|
2021-04-29 20:03:35 +00:00
|
|
|
}
|
|
|
|
#endif // TINT_BUILD_HLSL_WRITER
|
2021-01-12 16:23:48 +00:00
|
|
|
|
2021-04-29 20:06:25 +00:00
|
|
|
#if TINT_BUILD_MSL_WRITER
|
|
|
|
{
|
2021-05-06 15:43:33 +00:00
|
|
|
Config config(data, size);
|
2021-04-29 20:06:25 +00:00
|
|
|
|
|
|
|
if (!AddPlatformIndependentPasses(&config)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
config.manager.Add<transform::Msl>();
|
|
|
|
|
|
|
|
fuzzers::CommonFuzzer fuzzer(InputFormat::kWGSL, OutputFormat::kMSL);
|
|
|
|
fuzzer.SetTransformManager(&config.manager, std::move(config.inputs));
|
|
|
|
|
2021-05-06 15:43:33 +00:00
|
|
|
fuzzer.Run(config.reader.data(), config.reader.size());
|
2021-04-29 20:06:25 +00:00
|
|
|
}
|
|
|
|
#endif // TINT_BUILD_MSL_WRITER
|
2021-04-29 20:12:05 +00:00
|
|
|
#if TINT_BUILD_SPV_WRITER
|
|
|
|
{
|
2021-05-06 15:43:33 +00:00
|
|
|
Config config(data, size);
|
2021-04-29 20:12:05 +00:00
|
|
|
|
|
|
|
if (!AddPlatformIndependentPasses(&config)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
config.manager.Add<transform::Spirv>();
|
|
|
|
|
|
|
|
fuzzers::CommonFuzzer fuzzer(InputFormat::kWGSL, OutputFormat::kSpv);
|
|
|
|
fuzzer.SetTransformManager(&config.manager, std::move(config.inputs));
|
|
|
|
|
2021-05-06 15:43:33 +00:00
|
|
|
fuzzer.Run(config.reader.data(), config.reader.size());
|
2021-04-29 20:12:05 +00:00
|
|
|
}
|
|
|
|
#endif // TINT_BUILD_SPV_WRITER
|
2021-04-29 20:06:25 +00:00
|
|
|
|
2021-04-29 20:03:35 +00:00
|
|
|
return 0;
|
2021-01-12 16:23:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace fuzzers
|
|
|
|
} // namespace tint
|