Skip to content

Commit

Permalink
Add build-parameter test metadata to ART run-tests.
Browse files Browse the repository at this point in the history
For now, use these build parameters to determine whether to safely
ignore a test's `build.py` Python script while regenerating ART test
files.

Also remove the old logic checking the `build.py` Python script
(originally the `build` Bash script) directly.

Test: art/test/utils/regen-test-files
Bug: 147814778
Change-Id: I384258d3e1cd0d0a0589fe64b9c2bc1f599b1401
  • Loading branch information
roland-levillain committed Oct 29, 2022
1 parent 2847729 commit 3ed6b50
Show file tree
Hide file tree
Showing 27 changed files with 164 additions and 36 deletions.
5 changes: 5 additions & 0 deletions test/004-UnsafeTest/test-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"build-param": {
"jvm-supported": "false"
}
}
5 changes: 5 additions & 0 deletions test/030-bad-finalizer/test-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"build-param": {
"jvm-supported": "false"
}
}
5 changes: 5 additions & 0 deletions test/122-npe/test-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"build-param": {
"jvm-supported": "false"
}
}
5 changes: 5 additions & 0 deletions test/1336-short-finalizer-timeout/test-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"build-param": {
"jvm-supported": "false"
}
}
5 changes: 5 additions & 0 deletions test/1339-dead-reference-safe/test-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"build-param": {
"jvm-supported": "false"
}
}
6 changes: 6 additions & 0 deletions test/160-read-barrier-stress/test-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"build-param": {
"experimental": "var-handles",
"jvm-supported": "false"
}
}
5 changes: 5 additions & 0 deletions test/178-app-image-native-method/test-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"build-param": {
"jvm-supported": "false"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"build-param": {
"experimental": "var-handles"
}
}
5 changes: 5 additions & 0 deletions test/1983-structural-redefinition-failures/test-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"build-param": {
"experimental": "var-handles"
}
}
5 changes: 5 additions & 0 deletions test/2005-pause-all-redefine-multithreaded/test-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"build-param": {
"jvm-supported": "false"
}
}
5 changes: 5 additions & 0 deletions test/2040-huge-native-alloc/test-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"build-param": {
"jvm-supported": "false"
}
}
5 changes: 5 additions & 0 deletions test/2041-bad-cleaner/test-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"build-param": {
"jvm-supported": "false"
}
}
5 changes: 5 additions & 0 deletions test/2235-JdkUnsafeTest/test-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"build-param": {
"jvm-supported": "false"
}
}
5 changes: 5 additions & 0 deletions test/612-jit-dex-cache/test-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"build-param": {
"jvm-supported": "false"
}
}
5 changes: 5 additions & 0 deletions test/613-inlining-dex-cache/test-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"build-param": {
"jvm-supported": "false"
}
}
5 changes: 5 additions & 0 deletions test/676-resolve-field-type/test-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"build-param": {
"jvm-supported": "false"
}
}
5 changes: 5 additions & 0 deletions test/689-zygote-jit-deopt/test-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"build-param": {
"jvm-supported": "false"
}
}
5 changes: 5 additions & 0 deletions test/692-vdex-inmem-loader/test-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"build-param": {
"jvm-supported": "false"
}
}
5 changes: 5 additions & 0 deletions test/692-vdex-secondary-loader/test-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"build-param": {
"jvm-supported": "false"
}
}
5 changes: 5 additions & 0 deletions test/693-vdex-inmem-loader-evict/test-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"build-param": {
"jvm-supported": "false"
}
}
5 changes: 5 additions & 0 deletions test/710-varhandle-creation/test-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"build-param": {
"experimental": "var-handles"
}
}
5 changes: 5 additions & 0 deletions test/713-varhandle-invokers/test-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"build-param": {
"experimental": "var-handles"
}
}
5 changes: 5 additions & 0 deletions test/716-jli-jit-samples/test-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"build-param": {
"experimental": "var-handles"
}
}
5 changes: 5 additions & 0 deletions test/719-varhandle-concurrency/test-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"build-param": {
"experimental": "var-handles"
}
}
5 changes: 5 additions & 0 deletions test/811-checker-invoke-super-secondary/test-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"build-param": {
"jvm-supported": "false"
}
}
5 changes: 5 additions & 0 deletions test/831-unverified-bcp/test-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"build-param": {
"jvm-supported": "false"
}
}
69 changes: 33 additions & 36 deletions test/utils/regen-test-files
Original file line number Diff line number Diff line change
Expand Up @@ -319,36 +319,37 @@ class Generator:
for run_test in os.listdir(self.art_test_dir)
if re.match("^[0-9]{3,}-", run_test)])

# Read build file (Bash script) and return a canonized version of it
# (without comments, blank lines, "debugging" statements, etc.).
def canonize_build_script(self, build_file):

def is_comment(line):
return re.match("^\\s*#", line)

def is_blank(line):
return re.match("^\\s*$", line)

def is_import(line):
return re.match("^\\s*from .* import .*", line)

# Should `line` be kept in the canonized build script?
def keep_line(line):
return not (is_comment(line) or is_blank(line) or is_import(line))

with open(build_file, "r") as f:
lines = f.readlines()
return list(filter(keep_line, lines))

# Can the build script in `build_file` be safely ignored?
def can_ignore_build_script(self, build_file):
build_script = self.canonize_build_script(build_file)
if len(build_script) == 1:
if build_script[0] == 'build_run_test(experimental="var-handles")\n':
# Soong builds JARs with VarHandle support by default (i.e. by
# using an API level greater or equal to 28), so we can ignore
# build scripts that just request support for this feature.
return True
# Return the metadata of a test, if any.
def get_test_metadata(self, run_test):
run_test_path = os.path.join(self.art_test_dir, run_test)
metadata_file = os.path.join(run_test_path, "test-metadata.json")
metadata = {}
if os.path.exists(metadata_file):
with open(metadata_file, "r") as f:
try:
metadata = json.load(f)
except json.decoder.JSONDecodeError:
logging.error(f"Unable to parse test metadata file `{metadata_file}`")
raise
return metadata

# Can the build script of `run_test` be safely ignored?
def can_ignore_build_script(self, run_test):
# Check whether there are test metadata with build parameters
# enabling us to safely ignore the build script.
metadata = self.get_test_metadata(run_test)
build_param = metadata.get("build-param", {})
# Ignore build scripts that are just about preventing building for
# the JVM and/or using VarHandles (Soong builds JARs with
# VarHandle support by default (i.e. by using an API level greater
# or equal to 28), so we can ignore build scripts that just
# request support for this feature.)
experimental_var_handles = {"experimental": "var-handles"}
jvm_supported_false = {"jvm-supported": "false"}
if (build_param == experimental_var_handles or
build_param == jvm_supported_false or
build_param == experimental_var_handles | jvm_supported_false):
return True
return False

# Is building `run_test` supported?
Expand All @@ -362,7 +363,7 @@ class Generator:
os.path.isfile(os.path.join(run_test_path, "javac_wrapper.sh"))):
return False
if os.path.isfile(os.path.join(run_test_path, "build.py")):
if not self.can_ignore_build_script(os.path.join(run_test_path, "build.py")):
if not self.can_ignore_build_script(run_test):
return False
# Skip tests with sources outside the `src` directory.
for subdir in ["jasmin",
Expand Down Expand Up @@ -435,11 +436,7 @@ class Generator:
bp_file = os.path.join(run_test_path, "Android.bp")

# Optional test metadata (JSON file).
metadata_file = os.path.join(run_test_path, "test-metadata.json")
metadata = {}
if os.path.exists(metadata_file):
with open(metadata_file, "r") as f:
metadata = json.load(f)
metadata = self.get_test_metadata(run_test)

run_test_module_name = ART_RUN_TEST_MODULE_NAME_PREFIX + run_test

Expand Down

0 comments on commit 3ed6b50

Please sign in to comment.