Choose black-box fuzzer back-end based on data
Instead of uploading separate black-box fuzzers for each target language, it will be more convenient to have the target language chosen based on the data file being processed. This change facilitates that. Bug: https://crbug.com/1246587 Change-Id: I39f225835f8ca06cb8b8ea1c791b6c872f0f9d8f Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/66180 Auto-Submit: Alastair Donaldson <afdx@google.com> Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Ryan Harrison <rharrison@chromium.org> Commit-Queue: Ryan Harrison <rharrison@chromium.org>
This commit is contained in:
parent
37a666d91c
commit
8f780f1022
|
@ -23,6 +23,15 @@
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
/// Controls the target language in which code will be generated.
|
||||||
|
enum class TargetLanguage {
|
||||||
|
kHlsl,
|
||||||
|
kMsl,
|
||||||
|
kSpv,
|
||||||
|
kWgsl,
|
||||||
|
kTargetLanguageMax,
|
||||||
|
};
|
||||||
|
|
||||||
/// Copies the content from the file named `input_file` to `buffer`,
|
/// Copies the content from the file named `input_file` to `buffer`,
|
||||||
/// assuming each element in the file is of type `T`. If any error occurs,
|
/// assuming each element in the file is of type `T`. If any error occurs,
|
||||||
/// writes error messages to the standard error stream and returns false.
|
/// writes error messages to the standard error stream and returns false.
|
||||||
|
@ -80,45 +89,75 @@ bool ReadFile(const std::string& input_file, std::vector<T>* buffer) {
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
int main(int argc, const char** argv) {
|
int main(int argc, const char** argv) {
|
||||||
if (argc != 3) {
|
if (argc < 2 || argc > 3) {
|
||||||
std::cerr << "Usage: " << argv[0] << " <input file> <hlsl|msl|spv|wgsl>"
|
std::cerr << "Usage: " << argv[0] << " <input file> [hlsl|msl|spv|wgsl]"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string input_filename(argv[1]);
|
std::string input_filename(argv[1]);
|
||||||
std::string target_format(argv[2]);
|
|
||||||
|
|
||||||
std::vector<uint8_t> data;
|
std::vector<uint8_t> data;
|
||||||
if (!ReadFile<uint8_t>(input_filename, &data)) {
|
if (!ReadFile<uint8_t>(input_filename, &data)) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (target_format == "hlsl") {
|
if (data.empty()) {
|
||||||
tint::fuzzers::CommonFuzzer fuzzer(tint::fuzzers::InputFormat::kWGSL,
|
return 0;
|
||||||
tint::fuzzers::OutputFormat::kHLSL);
|
}
|
||||||
return fuzzer.Run(data.data(), data.size());
|
|
||||||
} else if (target_format == "msl") {
|
tint::fuzzers::DataBuilder builder(data.data(), data.size());
|
||||||
tint::fuzzers::DataBuilder builder(data.data(), data.size());
|
|
||||||
tint::writer::msl::Options options;
|
TargetLanguage target_language;
|
||||||
GenerateMslOptions(&builder, &options);
|
|
||||||
tint::fuzzers::CommonFuzzer fuzzer(tint::fuzzers::InputFormat::kWGSL,
|
if (argc == 3) {
|
||||||
tint::fuzzers::OutputFormat::kMSL);
|
std::string target_language_string = argv[2];
|
||||||
fuzzer.SetOptionsMsl(options);
|
if (target_language_string == "hlsl") {
|
||||||
return fuzzer.Run(data.data(), data.size());
|
target_language = TargetLanguage::kHlsl;
|
||||||
} else if (target_format == "spv") {
|
} else if (target_language_string == "msl") {
|
||||||
tint::fuzzers::DataBuilder builder(data.data(), data.size());
|
target_language = TargetLanguage::kMsl;
|
||||||
tint::writer::spirv::Options options;
|
} else if (target_language_string == "spv") {
|
||||||
GenerateSpirvOptions(&builder, &options);
|
target_language = TargetLanguage::kSpv;
|
||||||
tint::fuzzers::CommonFuzzer fuzzer(tint::fuzzers::InputFormat::kWGSL,
|
} else {
|
||||||
tint::fuzzers::OutputFormat::kSpv);
|
assert(target_language_string == "wgsl" && "Unknown target language.");
|
||||||
fuzzer.SetOptionsSpirv(options);
|
target_language = TargetLanguage::kWgsl;
|
||||||
return fuzzer.Run(data.data(), data.size());
|
}
|
||||||
} else if (target_format == "wgsl") {
|
} else {
|
||||||
tint::fuzzers::CommonFuzzer fuzzer(tint::fuzzers::InputFormat::kWGSL,
|
target_language = builder.enum_class<TargetLanguage>(
|
||||||
tint::fuzzers::OutputFormat::kWGSL);
|
static_cast<uint32_t>(TargetLanguage::kTargetLanguageMax));
|
||||||
return fuzzer.Run(data.data(), data.size());
|
}
|
||||||
|
|
||||||
|
switch (target_language) {
|
||||||
|
case TargetLanguage::kHlsl: {
|
||||||
|
tint::fuzzers::CommonFuzzer fuzzer(tint::fuzzers::InputFormat::kWGSL,
|
||||||
|
tint::fuzzers::OutputFormat::kHLSL);
|
||||||
|
return fuzzer.Run(data.data(), data.size());
|
||||||
|
}
|
||||||
|
case TargetLanguage::kMsl: {
|
||||||
|
tint::writer::msl::Options options;
|
||||||
|
GenerateMslOptions(&builder, &options);
|
||||||
|
tint::fuzzers::CommonFuzzer fuzzer(tint::fuzzers::InputFormat::kWGSL,
|
||||||
|
tint::fuzzers::OutputFormat::kMSL);
|
||||||
|
fuzzer.SetOptionsMsl(options);
|
||||||
|
return fuzzer.Run(data.data(), data.size());
|
||||||
|
}
|
||||||
|
case TargetLanguage::kSpv: {
|
||||||
|
tint::writer::spirv::Options options;
|
||||||
|
GenerateSpirvOptions(&builder, &options);
|
||||||
|
tint::fuzzers::CommonFuzzer fuzzer(tint::fuzzers::InputFormat::kWGSL,
|
||||||
|
tint::fuzzers::OutputFormat::kSpv);
|
||||||
|
fuzzer.SetOptionsSpirv(options);
|
||||||
|
return fuzzer.Run(data.data(), data.size());
|
||||||
|
}
|
||||||
|
case TargetLanguage::kWgsl: {
|
||||||
|
tint::fuzzers::CommonFuzzer fuzzer(tint::fuzzers::InputFormat::kWGSL,
|
||||||
|
tint::fuzzers::OutputFormat::kWGSL);
|
||||||
|
return fuzzer.Run(data.data(), data.size());
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
std::cerr << "Aborting due to unknown target language; fuzzer must be "
|
||||||
|
"misconfigured."
|
||||||
|
<< std::endl;
|
||||||
|
abort();
|
||||||
}
|
}
|
||||||
assert(false && "Fuzzer configuration problem: unknown target format.");
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue