mtklein | 65e5824 | 2016-01-13 12:57:57 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef Fuzz_DEFINED |
| 9 | #define Fuzz_DEFINED |
| 10 | |
| 11 | #include "SkData.h" |
| 12 | #include "SkTRegistry.h" |
| 13 | #include "SkTypes.h" |
mtklein | 65e5824 | 2016-01-13 12:57:57 -0800 | [diff] [blame] | 14 | |
| 15 | class Fuzz : SkNoncopyable { |
| 16 | public: |
| 17 | explicit Fuzz(SkData*); |
| 18 | |
kjlubick | 5bd98a2 | 2016-02-18 06:27:38 -0800 | [diff] [blame] | 19 | bool nextBool(); |
mtklein | 24a22c7 | 2016-01-14 04:59:42 -0800 | [diff] [blame] | 20 | uint8_t nextB(); |
mtklein | 65e5824 | 2016-01-13 12:57:57 -0800 | [diff] [blame] | 21 | uint32_t nextU(); |
kjlubick | 5bd98a2 | 2016-02-18 06:27:38 -0800 | [diff] [blame] | 22 | // This can be nan, +- infinity, 0, anything. |
mtklein | 65e5824 | 2016-01-13 12:57:57 -0800 | [diff] [blame] | 23 | float nextF(); |
kjlubick | 4319593 | 2016-04-05 12:48:47 -0700 | [diff] [blame] | 24 | // Returns a float between [0..1) as a IEEE float |
| 25 | float nextF1(); |
mtklein | 65e5824 | 2016-01-13 12:57:57 -0800 | [diff] [blame] | 26 | |
kjlubick | 5bd98a2 | 2016-02-18 06:27:38 -0800 | [diff] [blame] | 27 | // Return the next fuzzed value [min, max) as an unsigned 32bit integer. |
| 28 | uint32_t nextRangeU(uint32_t min, uint32_t max); |
| 29 | /** |
| 30 | * Returns next fuzzed value [min...max) as a float. |
| 31 | * Will not be Infinity or NaN. |
| 32 | */ |
| 33 | float nextRangeF(float min, float max); |
| 34 | |
mtklein | a115942 | 2016-01-15 05:46:54 -0800 | [diff] [blame] | 35 | void signalBug (); // Tell afl-fuzz these inputs found a bug. |
| 36 | void signalBoring(); // Tell afl-fuzz these inputs are not worth testing. |
| 37 | |
mtklein | 65e5824 | 2016-01-13 12:57:57 -0800 | [diff] [blame] | 38 | private: |
mtklein | a115942 | 2016-01-15 05:46:54 -0800 | [diff] [blame] | 39 | template <typename T> |
| 40 | T nextT(); |
| 41 | |
mtklein | 65e5824 | 2016-01-13 12:57:57 -0800 | [diff] [blame] | 42 | SkAutoTUnref<SkData> fBytes; |
mtklein | 24a22c7 | 2016-01-14 04:59:42 -0800 | [diff] [blame] | 43 | int fNextByte; |
mtklein | 65e5824 | 2016-01-13 12:57:57 -0800 | [diff] [blame] | 44 | }; |
| 45 | |
| 46 | struct Fuzzable { |
| 47 | const char* name; |
| 48 | void (*fn)(Fuzz*); |
| 49 | }; |
| 50 | |
| 51 | #define DEF_FUZZ(name, f) \ |
| 52 | static void fuzz_##name(Fuzz*); \ |
| 53 | SkTRegistry<Fuzzable> register_##name({#name, fuzz_##name}); \ |
| 54 | static void fuzz_##name(Fuzz* f) |
| 55 | |
mtklein | 65e5824 | 2016-01-13 12:57:57 -0800 | [diff] [blame] | 56 | #endif//Fuzz_DEFINED |