Make commandline flags nicer for fuzz executable

This cleans up the build so commandline flags defined in tools/*.cpp
don't get globbed into the fuzzer's.

Bug: skia:
Change-Id: I5994aa5bf75686641baf0cf97fd81141f0ac6f3a
Reviewed-on: https://skia-review.googlesource.com/92680
Commit-Queue: Kevin Lubick <kjlubick@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
This commit is contained in:
Kevin Lubick 2018-01-09 12:47:33 -05:00 committed by Skia Commit-Bot
parent db38573ca0
commit 9ff5dc9c9f
2 changed files with 30 additions and 10 deletions

View File

@ -1686,6 +1686,10 @@ if (skia_enable_tools) {
}
test_app("fuzz") {
include_dirs = [
"tools",
"tools/debugger",
]
sources = [
"fuzz/FilterFuzz.cpp",
"fuzz/FuzzCanvas.cpp",
@ -1695,12 +1699,19 @@ if (skia_enable_tools) {
"fuzz/FuzzPathop.cpp",
"fuzz/FuzzScaleToSides.cpp",
"fuzz/fuzz.cpp",
"tools/UrlDataManager.cpp",
"tools/debugger/SkDebugCanvas.cpp",
"tools/debugger/SkDrawCommand.cpp",
"tools/debugger/SkJsonWriteBuffer.cpp",
"tools/debugger/SkObjectParser.cpp",
"tools/picture_utils.cpp",
]
deps = [
":flags",
":gpu_tool_utils",
":skia",
":tool_utils",
"//third_party/jsoncpp",
"//third_party/libpng",
]
}

View File

@ -35,22 +35,28 @@
#include <signal.h>
#include "sk_tool_utils.h"
DEFINE_string2(bytes, b, "", "A path to a file or a directory. If a file, the "
"contents will be used as the fuzz bytes. If a directory, all files "
"in the directory will be used as fuzz bytes for the fuzzer, one at a "
"time.");
DEFINE_string2(name, n, "", "If --type is 'api', fuzz the API with this name.");
DEFINE_string2(type, t, "api", "How to interpret --bytes, either 'image_scale'"
", 'image_mode', 'skp', 'icc', or 'api'.");
DEFINE_string2(dump, d, "", "If not empty, dump 'image*' or 'skp' types as a "
"PNG with this name.");
DEFINE_bool2(verbose, v, false, "Print more information while fuzzing.");
DEFINE_string2(type, t, "", "How to interpret --bytes, one of:\n"
"api\n"
"color_deserialize\n"
"filter_fuzz (equivalent to Chrome's filter_fuzz_stub)\n"
"icc\n"
"image_mode\n"
"image_scale\n"
"path_deserialize\n"
"pipe\n"
"region_deserialize\n"
"skp\n"
"sksl2glsl\n"
"textblob");
static int printUsage() {
SkDebugf("Usage: fuzz -t <type> -b <path/to/file> [-n api-to-fuzz]\n");
return 1;
}
static int fuzz_file(const char* path);
static uint8_t calculate_option(SkData*);
@ -70,6 +76,8 @@ static void fuzz_sksl2glsl(sk_sp<SkData>);
#endif
int main(int argc, char** argv) {
SkCommandLineFlags::SetUsage("Usage: fuzz -t <type> -b <path/to/file> [-n api-to-fuzz]\n"
"--help lists the valid types\n");
SkCommandLineFlags::Parse(argc, argv);
const char* path = FLAGS_bytes.isEmpty() ? argv[0] : FLAGS_bytes[0];
@ -151,7 +159,8 @@ static int fuzz_file(const char* path) {
}
#endif
}
return printUsage();
SkCommandLineFlags::PrintUsage();
return 1;
}
// This adds up the first 1024 bytes and returns it as an 8 bit integer. This allows afl-fuzz to