|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +import os |
| 6 | +import subprocess |
| 7 | +import sys |
| 8 | +from pathlib import Path |
| 9 | + |
| 10 | +from common import main_error, repo_root, require_env, run |
| 11 | + |
| 12 | + |
| 13 | +def run_capture(command: list[str], *, env: dict[str, str] | None = None) -> subprocess.CompletedProcess[str]: |
| 14 | + print("+", " ".join(command), flush=True) |
| 15 | + return subprocess.run( |
| 16 | + command, |
| 17 | + check=False, |
| 18 | + text=True, |
| 19 | + capture_output=True, |
| 20 | + env=env, |
| 21 | + ) |
| 22 | + |
| 23 | + |
| 24 | +def main() -> None: |
| 25 | + platform = require_env("ITLABAI_CI_PLATFORM") |
| 26 | + |
| 27 | + base_env = os.environ.copy() |
| 28 | + device_selector = os.environ.get("DEVICE_SELECTOR", "") |
| 29 | + if device_selector: |
| 30 | + base_env["ONEAPI_DEVICE_SELECTOR"] = device_selector |
| 31 | + os.environ["ONEAPI_DEVICE_SELECTOR"] = device_selector |
| 32 | + |
| 33 | + if platform != "linux-x86_64": |
| 34 | + run(["ctest", "--test-dir", "build", "--output-on-failure", "--parallel"]) |
| 35 | + return |
| 36 | + |
| 37 | + run( |
| 38 | + [ |
| 39 | + "ctest", |
| 40 | + "--test-dir", |
| 41 | + "build", |
| 42 | + "--output-on-failure", |
| 43 | + "--parallel", |
| 44 | + "-E", |
| 45 | + "^SYCL\\.Example$", |
| 46 | + ] |
| 47 | + ) |
| 48 | + |
| 49 | + example_path = repo_root() / "build" / "bin" / "SYCL_Example" |
| 50 | + result = run_capture([str(example_path)], env=base_env) |
| 51 | + |
| 52 | + if result.returncode == 0: |
| 53 | + if result.stdout: |
| 54 | + print(result.stdout, end="") |
| 55 | + if result.stderr: |
| 56 | + print(result.stderr, end="", file=sys.stderr) |
| 57 | + return |
| 58 | + |
| 59 | + combined_output = f"{result.stdout}{result.stderr}" |
| 60 | + if "No device of requested type available" in combined_output: |
| 61 | + print("Skipping SYCL.Example on linux-x86_64: no supported SYCL device on this runner.") |
| 62 | + return |
| 63 | + |
| 64 | + if result.stdout: |
| 65 | + print(result.stdout, end="") |
| 66 | + if result.stderr: |
| 67 | + print(result.stderr, end="", file=sys.stderr) |
| 68 | + raise SystemExit(result.returncode) |
| 69 | + |
| 70 | + |
| 71 | +if __name__ == "__main__": |
| 72 | + main() |
0 commit comments