Bug 580786. Add support for fuzzy reftest matching. r=dbaron

This will let us convert a bunch of random-if() to fuzzy-if()
This commit is contained in:
Jeff Muizelaar 2011-12-19 09:02:53 -05:00
Родитель 5241915576
Коммит d6461a440d
7 изменённых файлов: 58 добавлений и 8 удалений

Просмотреть файл

@ -0,0 +1,6 @@
<!DOCTYPE html>
<html>
<body>
<div style="background: #ff00ff; width: 500px; height: 500px;"></div>
</body>
</html>

Просмотреть файл

@ -0,0 +1,6 @@
<!DOCTYPE html>
<html>
<body>
<div style="background: #ff01ff; width: 500px; height: 500px;"></div>
</body>
</html>

Просмотреть файл

@ -129,3 +129,10 @@ pref(font.default.x-western,"sans-serif") == font-sans-serif.html font-default.h
pref(font.default.x-western,"sans-serif") != font-serif.html font-default.html
fails pref(font.default.x-western,true) == font-serif.html font-default.html
fails pref(font.default.x-western,0) == font-serif.html font-default.html
# reftest syntax: fuzzy
fuzzy == fuzzy.html fuzzy-ref.html
fuzzy != too-fuzzy.html fuzzy-ref.html
fuzzy-if(true) == fuzzy.html fuzzy-ref.html
fuzzy-if(false) == fuzzy-ref.html fuzzy-ref.html
# When using 565 fuzzy.html and fuzzy-ref.html will compare as equal
fails fuzzy-if(false) random-if(Android) == fuzzy.html fuzzy-ref.html

Просмотреть файл

@ -0,0 +1,6 @@
<!DOCTYPE html>
<html>
<body>
<div style="background: #ff04ff; width: 500px; height: 500px;"></div>
</body>
</html>

Просмотреть файл

@ -106,6 +106,14 @@ must be one of the following:
fast on a 32-bit system but inordinately slow on a
64-bit system).
fuzzy This allows a test to pass if the pixel value differences
are <= 2. It can also be used with '!=' to ensure that the
difference is greater than 2.
fuzzy-if(condition) If the condition is met, the test is treated as if
'fuzzy' had been specified. This is useful if there
are differences on particular platforms.
require-or(cond1&&cond2&&...,fallback)
Require some particular setup be performed or environmental
condition(s) made true (eg setting debug mode) before the test

Просмотреть файл

@ -39,7 +39,7 @@
import sys, os.path, re
commentRE = re.compile(r"\s+#")
conditionsRE = re.compile(r"^(fails|needs-focus|random|skip|asserts)")
conditionsRE = re.compile(r"^(fails|needs-focus|random|skip|asserts|fuzzy)")
httpRE = re.compile(r"HTTP\((\.\.(\/\.\.)*)\)")
protocolRE = re.compile(r"^\w+:")

Просмотреть файл

@ -149,6 +149,7 @@ const EXPECTED_PASS = 0;
const EXPECTED_FAIL = 1;
const EXPECTED_RANDOM = 2;
const EXPECTED_DEATH = 3; // test must be skipped to avoid e.g. crash/hang
const EXPECTED_FUZZY = 4;
// types of preference value we might want to set for a specific test
const PREF_BOOLEAN = 0;
@ -686,16 +687,16 @@ function ReadManifest(aURL, inherited_status)
var slow = false;
var prefSettings = [];
while (items[0].match(/^(fails|needs-focus|random|skip|asserts|slow|require-or|silentfail|pref)/)) {
while (items[0].match(/^(fails|needs-focus|random|skip|asserts|slow|require-or|silentfail|pref|fuzzy)/)) {
var item = items.shift();
var stat;
var cond;
var m = item.match(/^(fails|random|skip|silentfail)-if(\(.*\))$/);
var m = item.match(/^(fails|random|skip|silentfail|fuzzy)-if(\(.*\))$/);
if (m) {
stat = m[1];
// Note: m[2] contains the parentheses, and we want them.
cond = Components.utils.evalInSandbox(m[2], sandbox);
} else if (item.match(/^(fails|random|skip)$/)) {
} else if (item.match(/^(fails|random|skip|fuzzy)$/)) {
stat = item;
cond = true;
} else if (item == "needs-focus") {
@ -777,6 +778,8 @@ function ReadManifest(aURL, inherited_status)
expected_status = EXPECTED_RANDOM;
} else if (stat == "skip") {
expected_status = EXPECTED_DEATH;
} else if (stat == "fuzzy") {
expected_status = EXPECTED_FUZZY;
} else if (stat == "silentfail") {
allow_silent_fail = true;
}
@ -1296,6 +1299,8 @@ function RecordResult(testRunTime, errorMsg, scriptResults)
true: {s: "TEST-PASS" + randomMsg , n: "Random"},
false: {s: "TEST-KNOWN-FAIL" + randomMsg, n: "Random"}
};
outputs[EXPECTED_FUZZY] = outputs[EXPECTED_PASS];
var output;
if (gURLs[0].type == TYPE_LOAD) {
@ -1398,14 +1403,25 @@ function RecordResult(testRunTime, errorMsg, scriptResults)
var differences;
// whether the two renderings match:
var equal;
var maxDifference = {};
differences = gWindowUtils.compareCanvases(gCanvas1, gCanvas2, {});
differences = gWindowUtils.compareCanvases(gCanvas1, gCanvas2, maxDifference);
equal = (differences == 0);
// what is expected on this platform (PASS, FAIL, or RANDOM)
var expected = gURLs[0].expected;
if (maxDifference.value > 0 && maxDifference.value <= 2) {
if (equal) {
throw "Inconsistent result from compareCanvases.";
}
equal = expected == EXPECTED_FUZZY;
gDumpLog("REFTEST fuzzy match\n");
}
// whether the comparison result matches what is in the manifest
var test_passed = (equal == (gURLs[0].type == TYPE_REFTEST_EQUAL));
// what is expected on this platform (PASS, FAIL, or RANDOM)
var expected = gURLs[0].expected;
output = outputs[expected][test_passed];
++gTestResults[output.n];
@ -1423,11 +1439,12 @@ function RecordResult(testRunTime, errorMsg, scriptResults)
gDumpLog(result + "\n");
if (!test_passed && expected == EXPECTED_PASS ||
!test_passed && expected == EXPECTED_FUZZY ||
test_passed && expected == EXPECTED_FAIL) {
if (!equal) {
gDumpLog("REFTEST IMAGE 1 (TEST): " + gCanvas1.toDataURL() + "\n");
gDumpLog("REFTEST IMAGE 2 (REFERENCE): " + gCanvas2.toDataURL() + "\n");
gDumpLog("REFTEST number of differing pixels: " + differences + "\n");
gDumpLog("REFTEST number of differing pixels: " + differences + " max difference: " + maxDifference.value + "\n");
} else {
gDumpLog("REFTEST IMAGE: " + gCanvas1.toDataURL() + "\n");
}