2021-06-24 18:10:46 +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.
|
|
|
|
|
|
|
|
#ifndef FUZZERS_TINT_SPIRV_TOOLS_FUZZER_CLI_H_
|
|
|
|
#define FUZZERS_TINT_SPIRV_TOOLS_FUZZER_CLI_H_
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "source/fuzz/fuzzer.h"
|
|
|
|
|
|
|
|
namespace tint {
|
|
|
|
namespace fuzzers {
|
|
|
|
namespace spvtools_fuzzer {
|
|
|
|
|
|
|
|
/// Default SPIR-V environment that will be used during fuzzing.
|
|
|
|
const auto kDefaultTargetEnv = SPV_ENV_VULKAN_1_1;
|
|
|
|
|
|
|
|
/// The type of the mutator to run.
|
|
|
|
enum class MutatorType {
|
|
|
|
kNone = 0,
|
|
|
|
kFuzz = 1 << 0,
|
|
|
|
kReduce = 1 << 1,
|
|
|
|
kOpt = 1 << 2,
|
|
|
|
kAll = kFuzz | kReduce | kOpt
|
|
|
|
};
|
|
|
|
|
|
|
|
inline MutatorType operator|(MutatorType a, MutatorType b) {
|
|
|
|
return static_cast<MutatorType>(static_cast<int>(a) | static_cast<int>(b));
|
|
|
|
}
|
|
|
|
|
|
|
|
inline MutatorType operator&(MutatorType a, MutatorType b) {
|
|
|
|
return static_cast<MutatorType>(static_cast<int>(a) & static_cast<int>(b));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Shading language to target during fuzzing.
|
|
|
|
enum class FuzzingTarget {
|
|
|
|
kNone = 0,
|
|
|
|
kHlsl = 1 << 0,
|
|
|
|
kMsl = 1 << 1,
|
|
|
|
kSpv = 1 << 2,
|
|
|
|
kWgsl = 1 << 3,
|
|
|
|
kAll = kHlsl | kMsl | kSpv | kWgsl
|
|
|
|
};
|
|
|
|
|
|
|
|
inline FuzzingTarget operator|(FuzzingTarget a, FuzzingTarget b) {
|
|
|
|
return static_cast<FuzzingTarget>(static_cast<int>(a) | static_cast<int>(b));
|
|
|
|
}
|
|
|
|
|
|
|
|
inline FuzzingTarget operator&(FuzzingTarget a, FuzzingTarget b) {
|
|
|
|
return static_cast<FuzzingTarget>(static_cast<int>(a) & static_cast<int>(b));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// These parameters are accepted by various mutators and thus they are accepted
|
|
|
|
/// by both the fuzzer and the mutator debugger.
|
|
|
|
struct MutatorCliParams {
|
2021-06-28 09:47:57 +00:00
|
|
|
/// SPIR-V target environment for fuzzing.
|
2021-06-24 18:10:46 +00:00
|
|
|
spv_target_env target_env = kDefaultTargetEnv;
|
2021-06-28 09:47:57 +00:00
|
|
|
|
|
|
|
/// The number of spirv-fuzz transformations to apply at a time.
|
2021-06-24 18:10:46 +00:00
|
|
|
uint32_t transformation_batch_size = 3;
|
2021-06-28 09:47:57 +00:00
|
|
|
|
|
|
|
/// The number of spirv-reduce reductions to apply at a time.
|
2021-06-24 18:10:46 +00:00
|
|
|
uint32_t reduction_batch_size = 3;
|
2021-06-28 09:47:57 +00:00
|
|
|
|
|
|
|
/// The number of spirv-opt optimizations to apply at a time.
|
2021-06-24 18:10:46 +00:00
|
|
|
uint32_t opt_batch_size = 6;
|
2021-06-28 09:47:57 +00:00
|
|
|
|
|
|
|
/// The vector of donors to use in spirv-fuzz (see the doc for spirv-fuzz to
|
|
|
|
/// learn more).
|
2021-06-24 18:10:46 +00:00
|
|
|
std::vector<spvtools::fuzz::fuzzerutil::ModuleSupplier> donors = {};
|
2021-06-28 09:47:57 +00:00
|
|
|
|
|
|
|
/// The strategy to use during fuzzing in spirv-fuzz (see the doc for
|
|
|
|
/// spirv-fuzz to learn more).
|
2021-06-24 18:10:46 +00:00
|
|
|
spvtools::fuzz::RepeatedPassStrategy repeated_pass_strategy =
|
|
|
|
spvtools::fuzz::RepeatedPassStrategy::kSimple;
|
2021-06-28 09:47:57 +00:00
|
|
|
|
|
|
|
/// Whether to use all fuzzer passes or a randomly selected subset of them.
|
2021-06-24 18:10:46 +00:00
|
|
|
bool enable_all_fuzzer_passes = false;
|
2021-06-28 09:47:57 +00:00
|
|
|
|
|
|
|
/// Whether to use all reduction passes or a randomly selected subset of them.
|
2021-06-24 18:10:46 +00:00
|
|
|
bool enable_all_reduce_passes = false;
|
2021-06-28 09:47:57 +00:00
|
|
|
|
|
|
|
/// Whether to validate the SPIR-V binary after each optimization pass.
|
2021-06-24 18:10:46 +00:00
|
|
|
bool validate_after_each_opt_pass = true;
|
2021-06-28 09:47:57 +00:00
|
|
|
|
|
|
|
/// Whether to validate the SPIR-V binary after each fuzzer pass.
|
2021-06-24 18:10:46 +00:00
|
|
|
bool validate_after_each_fuzzer_pass = true;
|
2021-06-28 09:47:57 +00:00
|
|
|
|
|
|
|
/// Whether to validate the SPIR-V binary after each reduction pass.
|
2021-06-24 18:10:46 +00:00
|
|
|
bool validate_after_each_reduce_pass = true;
|
|
|
|
};
|
|
|
|
|
2021-06-28 09:47:57 +00:00
|
|
|
/// Parameters specific to the fuzzer. Type `--help` in the CLI to learn more.
|
2021-06-24 18:10:46 +00:00
|
|
|
struct FuzzerCliParams {
|
2021-06-28 09:47:57 +00:00
|
|
|
/// The size of the cache that records ongoing mutation sessions.
|
2021-06-24 18:10:46 +00:00
|
|
|
uint32_t mutator_cache_size = 20;
|
2021-06-28 09:47:57 +00:00
|
|
|
|
|
|
|
/// The type of the mutator to run.
|
2021-06-24 18:10:46 +00:00
|
|
|
MutatorType mutator_type = MutatorType::kAll;
|
2021-06-28 09:47:57 +00:00
|
|
|
|
|
|
|
/// Tint backend to fuzz.
|
2021-06-24 18:10:46 +00:00
|
|
|
FuzzingTarget fuzzing_target = FuzzingTarget::kAll;
|
2021-06-28 09:47:57 +00:00
|
|
|
|
|
|
|
/// The path to the directory, that will be used to output buggy shaders.
|
2021-06-24 18:10:46 +00:00
|
|
|
std::string error_dir;
|
2021-06-28 09:47:57 +00:00
|
|
|
|
|
|
|
/// Parameters for various mutators.
|
2021-06-24 18:10:46 +00:00
|
|
|
MutatorCliParams mutator_params;
|
|
|
|
};
|
|
|
|
|
2021-06-28 09:47:57 +00:00
|
|
|
/// Parameters specific to the mutator debugger. Type `--help` in the CLI to
|
|
|
|
/// learn more.
|
2021-06-24 18:10:46 +00:00
|
|
|
struct MutatorDebuggerCliParams {
|
2021-06-28 09:47:57 +00:00
|
|
|
/// The type of the mutator to debug.
|
2021-06-24 18:10:46 +00:00
|
|
|
MutatorType mutator_type = MutatorType::kNone;
|
2021-06-28 09:47:57 +00:00
|
|
|
|
|
|
|
/// The seed that was used to initialize the mutator.
|
2021-06-24 18:10:46 +00:00
|
|
|
uint32_t seed = 0;
|
2021-06-28 09:47:57 +00:00
|
|
|
|
|
|
|
/// The binary that triggered a bug in the mutator.
|
2021-06-24 18:10:46 +00:00
|
|
|
std::vector<uint32_t> original_binary;
|
2021-06-28 09:47:57 +00:00
|
|
|
|
|
|
|
/// Parameters for various mutators.
|
2021-06-24 18:10:46 +00:00
|
|
|
MutatorCliParams mutator_params;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Parses CLI parameters for the fuzzer. This function exits with an error code
|
|
|
|
/// and a message is printed to the console if some parameter has invalid
|
|
|
|
/// format. You can pass `--help` to check out all available parameters.
|
|
|
|
///
|
|
|
|
/// @param argc - the number of parameters (identical to the `argc` in `main`
|
|
|
|
/// function).
|
|
|
|
/// @param argv - array of C strings of parameters.
|
|
|
|
/// @return the parsed parameters.
|
|
|
|
FuzzerCliParams ParseFuzzerCliParams(int argc, const char* const* argv);
|
|
|
|
|
|
|
|
/// Parses CLI parameters for the mutator debugger. This function exits with an
|
|
|
|
/// error code and a message is printed to the console if some parameter has
|
|
|
|
/// invalid format. You can pass `--help` to check out all available parameters.
|
|
|
|
///
|
|
|
|
/// @param argc - the number of parameters (identical to the `argc` in `main`
|
|
|
|
/// function).
|
|
|
|
/// @param argv - array of C strings of parameters.
|
|
|
|
/// @return the parsed parameters.
|
|
|
|
MutatorDebuggerCliParams ParseMutatorDebuggerCliParams(int argc,
|
|
|
|
const char* const* argv);
|
|
|
|
|
|
|
|
} // namespace spvtools_fuzzer
|
|
|
|
} // namespace fuzzers
|
|
|
|
} // namespace tint
|
|
|
|
|
|
|
|
#endif // FUZZERS_TINT_SPIRV_TOOLS_FUZZER_CLI_H_
|