Merge changes from topic "rust-tests-and-mappings-refactor"
* changes: cargo2android: Add tests to both test groups Use TEST_MAPPING imports for third-party crate tests.
This commit is contained in:
@@ -32,6 +32,7 @@ import glob
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
@@ -44,6 +45,13 @@ TEST_OPTIONS = {
|
|||||||
"ring_test_src_lib": [{"test-timeout": "100000"}],
|
"ring_test_src_lib": [{"test-timeout": "100000"}],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Groups to add tests to. "presubmit" runs x86_64 device tests+host tests, and
|
||||||
|
# "presubmit-rust" runs arm64 device tests on physical devices.
|
||||||
|
TEST_GROUPS = [
|
||||||
|
"presubmit",
|
||||||
|
"presubmit-rust"
|
||||||
|
]
|
||||||
|
|
||||||
# Excluded tests. These tests will be ignored by this script.
|
# Excluded tests. These tests will be ignored by this script.
|
||||||
TEST_EXCLUDE = [
|
TEST_EXCLUDE = [
|
||||||
"aidl_test_rust_client",
|
"aidl_test_rust_client",
|
||||||
@@ -63,6 +71,9 @@ EXCLUDE_PATHS = [
|
|||||||
"//external/vm_tools"
|
"//external/vm_tools"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
LABEL_PAT = re.compile('^//(.*):.*$')
|
||||||
|
EXTERNAL_PAT = re.compile('^//external/rust/')
|
||||||
|
|
||||||
|
|
||||||
class UpdaterException(Exception):
|
class UpdaterException(Exception):
|
||||||
"""Exception generated by this script."""
|
"""Exception generated by this script."""
|
||||||
@@ -155,16 +166,25 @@ class Bazel(object):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def query_rdep_tests(self, modules):
|
def query_rdep_tests_dirs(self, modules, path):
|
||||||
"""Returns all reverse dependency tests for modules in this package."""
|
"""Returns all reverse dependency tests for modules in this package."""
|
||||||
rdep_tests = set()
|
rdep_tests = set()
|
||||||
|
rdep_dirs = set()
|
||||||
|
path_pat = re.compile("^/%s:.*$" % path)
|
||||||
for module in modules:
|
for module in modules:
|
||||||
for rdep in self.query_rdeps(module):
|
for rdep in self.query_rdeps(module):
|
||||||
rule_type, _, mod = rdep.split(" ")
|
rule_type, _, mod = rdep.split(" ")
|
||||||
if rule_type == "rust_test_" or rule_type == "rust_test":
|
if rule_type == "rust_test_" or rule_type == "rust_test":
|
||||||
if self.exclude_module(mod) == False:
|
if self.exclude_module(mod):
|
||||||
|
continue
|
||||||
|
path_match = path_pat.match(mod)
|
||||||
|
if path_match or not EXTERNAL_PAT.match(mod):
|
||||||
rdep_tests.add(mod.split(":")[1].split("--")[0])
|
rdep_tests.add(mod.split(":")[1].split("--")[0])
|
||||||
return rdep_tests
|
else:
|
||||||
|
label_match = LABEL_PAT.match(mod)
|
||||||
|
if label_match:
|
||||||
|
rdep_dirs.add(label_match.group(1))
|
||||||
|
return (rdep_tests, rdep_dirs)
|
||||||
|
|
||||||
|
|
||||||
class Package(object):
|
class Package(object):
|
||||||
@@ -174,6 +194,7 @@ class Package(object):
|
|||||||
dir: The absolute path to this package.
|
dir: The absolute path to this package.
|
||||||
dir_rel: The relative path to this package.
|
dir_rel: The relative path to this package.
|
||||||
rdep_tests: The list of computed reverse dependencies.
|
rdep_tests: The list of computed reverse dependencies.
|
||||||
|
rdep_dirs: The list of computed reverse dependency directories.
|
||||||
"""
|
"""
|
||||||
def __init__(self, path, env, bazel):
|
def __init__(self, path, env, bazel):
|
||||||
"""Constructor.
|
"""Constructor.
|
||||||
@@ -202,10 +223,10 @@ class Package(object):
|
|||||||
# Move to the package_directory.
|
# Move to the package_directory.
|
||||||
os.chdir(self.dir)
|
os.chdir(self.dir)
|
||||||
modules = bazel.query_modules(self.dir_rel)
|
modules = bazel.query_modules(self.dir_rel)
|
||||||
self.rdep_tests = bazel.query_rdep_tests(modules)
|
(self.rdep_tests, self.rdep_dirs) = bazel.query_rdep_tests_dirs(modules, self.dir_rel)
|
||||||
|
|
||||||
def get_rdep_tests(self):
|
def get_rdep_tests_dirs(self):
|
||||||
return self.rdep_tests
|
return (self.rdep_tests, self.rdep_dirs)
|
||||||
|
|
||||||
|
|
||||||
class TestMapping(object):
|
class TestMapping(object):
|
||||||
@@ -226,23 +247,31 @@ class TestMapping(object):
|
|||||||
|
|
||||||
def create(self):
|
def create(self):
|
||||||
"""Generates the TEST_MAPPING file."""
|
"""Generates the TEST_MAPPING file."""
|
||||||
tests = self.package.get_rdep_tests()
|
(tests, dirs) = self.package.get_rdep_tests_dirs()
|
||||||
if not bool(tests):
|
if not bool(tests) and not bool(dirs):
|
||||||
|
if os.path.isfile('TEST_MAPPING'):
|
||||||
|
os.remove('TEST_MAPPING')
|
||||||
return
|
return
|
||||||
test_mapping = self.tests_to_mapping(tests)
|
test_mapping = self.tests_dirs_to_mapping(tests, dirs)
|
||||||
self.write_test_mapping(test_mapping)
|
self.write_test_mapping(test_mapping)
|
||||||
|
|
||||||
def tests_to_mapping(self, tests):
|
def tests_dirs_to_mapping(self, tests, dirs):
|
||||||
"""Translate the test list into a dictionary."""
|
"""Translate the test list into a dictionary."""
|
||||||
test_mapping = {"presubmit": []}
|
test_mapping = {"imports": []}
|
||||||
for test in tests:
|
for test_group in TEST_GROUPS:
|
||||||
if test in TEST_EXCLUDE:
|
test_mapping[test_group] = []
|
||||||
continue
|
for test in tests:
|
||||||
if test in TEST_OPTIONS:
|
if test in TEST_EXCLUDE:
|
||||||
test_mapping["presubmit"].append({"name": test, "options": TEST_OPTIONS[test]})
|
continue
|
||||||
else:
|
if test in TEST_OPTIONS:
|
||||||
test_mapping["presubmit"].append({"name": test})
|
test_mapping[test_group].append({"name": test, "options": TEST_OPTIONS[test]})
|
||||||
test_mapping["presubmit"] = sorted(test_mapping["presubmit"], key=lambda t: t["name"])
|
else:
|
||||||
|
test_mapping[test_group].append({"name": test})
|
||||||
|
test_mapping[test_group] = sorted(test_mapping[test_group], key=lambda t: t["name"])
|
||||||
|
for dir in dirs:
|
||||||
|
test_mapping["imports"].append({"path": dir})
|
||||||
|
test_mapping["imports"] = sorted(test_mapping["imports"], key=lambda t: t["path"])
|
||||||
|
test_mapping = {section: entry for (section, entry) in test_mapping.items() if entry}
|
||||||
return test_mapping
|
return test_mapping
|
||||||
|
|
||||||
def write_test_mapping(self, test_mapping):
|
def write_test_mapping(self, test_mapping):
|
||||||
|
|||||||
Reference in New Issue
Block a user