Commit ef82f4dd authored by Shu-yu Guo's avatar Shu-yu Guo Committed by V8 LUCI CQ

[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/+/3606391Reviewed-by: 's avatarMichael Achenbach <machenbach@chromium.org>
Commit-Queue: Shu-yu Guo <syg@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80189}
parent 4ff09885
...@@ -63,6 +63,10 @@ MODULE_FROM_RESOURCES_PATTERN = re.compile( ...@@ -63,6 +63,10 @@ MODULE_FROM_RESOURCES_PATTERN = re.compile(
MODULE_IMPORT_RESOURCES_PATTERN = re.compile( MODULE_IMPORT_RESOURCES_PATTERN = re.compile(
r"import\s*\(?['\"]([^'\"]+)['\"]", r"import\s*\(?['\"]([^'\"]+)['\"]",
re.MULTILINE | re.DOTALL) 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 # Pattern to detect and strip test262 frontmatter from tests to prevent false
# positives for MODULE_RESOURCES_PATTERN above. # positives for MODULE_RESOURCES_PATTERN above.
TEST262_FRONTMATTER_PATTERN = re.compile(r"/\*---.*?---\*/", re.DOTALL) TEST262_FRONTMATTER_PATTERN = re.compile(r"/\*---.*?---\*/", re.DOTALL)
...@@ -208,12 +212,13 @@ class TestCase(object): ...@@ -208,12 +212,13 @@ class TestCase(object):
def check_flags(incompatible_flags, actual_flags, rule): def check_flags(incompatible_flags, actual_flags, rule):
for incompatible_flag in incompatible_flags: for incompatible_flag in incompatible_flags:
if has_flag(incompatible_flag, actual_flags): if has_flag(incompatible_flag, actual_flags):
self._statusfile_outcomes = outproc.OUTCOMES_FAIL self._statusfile_outcomes = outproc.OUTCOMES_FAIL
self._expected_outcomes = outproc.OUTCOMES_FAIL self._expected_outcomes = outproc.OUTCOMES_FAIL
self.expected_failure_reason = ("Rule " + rule + " in " + self.expected_failure_reason = (
"tools/testrunner/local/variants.py expected a flag " + "Rule " + rule + " in " +
"contradiction error with " + incompatible_flag + ".") "tools/testrunner/local/variants.py expected a flag " +
"contradiction error with " + incompatible_flag + ".")
if not self._checked_flag_contradictions: if not self._checked_flag_contradictions:
self._checked_flag_contradictions = True self._checked_flag_contradictions = True
...@@ -241,14 +246,16 @@ class TestCase(object): ...@@ -241,14 +246,16 @@ class TestCase(object):
# incompatible with the build. # incompatible with the build.
for variable, incompatible_flags in INCOMPATIBLE_FLAGS_PER_BUILD_VARIABLE.items(): for variable, incompatible_flags in INCOMPATIBLE_FLAGS_PER_BUILD_VARIABLE.items():
if self.suite.statusfile.variables[variable]: if self.suite.statusfile.variables[variable]:
check_flags(incompatible_flags, file_specific_flags, check_flags(
"INCOMPATIBLE_FLAGS_PER_BUILD_VARIABLE[\""+variable+"\"]") incompatible_flags, file_specific_flags,
"INCOMPATIBLE_FLAGS_PER_BUILD_VARIABLE[\"" + variable + "\"]")
# Contradiction: flags passed through --extra-flags are incompatible. # Contradiction: flags passed through --extra-flags are incompatible.
for extra_flag, incompatible_flags in INCOMPATIBLE_FLAGS_PER_EXTRA_FLAG.items(): for extra_flag, incompatible_flags in INCOMPATIBLE_FLAGS_PER_EXTRA_FLAG.items():
if has_flag(extra_flag, extra_flags): if has_flag(extra_flag, extra_flags):
check_flags(incompatible_flags, file_specific_flags, check_flags(
"INCOMPATIBLE_FLAGS_PER_EXTRA_FLAG[\""+extra_flag+"\"]") incompatible_flags, file_specific_flags,
"INCOMPATIBLE_FLAGS_PER_EXTRA_FLAG[\"" + extra_flag + "\"]")
return self._expected_outcomes return self._expected_outcomes
@property @property
...@@ -276,8 +283,8 @@ class TestCase(object): ...@@ -276,8 +283,8 @@ class TestCase(object):
@property @property
def is_fail(self): def is_fail(self):
return (statusfile.FAIL in self._statusfile_outcomes and return (statusfile.FAIL in self._statusfile_outcomes and
statusfile.PASS not in self._statusfile_outcomes) statusfile.PASS not in self._statusfile_outcomes)
@property @property
def only_standard_variant(self): def only_standard_variant(self):
...@@ -476,6 +483,8 @@ class D8TestCase(TestCase): ...@@ -476,6 +483,8 @@ class D8TestCase(TestCase):
add_import_path(match.group(1)) add_import_path(match.group(1))
for match in MODULE_IMPORT_RESOURCES_PATTERN.finditer(source): for match in MODULE_IMPORT_RESOURCES_PATTERN.finditer(source):
add_import_path(match.group(1)) add_import_path(match.group(1))
for match in SHADOWREALM_IMPORTVALUE_RESOURCES_PATTERN.finditer(source):
add_import_path(match.group(1))
return result return result
def _get_resources(self): def _get_resources(self):
......
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