[ShadowRealm] Look for importValue("path/to/file" patterns for test sync

ShadowRealm.prototype.importValue dynamically imports other files, so
the testing infrastructure need to look for these calls to gather files
to push to e.g. test devices.

The reason to do this over explicit Resources: comment lines is to also
cover test262.

Bug: v8:12829
Cq-Include-Trybots: luci.v8.try:v8_android_arm64_n5x_rel_ng
Change-Id: I6a06933d5da849157b2c7d5fa6b7b98d39f7d39f
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3606391
Reviewed-by: Michael Achenbach <machenbach@chromium.org>
Commit-Queue: Shu-yu Guo <syg@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80189}
This commit is contained in:
Shu-yu Guo 2022-04-26 08:03:00 -07:00 committed by V8 LUCI CQ
parent 4ff098851a
commit ef82f4ddea

View File

@ -63,6 +63,10 @@ MODULE_FROM_RESOURCES_PATTERN = re.compile(
MODULE_IMPORT_RESOURCES_PATTERN = re.compile(
r"import\s*\(?['\"]([^'\"]+)['\"]",
re.MULTILINE | re.DOTALL)
# Pattern to detect files to push on Android for expressions like:
# shadowRealm.importValue("path/to/file.js", "obj")
SHADOWREALM_IMPORTVALUE_RESOURCES_PATTERN = re.compile(
r"(?:importValue)\((?:'|\")([^'\"]+)(?:'|\")", re.MULTILINE | re.DOTALL)
# Pattern to detect and strip test262 frontmatter from tests to prevent false
# positives for MODULE_RESOURCES_PATTERN above.
TEST262_FRONTMATTER_PATTERN = re.compile(r"/\*---.*?---\*/", re.DOTALL)
@ -208,12 +212,13 @@ class TestCase(object):
def check_flags(incompatible_flags, actual_flags, rule):
for incompatible_flag in incompatible_flags:
if has_flag(incompatible_flag, actual_flags):
self._statusfile_outcomes = outproc.OUTCOMES_FAIL
self._expected_outcomes = outproc.OUTCOMES_FAIL
self.expected_failure_reason = ("Rule " + rule + " in " +
"tools/testrunner/local/variants.py expected a flag " +
"contradiction error with " + incompatible_flag + ".")
if has_flag(incompatible_flag, actual_flags):
self._statusfile_outcomes = outproc.OUTCOMES_FAIL
self._expected_outcomes = outproc.OUTCOMES_FAIL
self.expected_failure_reason = (
"Rule " + rule + " in " +
"tools/testrunner/local/variants.py expected a flag " +
"contradiction error with " + incompatible_flag + ".")
if not self._checked_flag_contradictions:
self._checked_flag_contradictions = True
@ -241,14 +246,16 @@ class TestCase(object):
# incompatible with the build.
for variable, incompatible_flags in INCOMPATIBLE_FLAGS_PER_BUILD_VARIABLE.items():
if self.suite.statusfile.variables[variable]:
check_flags(incompatible_flags, file_specific_flags,
"INCOMPATIBLE_FLAGS_PER_BUILD_VARIABLE[\""+variable+"\"]")
check_flags(
incompatible_flags, file_specific_flags,
"INCOMPATIBLE_FLAGS_PER_BUILD_VARIABLE[\"" + variable + "\"]")
# Contradiction: flags passed through --extra-flags are incompatible.
for extra_flag, incompatible_flags in INCOMPATIBLE_FLAGS_PER_EXTRA_FLAG.items():
if has_flag(extra_flag, extra_flags):
check_flags(incompatible_flags, file_specific_flags,
"INCOMPATIBLE_FLAGS_PER_EXTRA_FLAG[\""+extra_flag+"\"]")
check_flags(
incompatible_flags, file_specific_flags,
"INCOMPATIBLE_FLAGS_PER_EXTRA_FLAG[\"" + extra_flag + "\"]")
return self._expected_outcomes
@property
@ -276,8 +283,8 @@ class TestCase(object):
@property
def is_fail(self):
return (statusfile.FAIL in self._statusfile_outcomes and
statusfile.PASS not in self._statusfile_outcomes)
return (statusfile.FAIL in self._statusfile_outcomes and
statusfile.PASS not in self._statusfile_outcomes)
@property
def only_standard_variant(self):
@ -476,6 +483,8 @@ class D8TestCase(TestCase):
add_import_path(match.group(1))
for match in MODULE_IMPORT_RESOURCES_PATTERN.finditer(source):
add_import_path(match.group(1))
for match in SHADOWREALM_IMPORTVALUE_RESOURCES_PATTERN.finditer(source):
add_import_path(match.group(1))
return result
def _get_resources(self):