twister: improve handling of ELF file parsing

We have been dealing with missing and multiple binaries the same way and
both would result in a build error, which is not accurate. multiple
binaries in the build directory are fine, we just need to pick the right
one for parsing.

If we get no binaries, raise an exception and report failure, however,
if we have multiple binaries, filter intermediate artifacts out and
parse what remains.

qemu binaries generated after a run are also being filtered here. Those
are not build artificats and appear only after running in qemu. However
they have been causing issues on retries.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
Anas Nashif 2023-07-27 12:41:07 +00:00 committed by Carles Cufí
parent 250748bfe6
commit 3191d08130
2 changed files with 9 additions and 5 deletions

View file

@ -680,7 +680,8 @@ class ProjectBuilder(FilterBuilder):
yaml_testsuite_name = self.instance.testsuite.id
logger.debug(f"Determine test cases for test suite: {yaml_testsuite_name}")
elf = ELFFile(open(self.instance.get_elf_file(), "rb"))
elf_file = self.instance.get_elf_file()
elf = ELFFile(open(elf_file, "rb"))
logger.debug(f"Test instance {self.instance.name} already has {len(self.instance.testcases)} cases.")
new_ztest_unit_test_regex = re.compile(r"z_ztest_unit_test__([^\s]*)__([^\s]*)")
@ -702,6 +703,7 @@ class ProjectBuilder(FilterBuilder):
detected_cases.append(testcase_id)
if detected_cases:
logger.debug(f"{', '.join(detected_cases)} in {elf_file}")
self.instance.testcases.clear()
self.instance.testsuite.testcases.clear()

View file

@ -290,15 +290,17 @@ class TestInstance:
build_dir = self.build_dir
fns = glob.glob(os.path.join(build_dir, "zephyr", "*.elf"))
fns.extend(glob.glob(os.path.join(build_dir, "zephyr", "*.exe")))
fns.extend(glob.glob(os.path.join(build_dir, "testbinary")))
blocklist = [
'remapped', # used for xtensa plaforms
'zefi', # EFI for Zephyr
'_pre' ]
'qemu', # elf files generated after running in qemu
'_pre']
fns = [x for x in fns if not any(bad in os.path.basename(x) for bad in blocklist)]
if len(fns) != 1 and self.platform.type != 'native':
raise BuildError("Missing/multiple output ELF binary")
if not fns:
raise BuildError("Missing output binary")
elif len(fns) > 1:
logger.warning(f"multiple ELF files detected: {', '.join(fns)}")
return fns[0]
def get_buildlog_file(self) -> str: