Skip to content

COMP: Compile the UnitTestCommon helpers once per test target - #1983

Merged
imikejackson merged 2 commits into
BlueQuartzSoftware:developfrom
joeykleingers:topic/unittestcommon-compile-time
Nov 19, 2026
Merged

imikejackson merged 2 commits into
BlueQuartzSoftware:developfrom
joeykleingers:topic/unittestcommon-compile-time

Conversation

@joeykleingers

Copy link
Copy Markdown
Contributor

Summary

UnitTestCommon.hpp defined 25 test helpers inline. Every test file that includes the header compiled their bodies and the templates that they instantiate, also when the file did not call them. This change moves 24 helpers to UnitTestCommon.cpp, which each test target compiles once. It also makes the namespace-scope constants one object per program, removes three names that nothing uses, and adds a knowledge-base entry. The behavior of the tests does not change. 3 files changed, +1149 / −1069 lines.

1. Helpers defined in the source file

  • test/UnitTestCommon/include/simplnx/UnitTest/UnitTestCommon.hpp: declarations, default arguments and documentation of the helpers.
  • test/UnitTestCommon/include/simplnx/UnitTest/UnitTestCommon.cpp: the 24 definitions, with unchanged bodies.

The moved helpers include LoadPlugins, CheckArraysInheritTupleDims, CompareDataStructures, CompareImageGeometry, CompareExemplarToGeneratedData, CreateDataStructure, the Cropping helpers and the SmallIn100 helpers. The template helpers stay in the header. The header keeps all of its includes, so test files that use names from those includes compile without changes.

The 18 DataPath constants, the two FilterHandle constants and the SmallIn100::k_TupleCheckIgnoredPaths list are inline const. Each test program has one object of each, not one copy in each test file. The three Uuid constants that the FilterHandle constants refer to are inline constexpr, so that every definition of a handle refers to the same objects.

2. Removed names

UnitTest::CompareMontage, Constants::k_CalculatedShiftsPath and Constants::k_ActiveArrayPath had no users in simplnx, DREAM3D-NX or the simplnx plugin repositories, and are removed.

3. Compatibility

  • Code that uses one of the three removed names does not compile.
  • A test target that includes UnitTestCommon.hpp and calls a moved helper must compile UnitTestCommon.cpp. Targets that link the simplnx::UnitTestCommon CMake target (all simplnx test targets, conversion_test and the DREAM3D-NX test targets) get it automatically.

4. Knowledge base

  • docs/Coding_Knowledge_Base.md: new Testing entry "Define shared test helpers in a source file, not inline in a header".

5. Measured compile time

On macOS (AppleClang, Release), each of the 332 objects in the in-core DREAM3D-NX build that includes UnitTestCommon.hpp was compiled with and without the change, two times each. The total compile CPU time is 1652 s before and 1374 s after (−278 s, −16.8%). The test files use 305 s less (0.96 s per file on average; no file is slower). UnitTestCommon.cpp uses 33.5 s more, for its 7 compiles. The out-of-core test targets were not measured.

Test plan

  • An independent token-level check shows that the 24 moved definitions have the same bodies, signatures, default arguments and namespaces as on develop.
  • macOS in-core Release build (DREAM3D-NX with this simplnx): all 4152 tests of the simplnx test programs, VizTests and the benchmark pass.
  • macOS out-of-core Release build: all 1052 tests with the ooc label (without benchmarks) pass, including the out-of-core plugin's test targets.
  • Each test target compiles UnitTestCommon.cpp one time and has one definition of each moved helper.
  • CI passes on Linux, macOS and Windows.

Related Issue

  • This PR has no related issue

@joeykleingers joeykleingers self-assigned this Nov 16, 2026
joeykleingers added a commit to joeykleingers/simplnx that referenced this pull request Nov 16, 2026
…e entry

Signed-off-by: Joey Kleingers <joey.kleingers@bluequartz.net>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

joeykleingers added a commit to joeykleingers/simplnx that referenced this pull request Nov 16, 2026
…e entry

Signed-off-by: Joey Kleingers <joey.kleingers@bluequartz.net>
@joeykleingers
joeykleingers force-pushed the topic/unittestcommon-compile-time branch from 8579166 to 426954b Compare November 16, 2026 16:00
@joeykleingers

Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@imikejackson
imikejackson enabled auto-merge (squash) November 19, 2026 18:34
imikejackson pushed a commit to joeykleingers/simplnx that referenced this pull request Nov 19, 2026
…e entry

Signed-off-by: Joey Kleingers <joey.kleingers@bluequartz.net>
@imikejackson
imikejackson force-pushed the topic/unittestcommon-compile-time branch from 426954b to 1ab10ea Compare November 19, 2026 18:34
UnitTestCommon.hpp defined 25 helpers inline. Every test file that
includes it compiled their bodies and the templates they instantiate,
and each object that called one generated it again. 24 of them are now
defined in UnitTestCommon.cpp, which each test target already compiles
once; the header keeps the declarations, default arguments and
documentation. CompareMontage, Constants::k_CalculatedShiftsPath and
Constants::k_ActiveArrayPath had no users and are removed.

The namespace-scope DataPath, FilterHandle and DataPath-list constants
are inline, so each program has one object instead of one per test
file. The UUIDs that the FilterHandle constants bind by reference are
inline as well, so every definition of a handle refers to the same
objects.

The knowledge base gets a Testing entry on defining shared test helpers
in a source file.

Signed-off-by: Joey Kleingers <joey.kleingers@bluequartz.net>
…e entry

Signed-off-by: Joey Kleingers <joey.kleingers@bluequartz.net>
@imikejackson
imikejackson force-pushed the topic/unittestcommon-compile-time branch from 1ab10ea to 0b4239a Compare November 19, 2026 20:34
@imikejackson

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@imikejackson
imikejackson merged commit 47933be into BlueQuartzSoftware:develop Nov 19, 2026
5 checks passed
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.

2 participants