moveit2: assert(false) not failing in tests but it should

Description

Public service announcement: I tried building from source to make some slight changes. I determined by running the tests that assert(false) was not failing though it should. One test in particular [0] calls state.getRigidlyConnectedParentLinkModel(...) successfully though it should fail since there are dirty link transforms and that method internally calls assert(checkLinkTransforms()) [1]. Since that second method should return false, the test should fail, but it is currently passing.

Looking further I found that assert() relies on the NDEBUG macro being undefined to work correctly. If NDEBUG is defined, the assertion is disabled, and assert() does nothing [2]. I wrote some test code to determine if NDEBUG is defined, and it is – though I cannot determine where.

This is causing the CI tests to run in such a way that assert(false) statements are silently passing, which is not good. Probably there are not many of these, but the one I linked to should fail.

[0] https://github.com/moveit/moveit2/blob/main/moveit_core/robot_state/test/robot_state_test.cpp#L785 [1] https://github.com/moveit/moveit2/blob/main/moveit_core/robot_state/src/robot_state.cpp#L1309 [2] https://en.cppreference.com/w/cpp/error/assert

ROS Distro

Rolling

OS and version

Ubuntu 24.04

Source or binary build?

Source

If binary, which release version?

No response

If source, which branch?

main

Which RMW are you using?

None

Steps to Reproduce

Run the test I mentioned.

Expected behavior

The test should fail.

You can force it to fail by putting this at the top of the test I mentioned [0], put this at the top to make NDEBUG undefined. Then run the test and it will fail.

#undef NDEBUG

[0] https://github.com/moveit/moveit2/blob/main/moveit_core/robot_state/test/robot_state_test.cpp#L785

If you want to fix that particular test so it doesn’t fail when NDEBUG is undefined, call this just before the line that is failing:

state.updateLinkTransforms();
EXPECT_EQ(state.getRigidlyConnectedParentLinkModel("link_b"), link_a);

Actual behavior

The test does not currently fail.

Backtrace or Console output

No response

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 1
  • Comments: 19 (18 by maintainers)

Most upvoted comments

I fully agree with https://github.com/moveit/moveit2/issues/3102#issuecomment-2480609001:

  • assert in tests can be (and probably should be) replaced by ASSERT_TRUE
  • assert in production code should not be touched

To evaluate those tests in CI we have Debug enabled for the ccov build (which requires Debug anyway): https://github.com/moveit/moveit2/blob/2490e51444df20bf64c05deacf903785703852b7/.github/workflows/ci.yaml#L56

I might let @henningkayser chime in on this one… it may be beyond my knowledge of computers 😃