Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ nlohmann/json@v3.8.0 -DCMAKE_POLICY_VERSION_MINIMUM=3.5
pybind/pybind11@3e9dfa2866941655c56877882565e7577de6fc7b --build
msgpack/msgpack-c@cpp-3.3.0 -DMSGPACK_BUILD_TESTS=Off -DMSGPACK_BUILD_EXAMPLES=Off -DCMAKE_POLICY_VERSION_MINIMUM=3.5
sqlite3@3.50.4 -DCMAKE_POSITION_INDEPENDENT_CODE=On
ROCm/rocm-cmake@b3959201846b9d9250a6f2a386ad43be04d1d051 --build
ROCm/rocm-cmake@fix_prop_scope --build
ROCm/composable_kernel@ad0db05b040bacda751c65c705261b8a0a7ed25d --cmake subdir -DCMAKE_DIR=codegen -DCMAKE_POSITION_INDEPENDENT_CODE=On -DBUILD_TESTING=Off -DCMAKE_POLICY_VERSION_MINIMUM=3.5
https://gitlab.com/libeigen/eigen/-/archive/5.0.1/eigen-5.0.1.tar.gz -DBUILD_TESTING=Off -DEIGEN_BUILD_DOC=Off -DEIGEN_BUILD_LAPACK=Off
ROCm/rocMLIR@364015202c7271708f6375f34eaf20c2a9c199a3 -DBUILD_FAT_LIBROCKCOMPILER=On -DLLVM_INCLUDE_TESTS=Off
3 changes: 3 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ if(MIGRAPHX_ENABLE_PYTHON)
add_subdirectory(py)
endif()

# Install a pytest bridge next to the installed C++ tests
rocm_install_test(FILES ${CMAKE_CURRENT_SOURCE_DIR}/test_pytest_bridge.py)

# Op builder test
set(TEST_OP_BUILDER_DIR ${CMAKE_CURRENT_SOURCE_DIR}/op)
add_subdirectory(op)
Expand Down
91 changes: 91 additions & 0 deletions test/test_pytest_bridge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#####################################################################################
# The MIT License (MIT)
#
# Copyright (c) 2015-2026 Advanced Micro Devices, Inc. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#####################################################################################
"""Pytest bridge for the MIGraphX test suite
NOTE: the file is named ``test_*`` on purpose so pytest's default discovery can find it
"""
import os
import shutil
import subprocess

import pytest

_HERE = os.path.dirname(os.path.abspath(__file__))


def _resolve_test_dir():
env_dir = os.environ.get("MIGRAPHX_TEST_DIR")
if env_dir:
return env_dir
for candidate in (_HERE, os.getcwd()):
if os.path.exists(os.path.join(candidate, "CTestTestfile.cmake")):
return candidate
return _HERE


def _migraphx_lib_dir():
try:
import migraphx
except ImportError:
return None
return os.path.dirname(os.path.abspath(migraphx.__file__))


def _ctest_env(test_dir):
env = dict(os.environ)
lib_dirs = [d for d in (os.path.join(test_dir, "lib"), _migraphx_lib_dir())
if d and os.path.isdir(d)]
if lib_dirs:
existing = env.get("LD_LIBRARY_PATH", "")
env["LD_LIBRARY_PATH"] = os.pathsep.join(
lib_dirs + ([existing] if existing else []))
return env


def _ensure_executable(test_dir):
bin_dir = os.path.join(test_dir, "bin")
if not os.path.isdir(bin_dir):
return
for name in os.listdir(bin_dir):
try:
os.chmod(os.path.join(bin_dir, name), 0o755)
except OSError:
pass


@pytest.mark.skipif(shutil.which("ctest") is None,
reason="ctest not found; install CMake to run the suite")
def test_migraphx():
test_dir = _resolve_test_dir()
if not os.path.exists(os.path.join(test_dir, "CTestTestfile.cmake")):
pytest.skip(
f"No CTestTestfile.cmake in {test_dir}; set MIGRAPHX_TEST_DIR to a "
"build or installed-tests directory.")
_ensure_executable(test_dir)
result = subprocess.run(
["ctest", "--test-dir", test_dir, "-j", str(os.cpu_count() or 1),
"--output-on-failure"],
env=_ctest_env(test_dir),
)
assert result.returncode == 0, f"ctest reported failures (exit {result.returncode})"
Loading