1 # Copyright 2018 the V8 project authors. All rights reserved. 2 # Use of this source code is governed by a BSD-style license that can be 3 # found in the LICENSE file. 4 5 import collections 6 7 from . import base 8 from .result import RerunResult 9 10 11 class RerunProc(base.TestProcProducer): 12 def __init__(self, rerun_max, rerun_max_total=None): 13 super(RerunProc, self).__init__('Rerun') 14 self._requirement = base.DROP_OUTPUT 15 16 self._rerun = {} 17 self._results = collections.defaultdict(list) 18 self._rerun_max = rerun_max 19 self._rerun_total_left = rerun_max_total 20 21 def _next_test(self, test): 22 self._send_next_subtest(test) 23 24 def _result_for(self, test, subtest, result): 25 # First result 26 if subtest.procid[-2:] == '-1': 27 # Passed, no reruns 28 if not result.has_unexpected_output: 29 self._send_result(test, result) 30 return 31 32 self._rerun[test.procid] = 0 33 34 results = self._results[test.procid] 35 results.append(result) 36 37 if not self.is_stopped and self._needs_rerun(test, result): 38 self._rerun[test.procid] += 1 39 if self._rerun_total_left is not None: 40 self._rerun_total_left -= 1 41 self._send_next_subtest(test, self._rerun[test.procid]) 42 else: 43 result = RerunResult.create(results) 44 self._finalize_test(test) 45 self._send_result(test, result) 46 47 def _needs_rerun(self, test, result): 48 # TODO(majeski): Limit reruns count for slow tests. 49 return ((self._rerun_total_left is None or self._rerun_total_left > 0) and 50 self._rerun[test.procid] < self._rerun_max and 51 result.has_unexpected_output) 52 53 def _send_next_subtest(self, test, run=0): 54 subtest = self._create_subtest(test, str(run + 1), keep_output=(run != 0)) 55 self._send_test(subtest) 56 57 def _finalize_test(self, test): 58 del self._rerun[test.procid] 59 del self._results[test.procid] 60