Define canvas fuzzers like the other API fuzzers
Invoke these like:
out/Clang/fuzz -n RasterN32Canvas -b [fuzz]
out/Clang/fuzz -n NullCanvas -b [fuzz]
out/Clang/fuzz -n PDFCanvas -b [fuzz]
For debugging:
out/Clang/fuzz -n _DumpCanvas -b [fuzz]
BUG=skia:
Change-Id: I19bd215df09ad2e4ceb7ab16ac6b232fb3f905ed
Reviewed-on: https://skia-review.googlesource.com/9097
Reviewed-by: Hal Canary <halcanary@google.com>
Commit-Queue: Kevin Lubick <kjlubick@google.com>
diff --git a/fuzz/FuzzCanvas.cpp b/fuzz/FuzzCanvas.cpp
index a99ce96..5ab94c9 100644
--- a/fuzz/FuzzCanvas.cpp
+++ b/fuzz/FuzzCanvas.cpp
@@ -6,17 +6,20 @@
*/
#include "Fuzz.h"
-#include "FuzzCanvas.h"
// CORE
#include "SkCanvas.h"
#include "SkColorFilter.h"
+#include "SkDebugCanvas.h"
+#include "SkDocument.h"
#include "SkFontMgr.h"
#include "SkImageFilter.h"
#include "SkMaskFilter.h"
+#include "SkNullCanvas.h"
#include "SkPathEffect.h"
#include "SkPictureRecorder.h"
#include "SkRegion.h"
+#include "SkSurface.h"
#include "SkTypeface.h"
// EFFECTS
@@ -27,6 +30,10 @@
// SRC
#include "SkUtils.h"
+// MISC
+
+#include <iostream>
+
// TODO:
// SkCanvas::drawTextBlob
// SkCanvas::drawTextRSXform
@@ -1130,8 +1137,33 @@
return pictureRecorder.finishRecordingAsPicture();
}
-void FuzzCanvas(Fuzz* fuzz, SkCanvas* canvas) {
- fuzz_canvas(fuzz, canvas);
- SkDebugf("[terminated] Finished Canvas Calls.\n");
+DEF_FUZZ(NullCanvas, fuzz) {
+ fuzz_canvas(fuzz, SkMakeNullCanvas().get());
}
+DEF_FUZZ(RasterN32Canvas, fuzz) {
+ fuzz_canvas(fuzz, SkMakeNullCanvas().get());
+ auto surface = SkSurface::MakeRasterN32Premul(612, 792);
+ SkASSERT(surface && surface->getCanvas());
+ fuzz_canvas(fuzz, surface->getCanvas());
+}
+
+DEF_FUZZ(PDFCanvas, fuzz) {
+ struct final : public SkWStream {
+ bool write(const void*, size_t n) override { fN += n; return true; }
+ size_t bytesWritten() const override { return fN; }
+ size_t fN = 0;
+ } stream;
+ auto doc = SkDocument::MakePDF(&stream);
+ fuzz_canvas(fuzz, doc->beginPage(612.0f, 792.0f));
+}
+
+// not a "real" thing to fuzz, used to debug errors found while fuzzing.
+DEF_FUZZ(_DumpCanvas, fuzz) {
+ SkDebugCanvas debugCanvas(612, 792);
+ fuzz_canvas(fuzz, &debugCanvas);
+ std::unique_ptr<SkCanvas> nullCanvas = SkMakeNullCanvas();
+ UrlDataManager dataManager(SkString("data"));
+ Json::Value json = debugCanvas.toJSON(dataManager, debugCanvas.getSize(), nullCanvas.get());
+ Json::StyledStreamWriter(" ").write(std::cout, json);
+}
diff --git a/fuzz/FuzzCanvas.h b/fuzz/FuzzCanvas.h
deleted file mode 100644
index bde0dea..0000000
--- a/fuzz/FuzzCanvas.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef FuzzCanvas_DEFINED
-#define FuzzCanvas_DEFINED
-
-class Fuzz;
-class SkCanvas;
-
-void FuzzCanvas(Fuzz*, SkCanvas*);
-
-#endif // FuzzCanvas_DEFINED
diff --git a/fuzz/fuzz.cpp b/fuzz/fuzz.cpp
index 12f11e5..ea385ad 100644
--- a/fuzz/fuzz.cpp
+++ b/fuzz/fuzz.cpp
@@ -10,12 +10,9 @@
#include "SkCodec.h"
#include "SkCommandLineFlags.h"
#include "SkData.h"
-#include "SkDebugCanvas.h"
-#include "SkDocument.h"
#include "SkImage.h"
#include "SkImageEncoder.h"
#include "SkMallocPixelRef.h"
-#include "SkNullCanvas.h"
#include "SkOSFile.h"
#include "SkOSPath.h"
#include "SkPath.h"
@@ -30,10 +27,8 @@
#include <iostream>
#include <signal.h>
-
#include "sk_tool_utils.h"
-#include "FuzzCanvas.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 "
@@ -59,10 +54,6 @@
static void fuzz_img(sk_sp<SkData>, uint8_t, uint8_t);
static void fuzz_path_deserialize(sk_sp<SkData>);
static void fuzz_region_deserialize(sk_sp<SkData>);
-static void fuzz_pdf_canvas(sk_sp<SkData>);
-static void fuzz_null_canvas(sk_sp<SkData>);
-static void fuzz_dump_canvas(sk_sp<SkData>);
-static void fuzz_raster_n32_canvas(sk_sp<SkData>);
static void fuzz_skp(sk_sp<SkData>);
#if SK_SUPPORT_GPU
static void fuzz_sksl2glsl(sk_sp<SkData>);
@@ -131,23 +122,6 @@
fuzz_skp(bytes);
return 0;
}
- if (0 == strcmp("pdf_canvas", FLAGS_type[0])) {
- fuzz_pdf_canvas(bytes);
- return 0;
- }
- if (0 == strcmp("n32_canvas", FLAGS_type[0])) {
- fuzz_raster_n32_canvas(bytes);
- return 0;
- }
- // not a "real" thing to fuzz, used to debug errors found while fuzzing.
- if (0 == strcmp("_dump_canvas", FLAGS_type[0])) {
- fuzz_dump_canvas(bytes);
- return 0;
- }
- if (0 == strcmp("null_canvas", FLAGS_type[0])) {
- fuzz_null_canvas(bytes);
- return 0;
- }
#if SK_SUPPORT_GPU
if (0 == strcmp("sksl2glsl", FLAGS_type[0])) {
fuzz_sksl2glsl(bytes);
@@ -179,7 +153,7 @@
auto fuzzable = r->factory();
if (0 == strcmp(name, fuzzable.name)) {
SkDebugf("Fuzzing %s...\n", fuzzable.name);
- Fuzz fuzz(bytes);
+ Fuzz fuzz(std::move(bytes));
fuzzable.fn(&fuzz);
SkDebugf("[terminated] Success!\n");
return;
@@ -469,39 +443,6 @@
dump_png(bitmap);
}
-static void fuzz_null_canvas(sk_sp<SkData> bytes) {
- Fuzz fuzz(std::move(bytes));
- FuzzCanvas(&fuzz, SkMakeNullCanvas().get());
-}
-
-static void fuzz_raster_n32_canvas(sk_sp<SkData> bytes) {
- Fuzz fuzz(std::move(bytes));
- auto surface = SkSurface::MakeRasterN32Premul(612, 792);
- SkASSERT(surface && surface->getCanvas());
- FuzzCanvas(&fuzz, surface->getCanvas());
-}
-
-static void fuzz_pdf_canvas(sk_sp<SkData> bytes) {
- Fuzz fuzz(std::move(bytes));
- struct final : public SkWStream {
- bool write(const void*, size_t n) override { fN += n; return true; }
- size_t bytesWritten() const override { return fN; }
- size_t fN = 0;
- } stream;
- auto doc = SkDocument::MakePDF(&stream);
- FuzzCanvas(&fuzz, doc->beginPage(612.0f, 792.0f));
-}
-
-static void fuzz_dump_canvas(sk_sp<SkData> bytes) {
- Fuzz fuzz(std::move(bytes));
- SkDebugCanvas debugCanvas(612, 792);
- FuzzCanvas(&fuzz, &debugCanvas);
- std::unique_ptr<SkCanvas> nullCanvas = SkMakeNullCanvas();
- UrlDataManager dataManager(SkString("data"));
- Json::Value json = debugCanvas.toJSON(dataManager, debugCanvas.getSize(), nullCanvas.get());
- Json::StyledStreamWriter(" ").write(std::cout, json);
-}
-
static void fuzz_skp(sk_sp<SkData> bytes) {
SkMemoryStream stream(bytes);
SkDebugf("Decoding\n");