blob: d2d072ff41d396e71f2cb787beff02961cef16a0 [file] [log] [blame]
scroggo@google.com4fed6432013-05-14 17:50:02 +00001#!/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
8import os
9import subprocess
10import sys
11
12class 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.
20def 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
33def 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.comcf5eb6a2013-06-07 12:43:15 +000052 results_file = os.path.join(file_dir, "skimage", "self_test_results.json")
scroggo@google.com4fed6432013-05-14 17:50:02 +000053 create_expectations_cmd = cmd_line + ["--createExpectationsPath",
scroggo@google.comcf5eb6a2013-06-07 12:43:15 +000054 results_file]
scroggo@google.com4fed6432013-05-14 17:50:02 +000055 subprocess.check_call(create_expectations_cmd)
56
57 # Now read from the expectations file
scroggo@google.com4fed6432013-05-14 17:50:02 +000058 check_expectations_cmd = cmd_line + ["--readExpectationsPath",
59 results_file]
60 subprocess.check_call(check_expectations_cmd)
61 print "Self tests succeeded!"
62
63if __name__ == "__main__":
64 main()