Merge "update_crate_tests.py: allow excluding tests by name or path" am: 714b2f1fe4

Original change: https://android-review.googlesource.com/c/platform/development/+/1556124

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: Idebad39984a14b59c0f6fffaa647227ef26f4b1d
This commit is contained in:
Treehugger Robot
2021-01-26 11:37:55 +00:00
committed by Automerger Merge Worker

View File

@@ -20,6 +20,18 @@ import platform
import subprocess import subprocess
import sys import sys
test_options = {"ring_device_test_tests_digest_tests": [{"test-timeout": "600000"}]}
test_exclude = [
"aidl_test_rust_client",
"aidl_test_rust_service"
]
exclude_paths = [
"//external/adhd",
"//external/crosvm",
"//external/libchromeos-rs",
"//external/vm_tools"
]
class Env(object): class Env(object):
def __init__(self): def __init__(self):
try: try:
@@ -61,29 +73,30 @@ class Bazel(object):
# Return all reverse dependencies for a single module. # Return all reverse dependencies for a single module.
def query_rdeps(self, module): def query_rdeps(self, module):
with open(os.devnull, 'wb') as DEVNULL: with open(os.devnull, 'wb') as DEVNULL:
# Bazel queryview special-cases external/ so we need two
# separate queries to collect all the reverse dependencies.
cmd = (self.path() + " query --config=queryview \'rdeps(//..., " + cmd = (self.path() + " query --config=queryview \'rdeps(//..., " +
module + ")\' --output=label_kind") module + ")\' --output=label_kind")
out = (subprocess.check_output(cmd, shell=True, stderr=DEVNULL, text=True) out = (subprocess.check_output(cmd, shell=True, stderr=DEVNULL, text=True)
.strip().split("\n")) .strip().split("\n"))
cmd = (self.path() + " query --config=queryview --universe_scope=//external/... " +
"--order_output=no \"allrdeps(" + module + ")\" --output=label_kind")
out += (subprocess.check_output(cmd, shell=True, stderr=DEVNULL, text=True)
.strip().split("\n"))
if '' in out: if '' in out:
out.remove('') out.remove('')
return out return out
def exclude_module(self, module):
for path in exclude_paths:
if module.startswith(path):
return True
return False
# Return all reverse dependency tests for modules in this package. # Return all reverse dependency tests for modules in this package.
def query_rdep_tests(self, modules): def query_rdep_tests(self, modules):
rdep_tests = set() rdep_tests = set()
print("Querying tests that depend on this crate for TEST_MAPPING. This can take a couple of minutes...") print("Querying tests that depend on this crate for TEST_MAPPING. This can take a couple of minutes...")
for module in modules: for module in modules:
for rdep in self.query_rdeps(module): for rdep in self.query_rdeps(module):
rule_type, tmp, module = rdep.split(" ") rule_type, tmp, mod = rdep.split(" ")
if rule_type == "rust_test_" or rule_type == "rust_test": if rule_type == "rust_test_" or rule_type == "rust_test":
rdep_tests.add(module.split(":")[1].split("--")[0]) if self.exclude_module(mod) == False:
rdep_tests.add(mod.split(":")[1].split("--")[0])
return rdep_tests return rdep_tests
@@ -118,7 +131,12 @@ class TestMapping(object):
def tests_to_mapping(self, tests): def tests_to_mapping(self, tests):
test_mapping = {"presubmit": []} test_mapping = {"presubmit": []}
for test in tests: for test in tests:
test_mapping["presubmit"].append({"name": test}) if test in test_exclude:
continue
if test in test_options:
test_mapping["presubmit"].append({"name": test, "options": test_options[test]})
else:
test_mapping["presubmit"].append({"name": test})
return test_mapping return test_mapping
def write_test_mapping(self, test_mapping): def write_test_mapping(self, test_mapping):