diff options
| -rwxr-xr-x | test/utils/regen-test-files | 164 |
1 files changed, 94 insertions, 70 deletions
diff --git a/test/utils/regen-test-files b/test/utils/regen-test-files index 83d54410e6..6d33ac5ee8 100755 --- a/test/utils/regen-test-files +++ b/test/utils/regen-test-files @@ -382,6 +382,69 @@ failing_tests_excluded_from_mainline_presubmits = ( def is_checker_test(run_test): return re.match("^[0-9]+-checker-", run_test) +def gen_mts_test_list_file(tests, test_list_file, copyright_year, configuration_description, + tests_description, comments = []): + """Generate an ART MTS test list file.""" + root = xml.dom.minidom.Document() + + advisory_header = root.createComment(f" {ADVISORY} ") + root.appendChild(advisory_header) + copyright_header = root.createComment(copyright_header_text(copyright_year)) + root.appendChild(copyright_header) + + configuration = root.createElement("configuration") + root.appendChild(configuration) + configuration.setAttribute("description", configuration_description) + + # Test declarations. + # ------------------ + + def append_test_declaration(test): + option = root.createElement("option") + option.setAttribute("name", "compatibility:include-filter") + option.setAttribute("value", test) + configuration.appendChild(option) + + test_declarations_comments = [tests_description + "."] + test_declarations_comments.extend(comments) + for c in test_declarations_comments: + xml_comment = root.createComment(f" {c} ") + configuration.appendChild(xml_comment) + for t in tests: + append_test_declaration(t) + + # `MainlineTestModuleController` configurations. + # ---------------------------------------------- + + def append_module_controller_configuration(test): + option = root.createElement("option") + option.setAttribute("name", "compatibility:module-arg") + option.setAttribute("value", f"{test}:enable:true") + configuration.appendChild(option) + + module_controller_configuration_comments = [ + f"Enable MainlineTestModuleController for {tests_description}."] + module_controller_configuration_comments.extend(comments) + for c in module_controller_configuration_comments: + xml_comment = root.createComment(f" {c} ") + configuration.appendChild(xml_comment) + for t in tests: + append_module_controller_configuration(t) + for t in tests: + if t in ["CtsLibcoreTestCases", "CtsLibcoreOjTestCases"]: + xml_comment = root.createComment( + " core-test-mode=mts tells ExpectationBasedFilter to exclude @NonMts Tests ") + configuration.appendChild(xml_comment) + option = root.createElement("option") + option.setAttribute("name", "compatibility:module-arg") + option.setAttribute("value", f"{t}:instrumentation-arg:core-test-mode:=mts") + configuration.appendChild(option) + + xml_str = root.toprettyxml(indent = XML_INDENT, encoding = "utf-8") + + with open(test_list_file, "wb") as f: + logging.debug(f"Writing `{test_list_file}`.") + f.write(xml_str) class Generator: def __init__(self, top_dir): @@ -818,17 +881,19 @@ class Generator: f.write(test_mapping_contents) f.write("\n") - def create_mts_test_shard(self, description, tests, shard_num, copyright_year, comments = []): + def create_mts_test_shard(self, tests_description, tests, shard_num, copyright_year, + comments = []): """Factory method instantiating an `MtsTestShard`.""" - return self.MtsTestShard(self.mts_config_dir, - description, tests, shard_num, copyright_year, comments) + return self.MtsTestShard(self.mts_config_dir, tests_description, tests, shard_num, + copyright_year, comments) class MtsTestShard: """Class encapsulating data and generation logic for an ART MTS test shard.""" - def __init__(self, mts_config_dir, description, tests, shard_num, copyright_year, comments): + def __init__(self, mts_config_dir, tests_description, tests, shard_num, copyright_year, + comments): self.mts_config_dir = mts_config_dir - self.description = description + self.tests_description = tests_description self.tests = tests self.shard_num = shard_num self.copyright_year = copyright_year @@ -887,70 +952,11 @@ class Generator: def regen_test_list_file(self): """Regenerate ART MTS test list file (`mts-art-tests-list-user-shard-<shard_num>.xml`).""" - root = xml.dom.minidom.Document() - - advisory_header = root.createComment(f" {ADVISORY} ") - root.appendChild(advisory_header) - copyright_header = root.createComment(copyright_header_text(self.copyright_year)) - root.appendChild(copyright_header) - - configuration = root.createElement("configuration") - root.appendChild(configuration) - configuration.setAttribute( - "description", - f"List of ART MTS tests that do not need root access (shard {self.shard_id()})" - ) - - # Test declarations. - # ------------------ - - def append_test_declaration(test): - option = root.createElement("option") - option.setAttribute("name", "compatibility:include-filter") - option.setAttribute("value", test) - configuration.appendChild(option) - - test_declarations_comments = [self.description + "."] - test_declarations_comments.extend(self.comments) - for c in test_declarations_comments: - xml_comment = root.createComment(f" {c} ") - configuration.appendChild(xml_comment) - for t in self.tests: - append_test_declaration(t) - - # `MainlineTestModuleController` configurations. - # ---------------------------------------------- - - def append_module_controller_configuration(test): - option = root.createElement("option") - option.setAttribute("name", "compatibility:module-arg") - option.setAttribute("value", f"{test}:enable:true") - configuration.appendChild(option) - - module_controller_configuration_comments = [ - f"Enable MainlineTestModuleController for {self.description}."] - module_controller_configuration_comments.extend(self.comments) - for c in module_controller_configuration_comments: - xml_comment = root.createComment(f" {c} ") - configuration.appendChild(xml_comment) - for t in self.tests: - append_module_controller_configuration(t) - for t in self.tests: - if t in ["CtsLibcoreTestCases", "CtsLibcoreOjTestCases"]: - xml_comment = root.createComment( - " core-test-mode=mts tells ExpectationBasedFilter to exclude @NonMts Tests ") - configuration.appendChild(xml_comment) - option = root.createElement("option") - option.setAttribute("name", "compatibility:module-arg") - option.setAttribute("value", f"{t}:instrumentation-arg:core-test-mode:=mts") - configuration.appendChild(option) - - xml_str = root.toprettyxml(indent = XML_INDENT, encoding = "utf-8") - + configuration_description = \ + f"List of ART MTS tests that do not need root access (shard {self.shard_id()})" test_list_file = os.path.join(self.mts_config_dir, self.test_list_name() + ".xml") - with open(test_list_file, "wb") as f: - logging.debug(f"Writing `{test_list_file}`.") - f.write(xml_str) + gen_mts_test_list_file(self.tests, test_list_file, self.copyright_year, + configuration_description, self.tests_description, self.comments) def regen_mts_art_tests_list_user_file(self, num_mts_art_run_test_shards): """Regenerate ART MTS test list file (`mts-art-tests-list-user.xml`).""" @@ -1049,8 +1055,6 @@ class Generator: mts_test_shards.append(other_cts_libcore_tests_shard) # ART gtests shard. - # TODO: Also handle the case of gtests requiring root access to the device - # (`art_gtest_eng_only_module_names`). art_gtests_shard_num = len(mts_test_shards) art_gtests_shard_tests = art_gtest_mts_user_module_names art_gtests_shard = self.create_mts_test_shard( @@ -1061,6 +1065,26 @@ class Generator: s.regen_test_plan_file() s.regen_test_list_file() + # Generate the MTS test list file of "eng-only" tests (tests that + # need root access to the device-under-test and are not part of + # "user" test plans). + # + # TODO(rpl): Use (and expand, if possible) `art_gtest_eng_only_module_names` + # here, instead of this minimal list of tests. + art_gtest_mts_eng_only_module_names = [ + "art_standalone_dexopt_chroot_setup_tests", + "libnativeloader_e2e_tests" + ] + # TODO(rpl): Refactor the MTS file generation logic to better + # handle the special case of "eng-only" tests, which do not play + # well with `MtsTestShard` at the moment). + eng_only_test_list_file = os.path.join(self.mts_config_dir, ENG_ONLY_TEST_LIST_NAME + ".xml") + gen_mts_test_list_file( + art_gtest_mts_eng_only_module_names, eng_only_test_list_file, + copyright_year = 2020, + configuration_description = "List of ART MTS tests that need root access.", + tests_description = "ART gtests") + self.regen_mts_art_tests_list_user_file(len(mts_test_shards)) def regen_test_files(self, regen_art_mts): |