aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/tests
diff options
context:
space:
mode:
authorGravatar scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-05-14 17:50:02 +0000
committerGravatar scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-05-14 17:50:02 +0000
commit4fed643cb9caf0cda27c9610f61f5915ab3a86a2 (patch)
tree65507d0962ad2b3e58566be8471a175b40ea0741 /tools/tests
parent6ca30ca849cb5a5fde1f88c0c2397c7e865c3aec (diff)
Create a self test for skimage.
Runs skimage twice: once to create an expectations file, and a second time comparing against the file. Uses the files in resources as test files. R=epoger@google.com Review URL: https://codereview.chromium.org/14969007 git-svn-id: http://skia.googlecode.com/svn/trunk@9123 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tools/tests')
-rw-r--r--tools/tests/skimage/.gitignore1
-rw-r--r--tools/tests/skimage/README1
-rwxr-xr-xtools/tests/skimage_self_test.py65
3 files changed, 67 insertions, 0 deletions
diff --git a/tools/tests/skimage/.gitignore b/tools/tests/skimage/.gitignore
new file mode 100644
index 0000000000..91a9c59281
--- /dev/null
+++ b/tools/tests/skimage/.gitignore
@@ -0,0 +1 @@
+results.json
diff --git a/tools/tests/skimage/README b/tools/tests/skimage/README
new file mode 100644
index 0000000000..0680184c19
--- /dev/null
+++ b/tools/tests/skimage/README
@@ -0,0 +1 @@
+This directory is for the output of skimage_self_test.
diff --git a/tools/tests/skimage_self_test.py b/tools/tests/skimage_self_test.py
new file mode 100755
index 0000000000..94a514458e
--- /dev/null
+++ b/tools/tests/skimage_self_test.py
@@ -0,0 +1,65 @@
+#!/usr/bin/env python
+# Copyright (c) 2013 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+# Self-test for skimage.
+
+import os
+import subprocess
+import sys
+
+class BinaryNotFoundException(Exception):
+ def __str__ (self):
+ return ("Could not find binary!\n"
+ "Did you forget to build the tools project?\n"
+ "Self tests failed")
+
+# Find a path to the binary to use. Iterates through a list of possible
+# locations the binary may be.
+def PickBinaryPath(base_dir):
+ POSSIBLE_BINARY_PATHS = [
+ 'out/Debug/skimage',
+ 'out/Release/skimage',
+ 'xcodebuild/Debug/skimage',
+ 'xcodebuild/Release/skimage',
+ ]
+ for binary in POSSIBLE_BINARY_PATHS:
+ binary_full_path = os.path.join(base_dir, binary)
+ if (os.path.exists(binary_full_path)):
+ return binary_full_path
+ raise BinaryNotFoundException
+
+def main():
+ # Use the directory of this file as the out directory
+ file_dir = os.path.abspath(os.path.dirname(__file__))
+
+ trunk_dir = os.path.normpath(os.path.join(file_dir, os.pardir, os.pardir))
+
+ # Find the binary
+ skimage_binary = PickBinaryPath(trunk_dir)
+ print "Running " + skimage_binary
+
+ # Run skimage twice, first to create an expectations file, and then
+ # comparing to it.
+
+ # Both commands will run the binary, reading from resources.
+ cmd_line = [skimage_binary]
+ resources_dir = os.path.join(trunk_dir, 'resources')
+ cmd_line.extend(["-r", resources_dir])
+
+ # Create the expectations file
+ results_dir = os.path.join(file_dir, "skimage")
+ create_expectations_cmd = cmd_line + ["--createExpectationsPath",
+ results_dir]
+ subprocess.check_call(create_expectations_cmd)
+
+ # Now read from the expectations file
+ results_file = os.path.join(results_dir, "results.json")
+ check_expectations_cmd = cmd_line + ["--readExpectationsPath",
+ results_file]
+ subprocess.check_call(check_expectations_cmd)
+ print "Self tests succeeded!"
+
+if __name__ == "__main__":
+ main()