OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef Fuzz_DEFINED | 8 #ifndef Fuzz_DEFINED |
9 #define Fuzz_DEFINED | 9 #define Fuzz_DEFINED |
10 | 10 |
11 #include "SkData.h" | 11 #include "SkData.h" |
12 #include "SkTRegistry.h" | 12 #include "SkTRegistry.h" |
13 #include "SkTypes.h" | 13 #include "SkTypes.h" |
14 #include <stdlib.h> | |
15 | 14 |
16 class Fuzz : SkNoncopyable { | 15 class Fuzz : SkNoncopyable { |
17 public: | 16 public: |
18 explicit Fuzz(SkData*); | 17 explicit Fuzz(SkData*); |
19 | 18 |
20 uint8_t nextB(); | 19 uint8_t nextB(); |
21 uint32_t nextU(); | 20 uint32_t nextU(); |
22 float nextF(); | 21 float nextF(); |
23 | 22 |
| 23 void signalBug (); // Tell afl-fuzz these inputs found a bug. |
| 24 void signalBoring(); // Tell afl-fuzz these inputs are not worth testing. |
| 25 |
24 private: | 26 private: |
| 27 template <typename T> |
| 28 T nextT(); |
| 29 |
25 SkAutoTUnref<SkData> fBytes; | 30 SkAutoTUnref<SkData> fBytes; |
26 int fNextByte; | 31 int fNextByte; |
27 }; | 32 }; |
28 | 33 |
29 struct Fuzzable { | 34 struct Fuzzable { |
30 const char* name; | 35 const char* name; |
31 void (*fn)(Fuzz*); | 36 void (*fn)(Fuzz*); |
32 }; | 37 }; |
33 | 38 |
34 #define DEF_FUZZ(name, f) \ | 39 #define DEF_FUZZ(name, f) \ |
35 static void fuzz_##name(Fuzz*); \ | 40 static void fuzz_##name(Fuzz*); \ |
36 SkTRegistry<Fuzzable> register_##name({#name, fuzz_##name}); \ | 41 SkTRegistry<Fuzzable> register_##name({#name, fuzz_##name}); \ |
37 static void fuzz_##name(Fuzz* f) | 42 static void fuzz_##name(Fuzz* f) |
38 | 43 |
39 #define ASSERT(cond) do { if (!(cond)) abort(); } while(false) | |
40 | |
41 #endif//Fuzz_DEFINED | 44 #endif//Fuzz_DEFINED |
OLD | NEW |