Skip to content

Add initial pytest test suite and wire it into CI#23

Merged
mawad-amd merged 7 commits intomainfrom
copilot/add-unittests-to-ci
Mar 23, 2026
Merged

Add initial pytest test suite and wire it into CI#23
mawad-amd merged 7 commits intomainfrom
copilot/add-unittests-to-ci

Conversation

Copy link
Contributor

Copilot AI commented Mar 18, 2026

KernelDB had no Python tests. This adds a pytest suite covering the core library features and hooks it into the existing CI pipeline.

Test structure

  • tests/conftest.py – Environment detection (_hipcc_available, _gpu_available), a requires_rocm skip marker, inline HIP source snippets for five test scenarios, and session-scoped fixtures that compile each binary once via hipcc -g.
  • tests/test_imports.py – Validates the public API contract: all symbols in __all__ are importable, __version__ is set, and key classes (KernelDB, Kernel, Instruction, BasicBlock, CDNAKernel, ArchDescriptor, HsaAgent, KernelArgument) are accessible.
  • tests/test_kernels.py – Covers kernel discovery (get_kernels), source-line mapping, instruction extraction with attribute checks (disassembly, line, column, file_name), regex filtering semantics, basic block extraction, and the high-level Kernel wrapper properties (.lines, .assembly, .files, .signature).
  • tests/test_arguments.py – Covers argument metadata (name, type, size, alignment), pointer/scalar sizes, Kernel.has_arguments(), nested struct member recursion (BoundingBoxPoint3D), typedef preservation vs. resolution (resolve_typedefs=False/True), and template instantiation (scale_values<float> / scale_values<double>).

Configuration

pyproject.toml gains a [tool.pytest.ini_options] section (testpaths = ["tests"], -v).

CI gets a Run pytest step that runs pytest tests/ -v inside the Apptainer container after the editable install:

- name: Run pytest
  run: |
    bash .github/scripts/container_exec.sh "
      pip install -e '.[dev]'
      pytest tests/ -v
    "

All GPU-dependent tests skip automatically via @requires_rocm when hipcc or an HSA agent is not present; all test modules skip cleanly when the C++ extension is not compiled.

Original prompt

This section details on the original issue you should resolve

<issue_title>Add unittests to CI</issue_title>
<issue_description>We just added CI to KernelDB and we would like to add some unittests to exercise the different features of KernelDB. Please add some initial set of tests and lets focus on Python tests only using pytest for now.</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

- tests/conftest.py: session-scoped HIP binary fixtures, GPU/hipcc detection helpers
- tests/test_imports.py: verify all public API symbols are importable
- tests/test_kernels.py: kernel discovery, line mapping, instruction extraction, filtering, basic blocks, Kernel wrapper
- tests/test_arguments.py: argument metadata, nested structs, typedef resolution, template instantiations
- pyproject.toml: add [tool.pytest.ini_options] with testpaths and -v flag
- .github/workflows/ci.yml: add 'Run pytest' step after editable install

Co-authored-by: mawad-amd <112003944+mawad-amd@users.noreply.github.com>
Copilot AI changed the title [WIP] Add unittests to CI for KernelDB Add initial pytest test suite and wire it into CI Mar 18, 2026
Copilot AI requested a review from mawad-amd March 18, 2026 03:27
- Remove exc_type=ImportError from pytest.importorskip() calls (added in
  pytest 8.x; CI runs 7.3.2)
- Consolidate granular single-assertion tests into broader per-feature tests:
  test_imports.py: 15 -> 3 tests
  test_kernels.py: 35 -> 5 tests
  test_arguments.py: 25 -> 5 tests

Co-authored-by: mawad-amd <112003944+mawad-amd@users.noreply.github.com>
- Fix test_kernel_lines and test_basic_blocks_and_kernel_wrapper:
  get_kernel_lines() can return line 0, relax assertion from ln > 0
  to ln >= 0
- Remove unused requires_hipcc / requires_gpu / requires_rocm marks
  from conftest.py (fixtures already handle skipping)
- Remove @requires_rocm decorator from all test functions in
  test_kernels.py and test_arguments.py (fixtures handle it)
- Remove 'from conftest import requires_rocm' imports from test files

Co-authored-by: mawad-amd <112003944+mawad-amd@users.noreply.github.com>
mawad-amd and others added 3 commits March 23, 2026 00:04
Each test file embeds its own HIP source and compiles inline.
conftest.py reduced to just the requires_rocm skip marker.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
We compile the binary ourselves with -g, so this should never be absent.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@mawad-amd mawad-amd marked this pull request as ready for review March 23, 2026 07:19
@mawad-amd mawad-amd merged commit 960df09 into main Mar 23, 2026
1 check passed
@mawad-amd mawad-amd deleted the copilot/add-unittests-to-ci branch March 23, 2026 07:23
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 unittests to CI

2 participants