v8/tools/testrunner/testproc/result.py
Liviu Rau b625371491 Reland "[resultdb] Add ResultDB indicator"
This is a reland of commit 237de893e1

We now guard against requests Python module not being available when running the testrunner. If preconditions (modules & luci context) are not met we no longer add ResultDBIndicator to the chain.

Original change's description:
> [resultdb] Add ResultDB indicator
>
> Adds a new indicator that will send every result to ResultDB (and ultimately in a bq table; to be configured later).
>
> If we are not running in a ResultDB context we introduce only a minimal overhead by exiting early from indicator.
>
> To test these changes in a luci context with ResultDB we activated resultdb feature flag via V8-Recipe-Flags. This feature got implemented in https://crrev.com/c/3925576 .
>
>
> V8-Recipe-Flags: resultdb
> Bug: v8:13316
> Change-Id: I5d98e8f27531b536686a8d63b993313b9d6f62c5
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3905385
> Commit-Queue: Liviu Rau <liviurau@google.com>
> Reviewed-by: Alexander Schulze <alexschulze@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#83672}

V8-Recipe-Flags: resultdb
Bug: v8:13316
Change-Id: I0bdfae13cc7f250c41a18f2d3a513a3bfc580f6d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3955263
Reviewed-by: Michael Achenbach <machenbach@chromium.org>
Commit-Queue: Liviu Rau <liviurau@google.com>
Cr-Commit-Position: refs/heads/main@{#83711}
2022-10-14 11:05:59 +00:00

125 lines
3.0 KiB
Python

# 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.
class ResultBase(object):
@property
def is_skipped(self):
return False
@property
def is_grouped(self):
return False
@property
def is_rerun(self):
return False
@property
def as_list(self):
return [self]
class Result(ResultBase):
"""Result created by the output processor."""
def __init__(self,
has_unexpected_output,
output,
cmd=None,
error_details=None):
self.has_unexpected_output = has_unexpected_output
self.output = output
self.cmd = cmd
self.error_details = error_details
def status(self):
if self.has_unexpected_output:
if not hasattr(self.output, "HasCrashed"):
raise Exception(type(self))
if self.output.HasCrashed():
return 'CRASH'
else:
return 'FAIL'
else:
return 'PASS'
class GroupedResult(ResultBase):
"""Result consisting of multiple results. It can be used by processors that
create multiple subtests for each test and want to pass all results back.
"""
@staticmethod
def create(results):
"""Create grouped result from the list of results. It filters out skipped
results. If all results are skipped results it returns skipped result.
Args:
results: list of pairs (test, result)
"""
results = [(t, r) for (t, r) in results if not r.is_skipped]
if not results:
return SKIPPED
return GroupedResult(results)
def __init__(self, results):
self.results = results
@property
def is_grouped(self):
return True
class SkippedResult(ResultBase):
"""Result without any meaningful value. Used primarily to inform the test
processor that it's test wasn't executed.
"""
@property
def is_skipped(self):
return True
SKIPPED = SkippedResult()
class RerunResult(Result):
"""Result generated from several reruns of the same test. It's a subclass of
Result since the result of rerun is result of the last run. In addition to
normal result it contains results of all reruns.
"""
@staticmethod
def create(results):
"""Create RerunResult based on list of results. List cannot be empty. If it
has only one element it's returned as a result.
"""
assert results
if len(results) == 1:
return results[0]
return RerunResult(results)
def __init__(self, results):
"""Has unexpected output and the output itself of the RerunResult equals to
the last result in the passed list.
"""
assert results
last = results[-1]
super(RerunResult, self).__init__(last.has_unexpected_output, last.output,
last.cmd)
self.results = results
@property
def is_rerun(self):
return True
@property
def as_list(self):
return self.results
def status(self):
return ' '.join(r.status() for r in self.results)