OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. |
| 5 |
| 6 # Self-test for skimage. |
| 7 |
| 8 import os |
| 9 import subprocess |
| 10 import sys |
| 11 |
| 12 class BinaryNotFoundException(Exception): |
| 13 def __str__ (self): |
| 14 return ("Could not find binary!\n" |
| 15 "Did you forget to build the tools project?\n" |
| 16 "Self tests failed") |
| 17 |
| 18 # Find a path to the binary to use. Iterates through a list of possible |
| 19 # locations the binary may be. |
| 20 def PickBinaryPath(base_dir): |
| 21 POSSIBLE_BINARY_PATHS = [ |
| 22 'out/Debug/skimage', |
| 23 'out/Release/skimage', |
| 24 'xcodebuild/Debug/skimage', |
| 25 'xcodebuild/Release/skimage', |
| 26 ] |
| 27 for binary in POSSIBLE_BINARY_PATHS: |
| 28 binary_full_path = os.path.join(base_dir, binary) |
| 29 if (os.path.exists(binary_full_path)): |
| 30 return binary_full_path |
| 31 raise BinaryNotFoundException |
| 32 |
| 33 def main(): |
| 34 # Use the directory of this file as the out directory |
| 35 file_dir = os.path.abspath(os.path.dirname(__file__)) |
| 36 |
| 37 trunk_dir = os.path.normpath(os.path.join(file_dir, os.pardir, os.pardir)) |
| 38 |
| 39 # Find the binary |
| 40 skimage_binary = PickBinaryPath(trunk_dir) |
| 41 print "Running " + skimage_binary |
| 42 |
| 43 # Run skimage twice, first to create an expectations file, and then |
| 44 # comparing to it. |
| 45 |
| 46 # Both commands will run the binary, reading from resources. |
| 47 cmd_line = [skimage_binary] |
| 48 resources_dir = os.path.join(trunk_dir, 'resources') |
| 49 cmd_line.extend(["-r", resources_dir]) |
| 50 |
| 51 # Create the expectations file |
| 52 results_dir = os.path.join(file_dir, "skimage") |
| 53 create_expectations_cmd = cmd_line + ["--createExpectationsPath", |
| 54 results_dir] |
| 55 subprocess.check_call(create_expectations_cmd) |
| 56 |
| 57 # Now read from the expectations file |
| 58 results_file = os.path.join(results_dir, "results.json") |
| 59 check_expectations_cmd = cmd_line + ["--readExpectationsPath", |
| 60 results_file] |
| 61 subprocess.check_call(check_expectations_cmd) |
| 62 print "Self tests succeeded!" |
| 63 |
| 64 if __name__ == "__main__": |
| 65 main() |
OLD | NEW |