Changeset 77603 in webkit


Ignore:
Timestamp:
Feb 3, 2011 9:36:15 PM (13 years ago)
Author:
hayato@chromium.org
Message:

2011-02-03 Hayato Ito <hayato@chromium.org>

Reviewed by Tony Chang.

[NRWT] Introduces Input/Output class used by base.Driver into port/base.py and
move _run_single_test() and _process_output() functions from
dump_render_tree_thread.py to a single_test_runner.py as an individual module.

This is clean up and acts as a preparation for elimination of test_types/*
classes. These classes will move to the single_test_runner module introduced
in this patch.

https://bugs.webkit.org/show_bug.cgi?id=53004

  • Scripts/webkitpy/layout_tests/layout_package/dump_render_tree_thread.py:
  • Scripts/webkitpy/layout_tests/layout_package/single_test_runner.py: Added.
  • Scripts/webkitpy/layout_tests/layout_package/test_input.py:
  • Scripts/webkitpy/layout_tests/layout_package/test_output.py: Removed.
  • Scripts/webkitpy/layout_tests/port/base.py:
  • Scripts/webkitpy/layout_tests/port/chromium.py:
  • Scripts/webkitpy/layout_tests/port/dryrun.py:
  • Scripts/webkitpy/layout_tests/port/test.py:
  • Scripts/webkitpy/layout_tests/port/webkit.py:
  • Scripts/webkitpy/layout_tests/test_types/image_diff.py:
  • Scripts/webkitpy/layout_tests/test_types/test_type_base.py:
  • Scripts/webkitpy/layout_tests/test_types/text_diff.py:
Location:
trunk/Tools
Files:
1 added
1 deleted
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r77595 r77603  
     12011-02-03  Hayato Ito  <hayato@chromium.org>
     2
     3        Reviewed by Tony Chang.
     4
     5        [NRWT] Introduces Input/Output class used by base.Driver into port/base.py and
     6        move _run_single_test() and _process_output() functions from
     7        dump_render_tree_thread.py to a single_test_runner.py as an individual module.
     8
     9        This is clean up and acts as a preparation for elimination of test_types/*
     10        classes. These classes will move to the single_test_runner module introduced
     11        in this patch.
     12
     13        https://bugs.webkit.org/show_bug.cgi?id=53004
     14
     15        * Scripts/webkitpy/layout_tests/layout_package/dump_render_tree_thread.py:
     16        * Scripts/webkitpy/layout_tests/layout_package/single_test_runner.py: Added.
     17        * Scripts/webkitpy/layout_tests/layout_package/test_input.py:
     18        * Scripts/webkitpy/layout_tests/layout_package/test_output.py: Removed.
     19        * Scripts/webkitpy/layout_tests/port/base.py:
     20        * Scripts/webkitpy/layout_tests/port/chromium.py:
     21        * Scripts/webkitpy/layout_tests/port/dryrun.py:
     22        * Scripts/webkitpy/layout_tests/port/test.py:
     23        * Scripts/webkitpy/layout_tests/port/webkit.py:
     24        * Scripts/webkitpy/layout_tests/test_types/image_diff.py:
     25        * Scripts/webkitpy/layout_tests/test_types/test_type_base.py:
     26        * Scripts/webkitpy/layout_tests/test_types/text_diff.py:
     27
    1282011-02-03  Dirk Pranke  <dpranke@chromium.org>
    229
  • trunk/Tools/Scripts/webkitpy/layout_tests/layout_package/dump_render_tree_thread.py

    r76199 r77603  
    5252from webkitpy.layout_tests.test_types import text_diff
    5353
     54import single_test_runner
    5455import test_failures
    55 import test_output
    5656import test_results
    5757
    5858_log = logging.getLogger("webkitpy.layout_tests.layout_package."
    5959                         "dump_render_tree_thread")
    60 
    61 
    62 def _expected_test_output(port, filename):
    63     """Returns an expected TestOutput object."""
    64     return test_output.TestOutput(port.expected_text(filename),
    65                                   port.expected_image(filename),
    66                                   port.expected_checksum(filename))
    67 
    68 def _process_output(port, options, test_input, test_types, test_args,
    69                     test_output, worker_name):
    70     """Receives the output from a DumpRenderTree process, subjects it to a
    71     number of tests, and returns a list of failure types the test produced.
    72 
    73     Args:
    74       port: port-specific hooks
    75       options: command line options argument from optparse
    76       proc: an active DumpRenderTree process
    77       test_input: Object containing the test filename and timeout
    78       test_types: list of test types to subject the output to
    79       test_args: arguments to be passed to each test
    80       test_output: a TestOutput object containing the output of the test
    81       worker_name: worker name for logging
    82 
    83     Returns: a TestResult object
    84     """
    85     failures = []
    86     fs = port._filesystem
    87 
    88     if test_output.crash:
    89         failures.append(test_failures.FailureCrash())
    90     if test_output.timeout:
    91         failures.append(test_failures.FailureTimeout())
    92 
    93     test_name = port.relative_test_filename(test_input.filename)
    94     if test_output.crash:
    95         _log.debug("%s Stacktrace for %s:\n%s" % (worker_name, test_name,
    96                                                   test_output.error))
    97         filename = fs.join(options.results_directory, test_name)
    98         filename = fs.splitext(filename)[0] + "-stack.txt"
    99         fs.maybe_make_directory(fs.dirname(filename))
    100         fs.write_text_file(filename, test_output.error)
    101     elif test_output.error:
    102         _log.debug("%s %s output stderr lines:\n%s" % (worker_name, test_name,
    103                                                        test_output.error))
    104 
    105     expected_test_output = _expected_test_output(port, test_input.filename)
    106 
    107     # Check the output and save the results.
    108     start_time = time.time()
    109     time_for_diffs = {}
    110     for test_type in test_types:
    111         start_diff_time = time.time()
    112         new_failures = test_type.compare_output(port, test_input.filename,
    113                                                 test_args, test_output,
    114                                                 expected_test_output)
    115         # Don't add any more failures if we already have a crash, so we don't
    116         # double-report those tests. We do double-report for timeouts since
    117         # we still want to see the text and image output.
    118         if not test_output.crash:
    119             failures.extend(new_failures)
    120         time_for_diffs[test_type.__class__.__name__] = (
    121             time.time() - start_diff_time)
    122 
    123     total_time_for_all_diffs = time.time() - start_diff_time
    124     return test_results.TestResult(test_input.filename, failures, test_output.test_time,
    125                                    total_time_for_all_diffs, time_for_diffs)
    12660
    12761
     
    14377def _should_fetch_expected_checksum(options):
    14478    return options.pixel_tests and not (options.new_baseline or options.reset_results)
    145 
    146 
    147 def _run_single_test(port, options, test_input, test_types, test_args, driver, worker_name):
    148     # FIXME: Pull this into TestShellThread._run().
    149 
    150     # The image hash is used to avoid doing an image dump if the
    151     # checksums match, so it should be set to a blank value if we
    152     # are generating a new baseline.  (Otherwise, an image from a
    153     # previous run will be copied into the baseline."""
    154     if _should_fetch_expected_checksum(options):
    155         test_input.image_hash = port.expected_checksum(test_input.filename)
    156     test_output = driver.run_test(test_input)
    157     return _process_output(port, options, test_input, test_types, test_args,
    158                            test_output, worker_name)
    15979
    16080
     
    194114        self._driver = self._port.create_driver(self._worker_number)
    195115        self._driver.start()
    196         self._test_result = _run_single_test(self._port, self._options,
    197                                              self._test_input, self._test_types,
    198                                              self._test_args, self._driver,
    199                                              self._name)
     116        self._test_result = single_test_runner.run_single_test(
     117            self._port, self._options, self._test_input, self._driver,
     118            self._name, self._test_types, self._test_args)
    200119        self._driver.stop()
    201120
     
    515434             _pad_timeout(int(test_input.timeout)))
    516435        self._next_timeout = time.time() + thread_timeout
    517         test_result = _run_single_test(self._port, self._options, test_input,
    518                                        self._test_types, self._test_args,
    519                                        self._driver, self._name)
     436        test_result = single_test_runner.run_single_test(
     437            self._port, self._options, test_input, self._driver, self._name,
     438            self._test_types, self._test_args)
    520439        self._test_results.append(test_result)
    521440        return test_result
  • trunk/Tools/Scripts/webkitpy/layout_tests/layout_package/test_input.py

    r74525 r77603  
    4242        self.filename = filename
    4343        self.timeout = timeout
    44         # The image_hash is used to avoid doing an image dump if the
    45         # checksums match. The image_hash is set later, and only if it is needed
    46         # for the test.
    47         self.image_hash = None
  • trunk/Tools/Scripts/webkitpy/layout_tests/port/base.py

    r77551 r77603  
    822822
    823823
     824class DriverInput(object):
     825    """Holds the input parameters for a driver."""
     826
     827    def __init__(self, filename, timeout, image_hash):
     828        """Initializes a DriverInput object.
     829
     830        Args:
     831          filename: Full path to the test.
     832          timeout: Timeout in msecs the driver should use while running the test
     833          image_hash: A image checksum which is used to avoid doing an image dump if
     834                     the checksums match.
     835        """
     836        self.filename = filename
     837        self.timeout = timeout
     838        self.image_hash = image_hash
     839
     840
     841class DriverOutput(object):
     842    """Groups information about a output from driver for easy passing of data."""
     843
     844    def __init__(self, text, image, image_hash,
     845                 crash=False, test_time=None, timeout=False, error=''):
     846        """Initializes a TestOutput object.
     847
     848        Args:
     849          text: a text output
     850          image: an image output
     851          image_hash: a string containing the checksum of the image
     852          crash: a boolean indicating whether the driver crashed on the test
     853          test_time: a time which the test has taken
     854          timeout: a boolean indicating whehter the test timed out
     855          error: any unexpected or additional (or error) text output
     856        """
     857        self.text = text
     858        self.image = image
     859        self.image_hash = image_hash
     860        self.crash = crash
     861        self.test_time = test_time
     862        self.timeout = timeout
     863        self.error = error
     864
     865
    824866class Driver:
    825867    """Abstract interface for the DumpRenderTree interface."""
     
    836878        raise NotImplementedError('Driver.__init__')
    837879
    838     def run_test(self, test_input):
     880    def run_test(self, driver_input):
    839881        """Run a single test and return the results.
    840882
     
    844886
    845887        Args:
    846           test_input: a TestInput object
    847 
    848         Returns a TestOutput object.
     888          driver_input: a DriverInput object
     889
     890        Returns a DriverOutput object.
    849891        """
    850892        raise NotImplementedError('Driver.run_test')
  • trunk/Tools/Scripts/webkitpy/layout_tests/port/chromium.py

    r77415 r77603  
    4242from webkitpy.common.system.path import cygpath
    4343from webkitpy.layout_tests.layout_package import test_expectations
    44 from webkitpy.layout_tests.layout_package import test_output
    4544
    4645import base
     
    446445        return self._output_image()
    447446
    448     def run_test(self, test_input):
     447    def run_test(self, driver_input):
    449448        output = []
    450449        error = []
     
    456455        start_time = time.time()
    457456
    458         uri = self._port.filename_to_uri(test_input.filename)
    459         cmd = self._test_shell_command(uri, test_input.timeout,
    460                                        test_input.image_hash)
     457        uri = self._port.filename_to_uri(driver_input.filename)
     458        cmd = self._test_shell_command(uri, driver_input.timeout,
     459                                       driver_input.image_hash)
    461460        (line, crash) = self._write_command_and_read_line(input=cmd)
    462461
     
    500499
    501500        run_time = time.time() - start_time
    502         return test_output.TestOutput(
     501        return base.DriverOutput(
    503502            ''.join(output), self._output_image_with_retry(), actual_checksum,
    504503            crash, run_time, timeout, ''.join(error))
  • trunk/Tools/Scripts/webkitpy/layout_tests/port/dryrun.py

    r76982 r77603  
    5050import sys
    5151import time
    52 
    53 from webkitpy.layout_tests.layout_package import test_output
    5452
    5553import base
     
    119117        return None
    120118
    121     def run_test(self, test_input):
     119    def run_test(self, driver_input):
    122120        start_time = time.time()
    123         text_output = self._port.expected_text(test_input.filename)
     121        text_output = self._port.expected_text(driver_input.filename)
    124122
    125         if test_input.image_hash is not None:
    126             image = self._port.expected_image(test_input.filename)
    127             hash = self._port.expected_checksum(test_input.filename)
     123        if driver_input.image_hash is not None:
     124            image = self._port.expected_image(driver_input.filename)
     125            hash = self._port.expected_checksum(driver_input.filename)
    128126        else:
    129127            image = None
    130128            hash = None
    131         return test_output.TestOutput(text_output, image, hash, False,
    132                                       time.time() - start_time, False, None)
     129        return base.DriverOutput(text_output, image, hash, False,
     130                                 time.time() - start_time, False, '')
    133131
    134132    def start(self):
  • trunk/Tools/Scripts/webkitpy/layout_tests/port/test.py

    r77550 r77603  
    3535from webkitpy.common.system import filesystem_mock
    3636from webkitpy.tool import mocktool
    37 
    38 from webkitpy.layout_tests.layout_package import test_output
    3937
    4038import base
     
    385383        if test.hang:
    386384            time.sleep((float(test_input.timeout) * 4) / 1000.0)
    387         return test_output.TestOutput(test.actual_text, test.actual_image,
    388                                       test.actual_checksum, test.crash,
    389                                       time.time() - start_time, test.timeout,
    390                                       test.error)
     385        return base.DriverOutput(test.actual_text, test.actual_image,
     386                                 test.actual_checksum, test.crash,
     387                                 time.time() - start_time, test.timeout,
     388                                 test.error)
    391389
    392390    def start(self):
  • trunk/Tools/Scripts/webkitpy/layout_tests/port/webkit.py

    r77163 r77603  
    4242
    4343import webkitpy.common.system.ospath as ospath
    44 import webkitpy.layout_tests.layout_package.test_output as test_output
    4544import webkitpy.layout_tests.port.base as base
    4645import webkitpy.layout_tests.port.server_process as server_process
     
    406405
    407406    # FIXME: This function is huge.
    408     def run_test(self, test_input):
    409         uri = self._port.filename_to_uri(test_input.filename)
     407    def run_test(self, driver_input):
     408        uri = self._port.filename_to_uri(driver_input.filename)
    410409        if uri.startswith("file:///"):
    411410            command = uri[7:]
     
    413412            command = uri
    414413
    415         if test_input.image_hash:
    416             command += "'" + test_input.image_hash
     414        if driver_input.image_hash:
     415            command += "'" + driver_input.image_hash
    417416        command += "\n"
    418417
     
    425424        image = str()
    426425
    427         timeout = int(test_input.timeout) / 1000.0
     426        timeout = int(driver_input.timeout) / 1000.0
    428427        deadline = time.time() + timeout
    429428        line = self._server_process.read_line(timeout)
     
    472471        # this reset in.
    473472        self._server_process.error = ""
    474         return test_output.TestOutput(output, image, actual_image_hash,
    475                                       self._server_process.crashed,
    476                                       time.time() - start_time,
    477                                       self._server_process.timed_out,
    478                                       error)
     473        return base.DriverOutput(output, image, actual_image_hash,
     474                                 self._server_process.crashed,
     475                                 time.time() - start_time,
     476                                 self._server_process.timed_out,
     477                                 error)
    479478
    480479    def stop(self):
  • trunk/Tools/Scripts/webkitpy/layout_tests/test_types/image_diff.py

    r76322 r77603  
    8686        return port.diff_image(actual_image, expected_image, diff_filename)
    8787
    88     def compare_output(self, port, filename, test_args, actual_test_output,
    89                        expected_test_output):
     88    def compare_output(self, port, filename, test_args, actual_driver_output,
     89                       expected_driver_output):
    9090        """Implementation of CompareOutput that checks the output image and
    9191        checksum against the expected files from the LayoutTest directory.
     
    9494
    9595        # If we didn't produce a hash file, this test must be text-only.
    96         if actual_test_output.image_hash is None:
     96        if actual_driver_output.image_hash is None:
    9797            return failures
    9898
    9999        # If we're generating a new baseline, we pass.
    100100        if test_args.new_baseline or test_args.reset_results:
    101             self._save_baseline_files(filename, actual_test_output.image,
    102                                       actual_test_output.image_hash,
     101            self._save_baseline_files(filename, actual_driver_output.image,
     102                                      actual_driver_output.image_hash,
    103103                                      test_args.new_baseline)
    104104            return failures
    105105
    106         if not expected_test_output.image:
     106        if not expected_driver_output.image:
    107107            # Report a missing expected PNG file.
    108             self._copy_image(filename, actual_test_output.image, expected_image=None)
    109             self._copy_image_hash(filename, actual_test_output.image_hash,
    110                                   expected_test_output.image_hash)
     108            self._copy_image(filename, actual_driver_output.image, expected_image=None)
     109            self._copy_image_hash(filename, actual_driver_output.image_hash,
     110                                  expected_driver_output.image_hash)
    111111            failures.append(test_failures.FailureMissingImage())
    112112            return failures
    113         if not expected_test_output.image_hash:
     113        if not expected_driver_output.image_hash:
    114114            # Report a missing expected checksum file.
    115             self._copy_image(filename, actual_test_output.image,
    116                              expected_test_output.image)
    117             self._copy_image_hash(filename, actual_test_output.image_hash,
     115            self._copy_image(filename, actual_driver_output.image,
     116                             expected_driver_output.image)
     117            self._copy_image_hash(filename, actual_driver_output.image_hash,
    118118                                  expected_image_hash=None)
    119119            failures.append(test_failures.FailureMissingImageHash())
    120120            return failures
    121121
    122         if actual_test_output.image_hash == expected_test_output.image_hash:
     122        if actual_driver_output.image_hash == expected_driver_output.image_hash:
    123123            # Hash matched (no diff needed, okay to return).
    124124            return failures
    125125
    126         self._copy_image(filename, actual_test_output.image,
    127                          expected_test_output.image)
    128         self._copy_image_hash(filename, actual_test_output.image_hash,
    129                               expected_test_output.image_hash)
     126        self._copy_image(filename, actual_driver_output.image,
     127                         expected_driver_output.image)
     128        self._copy_image_hash(filename, actual_driver_output.image_hash,
     129                              expected_driver_output.image_hash)
    130130
    131131        # Even though we only use the result in one codepath below but we
    132132        # still need to call CreateImageDiff for other codepaths.
    133133        images_are_different = self._create_diff_image(port, filename,
    134                                                        actual_test_output.image,
    135                                                        expected_test_output.image)
     134                                                       actual_driver_output.image,
     135                                                       expected_driver_output.image)
    136136        if not images_are_different:
    137137            failures.append(test_failures.FailureImageHashIncorrect())
  • trunk/Tools/Scripts/webkitpy/layout_tests/test_types/test_type_base.py

    r76150 r77603  
    140140        return fs.splitext(output_filename)[0] + modifier
    141141
    142     def compare_output(self, port, filename, test_args, actual_test_output,
    143                         expected_test_output):
     142    def compare_output(self, port, filename, test_args, actual_driver_output,
     143                        expected_driver_output):
    144144        """Method that compares the output from the test with the
    145145        expected value.
     
    152152          test_args: a TestArguments object holding optional additional
    153153              arguments
    154           actual_test_output: a TestOutput object which represents actual test
     154          actual_driver_output: a DriverOutput object which represents actual test
    155155              output
    156           expected_test_output: a TestOutput object which represents a expected
    157               test output
     156          expected_driver_output: a ExpectedDriverOutput object which represents a
     157              expected test output
    158158
    159159        Return:
  • trunk/Tools/Scripts/webkitpy/layout_tests/test_types/text_diff.py

    r77410 r77603  
    5454        return output.replace("\r\r\n", "\r\n").replace("\r\n", "\n")
    5555
    56     def compare_output(self, port, filename, test_args, actual_test_output,
    57                         expected_test_output):
     56    def compare_output(self, port, filename, test_args, actual_driver_output,
     57                        expected_driver_output):
    5858        """Implementation of CompareOutput that checks the output text against
    5959        the expected text from the LayoutTest directory."""
     
    6565            # ever decode it inside run-webkit-tests.  For some tests
    6666            # DumpRenderTree may not output utf-8 text (e.g.  webarchives).
    67             self._save_baseline_data(filename, actual_test_output.text,
     67            self._save_baseline_data(filename, actual_driver_output.text,
    6868                                     ".txt", encoding=None,
    6969                                     generate_new_baseline=test_args.new_baseline)
     
    7171
    7272        # Normalize text to diff
    73         actual_text = self._get_normalized_output_text(actual_test_output.text)
     73        actual_text = self._get_normalized_output_text(actual_driver_output.text)
    7474        # Assuming expected_text is already normalized.
    75         expected_text = expected_test_output.text
     75        expected_text = expected_driver_output.text
    7676
    7777        # Write output files for new tests, too.
Note: See TracChangeset for help on using the changeset viewer.