Skip to content
Merged
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
14 changes: 6 additions & 8 deletions pymtml.py
Original file line number Diff line number Diff line change
Expand Up @@ -2165,14 +2165,12 @@ class NVMLUtilization:
memory: int


class NVMLError(MTMLError):
def __new__(typ, value):
obj = super().__new__(MTMLError, value)

if not isinstance(obj, NVMLError):
obj.__class__ = NVMLError

return obj
# pynvml's contract is that every NVMLError_* is an NVMLError, and callers
# write `except NVMLError`. The MTML layer raises MTMLError (and its generated
# subclasses), so an alias - as MANUAL.md documents - is what makes both
# `except NVMLError` and `except MTMLError` catch every failure. A subclass
# here would leave `except NVMLError` catching nothing.
NVMLError = MTMLError


def nvmlStructToFriendlyObject(struct):
Expand Down
26 changes: 25 additions & 1 deletion test_pymtml.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@

from pymtml import *

# Every check is counted: an API that fails prints a line, and the script must
# still exit non-zero, otherwise CI is green while the binding is broken.
# `Not Supported` is the platform answering, not a defect, so it is a skip.
RESULTS = {"passed": 0, "skipped": 0, "failed": 0}


def print_section(title):
print(f"\n{'='*60}")
Expand All @@ -27,12 +32,19 @@ def test_error(name, func):
try:
result = func()
print_result(name, result)
RESULTS["passed"] += 1
return True
except MTMLError_NotSupported as e:
print_result(name, f"[MTMLError: {e}] (not supported)")
RESULTS["skipped"] += 1
return False
except MTMLError as e:
print_result(name, f"[MTMLError: {e}]")
RESULTS["failed"] += 1
return False
except Exception as e:
print_result(name, f"[Error: {e}]")
RESULTS["failed"] += 1
return False


Expand Down Expand Up @@ -370,6 +382,12 @@ def run_all_tests(self):
print_section("Test Complete")


# `test_error` is a helper called by main(), not a pytest case: pytest would
# collect it and stop with "fixture 'name' not found". `make test` runs
# `pytest test_*.py`, so keep it out of collection.
test_error.__test__ = False


def test_init_shutdown_cycle():
"""Test that library can be initialized and shutdown multiple times."""
print_section("Init/Shutdown Cycle Test")
Expand Down Expand Up @@ -419,7 +437,13 @@ def main():
traceback.print_exc()
return 1

return 0
print_section("Result")
print(
f" {RESULTS['passed']} passed, {RESULTS['skipped']} skipped"
f" (not supported), {RESULTS['failed']} failed"
)

return 1 if RESULTS["failed"] else 0


if __name__ == "__main__":
Expand Down
24 changes: 23 additions & 1 deletion test_pynvml.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
# Import pymtml as if it were pynvml
import pymtml as pynvml

# See test_pymtml.py: an API that fails must fail the run, and `Not Supported`
# is a platform answer rather than a defect.
RESULTS = {"passed": 0, "skipped": 0, "failed": 0}


def print_section(title):
print(f"\n{'='*60}")
Expand All @@ -29,12 +33,19 @@ def test_api(name, func):
try:
result = func()
print_result(name, result)
RESULTS["passed"] += 1
return True, result
except pynvml.NVMLError_NotSupported as e:
print_result(name, f"[NVMLError: {e}] (not supported)")
RESULTS["skipped"] += 1
return False, None
except pynvml.NVMLError as e:
print_result(name, f"[NVMLError: {e}]")
RESULTS["failed"] += 1
return False, None
except Exception as e:
print_result(name, f"[Error: {e}]")
RESULTS["failed"] += 1
return False, None


Expand Down Expand Up @@ -394,6 +405,11 @@ def run_all_tests(self):
print_section("Test Complete")


# `test_api` is a helper called by main(), not a pytest case: pytest would
# collect it and stop with "fixture 'name' not found".
test_api.__test__ = False


def main():
try:
# Initialize library
Expand All @@ -420,7 +436,13 @@ def main():
except Exception:
pass

return 0
print_section("Result")
print(
f" {RESULTS['passed']} passed, {RESULTS['skipped']} skipped"
f" (not supported), {RESULTS['failed']} failed"
)

return 1 if RESULTS["failed"] else 0


if __name__ == "__main__":
Expand Down
14 changes: 14 additions & 0 deletions test_sglang_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,20 @@ def test_sglang_nvlink_full_connection(physical_device_ids, logger=None):
return True


# The probes above take the device list from main(); they are not pytest cases.
# pytest collects a `test_*` function with arguments and stops with
# "fixture 'devices' not found", which is what `make test` reported.
for _probe in (
test_p2p_status,
test_topology_detection,
test_nvlink_apis,
test_device_info_apis,
test_ecc_apis,
test_sglang_nvlink_full_connection,
):
_probe.__test__ = False


def main():
print("\n" + "=" * 60)
print(" MTML sglang Compatibility Test Suite")
Expand Down
Loading