Skip to content

chore: S24.02 adopt CALLED_* test macros + standardise *CallCount naming#322

Merged
DavidCozens merged 10 commits into
mainfrom
chore/s24-02-called-function-macro
May 10, 2026
Merged

chore: S24.02 adopt CALLED_* test macros + standardise *CallCount naming#322
DavidCozens merged 10 commits into
mainfrom
chore/s24-02-called-function-macro

Conversation

@DavidCozens

@DavidCozens DavidCozens commented May 10, 2026

Copy link
Copy Markdown
Owner

Purpose

S24.02 (#321) under E24 Code Hygiene (#254). Closes #321.

The test base mixed several call-count assertion shapes —
LONGS_EQUAL(N, fooCallCount), LONGS_EQUAL(N, FakeFoo_BarCount()),
CHECK_TRUE(barCalled) — with inconsistent variable naming
(SenderFake_SendCount, StoreFake_WriteCount, g_sleepCallCount,
storeFullCallbackCount, etc.). Two partial implementations
(bespoke CHECK_HANDLER_INVOKED_ONCE macros in SolidSyslogErrorTest.cpp
and an expression-form CALLED_FUNCTION(f, n) already in TestUtils.h)
hinted at the shape of the answer but didn't enforce naming. This PR
generalises both into a single design across every test executable.

Change Description

Tests/Support/TestUtils.h now defines three token-paste macros backed
by the existing CososoTesting::NEVER/ONCE/TWICE/THRICE enum:

CALLED_FUNCTION(name, count)            // local static int counter
CALLED_FAKE(getter, count)              // global-state fake getter
CALLED_FAKE_ON(getter, instance, count) // instance-parameter getter

Token paste enforces the <functionName>CallCount naming rule at
compile time, so future drift is caught by the build rather than in
review.

Other notable changes:

  • Tests/TestUtils.h moved to Tests/Support/TestUtils.h so
    non-Tests/-root executables (Example, FreeRtos) can reach it via
    the established Support include path.
  • Counter renames to follow the <funcName>CallCount rule:
    SenderFake_SendCountSendCallCount, StoreFake_WriteCount
    WriteCallCount, g_sleepCallCountNoOpSleepCallCount,
    getPort/HostCallCountSpyGetPort/HostCallCount,
    sleepCallCountSleepFakeCallCount, storeFullCallbackCount
    CountStoreFullInvocationsCallCount, thresholdCallbackCount
    CountThresholdCrossingsCallCount.
  • Bool flags converted to int counters:
    storeFullCallbackInvoked / computeIntegrityCalled /
    verifyIntegrityCalled. Tests now also catch unexpected
    double-fires of these callbacks/spies.
  • Bespoke CHECK_HANDLER_INVOKED_ONCE / CHECK_HANDLER_NOT_INVOKED
    macros
    in SolidSyslogErrorTest.cpp removed in favour of the
    generic CALLED_FUNCTION(handler, ...).
  • Existing CALLED_FUNCTION(expr, n) callers in
    SolidSyslogSwitchingSenderTest.cpp migrated to CALLED_FAKE_ON
    (every site there was structurally an instance-getter call).
  • Tests/FreeRtos/CMakeLists.txt picks up Tests/Support on the
    include path of all four FreeRtos host test executables.

E24 itself was renamed from "Hardening" to "Code Hygiene" earlier in
the session — the body was already written for cross-cutting
non-functional sweeps; only the title was wrong. Robustness work
continues to live in E12 / E25 / E26.

Test Evidence

Pure refactor of existing test assertions; no new tests, no
production code touched. Verification:

  • cmake --build --preset debug --target junit — 1088 tests pass.
  • cmake --build --preset clang-debug --target junit — 1088 tests pass.
  • cmake --build --preset sanitize --target junit — 1088 tests pass.
  • cmake --build --preset coverage --target coverage — 100% lines,
    100% functions (no change from baseline).
  • cmake --build --preset tidy — clean.
  • cmake --build --preset cppcheck — clean.
  • clang-format --dry-run --Werror over Core/Tests/Example — clean.
  • FreeRtos host build verified separately:
    SolidSyslogFreeRtosDatagramTest (21 tests),
    CmsdkUartTest (15), SolidSyslogFreeRtosSysUpTimeTest (4),
    SolidSyslogFreeRtosStaticResolverTest (10) — all green.
  • Winsock-build variants (*Winsock*Test.cpp) converted via the same
    mechanical sweep but exercised by CI only.

Areas Affected

  • Tests/Support/TestUtils.h — new home for the three call-count
    macros. The existing MinSize helper and the CososoTesting
    namespace stay.
  • 23 test files swept across Tests/, Tests/Example/, and
    Tests/FreeRtos/. No production code touched (Tier 1/2 boundary
    preserved).
  • Tests/FreeRtos/CMakeLists.txt — three FreeRtos test
    executables now include Tests/Support on their include path.
  • No impact on derived projects: this PR only touches Tests/ and
    the test build's CMake. Core/Interface, Core/Source,
    Platform/, and the public API surface are unchanged.

Summary by CodeRabbit

Release Notes

  • Tests

    • Standardized test assertions across all test suites using unified call-count verification macros
    • Replaced manual fake call-count checks with consistent assertion patterns for improved test clarity
    • Enhanced test infrastructure with new utilities to better detect and prevent unexpected function invocations
  • Chores

    • Updated test build configuration to include new testing support utilities
    • Renamed test helper functions for naming consistency and clarity

Review Change Stack

DavidCozens and others added 10 commits May 10, 2026 21:43
Pure rename ahead of the upcoming CALLED_FUNCTION test macro sweep.
Aligns SenderFake_SendCount / DisconnectCount with the *CallCount
naming rule that the new token-paste macros enforce.

No behaviour change; 1088 tests still pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Replaces TestUtils.h's single expression-based CALLED_FUNCTION with
three token-paste macros that enforce the <name>CallCount naming rule
at compile time:

  CALLED_FUNCTION(name, count)            for local static counters
  CALLED_FAKE(getter, count)              for global-state fake getters
  CALLED_FAKE_ON(getter, instance, count) for instance-parameter getters

Migrates the two pre-existing call sites:

- SolidSyslogSwitchingSenderTest.cpp — was the only consumer of the
  old expression form; every site fits CALLED_FAKE_ON cleanly after
  the SenderFake *Count -> *CallCount rename.

- SolidSyslogErrorTest.cpp — the bespoke CHECK_HANDLER_INVOKED_ONCE /
  CHECK_HANDLER_NOT_INVOKED macros are now redundant; replaced with
  CALLED_FUNCTION(handler, ...).

CososoTesting namespace + NEVER/ONCE/TWICE/THRICE enum unchanged.
1088 tests still pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Aligns the last non-conforming fake-library getter with the *CallCount
naming rule. Pure rename; 1088 tests still pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Renames g_sleepCallCount to NoOpSleepCallCount (matches the function
that increments it), and converts every call-count assertion in the
file (50 sites) to the new macros: CALLED_FAKE for global-state
OpenSslFake getters, CALLED_FAKE_ON for instance-parameter StreamFake
getters, CALLED_FUNCTION for the local sleep counter.

1088 tests still pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…macros

Renames the local SpyGetHost / SpyGetPort callback counters from
get*CallCount to Spy*CallCount (matches the function names) and sweeps
every call-count assertion in both files: CALLED_FAKE for global-state
SocketFake getters, CALLED_FUNCTION for the local spy counters, with a
single explicit-literal site for the reconnect-relative count expression.

1088 tests still pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Test utilities header was reachable from files in Tests/ via the
implicit-source-dir lookup, but not from Tests/Example/ or
Tests/FreeRtos/ where the upcoming sweep will need it. Tests/Support
is the established home for shared test infrastructure (SafeString,
TestAtomicOps, fake libraries) and is already on the include path of
SolidSyslogTests and ExampleTests via the PosixFakes/WinsockFakes
PUBLIC include directory.

Adds Tests/Support to the FreeRtos test include paths preemptively
so the call-count macro sweep can reach TestUtils.h there too.

1088 tests still pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
ExampleServiceThreadTest:
- Renames sleepCallCount -> SleepFakeCallCount (matches the function
  that increments it).
- Converts the call-count assertion to CALLED_FUNCTION; the unrelated
  lastSleepMs assertion stays as LONGS_EQUAL (it tracks the captured
  argument, not a count).

BlockStoreTest (the substantial site):
- Converts three bool flags to int counters following the *CallCount
  rule: storeFullCallbackInvoked -> StoreFullCallbackCallCount,
  computeIntegrityCalled -> SpyComputeIntegrityCallCount,
  verifyIntegrityCalled -> SpyVerifyIntegrityCallCount. Now catches
  unexpected double-calls.
- Renames storeFullCallbackCount -> CountStoreFullInvocationsCallCount
  and thresholdCallbackCount -> CountThresholdCrossingsCallCount
  (matches the existing function names).
- All call-count assertions in both files migrated to CALLED_FUNCTION /
  CALLED_FAKE / CALLED_FAKE_ON; CHECK_TRUE/CHECK_FALSE on the converted
  flags become CALLED_FUNCTION(..., ONCE/NEVER).

1088 tests still pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Final conversion pass across the test base. Mechanical sed:
- LONGS_EQUAL(N, Foo_BarCallCount())     -> CALLED_FAKE(Foo_Bar, N)
- LONGS_EQUAL(N, Foo_BarCallCount(inst)) -> CALLED_FAKE_ON(Foo_Bar, inst, N)
- LONGS_EQUAL(N, fooCallCount)           -> CALLED_FUNCTION(foo, N)
where N is mapped to NEVER/ONCE/TWICE/THRICE for 0..3, otherwise
passed through as a literal.

Adds #include "TestUtils.h" + `using namespace CososoTesting;` to
each newly-affected file.

Files swept (19): DatagramFakeTest, OpenSslFakeTest, SenderFakeTest,
SocketFakeTest, StoreFakeTest, StreamFakeTest, WinsockFakeTest,
SolidSyslogTest, SolidSyslogNullBufferTest,
SolidSyslogPosixDatagramTest, SolidSyslogPosixMessageQueueBufferTest,
SolidSyslogPosixTcpStreamTest, SolidSyslogGetAddrInfoResolverTest,
SolidSyslogWinsockDatagramTest, SolidSyslogWinsockResolverTest,
SolidSyslogWinsockTcpStreamTest, Example/SolidSyslogExampleTest,
FreeRtos/CmsdkUartTest, FreeRtos/SolidSyslogFreeRtosDatagramTest.

Verified:
- gcc preset: 1088 tests pass.
- freertos-host build: SolidSyslogFreeRtosDatagramTest (21),
  CmsdkUartTest (15), SolidSyslogFreeRtosSysUpTimeTest (4),
  SolidSyslogFreeRtosStaticResolverTest (10) — all green.
- Winsock variants converted but compile-checked via CI only.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
clang-format -i across the touched test files. Picks up:
- a small alignment shift on the bool->int fields in BlockStoreTest
- the long `using namespace CososoTesting;` NOLINT comment wraps onto
  two lines under the 160-col limit
- minor indentation tweaks in TlsStreamTest macro definitions

No behaviour change; 1088 tests still pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented May 10, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f6dbb192-1de1-45ac-9d44-c16119bbbee3

📥 Commits

Reviewing files that changed from the base of the PR and between ae6a21c and 28363e0.

📒 Files selected for processing (34)
  • DEVLOG.md
  • Tests/DatagramFakeTest.cpp
  • Tests/Example/ExampleServiceThreadTest.cpp
  • Tests/Example/SolidSyslogExampleTest.cpp
  • Tests/FreeRtos/CMakeLists.txt
  • Tests/FreeRtos/CmsdkUartTest.cpp
  • Tests/FreeRtos/SolidSyslogFreeRtosDatagramTest.cpp
  • Tests/OpenSslFakeTest.cpp
  • Tests/SenderFake.c
  • Tests/SenderFake.h
  • Tests/SenderFakeTest.cpp
  • Tests/SocketFakeTest.cpp
  • Tests/SolidSyslogBlockStoreTest.cpp
  • Tests/SolidSyslogErrorTest.cpp
  • Tests/SolidSyslogGetAddrInfoResolverTest.cpp
  • Tests/SolidSyslogNullBufferTest.cpp
  • Tests/SolidSyslogPosixDatagramTest.cpp
  • Tests/SolidSyslogPosixMessageQueueBufferTest.cpp
  • Tests/SolidSyslogPosixTcpStreamTest.cpp
  • Tests/SolidSyslogStreamSenderTest.cpp
  • Tests/SolidSyslogSwitchingSenderTest.cpp
  • Tests/SolidSyslogTest.cpp
  • Tests/SolidSyslogTlsStreamTest.cpp
  • Tests/SolidSyslogUdpSenderTest.cpp
  • Tests/SolidSyslogWinsockDatagramTest.cpp
  • Tests/SolidSyslogWinsockResolverTest.cpp
  • Tests/SolidSyslogWinsockTcpStreamTest.cpp
  • Tests/StoreFake.c
  • Tests/StoreFake.h
  • Tests/StoreFakeTest.cpp
  • Tests/StreamFakeTest.cpp
  • Tests/Support/TestUtils.h
  • Tests/TestUtils.h
  • Tests/WinsockFakeTest.cpp
💤 Files with no reviewable changes (1)
  • Tests/TestUtils.h

📝 Walkthrough

Walkthrough

This PR standardizes test call-count assertions across 30+ test files by introducing three token-paste macros in a new Tests/Support/TestUtils.h header and renaming fake accessors to conform to the *CallCount convention. The refactor replaces ad-hoc LONGS_EQUAL and CHECK_TRUE patterns with intent-named CALLED_FUNCTION, CALLED_FAKE, and CALLED_FAKE_ON macros, centralizing the naming contract and making test bodies more readable.

Changes

Test Macro Standardization

Layer / File(s) Summary
Macro & Enum Definitions
Tests/Support/TestUtils.h
New header defines CALLED_FUNCTION(name, count), CALLED_FAKE(getter, count), and CALLED_FAKE_ON(getter, instance, count) macros alongside CososoTesting enum constants (NEVER=0, ONCE=1, TWICE=2, THRICE=3). Includes MinSize utility.
Old Header Removal
Tests/TestUtils.h
Delete original header after migrating utilities to Tests/Support/TestUtils.h.
Fake API Renames
Tests/SenderFake.h, Tests/SenderFake.c, Tests/StoreFake.h, Tests/StoreFake.c
Rename accessor functions to enforce *CallCount naming: SenderFake_SendCount()SenderFake_SendCallCount(), SenderFake_DisconnectCount()SenderFake_DisconnectCallCount(), StoreFake_WriteCount()StoreFake_WriteCallCount().
CMake Include Paths
Tests/FreeRtos/CMakeLists.txt
Add ${CMAKE_SOURCE_DIR}/Tests/Support to target_include_directories for SolidSyslogFreeRtosDatagramTest, SolidSyslogFreeRtosStaticResolverTest, and CmsdkUartTest.
Test Header Includes & Namespace
Tests/*/*.cpp, Tests/*FakeTest.cpp
Add #include "TestUtils.h" and using namespace CososoTesting; to 30+ test files to bring macros and enum constants into scope.
Counter Variable Renames
Tests/Example/ExampleServiceThreadTest.cpp, Tests/SolidSyslogBlockStoreTest.cpp, Tests/SolidSyslogTlsStreamTest.cpp, Tests/SolidSyslogStreamSenderTest.cpp, Tests/SolidSyslogUdpSenderTest.cpp
Rename boolean flags and counters to conform to *CallCount rule: sleepCallCountSleepFakeCallCount, g_sleepCallCountNoOpSleepCallCount, storeFullCallbackInvokedStoreFullCallbackCallCount, getPortCallCountSpyGetPortCallCount, computeIntegrityCalled/verifyIntegrityCalledSpyComputeIntegrityCallCount/SpyVerifyIntegrityCallCount.
Assertion Macro Migration
Tests/*FakeTest.cpp, Tests/Posix*.cpp, Tests/Winsock*.cpp, Tests/SolidSyslog*.cpp, Tests/Example/*.cpp, Tests/FreeRtos/*.cpp
Replace 200+ LONGS_EQUAL(*CallCount()) and CHECK_TRUE/FALSE(called) assertions with CALLED_FUNCTION, CALLED_FAKE, or CALLED_FAKE_ON across all test suites. Update helper macros (e.g., CHECK_SOCKET_CLOSED_ONCE()) to use new macro style.
Change Log
DEVLOG.md
Add entry for 2026-05-10 — S24.02: documents test-hygiene macro sweep, counter naming standardization, E24 epic rename, adoption details, and deferred items.

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly Related PRs

Poem

🐰 Hop, hop, test assertions now align,
CALLED_FAKE, CALLED_FUNCTION—macros so divine!
No more LONGS_EQUAL sprawl,
One naming rule to rule them all,
CallCounts crystal-clear and fine!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 9.35% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The PR title accurately describes the main changes: adoption of CALLED_* test macros and standardization of *CallCount naming across the test base.
Description check ✅ Passed The PR description comprehensively covers Purpose, Change Description, Test Evidence, and Areas Affected sections, matching the template requirements with detailed explanations of the refactoring scope and verification.
Linked Issues check ✅ Passed The PR implements all requirements from issue #321: moves TestUtils.h to Tests/Support, defines three token-paste macros (CALLED_FUNCTION, CALLED_FAKE, CALLED_FAKE_ON) with *CallCount naming enforcement, renames all non-conforming counters, converts boolean flags to int counters, removes bespoke macros, and sweeps 23 test files across all test executables to use the new macros consistently.
Out of Scope Changes check ✅ Passed All changes remain within scope: test-only refactoring across Tests/, Tests/Example/, Tests/FreeRtos/ and CMake configuration; no production code (Tier 1/2) touched; explicitly preserved exceptions (lastCount, spy.callCount) noted; move of TestUtils.h to Support directory is intentional to broaden test reachability.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/s24-02-called-function-macro

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

Copy link
Copy Markdown
Contributor

☀️   Quality Summary

   🚦   build-linux-gcc: 100% successful (✔️ 1109 passed, 🙈 3 skipped)
   🚦   build-linux-clang: 100% successful (✔️ 1046 passed, 🙈 3 skipped)
   🚦   sanitize-linux-gcc: 100% successful (✔️ 1046 passed, 🙈 3 skipped)
   🚦   integration-linux-openssl: 100% successful (✔️ 9 passed)
   🚦   integration-windows-openssl: 100% successful (✔️ 9 passed)
   🚦   bdd-linux-syslog-ng: 94% successful (✔️ 46 passed, 🙈 3 skipped)
   🚦   bdd-windows-otel: 90% successful (✔️ 44 passed, 🙈 5 skipped)
   🚦   bdd-freertos-qemu: 49% successful (✔️ 24 passed, 🙈 25 skipped)
   🚦   build-windows-msvc: 100% successful (✔️ 958 passed, 🙈 1 skipped)
   ⚠️   Clang-Tidy: No warnings
   ⚠️   CPPCheck: No warnings


Created by Quality Monitor v1.14.0 (#f3859fd). More details are shown in the GitHub Checks Result.

@DavidCozens DavidCozens merged commit e4c8b02 into main May 10, 2026
19 checks passed
@DavidCozens DavidCozens deleted the chore/s24-02-called-function-macro branch May 10, 2026 21:19
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.

S24.02: Adopt CALLED_FUNCTION test macro and standardise *CallCount naming

1 participant