Skip to content

test(sysinfo): add unit tests for hardware and pdh_adapters#911

Open
xieofxie wants to merge 1 commit into
mainfrom
hualxie/sysinfo_testcases
Open

test(sysinfo): add unit tests for hardware and pdh_adapters#911
xieofxie wants to merge 1 commit into
mainfrom
hualxie/sysinfo_testcases

Conversation

@xieofxie

Copy link
Copy Markdown
Contributor

Summary

Closes #54.

Adds unit-test coverage for the two sysinfo/ modules that had none: hardware.py and pdh_adapters.py. Scope is deliberately the architecture-agnostic, branchy logic that the existing e2e perf tests (tests/e2e/test_perf_e2e.py) cannot reach — those tests are hardware-conditional and skip when the relevant GPU/NPU isn't on the runner, so vendor quirks (notably the Qualcomm paths) and the NPU fingerprint branch essentially never execute there. These unit tests run deterministically on any host off constructed CimInstance/PnpDevice objects.

test_hardware.py (18 tests)

  • get_vendor_id_device_id_from_pnp_id — PCI hex path (NVIDIA/AMD/Intel), both Qualcomm byte-packing quirks (ACPI\QCOM#### and VEN_QCOM), and all three ValueError paths. QCOM expectations were derived independently of the implementation, not asserted against it.
  • CPU/GPU/NPU/RAM field mapping + to_dict() camelCase key contract, the CPU architecture-enum UNKNOWN = -1 fallback, the GPU PCI/ACPI software-adapter filter (drops RDP-style adapters), and byte→MiB truncation.

test_pdh_adapters.py (27 tests)

  • AdapterInfo.is_npu engine-type fingerprint, _parse_multi_sz buffer parsing, _format_pdh_luid hi/lo 64-bit split, _build_adapters grouping, and discover_npu_luid/discover_gpu_luid(s) selection incl. the enumeration-failure → None/[] degradation. Skipped at module level off Windows (the module binds pdh.dll at import).

Source change

Extracted the pure GPU-Engine instance-string parsing out of enumerate_adapters into a new _build_adapters(list[str]) -> dict helper so it is testable without the PDH ctypes sizing plumbing. enumerate_adapters behavior is unchanged.

The real PdhEnumObjectItemsW calls and deep ORT-resolution paths are intentionally left to the e2e suite, which exercises them on hosts that have the device.

🤖 Generated with Claude Code

Cover the architecture-agnostic, branchy logic in sysinfo/hardware.py and
sysinfo/pdh_adapters.py that the hardware-conditional e2e perf tests cannot
exercise on a runner lacking the relevant device:

- get_vendor_id_device_id_from_pnp_id: PCI hex path plus both Qualcomm
  byte-packing quirks and all three error paths
- CPU/GPU/NPU/RAM field mapping, GPU PCI/ACPI software-adapter filter,
  architecture-enum UNKNOWN fallback, and to_dict() key contract
- AdapterInfo.is_npu fingerprint, _parse_multi_sz, _format_pdh_luid,
  adapter grouping, and NPU/GPU LUID discovery selection

Extract the pure instance-string parsing out of enumerate_adapters into
_build_adapters() so it is testable without the PDH ctypes plumbing.

Resolves #54
@xieofxie xieofxie requested a review from a team as a code owner June 17, 2026 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add test cases for sysinfo/

1 participant