• 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_READER_WRITER_FUZZER_H_
16 #define FUZZERS_TINT_READER_WRITER_FUZZER_H_
17 
18 #include <memory>
19 
20 #include "fuzzers/tint_common_fuzzer.h"
21 #include "fuzzers/transform_builder.h"
22 
23 namespace tint {
24 namespace fuzzers {
25 
26 class ReaderWriterFuzzer : public CommonFuzzer {
27  public:
ReaderWriterFuzzer(InputFormat input,OutputFormat output)28   explicit ReaderWriterFuzzer(InputFormat input, OutputFormat output)
29       : CommonFuzzer(input, output) {}
~ReaderWriterFuzzer()30   ~ReaderWriterFuzzer() {}
31 
SetTransformManager(transform::Manager * tm,transform::DataMap * inputs)32   void SetTransformManager(transform::Manager* tm, transform::DataMap* inputs) {
33     tm_set_ = true;
34     CommonFuzzer::SetTransformManager(tm, inputs);
35   }
36 
Run(const uint8_t * data,size_t size)37   int Run(const uint8_t* data, size_t size) {
38     if (!tm_set_) {
39       tb_ = std::make_unique<TransformBuilder>(data, size);
40       tb_->AddTransform<tint::transform::Robustness>();
41       SetTransformManager(tb_->manager(), tb_->data_map());
42     }
43 
44     return CommonFuzzer::Run(data, size);
45   }
46 
47  private:
48   bool tm_set_ = false;
49   std::unique_ptr<TransformBuilder> tb_;
50 };
51 
52 }  // namespace fuzzers
53 }  // namespace tint
54 
55 #endif  // FUZZERS_TINT_READER_WRITER_FUZZER_H_
56