aboutsummaryrefslogtreecommitdiffhomepage
path: root/fuzz/fuzz.cpp
blob: 6e3179095103916661273bef6fadd4e5c7d6f51c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
 * Copyright 2016 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "Fuzz.h"
#include "SkCommandLineFlags.h"

DEFINE_string2(match, m, "", "The usual match patterns, applied to name.");
DEFINE_string2(bytes, b, "", "Path to file containing fuzzed bytes.");

int main(int argc, char** argv) {
    SkCommandLineFlags::Parse(argc, argv);
    SkAutoTUnref<SkData> bytes;
    if (!FLAGS_bytes.isEmpty()) {
        bytes.reset(SkData::NewFromFileName(FLAGS_bytes[0]));
    }

    for (auto r = SkTRegistry<Fuzzable>::Head(); r; r = r->next()) {
        auto fuzzable = r->factory();
        if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, fuzzable.name)) {
            SkDebugf("Running %s...\n", fuzzable.name);
            Fuzz fuzz(bytes);
            fuzzable.fn(&fuzz);
        }
    }
    return 0;
}


Fuzz::Fuzz(SkData* bytes) : fBytes(SkSafeRef(bytes)) {}

// These methods are all TODO(kjlubick).
uint32_t Fuzz::nextU() { return    0; }
float    Fuzz::nextF() { return 0.0f; }
uint32_t Fuzz::nextURange(uint32_t min, uint32_t max) { return min; }
float    Fuzz::nextFRange(float    min, float    max) { return min; }