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

Side by Side Diff: fuzz/fuzz.cpp

Issue 1587043009: If we pass no bytes, use the fuzz binary itself. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 11 months 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 | no next file » | 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 #include "Fuzz.h" 8 #include "Fuzz.h"
9 #include "SkCommandLineFlags.h" 9 #include "SkCommandLineFlags.h"
10 #include <signal.h> 10 #include <signal.h>
11 #include <stdlib.h> 11 #include <stdlib.h>
12 12
13 DEFINE_string2(bytes, b, "", "A path to a file containing fuzzed bytes."); 13 DEFINE_string2(bytes, b, "", "A path to a file containing fuzzed bytes.");
14 DEFINE_string2(match, m, "", "The usual --match, applied to DEF_FUZZ names."); 14 DEFINE_string2(match, m, "", "The usual --match, applied to DEF_FUZZ names.");
15 15
16 int main(int argc, char** argv) { 16 int main(int argc, char** argv) {
17 SkCommandLineFlags::Parse(argc, argv); 17 SkCommandLineFlags::Parse(argc, argv);
18 18
19 if (FLAGS_bytes.isEmpty()) { 19 const char* path = FLAGS_bytes.isEmpty() ? argv[0] : FLAGS_bytes[0];
20 SkDebugf("Usage: %s -b <path/to/fuzzed.data> [-m pattern]\n", argv[0]); 20 SkAutoTUnref<SkData> bytes(SkData::NewFromFileName(path));
21 return 1;
22 }
23 SkAutoTUnref<SkData> bytes(SkData::NewFromFileName(FLAGS_bytes[0]));
24 21
25 for (auto r = SkTRegistry<Fuzzable>::Head(); r; r = r->next()) { 22 for (auto r = SkTRegistry<Fuzzable>::Head(); r; r = r->next()) {
26 auto fuzzable = r->factory(); 23 auto fuzzable = r->factory();
27 if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, fuzzable.name)) { 24 if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, fuzzable.name)) {
28 SkDebugf("Fuzzing %s...\n", fuzzable.name); 25 SkDebugf("Fuzzing %s...\n", fuzzable.name);
29 Fuzz fuzz(bytes); 26 Fuzz fuzz(bytes);
30 fuzzable.fn(&fuzz); 27 fuzzable.fn(&fuzz);
31 } 28 }
32 } 29 }
33 return 0; 30 return 0;
(...skipping 14 matching lines...) Expand all
48 T val; 45 T val;
49 memcpy(&val, fBytes->bytes() + fNextByte, sizeof(T)); 46 memcpy(&val, fBytes->bytes() + fNextByte, sizeof(T));
50 fNextByte += sizeof(T); 47 fNextByte += sizeof(T);
51 return val; 48 return val;
52 } 49 }
53 50
54 uint8_t Fuzz::nextB() { return this->nextT<uint8_t >(); } 51 uint8_t Fuzz::nextB() { return this->nextT<uint8_t >(); }
55 uint32_t Fuzz::nextU() { return this->nextT<uint32_t>(); } 52 uint32_t Fuzz::nextU() { return this->nextT<uint32_t>(); }
56 float Fuzz::nextF() { return this->nextT<float >(); } 53 float Fuzz::nextF() { return this->nextT<float >(); }
57 54
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698