Skip to content

Conversation

@ahoarau
Copy link
Contributor

@ahoarau ahoarau commented Nov 20, 2025

Description

This PR adds initial support for the Realtime Sanitizer (RTSan) that appeared in clang 20. It allow to check for the "realtime-safeness", by detecting dynamic memory allocations and source of non-determinism (like mutex lock, systems calls etc).
Before going all-in and instrument all the code with [[clang::nonblocking]], we start by writing a unittest that check for a the main API functions.

To test:

pixi run -e sanitizers test

Typical output might look like this:
image

https://clang.llvm.org/docs/RealtimeSanitizer.html
https://clang.llvm.org/docs/FunctionEffectAnalysis.html
https://github.com/realtime-sanitizer/rtsan

Checklist

  • I have run pre-commit run --all-files or pixi run lint
  • I have performed a self-review of my own code
  • I have commented my code where necessary
  • I have made corresponding changes to the doxygen documentation
  • I have added tests that prove my fix or feature works
  • I have updated the CHANGELOG or added the "no changelog" label if it's a CI-related issue
  • I have updated the README credits section

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

👋 Hi,
This is a reminder message to assign an extra build label to this Pull Request if needed.
By default, this PR will be build with minimal build options (URDF support and Python bindings)
The possible extra labels are:

  • build_collision (build Pinocchio with coal support)
  • build_casadi (build Pinocchio with CasADi support)
  • build_autodiff (build Pinocchio with CppAD support)
  • build_codegen (build Pinocchio with CppADCodeGen support)
  • build_extra (build Pinocchio with extra algorithms)
  • build_mpfr (build Pinocchio with Boost.Multiprecision support)
  • build_sdf (build Pinocchio with SDF parser)
  • build_accelerate (build Pinocchio with APPLE Accelerate framework support)
  • build_all (build Pinocchio with ALL the options stated above)

Thanks.
The Pinocchio development team.


// Build model
Model model;
buildModels::humanoidRandom(model, true);
Copy link
Contributor

Choose a reason for hiding this comment

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

We should parametrize this test with different model.
Joint (mimic, composite) can have some hidden allocation.
Also, mimic only support the following algorithms:

  • RNEA
  • CRBA
  • Forward Kinematics
  • Jacobians and Frames
  • Centroidal Algorithm (ccrba)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added tests with additional robots. Allocations detected !

Copy link
Contributor

Choose a reason for hiding this comment

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

Mimic are only supported in few algorithm (listed in my previous comment).
Unsupported algo will throw and then biasing the test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

refactored the test to only execute certain tests if the model has composites or mimic joints. 👍
I'm waiting for the green CI, then I'll squash some commits

@ahoarau
Copy link
Contributor Author

ahoarau commented Nov 22, 2025

Added a warning annotation in the CI when RTSan unittest failed.

Squashed the commits.

warn

@ahoarau ahoarau force-pushed the realtime-sanitizer-support branch from 9cd50d8 to ac85bf2 Compare November 22, 2025 10:55
dont build benchmarks

make build depends on configure
later this could be used to instrument the whole library

format cmake

rewrite rtsan cmake comments
format dynamic-allocations.cpp

add more models to test
test is now failing in multiple parts

refactor rtsan test suite to only allow known
allocation-free functions
Joint Composites and Mimic causes dynamic
allocations for jacobian fonction
(and all the others).
Only the Fk is fully safe so far.

only enable nonallocating
static variables, depending on the variable type,
can be implemented with an underlying
pthread_mutex_lock.
This is the case on mac-arm64, where static int
is most probably implemented with an atomic,
but static MyClass is protected by a mutex,
causing rtsan to trigger an with nonblocking.
nonallocating is less strict, but still useful.
format .gitignore
only run on ubuntu-latest

add fail-fast strategy for rtsan build

continue on error (rtsan)

add rtsan build in the check list

display correct name on RTsan CI

only use run test

use || true as continue on error is not working as expected

build first, then test

display a warning when rtsan fails

using matrix.name in RTSan build

enable rtsan in CI by default
now that rtsan tests handle joint composites and mimics properly, the CI can be enabled by default
@ahoarau ahoarau force-pushed the realtime-sanitizer-support branch from 157c33d to 192cc0d Compare November 28, 2025 13:55
@jorisv jorisv merged commit b6f5f16 into stack-of-tasks:devel Dec 1, 2025
44 of 45 checks passed
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.

2 participants