Reviewers: Jakob, tandrii(chromium),
Message:
PTAL
Description:
[test] Refactoring - Use subject/observer pattern for progress indicators.
This should prevent bugs caused by missing super calls in
overloaded methods. The assumption is that methods of
different indicators are independent.
Please review this at https://codereview.chromium.org/1171943002/
Base URL: https://chromium.googlesource.com/v8/v8.git@master
Affected files (+27, -36 lines):
M tools/run-tests.py
M tools/testrunner/local/execution.py
M tools/testrunner/local/progress.py
Index: tools/run-tests.py
diff --git a/tools/run-tests.py b/tools/run-tests.py
index
78a7edc35e9614f291a43bc1a35ed5dd50551a29..d033f96bdd6e69138b695f05cb2ff98933eb5243
100755
--- a/tools/run-tests.py
+++ b/tools/run-tests.py
@@ -614,14 +614,14 @@ def Execute(arch, mode, args, options, suites,
workspace):
# Run the tests, either locally or distributed on the network.
start_time = time.time()
- progress_indicator = progress.PROGRESS_INDICATORS[options.progress]()
+ progress_indicator = progress.IndicatorNotifier()
+
progress_indicator.register(progress.PROGRESS_INDICATORS[options.progress]())
if options.junitout:
- progress_indicator = progress.JUnitTestProgressIndicator(
- progress_indicator, options.junitout, options.junittestsuite)
+ progress_indicator.register(progress.JUnitTestProgressIndicator(
+ options.junitout, options.junittestsuite))
if options.json_test_results:
- progress_indicator = progress.JsonTestProgressIndicator(
- progress_indicator, options.json_test_results, arch,
- MODES[mode]["execution_mode"])
+ progress_indicator.register(progress.JsonTestProgressIndicator(
+ options.json_test_results, arch, MODES[mode]["execution_mode"]))
run_networked = not options.no_network
if not run_networked:
Index: tools/testrunner/local/execution.py
diff --git a/tools/testrunner/local/execution.py
b/tools/testrunner/local/execution.py
index
2b2f876d24f06a421853e41d24f2ab1be6d5acca..fd23dff30798f4c30944cc314c9d2f23e0af206d
100644
--- a/tools/testrunner/local/execution.py
+++ b/tools/testrunner/local/execution.py
@@ -77,7 +77,7 @@ class Runner(object):
def _CommonInit(self, num_tests, progress_indicator, context):
self.indicator = progress_indicator
- progress_indicator.runner = self
+ progress_indicator.SetRunner(self)
self.context = context
self.succeeded = 0
self.total = num_tests
Index: tools/testrunner/local/progress.py
diff --git a/tools/testrunner/local/progress.py
b/tools/testrunner/local/progress.py
index
a9519e926d7552418e56aeaf2a7fb764e86bdfbb..9b03261233da07f28c65d4a479a40074fa76f8ed
100644
--- a/tools/testrunner/local/progress.py
+++ b/tools/testrunner/local/progress.py
@@ -49,10 +49,26 @@ def EscapeCommand(command):
return " ".join(parts)
+class IndicatorNotifier:
+ """Holds a list of progress indicators and notifies them all on
events."""
+ def __init__(self):
+ self.indicators = []
+
+ def register(self, indicator):
+ self.indicators.append(indicator)
+
+ def __getattr__(self, func_name):
+ """Generic event."""
+ def func(*args, **kwargs):
+ for indicator in self.indicators:
+ getattr(indicator, func_name)(*args, **kwargs)
+ return func
+
+
class ProgressIndicator(object):
- def __init__(self):
- self.runner = None
+ def SetRunner(self, runner):
+ self.runner = runner
def Starting(self):
pass
@@ -251,29 +267,19 @@ class
MonochromeProgressIndicator(CompactProgressIndicator):
class JUnitTestProgressIndicator(ProgressIndicator):
- def __init__(self, progress_indicator, junitout, junittestsuite):
- self.progress_indicator = progress_indicator
+ def __init__(self, junitout, junittestsuite):
self.outputter = junit_output.JUnitTestOutput(junittestsuite)
if junitout:
self.outfile = open(junitout, "w")
else:
self.outfile = sys.stdout
- def Starting(self):
- self.progress_indicator.runner = self.runner
- self.progress_indicator.Starting()
-
def Done(self):
- self.progress_indicator.Done()
self.outputter.FinishAndWrite(self.outfile)
if self.outfile != sys.stdout:
self.outfile.close()
- def AboutToRun(self, test):
- self.progress_indicator.AboutToRun(test)
-
def HasRun(self, test, has_unexpected_output):
- self.progress_indicator.HasRun(test, has_unexpected_output)
fail_text = ""
if has_unexpected_output:
stdout = test.output.stdout.strip()
@@ -292,25 +298,17 @@ class JUnitTestProgressIndicator(ProgressIndicator):
test.duration,
fail_text)
- def Heartbeat(self):
- self.progress_indicator.Heartbeat()
class JsonTestProgressIndicator(ProgressIndicator):
- def __init__(self, progress_indicator, json_test_results, arch, mode):
- self.progress_indicator = progress_indicator
+ def __init__(self, json_test_results, arch, mode):
self.json_test_results = json_test_results
self.arch = arch
self.mode = mode
self.results = []
self.tests = []
- def Starting(self):
- self.progress_indicator.runner = self.runner
- self.progress_indicator.Starting()
-
def Done(self):
- self.progress_indicator.Done()
complete_results = []
if os.path.exists(self.json_test_results):
with open(self.json_test_results, "r") as f:
@@ -340,11 +338,7 @@ class JsonTestProgressIndicator(ProgressIndicator):
with open(self.json_test_results, "w") as f:
f.write(json.dumps(complete_results))
- def AboutToRun(self, test):
- self.progress_indicator.AboutToRun(test)
-
def HasRun(self, test, has_unexpected_output):
- self.progress_indicator.HasRun(test, has_unexpected_output)
# Buffer all tests for sorting the durations in the end.
self.tests.append(test)
if not has_unexpected_output:
@@ -366,9 +360,6 @@ class JsonTestProgressIndicator(ProgressIndicator):
"duration": test.duration,
})
- def Heartbeat(self):
- self.progress_indicator.Heartbeat()
-
PROGRESS_INDICATORS = {
'verbose': VerboseProgressIndicator,
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.