sanitycheck: fix counting when using --test option

When running 1 specific test, counting was off. Combine functions adding
tests into one and optimize filtering.

Fixes #22270

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
Anas Nashif 2020-03-10 19:38:02 -04:00
parent 551601ea27
commit 49f6d5a6c6

View file

@ -2558,7 +2558,7 @@ class TestSuite:
return toolchain
def add_testcases(self):
def add_testcases(self, testcase_filter=[]):
for root in self.roots:
root = os.path.abspath(root)
@ -2577,14 +2577,12 @@ class TestSuite:
dirnames[:] = []
tc_path = os.path.join(dirpath, filename)
self.add_testcase(tc_path, root)
def add_testcase(self, tc_data_file, root):
try:
parsed_data = SanityConfigParser(tc_data_file, self.tc_schema)
parsed_data = SanityConfigParser(tc_path, self.tc_schema)
parsed_data.load()
tc_path = os.path.dirname(tc_data_file)
tc_path = os.path.dirname(tc_path)
workdir = os.path.relpath(tc_path, root)
for name in parsed_data.tests.keys():
@ -2594,7 +2592,7 @@ class TestSuite:
tc_dict = parsed_data.get_test(name, testcase_valid_keys)
tc.source_dir = tc_path
tc.yamlfile = tc_data_file
tc.yamlfile = tc_path
tc.id = name
tc.type = tc_dict["type"]
@ -2622,15 +2620,16 @@ class TestSuite:
tc.parse_subcases(tc_path)
if tc.name:
if testcase_filter:
if tc.name and tc.name in testcase_filter:
self.testcases[tc.name] = tc
else:
self.testcases[tc.name] = tc
except Exception as e:
logger.error("%s: can't load (skipping): %s" % (tc_data_file, e))
logger.error("%s: can't load (skipping): %s" % (tc_path, e))
self.load_errors += 1
return False
return True
def get_platform(self, name):
selected_platform = None
@ -4109,7 +4108,12 @@ def main():
suite.jobs = multiprocessing.cpu_count()
logger.info("JOBS: %d" % suite.jobs)
suite.add_testcases()
run_individual_tests = []
if options.test:
run_individual_tests = options.test
suite.add_testcases(testcase_filter=run_individual_tests)
suite.add_configurations()
if options.device_testing:
@ -4149,11 +4153,6 @@ def main():
export_tests(options.export_tests, tests)
return
run_individual_tests = []
if options.test:
run_individual_tests = options.test
if options.list_tests or options.test_tree or options.list_test_duplicates or options.sub_test:
cnt = 0
all_tests = suite.get_all_tests()