Skip to content

ENH: Adding cmocka for unit testing #21304

Open
@HaoZeke

Description

@HaoZeke

Proposed new feature or change: Unit testing C code

One of the primary motivations behind this change is to support F2PY generated codes better. Working with fortranobject.{c,h} while trying to have test coverage is effectively impossible right now. Currently we only have integration tests (at the Python level) and this makes it hard to track problems sometimes.

However, beyond F2PY as well, unit testing the NumPy-C API can be done in low-boilerplate way with cmocka.

Some nice features of cmocka:

  • C only
  • Surprisingly low boilerplate
  • Is easily available on conda
  • Used by a bunch of other projects (e.g. libssh)

Existing C-testing:

  • Integration (pytest)
  • Making small extension modules to test parts of the public API (test_mem_policy.py)

Some questions which have come up in discussions are:

  • Compiling on Windows is slow --> we can concatenate these on the CI
  • Compiling them in monolithic files might be hard to debug (e.g. F2PY generates wrong C code)
    • This should not be an issue for the most part, compiler errors are caught by our test suite now as well, which should not change.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions