Skip to content

Add unit tests infrastructure - #95

Merged
Mikolaj-A-Kowalski merged 4 commits into
mainfrom
add-unit-tests
Oct 15, 2026
Merged

Mikolaj-A-Kowalski merged 4 commits into
mainfrom
add-unit-tests

Conversation

@Mikolaj-A-Kowalski

Copy link
Copy Markdown
Contributor

Adds a skeleton (for now basically empty) to enable unit testing.

Developing the tripolar functionality I have found myself in want of being able to test the components of the algorithm (utility functions basically). The existing /integration/regression test suite is not really fit for that purpose.

Since the test folder is busy as it is I though it will be cleaner to put unit tests in a separate directory.

Naturally things refuse to be easy and there is a complication related to how we compile the project.

We cannot link the unit_tests executable against the shared library target because most of the functions that we wish to test are not part of the library's public API and hence are compiled with "hidden" visibility. As the result, if we try to use them in tests, this results in linking errors (symbols not being found due to visibility).

The solution at the moment is to introduce a 2nd, static library, which we can use to collect all sources, include directories and dependencies and feed them when compiling executables (decomp tool and unit_tests for the moment).

To discuss in review

  • Removing the dummy test before merging? I have put it there only to verify that symbols from the library are accessible.
  • Trying to avoid recompiling the sources twice (once for SHARED and STATIC libraries). I am not sure it will be easy. Furthermore it may not be really what we want. We do compile executables with position independent code -fPIC at the moment, but it is not something we need to do)

In contrast with the existing integration/regression tests, it will
enable more fine-grained testing of components.
We cannot link the unit_tests executable against the dynamic library
target since most of the symbols (i.e. functions) we wish to test are
not part of the dynamic library API and hence are hidden by visibility
specification.

To circumvent this issue we introduce an internal 'core' STATIC library
that allows us to share code and dependencies between executable
targets.
Comment thread CMakeLists.txt Resolved
@Mikolaj-A-Kowalski

Copy link
Copy Markdown
Contributor Author

Trying to avoid recompiling the sources twice (once for SHARED and STATIC libraries). I am not sure it will be easy. Furthermore it may not be really what we want. We do compile executables with position independent code -fPIC at the moment, but it is not something we need to do)

Ad above, just providing a static library as a dependency of a dynamic library runs into an issue that there are no "extra" sources in the dynamic library target. CMake complains about lack of sources in that case :-/

@TomMelt

TomMelt commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

thanks @Mikolaj-A-Kowalski this will be extremely useful for the decomp tool.

Comment thread unit_test/CMakeLists.txt Resolved

@jatkinson1000 jatkinson1000 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems sensible to me @Mikolaj-A-Kowalski and happy for merge.

Given the small source size I think a double compile is acceptable for now, and allows for a smoother integration with existing tests(?).

Happy for you to leave the dummy test for now and remove in a subsequent PR.

I see the building of unit tests is done, but are unit tests also included in the running (via ctest or similar)? Yes I think so, my CMake was a little fuzzy!

Comment thread unit_test/CMakeLists.txt Resolved
Comment thread CMakeLists.txt Resolved
NetCDF and Zoltan are already a dependency of the internal static
library and do not need to be attached to its consumers.
Doctest headers are already provided by the dependency on the doctest
target.
@Mikolaj-A-Kowalski
Mikolaj-A-Kowalski merged commit 0ee499f into main Oct 15, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants