Debian Codegraph @

third_party/spirv-tools/source/fuzz/pass_management/repeated_pass_manager.h

raw
1 // Copyright (c) 2020 Google LLC
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 SOURCE_FUZZ_REPEATED_PASS_MANAGER_H_
16 #define SOURCE_FUZZ_REPEATED_PASS_MANAGER_H_
17
18 #include "source/fuzz/fuzzer_context.h"
19 #include "source/fuzz/fuzzer_pass.h"
20 #include "source/fuzz/pass_management/repeated_pass_instances.h"
21 #include "source/fuzz/protobufs/spirvfuzz_protobufs.h"
22
23 namespace spvtools {
24 namespace fuzz {
25
26 // An interface to encapsulate the manner in which the sequence of repeated
27 // passes that are applied during fuzzing is chosen. An implementation of this
28 // interface could, for example, keep track of the history of passes that have
29 // been run and bias the selection of future passes according to this history.
30 class RepeatedPassManager {
31 public:
32 RepeatedPassManager(FuzzerContext* fuzzer_context,
33 RepeatedPassInstances* pass_instances);
34
35 virtual ~RepeatedPassManager();
36
37 // Returns the fuzzer pass instance that should be run next. The
38 // transformations that have been applied so far are provided via
39 // |applied_transformations| and can be used to influence the decision.
40 virtual FuzzerPass* ChoosePass(
41 const protobufs::TransformationSequence& applied_transformations) = 0;
42
43 protected:
44 FuzzerContext* GetFuzzerContext() { return fuzzer_context_; }
45
46 RepeatedPassInstances* GetPassInstances() { return pass_instances_; }
47
48 private:
49 // Provided in order to allow the pass manager to make random decisions.
50 FuzzerContext* fuzzer_context_;
51
52 // The repeated fuzzer passes that are enabled.
53 RepeatedPassInstances* pass_instances_;
54 };
55
56 } // namespace fuzz
57 } // namespace spvtools
58
59 #endif // SOURCE_FUZZ_REPEATED_PASS_MANAGER_H_