From 40e0183a6ab68e5d22528bdf6d54c52dc95f2589 Mon Sep 17 00:00:00 2001 From: Tristan Honscheid Date: Mon, 15 Aug 2022 16:15:18 -0600 Subject: zephyr: twister: Allow overriding toolchain options Allow overriding the TOOLCHAIN_ROOT and ZEPHYR_TOOLCHAIN_VARIANT environment variables, as well as the --gcov-tool CLI parameter. This is necessary for running tests with GCC outside of the chroot, such as in Gitlab. By default, the usual LLVM toolchain is used and there is no impact on users. BUG=b:242067249 BRANCH=None TEST=./twister -v -v Signed-off-by: Tristan Honscheid Change-Id: I2369c251ac43d05bc0246d8e1b35e1bc4a28b783 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3831536 Reviewed-by: Jeremy Bettis Commit-Queue: Jeremy Bettis --- util/twister_launcher.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/util/twister_launcher.py b/util/twister_launcher.py index 9725aa03a6..aad4a05931 100755 --- a/util/twister_launcher.py +++ b/util/twister_launcher.py @@ -90,12 +90,16 @@ def main(): zephyr_modules = find_modules(zephyr_modules_dir) zephyr_modules.append(ec_base) - # Prepare environment variables for export to Twister and inherit the - # parent environment. + # Prepare environment variables for export to Twister. Inherit the parent + # process's environment, but set some default values if not already set. twister_env = dict(os.environ) extra_env_vars = { - "TOOLCHAIN_ROOT": str(ec_base / "zephyr"), - "ZEPHYR_TOOLCHAIN_VARIANT": "llvm", + "TOOLCHAIN_ROOT": os.environ.get( + "TOOLCHAIN_ROOT", str(ec_base / "zephyr") + ), + "ZEPHYR_TOOLCHAIN_VARIANT": os.environ.get( + "ZEPHYR_TOOLCHAIN_VARIANT", "llvm" + ), } twister_env.update(extra_env_vars) @@ -107,8 +111,6 @@ def main(): f"-x=SYSCALL_INCLUDE_DIRS={str(ec_base / 'zephyr' / 'include' / 'drivers')}", f"-x=ZEPHYR_BASE={zephyr_base}", f"-x=ZEPHYR_MODULES={';'.join([str(p) for p in zephyr_modules])}", - "--gcov-tool", - ec_base / "util" / "llvm-gcov.sh", ] # `-T` flags (used for specifying test directories to build and run) @@ -122,6 +124,9 @@ def main(): parser = argparse.ArgumentParser(add_help=False, allow_abbrev=False) parser.add_argument("-T", "--testsuite-root", action="append") parser.add_argument("-v", "--verbose", action="count", default=0) + parser.add_argument( + "--gcov-tool", default=str(ec_base / "util" / "llvm-gcov.sh") + ) intercepted_args, other_args = parser.parse_known_args() for _ in range(intercepted_args.verbose): @@ -138,6 +143,15 @@ def main(): twister_cli.extend(["-T", str(ec_base)]) twister_cli.extend(["-T", str(zephyr_base / "tests/subsys/shell")]) + # Pass through the chosen coverage tool, or fall back on the default choice + # (see add_argument above). + twister_cli.extend( + [ + "--gcov-tool", + intercepted_args.gcov_tool, + ] + ) + # Append additional user-supplied args twister_cli.extend(other_args) -- cgit v1.2.1