scroggo@google.com | 4fed643 | 2013-05-14 17:50:02 +0000 | [diff] [blame] | 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 |
scroggo@google.com | cf5eb6a | 2013-06-07 12:43:15 +0000 | [diff] [blame] | 52 | results_file = os.path.join(file_dir, "skimage", "self_test_results.json") |
scroggo@google.com | 4fed643 | 2013-05-14 17:50:02 +0000 | [diff] [blame] | 53 | create_expectations_cmd = cmd_line + ["--createExpectationsPath", |
scroggo@google.com | cf5eb6a | 2013-06-07 12:43:15 +0000 | [diff] [blame] | 54 | results_file] |
scroggo@google.com | 4fed643 | 2013-05-14 17:50:02 +0000 | [diff] [blame] | 55 | subprocess.check_call(create_expectations_cmd) |
| 56 | |
| 57 | # Now read from the expectations file |
scroggo@google.com | 4fed643 | 2013-05-14 17:50:02 +0000 | [diff] [blame] | 58 | check_expectations_cmd = cmd_line + ["--readExpectationsPath", |
| 59 | results_file] |
| 60 | subprocess.check_call(check_expectations_cmd) |
| 61 | print "Self tests succeeded!" |
| 62 | |
| 63 | if __name__ == "__main__": |
| 64 | main() |