summaryrefslogtreecommitdiff
path: root/util/twister_launcher.py
diff options
context:
space:
mode:
Diffstat (limited to 'util/twister_launcher.py')
-rwxr-xr-xutil/twister_launcher.py182
1 files changed, 66 insertions, 116 deletions
diff --git a/util/twister_launcher.py b/util/twister_launcher.py
index 11202f9343..033b4c59dd 100755
--- a/util/twister_launcher.py
+++ b/util/twister_launcher.py
@@ -37,10 +37,6 @@ parameters that may be used, please consult the Twister documentation.
# version: "version:5.8.0.chromium.3"
# >
# wheel: <
-# name: "infra/python/wheels/pyelftools-py2_py3"
-# version: "version:0.29"
-# >
-# wheel: <
# name: "infra/python/wheels/pykwalify-py2_py3"
# version: "version:1.8.0"
# >
@@ -81,10 +77,8 @@ parameters that may be used, please consult the Twister documentation.
import argparse
import json
import os
-import pathlib
import re
import shlex
-import shutil
import subprocess
import sys
import time
@@ -98,8 +92,7 @@ def find_checkout() -> Path:
if cros_checkout is not None:
return Path(cros_checkout)
- # Attempt to locate checkout location relatively if being run outside of
- # chroot.
+ # Attempt to locate checkout location relatively if being run outside of chroot.
try:
cros_checkout = Path(__file__).resolve().parents[4]
assert (cros_checkout / "src").exists()
@@ -174,75 +167,59 @@ def is_rdb_login():
return ret.returncode == 0
-def upload_results(ec_base, outdir):
+def upload_results(ec_base):
"""Uploads Zephyr Test results to ResultDB"""
flag = False
if is_rdb_login():
- json_path = pathlib.Path(outdir) / "twister.json"
-
- if json_path.exists():
- cmd = [
- "rdb",
- "stream",
- "-new",
- "-realm",
- "chromium:public",
- "--",
- "vpython3",
- str(ec_base / "util/zephyr_to_resultdb.py"),
- "--result=" + str(json_path),
- "--upload=True",
- ]
-
- start_time = time.time()
- ret = subprocess.run(
- cmd, capture_output=True, text=True, check=True
- )
- end_time = time.time()
-
- # Extract URL to test report from captured output
- rdb_url = re.search(
- r"(?P<url>https?://[^\s]+)", ret.stderr.split("\n")[0]
- ).group("url")
- print(f"\nTEST RESULTS ({end_time - start_time:.3f}s): {rdb_url}\n")
- flag = ret.returncode == 0
+ json_path = ec_base / "twister-out" / "twister.json"
+ cmd = [
+ "rdb",
+ "stream",
+ "-new",
+ "-realm",
+ "chromium:public",
+ "--",
+ str(ec_base / "util/zephyr_to_resultdb.py"),
+ "--result=" + str(json_path),
+ "--upload=True",
+ ]
+
+ start_time = time.time()
+ ret = subprocess.run(cmd, capture_output=True, text=True, check=True)
+ end_time = time.time()
+
+ # Extract URL to test report from captured output
+ rdb_url = re.search(
+ r"(?P<url>https?://[^\s]+)", ret.stderr.split("\n")[0]
+ ).group("url")
+ print(f"\nTEST RESULTS ({end_time - start_time:.3f}s): {rdb_url}\n")
+ flag = ret.returncode == 0
else:
print("Unable to upload test results, please run 'rdb auth-login'\n")
return flag
-def check_for_skipped_tests(outdir):
+def check_for_skipped_tests(ec_base):
"""Checks Twister json test report for skipped tests"""
found_skipped = False
- json_path = pathlib.Path(outdir) / "twister.json"
- if json_path.exists():
- with open(json_path) as file:
- data = json.load(file)
+ json_path = ec_base / "twister-out" / "twister.json"
+ with open(json_path) as file:
+ data = json.load(file)
- for testsuite in data["testsuites"]:
- for testcase in testsuite["testcases"]:
- if testcase["status"] == "skipped":
- tc_name = testcase["identifier"]
- print(f"TEST SKIPPED: {tc_name}")
- found_skipped = True
+ for testsuite in data["testsuites"]:
+ for testcase in testsuite["testcases"]:
+ if testcase["status"] == "skipped":
+ tc_name = testcase["identifier"]
+ print(f"TEST SKIPPED: {tc_name}")
+ found_skipped = True
- file.close()
+ file.close()
return found_skipped
-def append_cmake_compiler(cmdline, cmake_var, exe_options):
- """Picks the first available exe from exe_options and adds a cmake variable
- to cmdline."""
- for exe in exe_options:
- exe_path = shutil.which(exe)
- if exe_path:
- cmdline.append(f"-x={cmake_var}={exe_path}")
- return
-
-
def main():
"""Run Twister using defaults for the EC project."""
@@ -256,6 +233,21 @@ def main():
if ec_base.resolve() not in zephyr_modules:
zephyr_modules.append(ec_base)
+ # 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)
+ is_in_chroot = Path("/etc/cros_chroot_version").is_file()
+ extra_env_vars = {
+ "TOOLCHAIN_ROOT": os.environ.get(
+ "TOOLCHAIN_ROOT",
+ str(ec_base / "zephyr") if is_in_chroot else zephyr_base,
+ ),
+ "ZEPHYR_TOOLCHAIN_VARIANT": os.environ.get(
+ "ZEPHYR_TOOLCHAIN_VARIANT", "llvm" if is_in_chroot else "host"
+ ),
+ }
+ twister_env.update(extra_env_vars)
+
# Twister CLI args
# TODO(b/239165779): Reduce or remove the usage of label properties
# Zephyr upstream has deprecated the label property. We need to allow
@@ -271,7 +263,6 @@ def main():
f"-x=ZEPHYR_BASE={zephyr_base}",
f"-x=ZEPHYR_MODULES={';'.join([str(p) for p in zephyr_modules])}",
]
- is_in_chroot = Path("/etc/cros_chroot_version").is_file()
# `-T` flags (used for specifying test directories to build and run)
# require special handling. When run without `-T` flags, Twister will
@@ -285,31 +276,11 @@ def main():
parser.add_argument("-T", "--testsuite-root", action="append")
parser.add_argument("-p", "--platform", action="append")
parser.add_argument("-v", "--verbose", action="count", default=0)
- parser.add_argument("--gcov-tool")
- parser.add_argument(
- "--no-upload-cros-rdb", dest="upload_cros_rdb", action="store_false"
- )
parser.add_argument(
- "-O",
- "--outdir",
- default=os.path.join(os.getcwd(), "twister-out"),
+ "--gcov-tool", default=str(ec_base / "util" / "llvm-gcov.sh")
)
parser.add_argument(
- "--toolchain",
- default=os.environ.get(
- "ZEPHYR_TOOLCHAIN_VARIANT",
- "llvm" if is_in_chroot else "host",
- ),
- )
- parser.add_argument(
- "--gcc", dest="toolchain", action="store_const", const="host"
- )
- parser.add_argument(
- "--llvm",
- "--clang",
- dest="toolchain",
- action="store_const",
- const="llvm",
+ "--no-upload-cros-rdb", dest="upload_cros_rdb", action="store_false"
)
intercepted_args, other_args = parser.parse_known_args()
@@ -323,14 +294,19 @@ def main():
for arg in intercepted_args.testsuite_root:
twister_cli.extend(["-T", arg])
else:
- # Use this set of test suite roots when no -T args are present. This
- # should encompass all current Zephyr EC tests. The paths are meant to
- # be as specific as possible to limit Twister's search scope. This saves
- # significant time when starting Twister.
- twister_cli.extend(["-T", str(ec_base / "common")])
- twister_cli.extend(["-T", str(ec_base / "zephyr/test")])
+ # Use EC base dir when no -T args specified. This will cause all
+ # Twister-compatible EC tests to run.
+ 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,
+ ]
+ )
if intercepted_args.platform:
# Pass user-provided -p args when present.
for arg in intercepted_args.platform:
@@ -340,32 +316,6 @@ def main():
twister_cli.extend(["-p", "native_posix"])
twister_cli.extend(["-p", "unit_testing"])
- twister_cli.extend(["--outdir", intercepted_args.outdir])
-
- # 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": os.environ.get(
- "TOOLCHAIN_ROOT",
- str(ec_base / "zephyr") if is_in_chroot else str(zephyr_base),
- ),
- "ZEPHYR_TOOLCHAIN_VARIANT": intercepted_args.toolchain,
- }
- gcov_tool = None
- if intercepted_args.toolchain == "host":
- gcov_tool = "gcov"
- elif intercepted_args.toolchain == "llvm":
- gcov_tool = str(ec_base / "util" / "llvm-gcov.sh")
- else:
- print("Unknown toolchain specified:", intercepted_args.toolchain)
- if intercepted_args.gcov_tool:
- gcov_tool = intercepted_args.gcov_tool
- if gcov_tool:
- twister_cli.extend(["--gcov-tool", gcov_tool])
-
- twister_env.update(extra_env_vars)
-
# Append additional user-supplied args
twister_cli.extend(other_args)
@@ -384,7 +334,7 @@ def main():
# Invoke Twister and wait for it to exit.
result = subprocess.run(twister_cli, env=twister_env, check=False)
- if check_for_skipped_tests(intercepted_args.outdir):
+ if check_for_skipped_tests(ec_base):
result.returncode = 1
if result.returncode == 0:
@@ -393,7 +343,7 @@ def main():
print("TEST EXECUTION FAILED")
if is_tool("rdb") and intercepted_args.upload_cros_rdb:
- upload_results(ec_base, intercepted_args.outdir)
+ upload_results(ec_base)
sys.exit(result.returncode)