Commit 7557be5a authored by Michal Majewski's avatar Michal Majewski Committed by Commit Bot

Reland "[test] Move timeout control to timeout processor"

This is a reland of 4de2be99.

Original change's description:
> [test] Move timeout control to timeout processor
> 
> Bug: v8:6917
> Change-Id: I03be38be952f0d59eb20fa98102ef09ca795de40
> Reviewed-on: https://chromium-review.googlesource.com/883446
> Commit-Queue: Michał Majewski <majeski@google.com>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#50848}

Bug: v8:6917
Change-Id: I52798af84991d4815910e9da5f4837329cdb3c96
Reviewed-on: https://chromium-review.googlesource.com/885765Reviewed-by: 's avatarMichael Achenbach <machenbach@chromium.org>
Commit-Queue: Michał Majewski <majeski@google.com>
Cr-Commit-Position: refs/heads/master@{#50870}
parent 3857b44e
......@@ -24,6 +24,7 @@ from testrunner.testproc.filter import StatusFileFilterProc, NameFilterProc
from testrunner.testproc.loader import LoadProc
from testrunner.testproc.progress import ResultsTracker, TestsCounter
from testrunner.testproc.rerun import RerunProc
from testrunner.testproc.timeout import TimeoutProc
DEFAULT_SUITES = ["mjsunit", "webkit", "benchmarks"]
......@@ -98,10 +99,11 @@ class NumFuzzer(base_runner.BaseTestRunner):
"between deopt points")
parser.add_option("--tests-count", default=5, type="int",
help="Number of tests to generate from each base test")
help="Number of tests to generate from each base test. "
"Can be combined with --total-timeout-sec with "
"value 0 to provide infinite number of subtests.")
parser.add_option("--total-timeout-sec", default=0, type="int",
help="How long should fuzzer run. It overrides "
"--tests-count")
help="How long should fuzzer run")
# Combine multiple tests
parser.add_option("--combine-tests", default=False, action="store_true",
......@@ -169,6 +171,7 @@ class NumFuzzer(base_runner.BaseTestRunner):
fuzzer_proc,
] + indicators + [
results,
self._create_timeout_proc(options),
self._create_rerun_proc(options),
execproc,
]
......@@ -276,6 +279,11 @@ class NumFuzzer(base_runner.BaseTestRunner):
add('deopt', options.stress_deopt, options.stress_deopt_min)
return fuzzers
def _create_timeout_proc(self, options):
if not options.total_timeout_sec:
return None
return TimeoutProc(options.total_timeout_sec)
def _create_rerun_proc(self, options):
if not options.rerun_failures_count:
return None
......
......@@ -42,6 +42,7 @@ class TestProc(object):
def __init__(self):
self._prev_proc = None
self._next_proc = None
self._stopped = False
self._requirement = DROP_RESULT
self._prev_requirement = None
self._reduce_result = lambda result: result
......@@ -92,6 +93,15 @@ class TestProc(object):
if self._prev_proc:
self._prev_proc.heartbeat()
def stop(self):
self._stopped = True
if self._prev_proc:
self._prev_proc.stop()
@property
def is_stopped(self):
return self._stopped
### Communication
def _send_test(self, test):
......
......@@ -65,17 +65,14 @@ class FuzzerProc(base.TestProcProducer):
self._disable_analysis = disable_analysis
self._gens = {}
self._start_time = None
self._stop = False
def setup(self, requirement=base.DROP_RESULT):
# Fuzzer is optimized to not store the results
assert requirement == base.DROP_RESULT
super(FuzzerProc, self).setup(requirement)
def _next_test(self, test):
if not self._start_time:
self._start_time = time.time()
if self.is_stopped:
return
analysis_subtest = self._create_analysis_subtest(test)
if analysis_subtest:
......@@ -100,11 +97,6 @@ class FuzzerProc(base.TestProcProducer):
def _result_for(self, test, subtest, result):
if self._fuzz_duration_sec and not self._stop:
if int(time.time() - self._start_time) > self._fuzz_duration_sec:
print '>>> Stopping fuzzing'
self._stop = True
if not self._disable_analysis:
if result is not None:
# Analysis phase, for fuzzing we drop the result.
......@@ -138,7 +130,7 @@ class FuzzerProc(base.TestProcProducer):
return
i = 0
while (self._fuzz_duration_sec and not self._stop) or i < self._count:
while not self._count or i < self._count:
main_index = self._rng.choice(indexes)
_, main_gen = gens[main_index]
......@@ -155,7 +147,7 @@ class FuzzerProc(base.TestProcProducer):
i += 1
def _try_send_next_test(self, test):
if not self._stop:
if not self.is_stopped:
for subtest in self._gens[test.procid]:
self._send_test(subtest)
return
......
# 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 time
from . import base
# TODO(majeski): Signal handler
class TimeoutProc(base.TestProcObserver):
def __init__(self, duration_sec):
super(TimeoutProc, self).__init__()
self._duration_sec = duration_sec
self._start = time.time()
def _on_next_test(self, test):
self._on_event()
def _on_result_for(self, test, result):
self._on_event()
def _on_event(self):
if not self.is_stopped:
if time.time() - self._start > self._duration_sec:
self.stop()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment