aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/PathOpsExtendedTest.cpp
diff options
context:
space:
mode:
authorGravatar caryclark <caryclark@google.com>2016-07-18 10:01:36 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-07-18 10:01:36 -0700
commit55888e44171ffd48b591d19256884a969fe4da17 (patch)
treee3aed151b6074bba5357263199a5915ec31a0b99 /tests/PathOpsExtendedTest.cpp
parent6451a0cea6007aff54565ec82e2f86cb1d32ecc7 (diff)
pathops coincidence and security rewrite
Most changes stem from working on an examples bracketed by #if DEBUG_UNDER_DEVELOPMENT // tiger These exposed many problems with coincident curves, as well as errors throughout the code. Fixing these errors also fixed a number of fuzzer-inspired bug reports. * Line/Curve Intersections Check to see if the end of the line nearly intersects the curve. This was a FIXME in the old code. * Performance Use a central chunk allocator. Plumb the allocator into the global variable state so that it can be shared. (Note that 'SkGlobalState' is allocated on the stack and is visible to children functions but not other threads.) * Refactor Let SkOpAngle grow up from a structure to a class. Let SkCoincidentSpans grow up from a structure to a class. Rename enum Alias to AliasMatch. * Coincidence Rewrite Add more debugging to coincidence detection. Parallel debugging routines have read-only logic to report the current coincidence state so that steps through the logic can expose whether things got better or worse. More functions can error-out and cause the pathops engine to non-destructively exit. * Accuracy Remove code that adjusted point locations. Instead, offset the curve part so that sorted curves all use the same origin. Reduce the size (and influence) of magic numbers. * Testing The debug suite with verify and the full release suite ./out/Debug/pathops_unittest -v -V ./out/Release/pathops_unittest -v -V -x expose one error. That error is captured as cubics_d3. This error exists in the checked in code as well. BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2128633003 BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2128633003 Review-Url: https://codereview.chromium.org/2128633003
Diffstat (limited to 'tests/PathOpsExtendedTest.cpp')
-rw-r--r--tests/PathOpsExtendedTest.cpp97
1 files changed, 72 insertions, 25 deletions
diff --git a/tests/PathOpsExtendedTest.cpp b/tests/PathOpsExtendedTest.cpp
index b71b115439..2f6d99d652 100644
--- a/tests/PathOpsExtendedTest.cpp
+++ b/tests/PathOpsExtendedTest.cpp
@@ -22,6 +22,15 @@
#include <sys/sysctl.h>
#endif
+bool OpDebug(const SkPath& one, const SkPath& two, SkPathOp op, SkPath* result
+ SkDEBUGPARAMS(bool skipAssert)
+ SkDEBUGPARAMS(const char* testName));
+
+bool SimplifyDebug(const SkPath& one, SkPath* result
+ SkDEBUGPARAMS(bool skipAssert)
+ SkDEBUGPARAMS(const char* testName));
+
+
__SK_FORCE_IMAGE_DECODER_LINKING;
DEFINE_bool2(runFail, f, false, "run tests known to fail.");
@@ -38,7 +47,7 @@ static const char* opStrs[] = {
"kDifference_SkPathOp",
"kIntersect_SkPathOp",
"kUnion_SkPathOp",
- "kXor_PathOp",
+ "kXOR_PathOp",
"kReverseDifference_SkPathOp",
};
@@ -47,6 +56,7 @@ static const char* opSuffixes[] = {
"i",
"u",
"o",
+ "r",
};
#if DEBUG_SHOW_TEST_NAME
@@ -443,20 +453,43 @@ bool testSimplify(SkPath& path, bool useXor, SkPath& out, PathOpsThreadState& st
return result == 0;
}
+enum class ExpectSuccess {
+ kNo,
+ kYes
+};
+
+enum class SkipAssert {
+ kNo,
+ kYes
+};
+
+enum class ExpectMatch {
+ kNo,
+ kYes
+};
+
static bool inner_simplify(skiatest::Reporter* reporter, const SkPath& path, const char* filename,
- bool checkFail) {
+ ExpectSuccess expectSuccess, SkipAssert skipAssert, ExpectMatch expectMatch) {
#if 0 && DEBUG_SHOW_TEST_NAME
showPathData(path);
#endif
SkPath out;
- if (!Simplify(path, &out)) {
- SkDebugf("%s did not expect %s failure\n", __FUNCTION__, filename);
- REPORTER_ASSERT(reporter, 0);
+ if (!SimplifyDebug(path, &out SkDEBUGPARAMS(SkipAssert::kYes == skipAssert)
+ SkDEBUGPARAMS(testName))) {
+ if (ExpectSuccess::kYes == expectSuccess) {
+ SkDebugf("%s did not expect %s failure\n", __FUNCTION__, filename);
+ REPORTER_ASSERT(reporter, 0);
+ }
return false;
+ } else {
+ if (ExpectSuccess::kNo == expectSuccess) {
+ SkDebugf("%s %s unexpected success\n", __FUNCTION__, filename);
+ REPORTER_ASSERT(reporter, 0);
+ }
}
SkBitmap bitmap;
int errors = comparePaths(reporter, filename, path, out, bitmap);
- if (!checkFail) {
+ if (ExpectMatch::kNo == expectMatch) {
if (!errors) {
SkDebugf("%s failing test %s now succeeds\n", __FUNCTION__, filename);
REPORTER_ASSERT(reporter, 0);
@@ -470,12 +503,19 @@ static bool inner_simplify(skiatest::Reporter* reporter, const SkPath& path, con
}
bool testSimplify(skiatest::Reporter* reporter, const SkPath& path, const char* filename) {
- return inner_simplify(reporter, path, filename, true);
+ return inner_simplify(reporter, path, filename, ExpectSuccess::kYes, SkipAssert::kNo,
+ ExpectMatch::kYes);
+}
+
+bool testSimplifyFailSkipAssert(skiatest::Reporter* reporter, const SkPath& path, const char* filename) {
+ return inner_simplify(reporter, path, filename, ExpectSuccess::kNo, SkipAssert::kYes,
+ ExpectMatch::kNo);
}
bool testSimplifyCheck(skiatest::Reporter* reporter, const SkPath& path, const char* filename,
bool checkFail) {
- return inner_simplify(reporter, path, filename, checkFail);
+ return inner_simplify(reporter, path, filename, checkFail ?
+ ExpectSuccess::kYes : ExpectSuccess::kNo, SkipAssert::kNo, ExpectMatch::kNo);
}
#if DEBUG_SHOW_TEST_NAME
@@ -487,23 +527,25 @@ static void showName(const SkPath& a, const SkPath& b, const SkPathOp shapeOp) {
}
#endif
-bool OpDebug(const SkPath& one, const SkPath& two, SkPathOp op, SkPath* result
- SkDEBUGPARAMS(bool skipAssert)
- SkDEBUGPARAMS(const char* testName));
-
static bool innerPathOp(skiatest::Reporter* reporter, const SkPath& a, const SkPath& b,
- const SkPathOp shapeOp, const char* testName, bool expectSuccess, bool skipAssert) {
+ const SkPathOp shapeOp, const char* testName, ExpectSuccess expectSuccess,
+ SkipAssert skipAssert, ExpectMatch expectMatch) {
#if 0 && DEBUG_SHOW_TEST_NAME
showName(a, b, shapeOp);
#endif
SkPath out;
- if (!OpDebug(a, b, shapeOp, &out SkDEBUGPARAMS(skipAssert)
+ if (!OpDebug(a, b, shapeOp, &out SkDEBUGPARAMS(SkipAssert::kYes == skipAssert)
SkDEBUGPARAMS(testName))) {
- if (expectSuccess) {
- SkDebugf("%s did not expect failure\n", __FUNCTION__);
+ if (ExpectSuccess::kYes == expectSuccess) {
+ SkDebugf("%s %s did not expect failure\n", __FUNCTION__, testName);
REPORTER_ASSERT(reporter, 0);
}
return false;
+ } else {
+ if (ExpectSuccess::kNo == expectSuccess) {
+ SkDebugf("%s %s unexpected success\n", __FUNCTION__, testName);
+ REPORTER_ASSERT(reporter, 0);
+ }
}
if (!reporter->verbose()) {
return true;
@@ -533,37 +575,42 @@ static bool innerPathOp(skiatest::Reporter* reporter, const SkPath& a, const SkP
scaledOut.addPath(out, scale);
scaledOut.setFillType(out.getFillType());
int result = comparePaths(reporter, testName, pathOut, scaledPathOut, out, scaledOut, bitmap,
- a, b, shapeOp, scale, expectSuccess);
+ a, b, shapeOp, scale, ExpectMatch::kYes == expectMatch);
reporter->bumpTestCount();
return result == 0;
}
bool testPathOp(skiatest::Reporter* reporter, const SkPath& a, const SkPath& b,
const SkPathOp shapeOp, const char* testName) {
- return innerPathOp(reporter, a, b, shapeOp, testName, true, false);
+ return innerPathOp(reporter, a, b, shapeOp, testName, ExpectSuccess::kYes, SkipAssert::kNo,
+ ExpectMatch::kYes);
}
bool testPathOpCheck(skiatest::Reporter* reporter, const SkPath& a, const SkPath& b,
const SkPathOp shapeOp, const char* testName, bool checkFail) {
- return innerPathOp(reporter, a, b, shapeOp, testName, checkFail, false);
+ return innerPathOp(reporter, a, b, shapeOp, testName, checkFail ?
+ ExpectSuccess::kYes : ExpectSuccess::kNo, SkipAssert::kNo, ExpectMatch::kNo);
}
bool testPathOpFailCheck(skiatest::Reporter* reporter, const SkPath& a, const SkPath& b,
const SkPathOp shapeOp, const char* testName) {
- return innerPathOp(reporter, a, b, shapeOp, testName, false, false);
+ return innerPathOp(reporter, a, b, shapeOp, testName, ExpectSuccess::kNo, SkipAssert::kNo,
+ ExpectMatch::kNo);
}
-bool testPathSkipAssertOp(skiatest::Reporter* reporter, const SkPath& a, const SkPath& b,
+bool testPathOpSkipAssert(skiatest::Reporter* reporter, const SkPath& a, const SkPath& b,
const SkPathOp shapeOp, const char* testName) {
- return innerPathOp(reporter, a, b, shapeOp, testName, true, true);
+ return innerPathOp(reporter, a, b, shapeOp, testName, ExpectSuccess::kYes, SkipAssert::kYes,
+ ExpectMatch::kYes);
}
-bool testPathFailSkipAssertOp(skiatest::Reporter* reporter, const SkPath& a, const SkPath& b,
+bool testPathOpFailSkipAssert(skiatest::Reporter* reporter, const SkPath& a, const SkPath& b,
const SkPathOp shapeOp, const char* testName) {
- return innerPathOp(reporter, a, b, shapeOp, testName, false, true);
+ return innerPathOp(reporter, a, b, shapeOp, testName, ExpectSuccess::kNo, SkipAssert::kYes,
+ ExpectMatch::kNo);
}
-bool testPathFailOp(skiatest::Reporter* reporter, const SkPath& a, const SkPath& b,
+bool testPathOpFail(skiatest::Reporter* reporter, const SkPath& a, const SkPath& b,
const SkPathOp shapeOp, const char* testName) {
#if DEBUG_SHOW_TEST_NAME
showName(a, b, shapeOp);