Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(887)

Side by Side Diff: fuzz/Fuzz.h

Issue 2447823002: Fix fuzzer's bools to be 0 or 1 only (Closed)
Patch Set: Line up Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | fuzz/FuzzGradients.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 14
15 class Fuzz : SkNoncopyable { 15 class Fuzz : SkNoncopyable {
16 public: 16 public:
17 explicit Fuzz(sk_sp<SkData>); 17 explicit Fuzz(sk_sp<SkData>);
18 18
19 // Returns the total number of "random" bytes available. 19 // Returns the total number of "random" bytes available.
20 size_t size(); 20 size_t size();
21 // Returns the total number of "random" bytes remaining for randomness. 21 // Returns the total number of "random" bytes remaining for randomness.
22 size_t remaining(); 22 size_t remaining();
23 23
24 template <typename T> 24 template <typename T>
25 bool next(T* n); 25 bool next(T* n);
26 26
27 // UBSAN reminds us that bool can only legally hold 0 or 1.
28 bool next(bool* b) {
29 uint8_t byte;
30 if (!this->next(&byte)) {
31 return false;
32 }
33 *b = (byte & 1) == 1;
34 return true;
35 }
36
37 // The nextFoo methods are deprecated.
38 // TODO(kjlubick): replace existing uses with next() and remove these.
27 bool nextBool(); 39 bool nextBool();
28 uint8_t nextB(); 40 uint8_t nextB();
29 uint32_t nextU(); 41 uint32_t nextU();
30 // This can be nan, +- infinity, 0, anything. 42 // This can be nan, +- infinity, 0, anything.
31 float nextF(); 43 float nextF();
32 // Returns a float between [0..1) as a IEEE float 44 // Returns a float between [0..1) as a IEEE float
33 float nextF1(); 45 float nextF1();
34 46
35 // Return the next fuzzed value [min, max) as an unsigned 32bit integer. 47 // Return the next fuzzed value [min, max) as an unsigned 32bit integer.
36 uint32_t nextRangeU(uint32_t min, uint32_t max); 48 uint32_t nextRangeU(uint32_t min, uint32_t max);
(...skipping 29 matching lines...) Expand all
66 const char* name; 78 const char* name;
67 void (*fn)(Fuzz*); 79 void (*fn)(Fuzz*);
68 }; 80 };
69 81
70 #define DEF_FUZZ(name, f) \ 82 #define DEF_FUZZ(name, f) \
71 static void fuzz_##name(Fuzz*); \ 83 static void fuzz_##name(Fuzz*); \
72 SkTRegistry<Fuzzable> register_##name({#name, fuzz_##name}); \ 84 SkTRegistry<Fuzzable> register_##name({#name, fuzz_##name}); \
73 static void fuzz_##name(Fuzz* f) 85 static void fuzz_##name(Fuzz* f)
74 86
75 #endif//Fuzz_DEFINED 87 #endif//Fuzz_DEFINED
OLDNEW
« no previous file with comments | « no previous file | fuzz/FuzzGradients.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698