• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 The Tint Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef FUZZERS_TINT_AST_FUZZER_CLI_H_
16 #define FUZZERS_TINT_AST_FUZZER_CLI_H_
17 
18 #include <cstdint>
19 
20 namespace tint {
21 namespace fuzzers {
22 namespace ast_fuzzer {
23 
24 /// The backend this fuzzer will test.
25 enum class FuzzingTarget {
26   kNone = 0,
27   kHlsl = 1 << 0,
28   kMsl = 1 << 1,
29   kSpv = 1 << 2,
30   kWgsl = 1 << 3,
31   kAll = kHlsl | kMsl | kSpv | kWgsl
32 };
33 
34 inline FuzzingTarget operator|(FuzzingTarget a, FuzzingTarget b) {
35   return static_cast<FuzzingTarget>(static_cast<int>(a) | static_cast<int>(b));
36 }
37 
38 inline FuzzingTarget operator&(FuzzingTarget a, FuzzingTarget b) {
39   return static_cast<FuzzingTarget>(static_cast<int>(a) & static_cast<int>(b));
40 }
41 
42 /// CLI parameters accepted by the fuzzer. Type -tint_help in the CLI to see the
43 /// help message
44 struct CliParams {
45   /// Whether to use all mutation finders or only a randomly selected subset of
46   /// them.
47   bool enable_all_mutations = false;
48 
49   /// The maximum number of mutations applied during a single mutation session
50   /// (i.e. a call to `ast_fuzzer::Mutate` function).
51   uint32_t mutation_batch_size = 5;
52 
53   /// Compiler backends we want to fuzz.
54   FuzzingTarget fuzzing_target = FuzzingTarget::kAll;
55 };
56 
57 /// @brief Parses CLI parameters.
58 ///
59 /// This function will exit the process with non-zero return code if some
60 /// parameters are invalid. This function will remove recognized parameters from
61 /// `argv` and adjust `argc` accordingly.
62 ///
63 /// @param argc - the total number of parameters.
64 /// @param argv - array of all CLI parameters.
65 /// @return parsed parameters.
66 CliParams ParseCliParams(int* argc, char** argv);
67 
68 }  // namespace ast_fuzzer
69 }  // namespace fuzzers
70 }  // namespace tint
71 
72 #endif  // FUZZERS_TINT_AST_FUZZER_CLI_H_
73