skia2/fuzz/FuzzPaeth.cpp
mtklein a115942ed6 fuzz: signalBug() / signalBoring()
Instead of a single ASSERT macro, this switches to two new methods:
   - signalBug():    tell afl-fuzz there's a bug caused by its inputs (by crashing)
   - signalBoring(): tell afl-fuzz these inputs are not worth testing (by exiting gracefully)

I'm not seeing any effect on fuzz/s when I just always log verbosely.

signalBug() now triggers SIGSEGV rather than SIGABRT.  This should make it work with catchsegv more easily.

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1585353002

Review URL: https://codereview.chromium.org/1585353002
2016-01-15 05:46:54 -08:00

50 lines
1.1 KiB
C++

/*
* 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 <stdlib.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) {
auto a = fuzz->nextB(),
b = fuzz->nextB(),
c = fuzz->nextB();
SkDebugf("Paeth(%d,%d,%d)\n", a,b,c);
if (a == b && b == c) {
fuzz->signalBoring(); // Not really boring, just demoing signalBoring().
}
if (paeth_alt(a,b,c) != paeth_std(a,b,c)) {
fuzz->signalBug();
}
}