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
21
22def get_runtime_root() -> Path:
23 import esiaccel
24 return Path(esiaccel.__file__).resolve().parent.parent.parent
25
26
27def require_tool(tool: str) -> None:
28 if shutil.which(tool) is None:
29 pytest.skip(f"Required tool not found in PATH: {tool}")
30
31
32def require_env(var_name: str) -> str:
33 value = os.environ.get(var_name)
34 if not value:
35 pytest.skip(f"Required environment variable not set: {var_name}")
36 return value
37
38
39def run_cmd(cmd, **kwargs) -> str:
40 """Run a command, capture stdout, and return it. Raises on failure."""
41 _logger.info("run_cmd: %s", cmd)
42 result = subprocess.run(cmd,
43 check=True,
44 capture_output=True,
45 text=True,
46 **kwargs)
47 _logger.debug("stdout: %s", result.stdout)
48 _logger.debug("stderr: %s", result.stderr)
49 return result.stdout
50
51
52def check_lines(stdout: str, expected: list[str]) -> None:
53 """Assert that every expected substring appears in stdout in order."""
54 remaining = stdout
55 for line in expected:
56 idx = remaining.find(line)
57 assert idx >= 0, \
58 f"Expected output not found: {line!r}"
59 remaining = remaining[idx + len(line):]
static mlir::Operation * resolve(Context &context, mlir::SymbolRefAttr sym)
str require_env(str var_name)
Definition conftest.py:32