Commit 0ecbda14 authored by Z Nguyen-Huu's avatar Z Nguyen-Huu Committed by Commit Bot

Introduce regenerate-expected-files for run-test

Example can be inspector tests.

Bug: v8:10264
Change-Id: I996bb68d0f36920568a04f93cd8c1256a4f41a96
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2070912
Commit-Queue: Z Nguyen-Huu <duongn@microsoft.com>
Reviewed-by: 's avatarMichael Achenbach <machenbach@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66572}
parent 0ba4c8d4
...@@ -62,7 +62,8 @@ class TestCase(testcase.TestCase): ...@@ -62,7 +62,8 @@ class TestCase(testcase.TestCase):
def output_proc(self): def output_proc(self):
return outproc.ExpectedOutProc( return outproc.ExpectedOutProc(
self.expected_outcomes, self.expected_outcomes,
os.path.join(self.suite.root, self.path) + EXPECTED_SUFFIX) os.path.join(self.suite.root, self.path) + EXPECTED_SUFFIX,
self.suite.test_config.regenerate_expected_files)
def GetSuite(*args, **kwargs): def GetSuite(*args, **kwargs):
......
...@@ -379,6 +379,8 @@ class BaseTestRunner(object): ...@@ -379,6 +379,8 @@ class BaseTestRunner(object):
help="Timeout for single test in seconds") help="Timeout for single test in seconds")
parser.add_option("-v", "--verbose", default=False, action="store_true", parser.add_option("-v", "--verbose", default=False, action="store_true",
help="Verbose output") help="Verbose output")
parser.add_option('--regenerate-expected-files', default=False, action='store_true',
help='Regenerate expected files')
# TODO(machenbach): Temporary options for rolling out new test runner # TODO(machenbach): Temporary options for rolling out new test runner
# features. # features.
...@@ -721,6 +723,7 @@ class BaseTestRunner(object): ...@@ -721,6 +723,7 @@ class BaseTestRunner(object):
shell_dir=self.outdir, shell_dir=self.outdir,
timeout=timeout, timeout=timeout,
verbose=options.verbose, verbose=options.verbose,
regenerate_expected_files=options.regenerate_expected_files,
) )
def _timeout_scalefactor(self, options): def _timeout_scalefactor(self, options):
......
...@@ -19,8 +19,13 @@ OUTCOMES_FAIL_OR_TIMEOUT = [statusfile.FAIL, statusfile.TIMEOUT] ...@@ -19,8 +19,13 @@ OUTCOMES_FAIL_OR_TIMEOUT = [statusfile.FAIL, statusfile.TIMEOUT]
class BaseOutProc(object): class BaseOutProc(object):
def process(self, output, reduction=None): def process(self, output, reduction=None):
has_unexpected_output = self.has_unexpected_output(output) has_unexpected_output = self.has_unexpected_output(output)
if has_unexpected_output:
self.regenerate_expected_files(output)
return self._create_result(has_unexpected_output, output, reduction) return self._create_result(has_unexpected_output, output, reduction)
def regenerate_expected_files(self, output):
return
def has_unexpected_output(self, output): def has_unexpected_output(self, output):
return self.get_outcome(output) not in self.expected_outcomes return self.get_outcome(output) not in self.expected_outcomes
...@@ -125,9 +130,11 @@ class ExpectedOutProc(OutProc): ...@@ -125,9 +130,11 @@ class ExpectedOutProc(OutProc):
"""Output processor that has is_failure_output depending on comparing the """Output processor that has is_failure_output depending on comparing the
output with the expected output. output with the expected output.
""" """
def __init__(self, expected_outcomes, expected_filename): def __init__(self, expected_outcomes, expected_filename,
regenerate_expected_files=False):
super(ExpectedOutProc, self).__init__(expected_outcomes) super(ExpectedOutProc, self).__init__(expected_outcomes)
self._expected_filename = expected_filename self._expected_filename = expected_filename
self._regenerate_expected_files = regenerate_expected_files
def _is_failure_output(self, output): def _is_failure_output(self, output):
with open(self._expected_filename, 'r') as f: with open(self._expected_filename, 'r') as f:
...@@ -143,6 +150,14 @@ class ExpectedOutProc(OutProc): ...@@ -143,6 +150,14 @@ class ExpectedOutProc(OutProc):
return True return True
return False return False
def regenerate_expected_files(self, output):
if not self._regenerate_expected_files:
return
lines = output.stdout.splitlines()
with open(self._expected_filename, 'w') as f:
for _, line in enumerate(lines):
f.write(line+'\n')
def _act_block_iterator(self, output): def _act_block_iterator(self, output):
"""Iterates over blocks of actual output lines.""" """Iterates over blocks of actual output lines."""
lines = output.stdout.splitlines() lines = output.stdout.splitlines()
......
...@@ -19,7 +19,8 @@ class TestConfig(object): ...@@ -19,7 +19,8 @@ class TestConfig(object):
run_skipped, run_skipped,
shell_dir, shell_dir,
timeout, timeout,
verbose): verbose,
regenerate_expected_files=False):
self.command_prefix = command_prefix self.command_prefix = command_prefix
self.extra_flags = extra_flags self.extra_flags = extra_flags
self.isolates = isolates self.isolates = isolates
...@@ -32,3 +33,4 @@ class TestConfig(object): ...@@ -32,3 +33,4 @@ class TestConfig(object):
self.shell_dir = shell_dir self.shell_dir = shell_dir
self.timeout = timeout self.timeout = timeout
self.verbose = verbose self.verbose = verbose
self.regenerate_expected_files = regenerate_expected_files
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