2024-08-19 09:56:10 +02:00
|
|
|
#!/usr/bin/env python3
|
2020-02-19 12:01:02 +01:00
|
|
|
|
|
|
|
import argparse
|
2023-12-25 22:45:38 +01:00
|
|
|
import json
|
2020-02-19 12:01:02 +01:00
|
|
|
import multiprocessing
|
|
|
|
import re
|
2024-08-19 09:56:10 +02:00
|
|
|
import shlex
|
2020-02-19 12:01:02 +01:00
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
from pathlib import Path
|
2023-12-25 22:45:38 +01:00
|
|
|
from tempfile import TemporaryDirectory
|
2020-02-19 12:01:02 +01:00
|
|
|
|
|
|
|
TEST_ROOT = Path(__file__).resolve().parent
|
|
|
|
ROOT = TEST_ROOT.parent
|
|
|
|
|
|
|
|
GREEN = "\033[92m"
|
|
|
|
RED = "\033[91m"
|
|
|
|
RESET = "\033[0m"
|
|
|
|
|
2023-12-25 22:45:38 +01:00
|
|
|
re_nixos_hardware = re.compile(r"<nixos-hardware/([^>]+)>")
|
|
|
|
|
2020-02-19 12:01:02 +01:00
|
|
|
|
|
|
|
def parse_args() -> argparse.Namespace:
|
|
|
|
parser = argparse.ArgumentParser(description="Run hardware tests")
|
|
|
|
parser.add_argument(
|
|
|
|
"--jobs",
|
|
|
|
type=int,
|
|
|
|
default=multiprocessing.cpu_count(),
|
|
|
|
help="Number of parallel evaluations."
|
|
|
|
"If set to 1 it disable multi processing (suitable for debugging)",
|
|
|
|
)
|
2020-05-18 12:38:36 +02:00
|
|
|
parser.add_argument(
|
2023-12-25 21:21:26 +01:00
|
|
|
"--verbose",
|
|
|
|
action="store_true",
|
|
|
|
help="Print evaluation commands executed",
|
2020-05-18 12:38:36 +02:00
|
|
|
)
|
2024-08-19 09:56:10 +02:00
|
|
|
parser.add_argument(
|
|
|
|
"--nixos-hardware",
|
|
|
|
help="Print evaluation commands executed",
|
|
|
|
)
|
2020-02-19 12:01:02 +01:00
|
|
|
return parser.parse_args()
|
|
|
|
|
|
|
|
|
2024-08-19 09:56:10 +02:00
|
|
|
def run_eval_test(nixos_hardware: str, gcroot_dir: Path, jobs: int) -> list[str]:
|
2023-12-25 22:45:38 +01:00
|
|
|
failed_profiles = []
|
|
|
|
cmd = [
|
|
|
|
"nix-eval-jobs",
|
2024-08-19 09:56:10 +02:00
|
|
|
"--extra-experimental-features",
|
|
|
|
"flakes",
|
|
|
|
"--override-input",
|
|
|
|
"nixos-hardware",
|
|
|
|
nixos_hardware,
|
2023-12-25 22:45:38 +01:00
|
|
|
"--gc-roots-dir",
|
2024-08-19 09:56:10 +02:00
|
|
|
str(gcroot_dir),
|
2023-12-25 22:45:38 +01:00
|
|
|
"--max-memory-size",
|
|
|
|
"2048",
|
|
|
|
"--workers",
|
|
|
|
str(jobs),
|
2024-08-19 09:56:10 +02:00
|
|
|
"--flake",
|
|
|
|
str(TEST_ROOT) + "#checks",
|
|
|
|
"--force-recurse",
|
2023-12-25 22:45:38 +01:00
|
|
|
]
|
2024-08-19 09:56:10 +02:00
|
|
|
print(" ".join(map(shlex.quote,cmd)))
|
2023-12-25 22:45:38 +01:00
|
|
|
proc = subprocess.Popen(
|
|
|
|
cmd,
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
text=True,
|
|
|
|
)
|
2024-08-19 09:56:10 +02:00
|
|
|
|
2023-12-25 22:45:38 +01:00
|
|
|
with proc as p:
|
|
|
|
assert p.stdout is not None
|
|
|
|
for line in p.stdout:
|
|
|
|
data = json.loads(line)
|
|
|
|
attr = data.get("attr")
|
|
|
|
if "error" in data:
|
|
|
|
failed_profiles.append(attr)
|
|
|
|
print(f"{RED}FAIL {attr}:{RESET}", file=sys.stderr)
|
|
|
|
print(f"{RED}{data['error']}{RESET}", file=sys.stderr)
|
|
|
|
else:
|
|
|
|
print(f"{GREEN}OK {attr}{RESET}")
|
|
|
|
return failed_profiles
|
|
|
|
|
|
|
|
|
2020-02-19 12:01:02 +01:00
|
|
|
def main() -> None:
|
|
|
|
args = parse_args()
|
|
|
|
|
|
|
|
failed_profiles = []
|
2024-08-19 09:56:10 +02:00
|
|
|
|
2023-12-25 22:45:38 +01:00
|
|
|
with TemporaryDirectory() as tmpdir:
|
|
|
|
gcroot_dir = Path(tmpdir) / "gcroot"
|
2024-08-19 09:56:10 +02:00
|
|
|
failed_profiles = run_eval_test(args.nixos_hardware, gcroot_dir, args.jobs)
|
2020-02-19 12:01:02 +01:00
|
|
|
|
|
|
|
if len(failed_profiles) > 0:
|
|
|
|
print(f"\n{RED}The following {len(failed_profiles)} test(s) failed:{RESET}")
|
|
|
|
for profile in failed_profiles:
|
2024-08-19 09:56:10 +02:00
|
|
|
print(f" '{profile}'")
|
2020-02-19 12:01:02 +01:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|