twister: Add --keep-artifacts option

Introduce a new command-line option `--keep-artifacts` in twister that
allows users to specify which artifacts should be preserved
during test cleanup in addition to the default set.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Co-authored-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
Benjamin Cabé 2025-02-18 07:40:53 +01:00 committed by Fabio Baltieri
commit 09d2a6c08c
2 changed files with 6 additions and 1 deletions

View file

@ -578,6 +578,11 @@ structure in the main Zephyr tree: boards/<vendor>/<board_name>/""")
which only removes artifacts of passing tests. If you wish to
remove all artificats including those of failed tests, use 'all'.""")
parser.add_argument(
"--keep-artifacts", action="append", default=[],
help="""Keep specified artifacts when cleaning up at runtime. Multiple invocations
are possible."""
)
test_xor_generator.add_argument(
"-N", "--ninja", action="store_true",
default=not any(a in sys.argv for a in ("-k", "--make")),

View file

@ -1207,7 +1207,7 @@ class ProjectBuilder(FilterBuilder):
mode == "passed"
or (mode == "all" and self.instance.reason != "CMake build failure")
):
self.cleanup_artifacts()
self.cleanup_artifacts(self.options.keep_artifacts)
except StatusAttributeError as sae:
logger.error(str(sae))
self.instance.status = TwisterStatus.ERROR