Skip to content

Add testcase and fix for include order of generated code with stdint.h - #263

Open
mathias-luedtke wants to merge 2 commits into
ros2:rollingfrom
mathias-luedtke:feature/buffer-test-case
Open

mathias-luedtke wants to merge 2 commits into
ros2:rollingfrom
mathias-luedtke:feature/buffer-test-case

Conversation

@mathias-luedtke

Copy link
Copy Markdown

Description

This PR add a test case that shows that cpplint checks fail for generated code for services that have buffers in their response, but not in the request.
The same issue should happen for actions.

The tests will fail with:

- rosidl_generator_py.cpplint_rosidl_generated_py build/include_order [4] (/ws/build/rosidl_generator_py/rosidl_generator_py/rosidl_generator_py/srv/_get_buffer_s.c:83)
  <<< failure message
    Found C system header after other header. Should be: _get_buffer_s.h, c system, c++ system, other.
  >>>

Is this user-facing behavior change?

No

Did you use Generative AI?

No

Additional Information

This issue was introduced by #250

@mergify

mergify Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@skyegalaxy

Copy link
Copy Markdown
Member

@adbidwai to take a look

@adbidwai

adbidwai commented Aug 13, 2026 •

Copy link
Copy Markdown

Hi, I can take a look at this. Thanks!

@fujitatomoya fujitatomoya left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I do not think we can take this without fixes, because this generates intentionally red test.

Comment thread rosidl_generator_py/srv/GetBuffer.srv Resolved
@mathias-luedtke
mathias-luedtke force-pushed the feature/buffer-test-case branch from 26b66a6 to 6222bb3 Compare August 14, 2026 11:00
@mathias-luedtke

mathias-luedtke commented Aug 14, 2026 •

Copy link
Copy Markdown
Author

I do not think we can take this without fixes, because this generates intentionally red test.

I can add the fix as well, but I need to know which option you do prefer (see #264)

@mathias-luedtke

mathias-luedtke commented Aug 19, 2026 •

Copy link
Copy Markdown
Author

@fujitatomoya: Which fix would you prefer?

  • silence build/include_order in the cpplint checks
  • always include <stdint.h>
  • more complicated fix: add stdint.h in the request/goal part, if the parts use buffers

@fujitatomoya

Copy link
Copy Markdown

I'd say that the best option we got here is to hoist the include to the top-of-file system-header block, conditionally at the interface level with checking that interface requires the header. but i guess that perfectly acceptable fallback: always include <stdint.h> in the top block if that makes the complicatoin. I was thinking about the compile-time concern but stdint.h is one of the smallest headers in the standard library. what do you think?

@mathias-luedtke
mathias-luedtke force-pushed the feature/buffer-test-case branch from fb9dcee to 9dbae59 Compare August 24, 2026 20:40
@mathias-luedtke

Copy link
Copy Markdown
Author

I'd say that the best option we got here is to hoist the include to the top-of-file system-header block, conditionally at the interface level with checking that interface requires the header.

I came up with mathias-luedtke@620a026
However, I am not convinced..

but i guess that perfectly acceptable fallback: always include <stdint.h>

It turns out that Python.h already includes it, so it should not affect compile time.
-> We could even drop the stdint.h include and it still passes.

Furthermore - depending on the message type - the generated code already uses the types from stdint.h without including them explicitly.

IMHO always including stdint.h is the better fix: it is simple and maintainable.
And it allows us to drop the has_buffer_fields handling, which should make up for any (negligible) include overhead.

@mathias-luedtke mathias-luedtke changed the title Add testcase for services with buffer in the response only Add testcase and fix for include order of stdint.h Sep 2, 2026
@mathias-luedtke mathias-luedtke changed the title Add testcase and fix for include order of stdint.h Add testcase and fix for include order of generated code with stdint.h Sep 2, 2026
@MatthijsBurgh

Copy link
Copy Markdown

For whatever it is worth for the re-review: I checked 9dbae59 against a real downstream failure and it resolves it.

ed_gui_server_interfaces/srv/GetEntityInfo.srv has exactly the shape from #264 — no buffer in the request, two in the response — and is red on rolling:

- ed_gui_server_interfaces.cpplint_rosidl_generated_py build/include_order [4] (.../srv/_get_entity_info_s.c:137)
  <<< failure message
    Found C system header after other header. Should be: _get_entity_info_s.h, c system, c++ system, other.
  >>>

(https://github.com/tue-robotics/ed_gui_server/actions/runs/33599833100)

I have no rolling environment at hand, so I checked it two ways:

  • The include-emission region of _msg_support.c.em on this branch — from include_parts = down to // end nested array functions include — is identical to jazzy's apart from the 'stdint.h' entry and an empy comment. Jazzy generates a cpplint-clean _get_entity_info_s.c for this service, so this branch does too.
  • ament_cpplint --filters=-readability/fn_size --linelength 999 over the generated file for that service: clean as jazzy generates it, reproduces the error above with <stdint.h> live in the response block as rolling emits it today, clean again with <stdint.h> in the top block as this branch emits it.

The second is on a reconstruction of the rolling output rather than the real thing, so please read it as corroboration of the first rather than an independent result. The middle case is the control — without it a clean run would not mean much.

The same argument covers the GetBuffer.srv added here: with stdint.h unconditional it is always in the first block, so the testcase should be red before 9dbae59 and green after, which I think addresses the "generates intentionally red test" point from the review.

@mathias-luedtke

Copy link
Copy Markdown
Author

@fujitatomoya: Is there anything else blocking this?

MatthijsBurgh added a commit to tue-robotics/ed_gui_server that referenced this pull request Nov 10, 2026
On Rolling, rosidl_generator_py puts <stdint.h> after the other headers
in the generated C code of a service that has buffers only in its
response. GetEntityInfo has that shape, so cpplint_rosidl_generated_py
fails with build/include_order. The generated file is not ours to fix.

Disable only that test, and only on Rolling, until
ros2/rosidl_python#263 (fixing ros2/rosidl_python#264) is released.
Jazzy still runs it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@MatthijsBurgh

MatthijsBurgh commented Nov 10, 2026 •

Copy link
Copy Markdown

Follow-up to my earlier comment: I have now tested this in a real build, not a reconstruction.

Setup: the released Rolling packages for Ubuntu 24.04 (ros-rolling-rosidl-generator-py 0.27.2-1noble.20260425), unpacked into a separate prefix, with ed_gui_server_interfaces built on top with BUILD_TESTING=ON. For the fix, 6222bb3 and 9dbae59 cherry-picked onto the 0.27.2 tag (they apply cleanly) and rosidl_generator_py built from source as an overlay.

generator cpplint_rosidl_generated_py all package tests
0.27.2 as released fails: srv/_get_entity_info_s.c:137: Found C system header after other header 897 tests, 1 failure
0.27.2 + this PR passes 897 tests, 0 failures

With this PR, <stdint.h> moves from the response block (line 137) to the system-header block at the top of _get_entity_info_s.c. The generated extension also still imports, and its uint8[] buffer fields can be set and read back from Python.

Not covered: I did not build the PR head on 0.28.1, and did not run this package's own test suite, so the new GetBuffer.srv case was not exercised here.

@MatthijsBurgh

Copy link
Copy Markdown

This covers the gap from my last comment: the PR head as-is, on current Rolling.

Setup: the ros:rolling image (Ubuntu 26.04, ros-rolling-rosidl-generator-py 0.28.0-1resolute.20261004), which is the base of this PR. The fix is 9dbae59, unmodified, built with BUILD_TESTING=ON as an overlay. The test case alone is 6222bb3.

generator tests result
this package, test case only 6222bb3 rosidl_generator_py 1227 tests, 1 failure: srv/_get_buffer_s.c:83: Found C system header after other header
this package, PR head 9dbae59 rosidl_generator_py 1227 tests, 0 failures
downstream 0.28.0 as released ed_gui_server_interfaces 897 tests, 1 failure: srv/_get_entity_info_s.c:137, the same as on 24.04
downstream 9dbae59 ed_gui_server_interfaces 897 tests, 0 failures

So the new GetBuffer.srv case is red without the fix and green with it, which I think settles the "intentionally red test" concern. With the fix, <stdint.h> is at line 7 of _get_entity_info_s.c, in the system-header block. A GetEntityInfo response with both uint8[] buffers set also survives rclpy.serialization serialize/deserialize unchanged.

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.

5 participants