-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RSDK-5863] Add Address Sanitizer (ASan) option for intel realsense module #38
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding Bijan/nick s because I can't give it a thorough read through,, but lgtm!
For context @bhaney @nicksanford the criterea for this is to ensure that our devs don't introduce memory leaks, we're not going to battle test real sense's code for them and address issues on their side if there is ever a customer blocking bug. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hexbabe can you please add in the PR description:
- What manual testing have you done for the asan build?
- On which CPU / Board / OS platforms?
CMakeLists.txt
Outdated
add_compile_options(-fsanitize=address) | ||
add_link_options(-fsanitize=address) | ||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -static-libasan") | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libasan") | ||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libasan") | ||
target_compile_options(viamrealsense PRIVATE -fsanitize=address) | ||
target_link_options(viamrealsense PRIVATE -fsanitize=address) | ||
target_compile_options(viam-camera-realsense PRIVATE -fsanitize=address) | ||
target_link_options(viam-camera-realsense PRIVATE -fsanitize=address) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do you know these are the correct options to enable ASan? Is there a guide you are working from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might want to consider adding:
-fsanitize-address-use-after-scope and -fno-omit-frame-pointer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
README.md
Outdated
@@ -164,3 +164,6 @@ If you would like to try to gather all of the dependencies yourself and not use | |||
|
|||
then do `make viam-camera-realsense` to compile the binary, and `make appimage` to create the AppImage. | |||
|
|||
## Building with Address Sanitizer | |||
|
|||
When developing, you also have the option to build the module with ASAN/LSAN enabled to help test for memory leaks. You can do so by running `canon -arch arm64 make clean appimage-arm64 SANITIZE=ON`. ASAN/LSAN logs will then be included as error logs in your robot logs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add which platforms ASAN is supported on?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
What C compiler(s) do we support on the intel realsense? |
Can you confirm that there are no new dynamic lib deps added to the module after adding sanitizer? |
From logs: The Realsense build process uses Docker with the image defined here |
@hexbabe can you please test if the debug build works on all platforms the intel realsense module currently targets & add to the README if the debug build doesn't work on them? |
@hexbabe can you please confirm that tests FAIL if there is a memory leak introduced on all platforms we support? I don't mean in CI, I mean wherever we support running tests (like on your laptop). |
I am currently unable to get this ASAN/LSAN debug build to work on amd64. (For manager/PM mode Nick) Thoughts on how much time I should allocate to trying to get it to work? If after the allocated time I am still unable, I can put on the README that the debug build is currently only verified to work on linux/arm64 |
…fno-omit-frame-pointer
@nicksanford I was wrong. By default, ASAN/LSAN does non-zero exit when a leak is detected (I think I was mislead bc viam-server would just restart the module). Running: Logs:
So no need to used the observed test logger |
If you are hitting friction, then don't worry about amd64 support for now, just document that the ASAN build doesn't work on amd64. |
@hexbabe please remove: |
Removed all artifacts |
RSDK-5863
Originally, we wanted to add CI for ASAN, but since CI runners don't come with Intel Realsenses + it is difficult to software emulate the Realsense + adding mocks & unit tests would be quite unwieldy and difficult, we are just gonna support ASAN/LSAN as a build option.
This PR enables developers to run something like
canon -arch arm64 make clean appimage-arm64 SANITIZE=ON
to build the module with address sanitizer on. This allows ASAN/LSAN to analyze the code as it runs with viam-server.Testing
On linux/arm64
Commented out
tjDestroy(handle);
incamera_realsense.cpp
encodeJPEG
function to intentionally introduce a similar leak fixed in https://viam.atlassian.net/browse/RSDK-5869.Ran
canon -arch arm64 make clean appimage-arm64 SANITIZE=ON