Changeset 78502 in webkit


Ignore:
Timestamp:
Feb 14, 2011 1:48:25 PM (13 years ago)
Author:
dpranke@chromium.org
Message:

2011-02-14 Dirk Pranke <dpranke@chromium.org>

Reviewed by Tony Chang.

update the NRWT multiprocessing code to spawn multiple workers
instead of just using one.

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

  • Scripts/webkitpy/layout_tests/layout_package/test_runner2.py:
Location:
trunk/Tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r78420 r78502  
     12011-02-14  Dirk Pranke  <dpranke@chromium.org>
     2
     3        Reviewed by Tony Chang.
     4
     5        update the NRWT multiprocessing code to spawn multiple workers
     6        instead of just using one.
     7
     8        https://bugs.webkit.org/show_bug.cgi?id=54071
     9
     10        * Scripts/webkitpy/layout_tests/layout_package/test_runner2.py:
     11
    1122011-02-12  Chang Shu  <cshu@webkit.org>
    213
  • trunk/Tools/Scripts/webkitpy/layout_tests/layout_package/test_runner2.py

    r78398 r78502  
    3535
    3636import logging
     37import time
    3738
     39from webkitpy.tool import grammar
    3840
    3941from webkitpy.layout_tests.layout_package import manager_worker_broker
     
    4446
    4547
     48class _WorkerState(object):
     49    """A class for the TestRunner/manager to use to track the current state
     50    of the workers."""
     51    def __init__(self, number, worker_connection):
     52        self.worker_connection = worker_connection
     53        self.number = number
     54        self.done = False
     55
     56    def __repr__(self):
     57        return "_WorkerState(" + str(self.__dict__) + ")"
     58
     59
    4660class TestRunner2(test_runner.TestRunner):
    4761    def __init__(self, port, options, printer):
     
    5064        self._group_stats = {}
    5165        self._current_result_summary = None
    52         self._done = False
     66
     67        # This maps worker names to the state we are tracking for each of them.
     68        self._worker_states = {}
    5369
    5470    def is_done(self):
    55         return self._done
     71        worker_states = self._worker_states.values()
     72        return worker_states and all(self._worker_is_done(worker_state) for worker_state in worker_states)
     73
     74    def _worker_is_done(self, worker_state):
     75        # FIXME: check if the worker is wedged.
     76        return worker_state.done
    5677
    5778    def name(self):
     
    7394        """
    7495        self._current_result_summary = result_summary
     96        self._all_results = []
     97        self._worker_states = {}
    7598
    76         # FIXME: shard properly.
     99        num_workers = self._num_workers()
    77100
    78         # FIXME: should shard_tests return a list of objects rather than tuples?
    79         test_lists = self._shard_tests(file_list, False)
     101        self._printer.print_update('Sharding tests ...')
     102        test_lists = self._shard_tests(file_list,
     103            num_workers > 1 and not self._options.experimental_fully_parallel)
     104        _log.debug("Using %d shards" % len(test_lists))
    80105
    81         manager_connection = manager_worker_broker.get(self._port, self._options, self, worker.Worker)
     106        manager_connection = manager_worker_broker.get(self._port, self._options,
     107                                                       self, worker.Worker)
    82108
    83         # FIXME: start all of the workers.
    84         manager_connection.start_worker(0)
     109        self._printer.print_update('Starting %s ...' %
     110                                   grammar.pluralize('worker', num_workers))
     111        for worker_number in xrange(num_workers):
     112            worker_connection = manager_connection.start_worker(worker_number)
     113            worker_state = _WorkerState(worker_number, worker_connection)
     114            self._worker_states[worker_connection.name] = worker_state
     115
     116            # FIXME: If we start workers up too quickly, DumpRenderTree appears
     117            # to thrash on something and time out its first few tests. Until
     118            # we can figure out what's going on, sleep a bit in between
     119            # workers.
     120            time.sleep(0.1)
    85121
    86122        for test_list in test_lists:
    87123            manager_connection.post_message('test_list', test_list[0], test_list[1])
    88124
    89         manager_connection.post_message('stop')
     125        # We post one 'stop' message for each worker. Because the stop message
     126        # are sent after all of the tests, and because each worker will stop
     127        # reading messsages after receiving a stop, we can be sure each
     128        # worker will get a stop message and hence they will all shut down.
     129        for i in xrange(num_workers):
     130            manager_connection.post_message('stop')
    90131
    91132        keyboard_interrupted = False
    92133        interrupted = False
    93134        if not self._options.dry_run:
    94             while not self._check_if_done():
     135            while not self.is_done():
     136                # We loop with a timeout in order to be able to detect wedged threads.
    95137                manager_connection.run_message_loop(delay_secs=1.0)
    96138
     139        # FIXME: handle exceptions, interrupts.
     140
    97141        # FIXME: implement stats.
     142
    98143        thread_timings = []
    99144
     
    102147                self._group_stats, self._all_results)
    103148
    104     def _check_if_done(self):
    105         """Returns true iff all the workers have either completed or wedged."""
    106         # FIXME: implement to check for wedged workers.
    107         return self._done
    108 
    109     def handle_started_test(self, src, test_info, hang_timeout):
     149    def handle_started_test(self, source, test_info, hang_timeout):
    110150        # FIXME: implement
    111151        pass
    112152
    113     def handle_done(self, src):
    114         # FIXME: implement properly to handle multiple workers.
    115         self._done = True
    116         pass
     153    def handle_done(self, source):
     154        worker_state = self._worker_states[source]
     155        worker_state.done = True
    117156
    118     def handle_exception(self, src, exception_info):
     157    def handle_exception(self, source, exception_info):
    119158        raise exception_info
    120159
    121     def handle_finished_list(self, src, list_name, num_tests, elapsed_time):
     160    def handle_finished_list(self, source, list_name, num_tests, elapsed_time):
    122161        # FIXME: update stats
    123162        pass
    124163
    125     def handle_finished_test(self, src, result, elapsed_time):
     164    def handle_finished_test(self, source, result, elapsed_time):
    126165        self._update_summary_with_result(self._current_result_summary, result)
    127166
Note: See TracChangeset for help on using the changeset viewer.