⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 99379 in webkit


Ignore:
Timestamp:
Nov 6, 2011, 12:49:40 PM (15 years ago)
Author:
eric@webkit.org
Message:

Split chunk handling out of prepare_lists_and_print_output to make it more readable
https://bugs.webkit.org/show_bug.cgi?id=71629

Reviewed by Adam Barth.

  • Scripts/webkitpy/layout_tests/controllers/manager.py:
Location:
trunk/Tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r99377 r99379  
     12011-11-06  Eric Seidel  <eric@webkit.org>
     2
     3        Split chunk handling out of prepare_lists_and_print_output to make it more readable
     4        https://bugs.webkit.org/show_bug.cgi?id=71629
     5
     6        Reviewed by Adam Barth.
     7
     8        * Scripts/webkitpy/layout_tests/controllers/manager.py:
     9
    1102011-11-06  Eric Seidel  <eric@webkit.org>
    211
  • trunk/Tools/Scripts/webkitpy/layout_tests/controllers/manager.py

    r97672 r99379  
    386386            port.test_expectations_overrides())
    387387
     388    def _split_into_chunks_if_necessary(self, skipped):
     389        if not self._options.run_chunk and not self._options.run_part:
     390            return skipped
     391
     392        # If the user specifies they just want to run a subset of the tests,
     393        # just grab a subset of the non-skipped tests.
     394        chunk_value = self._options.run_chunk or self._options.run_part
     395        test_files = self._test_files_list
     396        try:
     397            (chunk_num, chunk_len) = chunk_value.split(":")
     398            chunk_num = int(chunk_num)
     399            assert(chunk_num >= 0)
     400            test_size = int(chunk_len)
     401            assert(test_size > 0)
     402        except AssertionError:
     403            _log.critical("invalid chunk '%s'" % chunk_value)
     404            return None
     405
     406        # Get the number of tests
     407        num_tests = len(test_files)
     408
     409        # Get the start offset of the slice.
     410        if self._options.run_chunk:
     411            chunk_len = test_size
     412            # In this case chunk_num can be really large. We need
     413            # to make the slave fit in the current number of tests.
     414            slice_start = (chunk_num * chunk_len) % num_tests
     415        else:
     416            # Validate the data.
     417            assert(test_size <= num_tests)
     418            assert(chunk_num <= test_size)
     419
     420            # To count the chunk_len, and make sure we don't skip
     421            # some tests, we round to the next value that fits exactly
     422            # all the parts.
     423            rounded_tests = num_tests
     424            if rounded_tests % test_size != 0:
     425                rounded_tests = (num_tests + test_size - (num_tests % test_size))
     426
     427            chunk_len = rounded_tests / test_size
     428            slice_start = chunk_len * (chunk_num - 1)
     429            # It does not mind if we go over test_size.
     430
     431        # Get the end offset of the slice.
     432        slice_end = min(num_tests, slice_start + chunk_len)
     433
     434        files = test_files[slice_start:slice_end]
     435
     436        tests_run_msg = 'Running: %d tests (chunk slice [%d:%d] of %d)' % ((slice_end - slice_start), slice_start, slice_end, num_tests)
     437        self._printer.print_expected(tests_run_msg)
     438
     439        # If we reached the end and we don't have enough tests, we run some
     440        # from the beginning.
     441        if slice_end - slice_start < chunk_len:
     442            extra = chunk_len - (slice_end - slice_start)
     443            extra_msg = ('   last chunk is partial, appending [0:%d]' % extra)
     444            self._printer.print_expected(extra_msg)
     445            tests_run_msg += "\n" + extra_msg
     446            files.extend(test_files[0:extra])
     447        tests_run_filename = self._fs.join(self._results_directory, "tests_run.txt")
     448        self._fs.write_text_file(tests_run_filename, tests_run_msg)
     449
     450        len_skip_chunk = int(len(files) * len(skipped) / float(len(self._test_files)))
     451        skip_chunk_list = list(skipped)[0:len_skip_chunk]
     452        skip_chunk = set(skip_chunk_list)
     453
     454        # FIXME: This is a total hack.
     455        # Update expectations so that the stats are calculated correctly.
     456        # We need to pass a list that includes the right # of skipped files
     457        # to ParseExpectations so that ResultSummary() will get the correct
     458        # stats. So, we add in the subset of skipped files, and then
     459        # subtract them back out.
     460        self._test_files_list = files + skip_chunk_list
     461        self._test_files = set(self._test_files_list)
     462
     463        self.parse_expectations()
     464
     465        self._test_files = set(files)
     466        self._test_files_list = files
     467
     468        return skip_chunk
     469
    388470    # FIXME: This method is way too long and needs to be broken into pieces.
    389471    def prepare_lists_and_print_output(self):
     
    395477        # top-level list of files to test.
    396478        num_all_test_files = len(self._test_files)
    397         self._printer.print_expected("Found:  %d tests" %
    398                                      (len(self._test_files)))
     479        self._printer.print_expected("Found:  %d tests" % (len(self._test_files)))
    399480        if not num_all_test_files:
    400481            _log.critical('No tests to run.')
     
    422503            self._test_files_list.sort(key=lambda test: test_key(self._port, test))
    423504
    424         # If the user specifies they just want to run a subset of the tests,
    425         # just grab a subset of the non-skipped tests.
    426         if self._options.run_chunk or self._options.run_part:
    427             chunk_value = self._options.run_chunk or self._options.run_part
    428             test_files = self._test_files_list
    429             try:
    430                 (chunk_num, chunk_len) = chunk_value.split(":")
    431                 chunk_num = int(chunk_num)
    432                 assert(chunk_num >= 0)
    433                 test_size = int(chunk_len)
    434                 assert(test_size > 0)
    435             except AssertionError:
    436                 _log.critical("invalid chunk '%s'" % chunk_value)
    437                 return None
    438 
    439             # Get the number of tests
    440             num_tests = len(test_files)
    441 
    442             # Get the start offset of the slice.
    443             if self._options.run_chunk:
    444                 chunk_len = test_size
    445                 # In this case chunk_num can be really large. We need
    446                 # to make the slave fit in the current number of tests.
    447                 slice_start = (chunk_num * chunk_len) % num_tests
    448             else:
    449                 # Validate the data.
    450                 assert(test_size <= num_tests)
    451                 assert(chunk_num <= test_size)
    452 
    453                 # To count the chunk_len, and make sure we don't skip
    454                 # some tests, we round to the next value that fits exactly
    455                 # all the parts.
    456                 rounded_tests = num_tests
    457                 if rounded_tests % test_size != 0:
    458                     rounded_tests = (num_tests + test_size -
    459                                      (num_tests % test_size))
    460 
    461                 chunk_len = rounded_tests / test_size
    462                 slice_start = chunk_len * (chunk_num - 1)
    463                 # It does not mind if we go over test_size.
    464 
    465             # Get the end offset of the slice.
    466             slice_end = min(num_tests, slice_start + chunk_len)
    467 
    468             files = test_files[slice_start:slice_end]
    469 
    470             tests_run_msg = 'Running: %d tests (chunk slice [%d:%d] of %d)' % (
    471                 (slice_end - slice_start), slice_start, slice_end, num_tests)
    472             self._printer.print_expected(tests_run_msg)
    473 
    474             # If we reached the end and we don't have enough tests, we run some
    475             # from the beginning.
    476             if slice_end - slice_start < chunk_len:
    477                 extra = chunk_len - (slice_end - slice_start)
    478                 extra_msg = ('   last chunk is partial, appending [0:%d]' %
    479                             extra)
    480                 self._printer.print_expected(extra_msg)
    481                 tests_run_msg += "\n" + extra_msg
    482                 files.extend(test_files[0:extra])
    483             tests_run_filename = self._fs.join(self._results_directory, "tests_run.txt")
    484             self._fs.write_text_file(tests_run_filename, tests_run_msg)
    485 
    486             len_skip_chunk = int(len(files) * len(skipped) /
    487                                  float(len(self._test_files)))
    488             skip_chunk_list = list(skipped)[0:len_skip_chunk]
    489             skip_chunk = set(skip_chunk_list)
    490 
    491             # Update expectations so that the stats are calculated correctly.
    492             # We need to pass a list that includes the right # of skipped files
    493             # to ParseExpectations so that ResultSummary() will get the correct
    494             # stats. So, we add in the subset of skipped files, and then
    495             # subtract them back out.
    496             self._test_files_list = files + skip_chunk_list
    497             self._test_files = set(self._test_files_list)
    498 
    499             self.parse_expectations()
    500 
    501             self._test_files = set(files)
    502             self._test_files_list = files
    503         else:
    504             skip_chunk = skipped
    505 
    506         result_summary = ResultSummary(self._expectations, self._test_files | skip_chunk)
     505        skipped = self._split_into_chunks_if_necessary(skipped)
     506
     507        result_summary = ResultSummary(self._expectations, self._test_files | skipped)
    507508        self._print_expected_results_of_type(result_summary, test_expectations.PASS, "passes")
    508509        self._print_expected_results_of_type(result_summary, test_expectations.FAIL, "failures")
     
    511512
    512513        if self._options.force:
    513             self._printer.print_expected('Running all tests, including '
    514                                          'skips (--force)')
     514            self._printer.print_expected('Running all tests, including skips (--force)')
    515515        else:
    516516            # Note that we don't actually run the skipped tests (they were
    517517            # subtracted out of self._test_files, above), but we stub out the
    518518            # results here so the statistics can remain accurate.
    519             for test in skip_chunk:
     519            for test in skipped:
    520520                result = test_results.TestResult(test)
    521521                result.type = test_expectations.SKIP
     
    874874          The number of unexpected results (0 == success)
    875875        """
    876         # gather_test_files() must have been called first to initialize us.
     876        # collect_tests() must have been called first to initialize us.
    877877        # If we didn't find any files to test, we've errored out already in
    878878        # prepare_lists_and_print_output().
Note: See TracChangeset for help on using the changeset viewer.