Home | History | Annotate | Download | only in port
      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 Google name 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 """This is a test implementation of the Port interface that generates the
     31    correct output for every test. It can be used for perf testing, because
     32    it is pretty much a lower limit on how fast a port can possibly run.
     33 
     34    This implementation acts as a wrapper around a real port (the real port
     35    is held as a delegate object). To specify which port, use the port name
     36    'dryrun-XXX' (e.g., 'dryrun-chromium-mac-leopard'). If you use just
     37    'dryrun', it uses the default port.
     38 
     39    Note that because this is really acting as a wrapper around the underlying
     40    port, you must be able to run the underlying port as well
     41    (check_build() and check_sys_deps() must pass and auxiliary binaries
     42    like layout_test_helper and httpd must work).
     43 
     44    This implementation also modifies the test expectations so that all
     45    tests are either SKIPPED or expected to PASS."""
     46 
     47 from __future__ import with_statement
     48 
     49 import os
     50 import sys
     51 import time
     52 
     53 import base
     54 import factory
     55 
     56 
     57 class DryRunPort(object):
     58     """DryRun implementation of the Port interface."""
     59 
     60     def __init__(self, **kwargs):
     61         pfx = 'dryrun-'
     62         if 'port_name' in kwargs:
     63             if kwargs['port_name'].startswith(pfx):
     64                 kwargs['port_name'] = kwargs['port_name'][len(pfx):]
     65             else:
     66                 kwargs['port_name'] = None
     67         self.__delegate = factory.get(**kwargs)
     68 
     69     def __getattr__(self, name):
     70         return getattr(self.__delegate, name)
     71 
     72     def acquire_http_lock(self):
     73         pass
     74 
     75     def release_http_lock(self):
     76         pass
     77 
     78     def check_build(self, needs_http):
     79         return True
     80 
     81     def check_sys_deps(self, needs_http):
     82         return True
     83 
     84     def start_helper(self):
     85         pass
     86 
     87     def start_http_server(self):
     88         pass
     89 
     90     def start_websocket_server(self):
     91         pass
     92 
     93     def stop_helper(self):
     94         pass
     95 
     96     def stop_http_server(self):
     97         pass
     98 
     99     def stop_websocket_server(self):
    100         pass
    101 
    102     def create_driver(self, worker_number):
    103         return DryrunDriver(self, worker_number)
    104 
    105 
    106 class DryrunDriver(base.Driver):
    107     """Dryrun implementation of the DumpRenderTree / Driver interface."""
    108 
    109     def __init__(self, port, worker_number):
    110         self._port = port
    111         self._worker_number = worker_number
    112 
    113     def cmd_line(self):
    114         return ['None']
    115 
    116     def poll(self):
    117         return None
    118 
    119     def run_test(self, driver_input):
    120         start_time = time.time()
    121         fs = self._port._filesystem
    122         if (fs.exists(self._port.reftest_expected_filename(driver_input.filename)) or
    123             fs.exists(self._port.reftest_expected_mismatch_filename(driver_input.filename)) or
    124             driver_input.filename.endswith('-expected.html')):
    125             text = 'test-text'
    126             image = 'test-image'
    127             checksum = 'test-checksum'
    128             audio = None
    129         elif driver_input.filename.endswith('-expected-mismatch.html'):
    130             text = 'test-text-mismatch'
    131             image = 'test-image-mismatch'
    132             checksum = 'test-checksum-mismatch'
    133             audio = None
    134         else:
    135             text = self._port.expected_text(driver_input.filename)
    136             image = self._port.expected_image(driver_input.filename)
    137             checksum = self._port.expected_checksum(driver_input.filename)
    138             audio = self._port.expected_audio(driver_input.filename)
    139         return base.DriverOutput(text, image, checksum, audio, crash=False,
    140             test_time=time.time() - start_time, timeout=False, error='')
    141 
    142     def start(self):
    143         pass
    144 
    145     def stop(self):
    146         pass
    147