diff --git a/scripts/pylib/twister/twisterlib/environment.py b/scripts/pylib/twister/twisterlib/environment.py index 751f8d29a85..48e249fb036 100644 --- a/scripts/pylib/twister/twisterlib/environment.py +++ b/scripts/pylib/twister/twisterlib/environment.py @@ -184,6 +184,11 @@ Artificially long but functional example: help="Generate artifacts for testing, do not attempt to run the" "code on targets.") + parser.add_argument( + "--package-artifacts", + help="Package artifacts needed for flashing in a file to be used with --test-only" + ) + test_or_build.add_argument( "--test-only", action="store_true", help="""Only run device tests with current artifacts, do not build diff --git a/scripts/pylib/twister/twisterlib/package.py b/scripts/pylib/twister/twisterlib/package.py new file mode 100644 index 00000000000..aaf065d625d --- /dev/null +++ b/scripts/pylib/twister/twisterlib/package.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python3 +# vim: set syntax=python ts=4 : +# Copyright (c) 2020 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +import tarfile +import json +import os + +class Artifacts: + + def __init__(self, env): + self.options = env.options + + def make_tarfile(self, output_filename, source_dirs): + root = os.path.basename(self.options.outdir) + with tarfile.open(output_filename, "w:bz2") as tar: + tar.add("twister-out", recursive=False) + for d in source_dirs: + f = os.path.relpath(d, self.options.outdir) + tar.add(d, arcname=os.path.join(root, f)) + + def package(self): + dirs = [] + with open(os.path.join(self.options.outdir, "twister.json"), "r") as json_test_plan: + jtp = json.load(json_test_plan) + for t in jtp['testsuites']: + if t['status'] != "filtered": + dirs.append(os.path.join(self.options.outdir, t['platform'], t['name'])) + + dirs.extend( + [ + os.path.join(self.options.outdir, "twister.json"), + os.path.join(self.options.outdir, "testplan.json") + ] + ) + self.make_tarfile(self.options.package_artifacts, dirs) diff --git a/scripts/twister b/scripts/twister index 36b99fdb83b..f42602ff598 100755 --- a/scripts/twister +++ b/scripts/twister @@ -201,6 +201,7 @@ from twisterlib.reports import Reporting from twisterlib.hardwaremap import HardwareMap from twisterlib.coverage import run_coverage from twisterlib.runner import TwisterRunner +from twisterlib.package import Artifacts logger = logging.getLogger('twister') logger.setLevel(logging.DEBUG) @@ -398,6 +399,10 @@ def main(): options.platform_reports ) + if options.package_artifacts: + artifacts = Artifacts(env) + artifacts.package() + logger.info("Run completed") if runner.results.failed or runner.results.error or (tplan.warnings and options.warnings_as_errors): return 1