update_crate_tests.py: allow excluding tests by name or path

The aidl tests and ChromeOS tests are not intended to be run in
presubmit, so exclude them.

Test: run cargo2android in external/rust/crates/libc.
Change-Id: I1ed92ed6e88886e3fea38612325ce5349db0fb69
This commit is contained in:
Jeff Vander Stoep
2021-01-24 20:50:26 +01:00
parent cec8bac2cb
commit 0b0e24f201

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):