Add test_mapping_config to update_crate_tests
Adds support for configuring TEST_MAPPING output in
update_crate_tests.py by defining a test_mapping_config.json.
The initial option that can be set is whether a test should be a
postsubmit test instead of a presubmit test.
Bug: 229727993
Test: update_crate_tests.py with test_mapping_config.json produces
postsubmit tests
Change-Id: I2f5a336c1af12630cc5df9d2c32ab63ac6099af8
This commit is contained in:
@@ -25,6 +25,15 @@ argument is provided, it assumes the crate is the current directory.
|
|||||||
$ update_crate_tests.py $ANDROID_BUILD_TOP/external/rust/crates/libc
|
$ update_crate_tests.py $ANDROID_BUILD_TOP/external/rust/crates/libc
|
||||||
|
|
||||||
This script is automatically called by external_updater.
|
This script is automatically called by external_updater.
|
||||||
|
|
||||||
|
A test_mapping_config.json file can be defined in the project directory to
|
||||||
|
configure the generated TEST_MAPPING file, for example:
|
||||||
|
|
||||||
|
{
|
||||||
|
// Run tests in postsubmit instead of presubmit.
|
||||||
|
"postsubmit_tests":["foo"]
|
||||||
|
}
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
@@ -49,7 +58,8 @@ TEST_OPTIONS = {
|
|||||||
# "presubmit-rust" runs arm64 device tests on physical devices.
|
# "presubmit-rust" runs arm64 device tests on physical devices.
|
||||||
TEST_GROUPS = [
|
TEST_GROUPS = [
|
||||||
"presubmit",
|
"presubmit",
|
||||||
"presubmit-rust"
|
"presubmit-rust",
|
||||||
|
"postsubmit",
|
||||||
]
|
]
|
||||||
|
|
||||||
# Excluded tests. These tests will be ignored by this script.
|
# Excluded tests. These tests will be ignored by this script.
|
||||||
@@ -269,16 +279,27 @@ class TestMapping(object):
|
|||||||
def tests_dirs_to_mapping(self, tests, dirs):
|
def tests_dirs_to_mapping(self, tests, dirs):
|
||||||
"""Translate the test list into a dictionary."""
|
"""Translate the test list into a dictionary."""
|
||||||
test_mapping = {"imports": []}
|
test_mapping = {"imports": []}
|
||||||
|
config = None
|
||||||
|
if os.path.isfile(os.path.join(self.package.dir, "test_mapping_config.json")):
|
||||||
|
with open(os.path.join(self.package.dir, "test_mapping_config.json"), 'r') as fd:
|
||||||
|
config = json.load(fd)
|
||||||
|
|
||||||
for test_group in TEST_GROUPS:
|
for test_group in TEST_GROUPS:
|
||||||
test_mapping[test_group] = []
|
test_mapping[test_group] = []
|
||||||
for test in tests:
|
for test in tests:
|
||||||
if test in TEST_EXCLUDE:
|
if test in TEST_EXCLUDE:
|
||||||
continue
|
continue
|
||||||
|
if config and 'postsubmit_tests' in config:
|
||||||
|
if test in config['postsubmit_tests'] and 'postsubmit' not in test_group:
|
||||||
|
continue
|
||||||
|
if test not in config['postsubmit_tests'] and 'postsubmit' in test_group:
|
||||||
|
continue
|
||||||
if test in TEST_OPTIONS:
|
if test in TEST_OPTIONS:
|
||||||
test_mapping[test_group].append({"name": test, "options": TEST_OPTIONS[test]})
|
test_mapping[test_group].append({"name": test, "options": TEST_OPTIONS[test]})
|
||||||
else:
|
else:
|
||||||
test_mapping[test_group].append({"name": test})
|
test_mapping[test_group].append({"name": test})
|
||||||
test_mapping[test_group] = sorted(test_mapping[test_group], key=lambda t: t["name"])
|
test_mapping[test_group] = sorted(test_mapping[test_group], key=lambda t: t["name"])
|
||||||
|
|
||||||
for dir in dirs:
|
for dir in dirs:
|
||||||
test_mapping["imports"].append({"path": dir})
|
test_mapping["imports"].append({"path": dir})
|
||||||
test_mapping["imports"] = sorted(test_mapping["imports"], key=lambda t: t["path"])
|
test_mapping["imports"] = sorted(test_mapping["imports"], key=lambda t: t["path"])
|
||||||
@@ -331,6 +352,7 @@ def main():
|
|||||||
subprocess.check_output(['repo', 'start',
|
subprocess.check_output(['repo', 'start',
|
||||||
'tmp_auto_test_mapping', '.'])
|
'tmp_auto_test_mapping', '.'])
|
||||||
subprocess.check_output(['git', 'add', 'TEST_MAPPING'])
|
subprocess.check_output(['git', 'add', 'TEST_MAPPING'])
|
||||||
|
subprocess.check_output(['git', 'add', 'test_mapping_config.json'])
|
||||||
subprocess.check_output(['git', 'commit', '-m',
|
subprocess.check_output(['git', 'commit', '-m',
|
||||||
'Update TEST_MAPPING\n\nTest: None'])
|
'Update TEST_MAPPING\n\nTest: None'])
|
||||||
if args.push_change and (changed or untracked):
|
if args.push_change and (changed or untracked):
|
||||||
|
|||||||
Reference in New Issue
Block a user