aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--fuzz/Fuzz.h43
-rw-r--r--fuzz/FuzzPaeth.cpp40
-rw-r--r--fuzz/fuzz.cpp40
-rw-r--r--gyp/fuzz.gyp17
-rw-r--r--gyp/most.gyp15
5 files changed, 148 insertions, 7 deletions
diff --git a/fuzz/Fuzz.h b/fuzz/Fuzz.h
new file mode 100644
index 0000000000..cf5bcb9ead
--- /dev/null
+++ b/fuzz/Fuzz.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef Fuzz_DEFINED
+#define Fuzz_DEFINED
+
+#include "SkData.h"
+#include "SkTRegistry.h"
+#include "SkTypes.h"
+#include <stdlib.h>
+
+class Fuzz : SkNoncopyable {
+public:
+ explicit Fuzz(SkData*);
+
+ uint32_t nextU();
+ float nextF();
+
+ // These return a value in [min, max).
+ uint32_t nextURange(uint32_t min, uint32_t max);
+ float nextFRange(float min, float max);
+
+private:
+ SkAutoTUnref<SkData> fBytes;
+};
+
+struct Fuzzable {
+ const char* name;
+ void (*fn)(Fuzz*);
+};
+
+#define DEF_FUZZ(name, f) \
+ static void fuzz_##name(Fuzz*); \
+ SkTRegistry<Fuzzable> register_##name({#name, fuzz_##name}); \
+ static void fuzz_##name(Fuzz* f)
+
+#define ASSERT(cond) do { if (!(cond)) abort(); } while(false)
+
+#endif//Fuzz_DEFINED
diff --git a/fuzz/FuzzPaeth.cpp b/fuzz/FuzzPaeth.cpp
new file mode 100644
index 0000000000..aa7deb09e2
--- /dev/null
+++ b/fuzz/FuzzPaeth.cpp
@@ -0,0 +1,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"
+
+// This really is just an example Fuzz*.cpp file.
+// It tests that two different ways of calculating the Paeth predictor function are equivalent.
+
+static uint8_t paeth_std(uint8_t a, uint8_t b, uint8_t c) {
+ int p = a+b-c;
+
+ int pa = abs(p-a),
+ pb = abs(p-b),
+ pc = abs(p-c);
+
+ if (pb < pa) { pa = pb; a = b; }
+ if (pc < pa) { a = c; }
+ return a;
+}
+
+static uint8_t paeth_alt(uint8_t a, uint8_t b, uint8_t c) {
+ int min = SkTMin(a,b),
+ max = SkTMax(a,b);
+ int delta = (max-min)/3;
+
+ if (c <= min+delta) return max;
+ if (c >= max-delta) return min;
+ return c;
+}
+
+DEF_FUZZ(Paeth, fuzz) {
+ int a = fuzz->nextU(),
+ b = fuzz->nextU(),
+ c = fuzz->nextU();
+ ASSERT(paeth_alt(a,b,c) == paeth_std(a,b,c));
+}
diff --git a/fuzz/fuzz.cpp b/fuzz/fuzz.cpp
new file mode 100644
index 0000000000..6e31790951
--- /dev/null
+++ b/fuzz/fuzz.cpp
@@ -0,0 +1,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; }
+
diff --git a/gyp/fuzz.gyp b/gyp/fuzz.gyp
new file mode 100644
index 0000000000..40845a1653
--- /dev/null
+++ b/gyp/fuzz.gyp
@@ -0,0 +1,17 @@
+# Copyright 2016 Google Inc.
+#
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+{
+ 'includes': [ 'apptype_console.gypi' ],
+ 'targets': [{
+ 'target_name': 'fuzz',
+ 'type': 'executable',
+ 'sources': [ '<!@(python find.py ../fuzz "*.cpp")' ],
+ 'dependencies': [
+ 'flags.gyp:flags',
+ 'skia_lib.gyp:skia_lib',
+ ],
+ }],
+}
diff --git a/gyp/most.gyp b/gyp/most.gyp
index f289aeaa0f..4723cdbc14 100644
--- a/gyp/most.gyp
+++ b/gyp/most.gyp
@@ -27,12 +27,13 @@
'pathops_skpclip.gyp:*',
'dm.gyp:dm',
'visualbench.gyp:visualbench',
+ 'fuzz.gyp:fuzz',
],
'conditions': [
- [ 'skia_gpu == 0', {
- 'dependencies!': [
- 'visualbench.gyp:visualbench'
- ]
+ [ 'skia_gpu == 0', {
+ 'dependencies!': [
+ 'visualbench.gyp:visualbench'
+ ]
}],
[ 'skia_gpu == 0 or skia_os == "android"', {
'dependencies!': [
@@ -40,13 +41,13 @@
],
}],
['skia_os == "android"', {
- 'dependencies': [
- 'android_system.gyp:SampleApp_APK',
+ 'dependencies': [
+ 'android_system.gyp:SampleApp_APK',
],
'conditions': [
[ 'skia_gpu == 1', {
'dependencies': [
- 'android_system.gyp:VisualBench_APK',
+ 'android_system.gyp:VisualBench_APK',
],
}],
],