Skip to content

Add native C++ ctest suite#1162

Merged
bengineerd merged 26 commits into
pre-releasefrom
cpp-tests
Apr 13, 2026
Merged

Add native C++ ctest suite#1162
bengineerd merged 26 commits into
pre-releasefrom
cpp-tests

Conversation

@bengineerd

@bengineerd bengineerd commented Mar 31, 2026

Copy link
Copy Markdown
Contributor

Description

This branch adds the first native C++ regression suite under tests/cpp/ and wires it into the main CMake/CTest flow. The new coverage stays intentionally narrow and fast. It implements deterministic native tests for version helpers, memory bit helpers, stream frame/pool behavior, and stream iterator behavior, plus a Python-enabled API smoke test managed by CTest.

This change also replaces the old standalone tests/api_test sample executable with a CTest-managed smoke test, updates the test documentation to describe how the native suite is built and run from the standard build/ tree, and updates CI so the native test labels run as part of the existing build jobs.

Details

The native test system is added behind ROGUE_BUILD_TESTS in the top-level CMake build and uses an in-tree single-header doctest-compatible harness plus a shared support target so individual test files stay focused on behavior. The suite is organized under tests/cpp/ by subsystem and uses CTest labels (cpp, cpp-core, no-python, requires-python, smoke) to keep local runs and CI selection predictable.

Two product bugs were exposed while building the deterministic native coverage and are fixed here:

  1. src/rogue/interfaces/memory/Master.cpp
    The copyBits, setBits, and anyBits helpers all use a do { ... } while (...) structure after initializing rem = size. When size == 0, the old code still executed the loop body once before checking termination. That made zero-length operations unsafe: a no-op request could still calculate masks, read source bits, inspect destination bits, or write into the destination buffer even though no bits were requested. The fix adds an immediate zero-length return at the top of each helper, preserving the expected semantics: copyBits and setBits become true no-ops, and anyBits returns false without touching memory.

  2. src/rogue/interfaces/stream/Pool.cpp
    The pool destructor previously freed dataQ_.front() inside while (!dataQ_.empty()) but never removed the front element from the queue. In practice that means the destructor repeatedly frees the same pointer while the queue never advances, which can lead to double-free behavior or an infinite drain loop during teardown. The fix pops the queue entry after each free() so the destructor actually walks and releases every pooled allocation exactly once.

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 54.51%. Comparing base (b89f702) to head (c528122).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff              @@
##           pre-release    #1162   +/-   ##
============================================
  Coverage        54.51%   54.51%           
============================================
  Files               70       70           
  Lines             7862     7862           
  Branches          1179     1179           
============================================
  Hits              4286     4286           
  Misses            3300     3300           
  Partials           276      276           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI 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.

Pull request overview

Adds a first native C++ test suite under tests/cpp/ and wires it into the main CMake/CTest flow, while also replacing the legacy standalone tests/api_test executable with a CTest-managed API smoke test. This also includes two small product bug fixes uncovered by the new deterministic coverage.

Changes:

  • Introduce a native C++ doctest-compatible harness + shared test support target and add initial deterministic unit tests + a Python-backed API smoke test.
  • Integrate the native suite into top-level CMake/CTest and CI (CTest labels for selection).
  • Fix two runtime bugs: zero-length safety in memory bit helpers and Pool destructor queue draining.

Reviewed changes

Copilot reviewed 27 out of 28 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
CMakeLists.txt Adds ROGUE_BUILD_TESTS option and wires tests/cpp into the main build/CTest flow.
.github/workflows/rogue_ci.yml Updates CI to build via cmake -S/-B and run labeled native CTest suites in both Python and no-Python jobs.
src/rogue/interfaces/memory/Master.cpp Fixes zero-length handling in copyBits, setBits, and anyBits.
src/rogue/interfaces/stream/Pool.cpp Fixes destructor draining logic by popping the queue after free().
tests/README.md Updates test layout docs to include the new native C++ suite and CTest commands.
tests/BRANCH_STATUS.md Adds branch handoff/status documentation for the broader test/coverage effort.
tests/NEXT_STEPS.md Adds follow-up checklist and recommended validation commands.
tests/cpp/CMakeLists.txt Adds shared test support library and rogue_add_cpp_test() helper; registers sub-suites and labels.
tests/cpp/README.md Documents native C++ suite structure, labels, and common build/run commands.
tests/cpp/vendor/doctest/doctest.h Adds in-tree minimal doctest-compatible single-header test harness.
tests/cpp/support/test_main.cpp Adds shared test runner main() with optional embedded Python/NumPy bootstrap.
tests/cpp/support/test_python.h Declares shared Python/NumPy initialization helper for smoke tests.
tests/cpp/support/test_helpers.h Adds shared stream pool/frame helpers and a polling helper for async assertions.
tests/cpp/core/CMakeLists.txt Registers core native test targets and labels.
tests/cpp/core/test_version.cpp Adds deterministic tests for rogue::Version helpers and validation behavior.
tests/cpp/memory/CMakeLists.txt Registers memory native test targets and labels.
tests/cpp/memory/test_memory_bits.cpp Adds deterministic tests for memory bit helper routines, including zero-length behavior.
tests/cpp/memory/test_transaction_block.cpp Adds deterministic tests for block transaction sequencing/min-access expansion/verify mismatch behavior.
tests/cpp/memory/test_variable.cpp Adds deterministic tests for variable metadata, offset shifting, typed accessor rejection, and list stride/range checks.
tests/cpp/stream/CMakeLists.txt Registers stream native test targets and labels.
tests/cpp/stream/test_frame_pool.cpp Adds deterministic tests for pool allocation, multi-buffer frame behavior, append semantics, and payload helpers.
tests/cpp/stream/test_iterator.cpp Adds deterministic tests for frame iterator traversal, payload vs capacity, and iterator-driven copies.
tests/cpp/stream/test_fifo_filter_rate_drop.cpp Adds deterministic tests for FIFO trim/drop behavior, filter rules, and RateDrop count-mode behavior.
tests/cpp/smoke/CMakeLists.txt Registers Python-required API smoke test and labels.
tests/cpp/smoke/test_api_smoke.cpp Adds embedded-Python API smoke test exercising rogue::interfaces::api::Bsp against a minimal in-test module/root.
tests/api_test/README.md Marks legacy standalone API test path as deprecated in favor of CTest smoke.
tests/api_test/src/api_test.cpp Removes legacy standalone sample executable source.
tests/api_test/CMakeLists.txt Removes legacy standalone sample build system.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/README.md Outdated
Comment thread tests/cpp/smoke/test_api_smoke.cpp Outdated
Comment thread CMakeLists.txt Outdated
@bengineerd bengineerd requested a review from Copilot April 13, 2026 16:50

Copilot AI 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.

Pull request overview

Copilot reviewed 27 out of 28 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/cpp/README.md
Comment thread tests/README.md
Comment thread tests/cpp/support/test_helpers.h
@bengineerd bengineerd marked this pull request as ready for review April 13, 2026 17:17

Copilot AI 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.

Pull request overview

Copilot reviewed 27 out of 28 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/cpp/vendor/doctest/doctest.h Outdated
Comment thread tests/cpp/vendor/doctest/doctest.h Outdated
@bengineerd bengineerd merged commit 5ae84d9 into pre-release Apr 13, 2026
7 checks passed
@bengineerd bengineerd deleted the cpp-tests branch April 13, 2026 20:45
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.

5 participants