File: rerun.py

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (66 lines) | stat: -rw-r--r-- 2,079 bytes parent folder | download | duplicates (14)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Copyright 2018 the V8 project authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import collections

from . import base
from .result import RerunResult


class RerunProc(base.TestProcProducer):
  @staticmethod
  def create(options):
    if not options.rerun_failures_count:
      return None
    return RerunProc(options.rerun_failures_count,
                     options.rerun_failures_max)

  def __init__(self, rerun_max, rerun_max_total=None):
    super(RerunProc, self).__init__('Rerun')
    self._requirement = base.DROP_OUTPUT

    self._rerun = {}
    self._results = collections.defaultdict(list)
    self._rerun_max = rerun_max
    self._rerun_total_left = rerun_max_total

  def _next_test(self, test):
    return self._send_next_subtest(test)

  def _result_for(self, test, subtest, result):
    # First result
    if subtest.procid[-2:] == '-1':
      # Passed, no reruns
      if not result.has_unexpected_output:
        self._send_result(test, result)
        return

      self._rerun[test.procid] = 0

    results = self._results[test.procid]
    results.append(result)

    if not self.is_stopped and self._needs_rerun(test, result):
      self._rerun[test.procid] += 1
      if self._rerun_total_left is not None:
        self._rerun_total_left -= 1
      self._send_next_subtest(test, self._rerun[test.procid])
    else:
      result = RerunResult.create(results)
      self._finalize_test(test)
      self._send_result(test, result)

  def _needs_rerun(self, test, result):
    # TODO(majeski): Limit reruns count for slow tests.
    return ((self._rerun_total_left is None or self._rerun_total_left > 0) and
            self._rerun[test.procid] < self._rerun_max and
            result.has_unexpected_output)

  def _send_next_subtest(self, test, run=0):
    subtest = test.create_subtest(self, str(run + 1), keep_output=(run != 0))
    return self._send_test(subtest)

  def _finalize_test(self, test):
    del self._rerun[test.procid]
    del self._results[test.procid]