Skip to content

Commit

Permalink
twister: improve handling of ELF file parsing
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
nashif authored and carlescufi committed Jul 28, 2023
1 parent 250748b commit 3191d08
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 3 additions & 1 deletion scripts/pylib/twister/twisterlib/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,8 @@ def determine_testcases(self, results):
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]*)")
Expand All @@ -702,6 +703,7 @@ def determine_testcases(self, results):
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()

Expand Down
10 changes: 6 additions & 4 deletions scripts/pylib/twister/twisterlib/testinstance.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,15 +290,17 @@ def get_elf_file(self) -> str:
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:
Expand Down

0 comments on commit 3191d08

Please sign in to comment.