CIRCT 23.0.0git
Loading...
Searching...
No Matches
conftest.py
Go to the documentation of this file.
1# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2# See https://llvm.org/LICENSE.txt for license information.
3# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5from __future__ import annotations
6
7import os
8from pathlib import Path
9import logging
10import shutil
11import subprocess
12
13import pytest
14
15_logger = logging.getLogger(__name__)
16
17ROOT_DIR = Path(__file__).resolve().parent
18HW_DIR = ROOT_DIR / "hw"
19SW_DIR = ROOT_DIR / "sw"
20
21from tests.conftest import get_runtime_root # noqa: F401 – re-exported
22
23
24def require_tool(tool: str) -> None:
25 if shutil.which(tool) is None:
26 pytest.skip(f"Required tool not found in PATH: {tool}")
27
28
29def require_env(var_name: str) -> str:
30 value = os.environ.get(var_name)
31 if not value:
32 pytest.skip(f"Required environment variable not set: {var_name}")
33 return value
34
35
36def run_cmd(cmd, **kwargs) -> str:
37 """Run a command, capture stdout, and return it. Raises on failure."""
38 _logger.info("run_cmd: %s", cmd)
39 result = subprocess.run(cmd,
40 check=True,
41 capture_output=True,
42 text=True,
43 **kwargs)
44 _logger.debug("stdout: %s", result.stdout)
45 _logger.debug("stderr: %s", result.stderr)
46 return result.stdout
47
48
49def check_lines(stdout: str, expected: list[str]) -> None:
50 """Assert that every expected substring appears in stdout in order."""
51 remaining = stdout
52 for line in expected:
53 idx = remaining.find(line)
54 assert idx >= 0, \
55 f"Expected output not found: {line!r}"
56 remaining = remaining[idx + len(line):]
static mlir::Operation * resolve(Context &context, mlir::SymbolRefAttr sym)
str require_env(str var_name)
Definition conftest.py:29