Repository navigation
test: call the library API from C++ and build a consumer project - #22
Merged
Merged
Conversation
The public header uses std::optional and a nested namespace, but the C++
standard was only set for this project's own targets. A consumer linking
coretrace::runtime-analyzer_lib with its compiler's default standard failed
to include runtime_analyzer.hpp ("no template named 'optional'"). The
library now carries cxx_std_20 as a public compile feature.
Found by the consumer test of the next commit. Part of #21.
Run and RunBatch were only reached through the CLI, while ctrace will link the library (CoreTrace/coretrace#112). api_unit drives them on real programs: the heap overflow fixture gives one finding with its rule, CWE, severity, faulting line and allocation site; a compile-only run succeeds without executing; a hanging program is killed at the timeout and reported as timed out; a batch of three sources reports each one in path order with its counters and verdict 2; compile-only flags with a run are refused; an empty directory is not analyzed. The consumer test configures and builds unittests/consumer, a project that fetches this repository on a release tag the way ctrace does, links coretrace::runtime-analyzer_lib and analyzes a program. The test points FetchContent at the checkout under test and at the already fetched coretrace-compiler and logger sources, so nothing is cloned. Its first run failed on the missing C++20 requirement fixed by the previous commit. Part of #21.
This was referenced Sep 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Item 1 of #21: the library API called from C++, and a project consuming the library the way ctrace will (CoreTrace/coretrace#112).
Change
api_unit(unittests/api_test.cpp):RunandRunBatchon real programs, compiled with coretrace-compiler and executed. The heap overflow fixture gives one finding with its rule, CWE, severity, message, faulting line and column, and allocation site in the same source. A compile-only run succeeds without executing and leaves the binary atoutput_path. A hanging program is killed after the 1 s timeout, reportedtimed_outand not a success, within seconds. A batch of three sources (hang, overflow, clean) reports them in path order with each one's result,timeouts=1, no compile failure,successand verdict2. Compile-only flags with a run are refused with a diagnostic naming--no-run. An empty directory is not analyzed and says so.consumer:unittests/consumer/is a complete consumer,FetchContent_Declareon the release tag andcoretrace::runtime-analyzer_lib, whosemainanalyzes a program and prints its findings. The test configures it with the same generator, compilers and LLVM as this build, pointsFETCHCONTENT_SOURCE_DIR_RUNTIME_ANALYZERat the checkout under test and theCCandCORETRACE_LOGGERones at the sources already fetched here (nothing is cloned), builds it and expectsheap-buffer-overflow CWE-122onheap_overflow_write.c. It lives underunittests/, nottest/, which the sweeps run in full.build: require C++20 of the library's consumers: the first run of the consumer test failed to includeruntime_analyzer.hpp(no template named 'optional' in namespace 'std'), because the C++ standard was set for this project's targets only.cxx_std_20is now a public compile feature of the library. ctrace would have hit this on its first build.Tests (written first)
Both tests are the deliverable.
api_unitfailed on its first run on my prediction of the location's path (the runtime names the source as coretrace-compiler recorded it, which can be relative; the test checks the tail of the path and that the allocation site is in the same source).consumerfailed on the C++20 requirement, item 3 fixed it. WithParseFindingsdisabled inRun, both fail again: 2 checks inapi_unit, thegrepinconsumer.Verification
ctest --test-dir build14/14,consumerin 10 to 18 s;./scripts/format-check.shclean.Buildworkflow.