Skip to content

Commit 3191d08

Browse files
nashifcarlescufi
authored andcommitted
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 <[email protected]>
1 parent 250748b commit 3191d08

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

scripts/pylib/twister/twisterlib/runner.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,8 @@ def determine_testcases(self, results):
680680
yaml_testsuite_name = self.instance.testsuite.id
681681
logger.debug(f"Determine test cases for test suite: {yaml_testsuite_name}")
682682

683-
elf = ELFFile(open(self.instance.get_elf_file(), "rb"))
683+
elf_file = self.instance.get_elf_file()
684+
elf = ELFFile(open(elf_file, "rb"))
684685

685686
logger.debug(f"Test instance {self.instance.name} already has {len(self.instance.testcases)} cases.")
686687
new_ztest_unit_test_regex = re.compile(r"z_ztest_unit_test__([^\s]*)__([^\s]*)")
@@ -702,6 +703,7 @@ def determine_testcases(self, results):
702703
detected_cases.append(testcase_id)
703704

704705
if detected_cases:
706+
logger.debug(f"{', '.join(detected_cases)} in {elf_file}")
705707
self.instance.testcases.clear()
706708
self.instance.testsuite.testcases.clear()
707709

scripts/pylib/twister/twisterlib/testinstance.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,15 +290,17 @@ def get_elf_file(self) -> str:
290290
build_dir = self.build_dir
291291

292292
fns = glob.glob(os.path.join(build_dir, "zephyr", "*.elf"))
293-
fns.extend(glob.glob(os.path.join(build_dir, "zephyr", "*.exe")))
294293
fns.extend(glob.glob(os.path.join(build_dir, "testbinary")))
295294
blocklist = [
296295
'remapped', # used for xtensa plaforms
297296
'zefi', # EFI for Zephyr
298-
'_pre' ]
297+
'qemu', # elf files generated after running in qemu
298+
'_pre']
299299
fns = [x for x in fns if not any(bad in os.path.basename(x) for bad in blocklist)]
300-
if len(fns) != 1 and self.platform.type != 'native':
301-
raise BuildError("Missing/multiple output ELF binary")
300+
if not fns:
301+
raise BuildError("Missing output binary")
302+
elif len(fns) > 1:
303+
logger.warning(f"multiple ELF files detected: {', '.join(fns)}")
302304
return fns[0]
303305

304306
def get_buildlog_file(self) -> str:

0 commit comments

Comments
 (0)