Skip to content

Added tests for static cache#920

Merged
ahcorde merged 1 commit intorollingfrom
ahcorde/rolling/test_static_cache
Apr 1, 2026
Merged

Added tests for static cache#920
ahcorde merged 1 commit intorollingfrom
ahcorde/rolling/test_static_cache

Conversation

@ahcorde
Copy link
Copy Markdown
Contributor

@ahcorde ahcorde commented Mar 24, 2026

Description

@PavelGuzenfeld do you mind to review this one ?

Add test to check static cache functionality. related with #769 and #908

Signed-off-by: Alejandro Hernandez Cordero <ahcorde@gmail.com>
@ahcorde ahcorde requested a review from asymingt March 24, 2026 11:03
@PavelGuzenfeld
Copy link
Copy Markdown
Contributor

Description

@PavelGuzenfeld do you mind to review this one ?

Add test to check static cache functionality. related with #769 and #908

NP. On it.

Copy link
Copy Markdown
Contributor

@PavelGuzenfeld PavelGuzenfeld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the tests @ahcorde! The two added tests correctly validate the core bug from #769getData() on an empty cache now returns false, and returns true after insertion.

Missing unit test coverage — the fix in #908 also changed these methods:

  • clearList() — now resets populated_ to false. Without a test, a regression here means cleared caches would still return stale data.
  • getListLength() — now returns 0 when empty, 1 when populated. Previously always returned 1.
  • getParent() — now returns 0 on empty cache instead of reading uninitialized frame_id_.

Sanitizer considerations — the original issue was actually discovered under ASan (--mixin asan-gcc). The bug caused callers to read uninitialized TransformStorage fields when the cache was empty. Worth verifying:

  • ASan — confirms no reads of uninitialized/out-of-bounds memory on the empty-cache path
  • UBSan — the old code returned storage_.frame_id_ from a default-constructed TransformStorage; depending on the type, this could be undefined behavior

Integration test idea — a tf2_ros level test that sets up a StaticTransformBroadcaster, queries a frame before any static transform is published, and confirms the lookup fails cleanly rather than returning garbage data. This would catch the bug at the user-facing API level, not just the cache internals.

Thread safetyStaticCache can be read/written from different threads (executor callbacks vs. transform lookups). A test that hammers insertData() and getData() concurrently under TSan would confirm the populated_ flag doesn't introduce a data race. The flag is a plain bool, not std::atomic<bool> — worth verifying this is safe under the existing mutex in BufferCore.

resetStorage() helper placement — it's defined as a free function between test cases. Moving it into the test fixture or an anonymous namespace would be cleaner and avoid potential ODR issues if more test files are added later.

Error string/code validation — the EmptyCacheRetrieval test checks the return value but not the error_str or error_code output parameters. The fix in #908 sets error_str = "Static cache is empty" and error_code = TF2_LOOKUP_ERROR — asserting on those would prevent someone from accidentally removing the error reporting while keeping the return false.

@ahcorde
Copy link
Copy Markdown
Contributor Author

ahcorde commented Apr 1, 2026

Pulls: #920
Gist: https://gist.githubusercontent.com/ahcorde/ae82445d32176e16abc4cf24ae9b6468/raw/7dad7659a16a284effbf9e3d12fd00e651020406/ros2.repos
BUILD args: --packages-above-and-dependencies tf2
TEST args: --packages-above tf2
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/18782

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

@ahcorde ahcorde merged commit a9e2147 into rolling Apr 1, 2026
2 of 3 checks passed
@ahcorde ahcorde deleted the ahcorde/rolling/test_static_cache branch April 1, 2026 17:01
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.

3 participants