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

Unified Diff: tools/chrome_fuzz.cpp

Issue 1126423005: quickie tool to exercise chrome filter fuzz files (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: forgot to add the source file Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gyp/tools.gyp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/chrome_fuzz.cpp
diff --git a/tools/chrome_fuzz.cpp b/tools/chrome_fuzz.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..94d276fb9bfa57ee536e4b6000965a65601f4107
--- /dev/null
+++ b/tools/chrome_fuzz.cpp
@@ -0,0 +1,82 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
robertphillips 2015/05/12 15:34:17 Does this header need to change?
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "SkCanvas.h"
+#include "SkFlattenableSerialization.h"
+#include "SkImageFilter.h"
+#include "SkOSFile.h"
+#include "SkString.h"
+
+static const int kBitmapSize = 24;
+
+static bool read_test_case(const char* filename, SkString* testdata) {
+ SkFILE* file = sk_fopen(filename, kRead_SkFILE_Flag);
+ if (!file) {
+ SkDebugf("couldn't open file %s\n", filename);
+ return false;
+ }
+ size_t len = sk_fgetsize(file);
+ if (!len) {
+ SkDebugf("couldn't read file %s\n", filename);
+ return false;
+ }
+ testdata->resize(len);
+ (void) sk_fread(testdata->writable_str(), len, file);
+ return true;
+}
+
+static void run_test_case(const SkString& testdata, const SkBitmap& bitmap,
+ SkCanvas* canvas) {
+ // This call shouldn't crash or cause ASAN to flag any memory issues
+ // If nothing bad happens within this call, everything is fine
+ SkFlattenable* flattenable = SkValidatingDeserializeFlattenable(
+ testdata.c_str(), testdata.size(), SkImageFilter::GetFlattenableType());
+
+ // Adding some info, but the test passed if we got here without any trouble
+ if (flattenable != NULL) {
+ SkDebugf("Valid stream detected.\n");
+ // Let's see if using the filters can cause any trouble...
+ SkPaint paint;
+ paint.setImageFilter(static_cast<SkImageFilter*>(flattenable))->unref();
+ canvas->save();
+ canvas->clipRect(SkRect::MakeXYWH(
+ 0, 0, SkIntToScalar(kBitmapSize), SkIntToScalar(kBitmapSize)));
+
+ // This call shouldn't crash or cause ASAN to flag any memory issues
+ // If nothing bad happens within this call, everything is fine
+ canvas->drawBitmap(bitmap, 0, 0, &paint);
+
+ SkDebugf("Filter DAG rendered successfully.\n");
+ canvas->restore();
+ } else {
+ SkDebugf("Invalid stream detected.\n");
+ }
+}
+
+static bool read_and_run_test_case(const char* filename, const SkBitmap& bitmap,
+ SkCanvas* canvas) {
+ SkString testdata;
+ SkDebugf("Test case: %s\n", filename);
+ // read_test_case will print a useful error message if it fails.
+ if (!read_test_case(filename, &testdata))
+ return false;
+ run_test_case(testdata, bitmap, canvas);
+ return true;
+}
+
+int main(int argc, char** argv) {
+ int ret = 0;
+ SkBitmap bitmap;
+ bitmap.allocN32Pixels(kBitmapSize, kBitmapSize);
+ SkCanvas canvas(bitmap);
+ canvas.clear(0x00000000);
+ for (int i = 1; i < argc; i++)
+ if (!read_and_run_test_case(argv[i], bitmap, &canvas))
+ ret = 2;
+ // Cluster-Fuzz likes "#EOF" as the last line of output to help distinguish
+ // successful runs from crashes.
+ SkDebugf("#EOF\n");
+ return ret;
+}
+
« no previous file with comments | « gyp/tools.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698