summaryrefslogtreecommitdiff
path: root/testing/tools
diff options
context:
space:
mode:
authorHenrique Nakashima <hnakashima@chromium.org>2018-04-26 15:55:07 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-04-26 15:55:07 +0000
commit15bc974936fd14598214a37aafd62f29c3b42a61 (patch)
tree9efda15e29032901863bb00529a2edd9b309676e /testing/tools
parent789a227a635b13b782a38f0a38bcb35b099f12d8 (diff)
downloadpdfium-15bc974936fd14598214a37aafd62f29c3b42a61.tar.xz
Improve diffing and regeneration of expected pngs.
- If a .pdf had more than one page and any of them except the first had no expectation, that page and the ones after it were not diff'ed. - If a .pdf did not have expectations for any or all pages, --regen did not generate those expectations. Change-Id: Ie6dacf07e44feb4a14a6a92eb20c9aa19858a8f9 Reviewed-on: https://pdfium-review.googlesource.com/25770 Commit-Queue: Henrique Nakashima <hnakashima@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'testing/tools')
-rwxr-xr-xtesting/tools/pngdiffer.py39
-rw-r--r--testing/tools/test_runner.py18
2 files changed, 31 insertions, 26 deletions
diff --git a/testing/tools/pngdiffer.py b/testing/tools/pngdiffer.py
index a9bc9d6529..f40cc2596f 100755
--- a/testing/tools/pngdiffer.py
+++ b/testing/tools/pngdiffer.py
@@ -3,6 +3,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+import itertools
import os
import shutil
import sys
@@ -18,35 +19,37 @@ class PNGDiffer():
actual_paths = []
path_templates = PathTemplates(input_filename, source_dir, working_dir)
- i = 0
- while True:
- actual_path = path_templates.GetActualPath(i)
- expected_path = path_templates.GetExpectedPath(i)
+ for page in itertools.count():
+ actual_path = path_templates.GetActualPath(page)
+ expected_path = path_templates.GetExpectedPath(page)
platform_expected_path = path_templates.GetPlatformExpectedPath(
- self.os_name, i)
+ self.os_name, page)
if os.path.exists(platform_expected_path):
expected_path = platform_expected_path
elif not os.path.exists(expected_path):
break
actual_paths.append(actual_path)
- i += 1
+
return actual_paths
def HasDifferences(self, input_filename, source_dir, working_dir):
path_templates = PathTemplates(input_filename, source_dir, working_dir)
- i = 0
- while True:
- actual_path = path_templates.GetActualPath(i)
- expected_path = path_templates.GetExpectedPath(i)
+ for page in itertools.count():
+ actual_path = path_templates.GetActualPath(page)
+ expected_path = path_templates.GetExpectedPath(page)
# PDFium tests should be platform independent. Platform based results are
# used to capture platform dependent implementations.
platform_expected_path = path_templates.GetPlatformExpectedPath(
- self.os_name, i)
+ self.os_name, page)
if (not os.path.exists(expected_path) and
not os.path.exists(platform_expected_path)):
- if i == 0:
+ if page == 0:
print "WARNING: no expected results files for " + input_filename
+ if os.path.exists(actual_path):
+ print ('FAILURE: Missing expected result for 0-based page %d of %s'
+ % (page, input_filename))
+ return True
break
print "Checking " + actual_path
sys.stdout.flush()
@@ -63,14 +66,13 @@ class PNGDiffer():
if error:
print "FAILURE: " + input_filename + "; " + str(error)
return True
- i += 1
+
return False
def Regenerate(self, input_filename, source_dir, working_dir, platform_only):
path_templates = PathTemplates(input_filename, source_dir, working_dir)
- page = 0
- while True:
+ for page in itertools.count():
# Loop through the generated page images. Stop when there is a page
# missing a png, which means the document ended.
actual_path = path_templates.GetActualPath(page)
@@ -88,12 +90,9 @@ class PNGDiffer():
elif not platform_only:
expected_path = path_templates.GetExpectedPath(page)
else:
- expected_path = None
-
- if expected_path is not None and os.path.exists(expected_path):
- shutil.copyfile(actual_path, expected_path)
+ continue
- page += 1
+ shutil.copyfile(actual_path, expected_path)
ACTUAL_TEMPLATE = '.pdf.%d.png'
diff --git a/testing/tools/test_runner.py b/testing/tools/test_runner.py
index 90202f8e55..5acda86f54 100644
--- a/testing/tools/test_runner.py
+++ b/testing/tools/test_runner.py
@@ -80,21 +80,27 @@ class TestRunner:
if actual_images:
if self.image_differ.HasDifferences(input_filename, source_dir,
self.working_dir):
- if (self.options.regenerate_expected
- and not self.test_suppressor.IsResultSuppressed(input_filename)
- and not self.test_suppressor.IsImageDiffSuppressed(input_filename)):
- platform_only = (self.options.regenerate_expected == 'platform')
- self.image_differ.Regenerate(input_filename, source_dir,
- self.working_dir, platform_only)
+ self.RegenerateIfNeeded_(input_filename, source_dir)
return False, results
else:
if (self.enforce_expected_images
and not self.test_suppressor.IsImageDiffSuppressed(input_filename)):
+ self.RegenerateIfNeeded_(input_filename, source_dir)
print 'FAILURE: %s; Missing expected images' % input_filename
return False, results
return True, results
+ def RegenerateIfNeeded_(self, input_filename, source_dir):
+ if (not self.options.regenerate_expected
+ or self.test_suppressor.IsResultSuppressed(input_filename)
+ or self.test_suppressor.IsImageDiffSuppressed(input_filename)):
+ return
+
+ platform_only = (self.options.regenerate_expected == 'platform')
+ self.image_differ.Regenerate(input_filename, source_dir,
+ self.working_dir, platform_only)
+
def Generate(self, source_dir, input_filename, input_root, pdf_path):
original_path = os.path.join(source_dir, input_filename)
input_path = os.path.join(source_dir, input_root + '.in')