Let test driver export json results.

BUG=374134
LOG=n
R=jkummerow@chromium.org

Review URL: https://codereview.chromium.org/285193009

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@21358 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 62e09a35
...@@ -173,6 +173,8 @@ def BuildOptions(): ...@@ -173,6 +173,8 @@ def BuildOptions():
help=("Quick check mode (skip slow/flaky tests)")) help=("Quick check mode (skip slow/flaky tests)"))
result.add_option("--report", help="Print a summary of the tests to be run", result.add_option("--report", help="Print a summary of the tests to be run",
default=False, action="store_true") default=False, action="store_true")
result.add_option("--json-test-results",
help="Path to a file for storing json results.")
result.add_option("--shard-count", result.add_option("--shard-count",
help="Split testsuites into this number of shards", help="Split testsuites into this number of shards",
default=1, type="int") default=1, type="int")
...@@ -463,6 +465,9 @@ def Execute(arch, mode, args, options, suites, workspace): ...@@ -463,6 +465,9 @@ def Execute(arch, mode, args, options, suites, workspace):
if options.junitout: if options.junitout:
progress_indicator = progress.JUnitTestProgressIndicator( progress_indicator = progress.JUnitTestProgressIndicator(
progress_indicator, options.junitout, options.junittestsuite) progress_indicator, options.junitout, options.junittestsuite)
if options.json_test_results:
progress_indicator = progress.JsonTestProgressIndicator(
progress_indicator, options.json_test_results, arch, mode)
run_networked = not options.no_network run_networked = not options.no_network
if not run_networked: if not run_networked:
......
...@@ -26,11 +26,17 @@ ...@@ -26,11 +26,17 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import json
import os
import sys import sys
import time import time
from . import junit_output from . import junit_output
ABS_PATH_PREFIX = os.getcwd() + os.sep
def EscapeCommand(command): def EscapeCommand(command):
parts = [] parts = []
for part in command: for part in command:
...@@ -277,6 +283,55 @@ class JUnitTestProgressIndicator(ProgressIndicator): ...@@ -277,6 +283,55 @@ class JUnitTestProgressIndicator(ProgressIndicator):
fail_text) fail_text)
class JsonTestProgressIndicator(ProgressIndicator):
def __init__(self, progress_indicator, json_test_results, arch, mode):
self.progress_indicator = progress_indicator
self.json_test_results = json_test_results
self.arch = arch
self.mode = mode
self.results = []
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:
# Buildbot might start out with an empty file.
complete_results = json.loads(f.read() or "[]")
complete_results.append({
"arch": self.arch,
"mode": self.mode,
"results": self.results,
})
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)
if not has_unexpected_output:
return
self.results.append({
"name": test.GetLabel(),
"flags": test.flags,
"command": EscapeCommand(self.runner.GetCommand(test)).replace(
ABS_PATH_PREFIX, ""),
"stdout": test.output.stdout,
"stderr": test.output.stderr,
"exit_code": test.output.exit_code,
"result": "CRASH" if test.output.HasCrashed() else "FAIL",
})
PROGRESS_INDICATORS = { PROGRESS_INDICATORS = {
'verbose': VerboseProgressIndicator, 'verbose': VerboseProgressIndicator,
'dots': DotsProgressIndicator, 'dots': DotsProgressIndicator,
......
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