Skip to content

Wrap macro test driver code inside ptf::TestRunner#2088

Open
Dimi1010 wants to merge 3 commits intoseladb:devfrom
Dimi1010:refactor/test-runner
Open

Wrap macro test driver code inside ptf::TestRunner#2088
Dimi1010 wants to merge 3 commits intoseladb:devfrom
Dimi1010:refactor/test-runner

Conversation

@Dimi1010
Copy link
Copy Markdown
Collaborator

@Dimi1010 Dimi1010 commented Mar 24, 2026

The PR wraps the test driver code that was previously embedded in the macros PTF_START_RUNNING_TESTS, PTF_RUN_TEST and PTF_END_RUNNING_TESTS inside the ptf::TestRunner class.

Rationale

The change improves debugging UX by allowing step through debugging inside the test driver code.
Previously the embedded macro code was not "seen" by the IDE environment as actual code. This meant that debugging functionality like breakpoints and step through debuggers were unavailable inside those fragments. The entire macro code was treated as one line, instead of a code block.

Changes

The PR moves the code from the embedded macros into a wrapper class TestRunner. This allows the IDE to treat the code as regular code instead of macro text, thus allowing improved debugger support.

The functionality has been moved according to the following table:

Functionality Original location New location
Setup test environment PTF_START_RUNNING_TESTS TestRunner constructor
Run test case PTF_RUN_TEST TestRunner::runTest
Display aggregated test results PTF_END_RUNNING_TESTS TestRunner::finalizeResults

Compatibility

The old macros are kept as thin wrappers over the TestRunner instance to preserve compatibility with existing code.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 24, 2026

Codecov Report

❌ Patch coverage is 49.15254% with 30 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.97%. Comparing base (c70465d) to head (0481257).
⚠️ Report is 5 commits behind head on dev.

Files with missing lines Patch % Lines
Tests/PcppTestFramework/PcppTestFrameworkRun.h 49.15% 21 Missing and 9 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #2088      +/-   ##
==========================================
- Coverage   84.42%   83.97%   -0.45%     
==========================================
  Files         312      316       +4     
  Lines       56369    57031     +662     
  Branches    11603    11799     +196     
==========================================
+ Hits        47587    47893     +306     
- Misses       7637     7975     +338     
- Partials     1145     1163      +18     
Flag Coverage Δ
alpine320 76.96% <50.00%> (+0.21%) ⬆️
fedora42 76.52% <50.00%> (+0.22%) ⬆️
macos-14 82.07% <46.55%> (-0.04%) ⬇️
macos-15 82.06% <46.55%> (-0.04%) ⬇️
mingw32 70.71% <ø> (-0.01%) ⬇️
mingw64 70.69% <ø> (+0.10%) ⬆️
npcap ?
rhel94 76.35% <48.78%> (+0.23%) ⬆️
ubuntu2004 59.80% <45.23%> (-0.02%) ⬇️
ubuntu2004-zstd 59.90% <45.23%> (-0.02%) ⬇️
ubuntu2204 76.35% <48.78%> (+0.23%) ⬆️
ubuntu2204-icpx 59.08% <ø> (-0.04%) ⬇️
ubuntu2404 76.64% <50.00%> (+0.22%) ⬆️
ubuntu2404-arm64 76.65% <50.00%> (+0.22%) ⬆️
unittest 83.97% <49.15%> (-0.45%) ⬇️
windows-2022 85.59% <ø> (+0.11%) ⬆️
windows-2025 85.62% <ø> (+0.12%) ⬆️
winpcap 85.62% <ø> (-0.09%) ⬇️
xdp 53.26% <51.21%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

@Dimi1010 Dimi1010 marked this pull request as ready for review March 24, 2026 13:49
@Dimi1010 Dimi1010 requested a review from seladb as a code owner March 24, 2026 13:49
@seladb
Copy link
Copy Markdown
Owner

seladb commented Apr 6, 2026

@Dimi1010 this is (yet another) PR with many changes that is hard to review... TBH I'm not sure what's the benefit of it...

@Dimi1010
Copy link
Copy Markdown
Collaborator Author

Dimi1010 commented Apr 6, 2026

@Dimi1010 this is (yet another) PR with many changes that is hard to review... TBH I'm not sure what's the benefit of it...

The main benefit is improved IDE step through debugging support. When the code is directly embedded into the macro, it can't be stepped through via debugger (which I needed at the time I made this) since the IDE doesn't "see" the source code in the files. You also can't place breakpoints on it.

For example PTF_RUN_TEST, in the old version is treated as 1 line of code for the step through debugger. In the new version it can be stepped through line by line.

The changes are mainly just moving the code without functional changes.
PTR_RUN_TEST -> TestRunner::runTest
PTF_START_RUNNING_TESTS -> TestRunner ctor
PTF_END_RUNNING_TESTS ->TestRunner::finalizeResults

I can separate the rename of __ptfSplitString to ptfSplitString, because that is independent. But the rest are tied together or it won't compile.

The reason behind the rename of __ptfSplitString and __ptfCheckTags is because the current naming breaks this rule in the C++ standard for reserved identifiers:

The following identifiers are reserved and may not be declared in a program (doing so invokes undefined behavior):

Edit: The link is to the C reference, but it also applies to the C++ language spec here.

in the global namespace, identifiers that begin with an underscore

PS: I suppose I should have elaborated more in the PR description in the first place. Sorry.

@Dimi1010
Copy link
Copy Markdown
Collaborator Author

Dimi1010 commented Apr 6, 2026

@seladb Reverted the changes that aren't critical to the PR and improved the PR description. Hope it helps. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants