WebKitTools/Scripts/webkitpy/layout_tests/driver_test.py
changeset 0 4f2f89ce4247
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     1 #!/usr/bin/env python
       
     2 # Copyright (C) 2010 Google Inc. All rights reserved.
       
     3 #
       
     4 # Redistribution and use in source and binary forms, with or without
       
     5 # modification, are permitted provided that the following conditions are
       
     6 # met:
       
     7 #
       
     8 #     * Redistributions of source code must retain the above copyright
       
     9 # notice, this list of conditions and the following disclaimer.
       
    10 #     * Redistributions in binary form must reproduce the above
       
    11 # copyright notice, this list of conditions and the following disclaimer
       
    12 # in the documentation and/or other materials provided with the
       
    13 # distribution.
       
    14 #     * Neither the name of Google Inc. nor the names of its
       
    15 # contributors may be used to endorse or promote products derived from
       
    16 # this software without specific prior written permission.
       
    17 #
       
    18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
       
    19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
       
    20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
       
    21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
       
    22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
       
    23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
       
    24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
       
    25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
       
    26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
       
    27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
       
    28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
       
    29 
       
    30 #
       
    31 # FIXME: this is a poor attempt at a unit tests driver. We should replace
       
    32 # this with something that actually uses a unit testing framework or
       
    33 # at least produces output that could be useful.
       
    34 
       
    35 """Simple test client for the port/Driver interface."""
       
    36 
       
    37 import os
       
    38 import optparse
       
    39 import port
       
    40 
       
    41 
       
    42 def run_tests(port, options, tests):
       
    43     # |image_path| is a path to the image capture from the driver.
       
    44     image_path = 'image_result.png'
       
    45     driver = port.create_driver(image_path, None)
       
    46     driver.start()
       
    47     for t in tests:
       
    48         uri = port.filename_to_uri(os.path.join(port.layout_tests_dir(), t))
       
    49         print "uri: " + uri
       
    50         crash, timeout, checksum, output, err = \
       
    51             driver.run_test(uri, int(options.timeout), None)
       
    52         print "crash:         " + str(crash)
       
    53         print "timeout:       " + str(timeout)
       
    54         print "checksum:      " + str(checksum)
       
    55         print 'stdout: """'
       
    56         print ''.join(output)
       
    57         print '"""'
       
    58         print 'stderr: """'
       
    59         print ''.join(err)
       
    60         print '"""'
       
    61         print
       
    62     driver.stop()
       
    63 
       
    64 
       
    65 if __name__ == '__main__':
       
    66     # FIXME: configuration_options belong in a shared location.
       
    67     configuration_options = [
       
    68         optparse.make_option('--debug', action='store_const', const='Debug', dest="configuration", help='Set the configuration to Debug'),
       
    69         optparse.make_option('--release', action='store_const', const='Release', dest="configuration", help='Set the configuration to Release'),
       
    70     ]
       
    71     misc_options = [
       
    72         optparse.make_option('-p', '--platform', action='store', default='mac', help='Platform to test (e.g., "mac", "chromium-mac", etc.'),
       
    73         optparse.make_option('--timeout', action='store', default='2000', help='test timeout in milliseconds (2000 by default)'),
       
    74         optparse.make_option('--wrapper', action='store'),
       
    75         optparse.make_option('--no-pixel-tests', action='store_true', default=False, help='disable pixel-to-pixel PNG comparisons'),
       
    76     ]
       
    77     option_list = configuration_options + misc_options
       
    78     optparser = optparse.OptionParser(option_list=option_list)
       
    79     options, args = optparser.parse_args()
       
    80     p = port.get(options.platform, options)
       
    81     run_tests(p, options, args)