Skip to content

Add autotest option to run unit tests under asan / run them in CI / fix bugs foud - #33976

Open
peterbarker wants to merge 5 commits into
ArduPilot:masterfrom
peterbarker:pr-claude/ci-unit-tests-asan
Open

Add autotest option to run unit tests under asan / run them in CI / fix bugs foud#33976
peterbarker wants to merge 5 commits into
ArduPilot:masterfrom
peterbarker:pr-claude/ci-unit-tests-asan

Conversation

@peterbarker

Copy link
Copy Markdown
Contributor

Summary

Fixes bugs found by running the unit tests under asan

Classification & Testing (check all that apply and add your own)

  • Checked by a human programmer
  • Non-functional change
  • No-binary change
  • Infrastructure change (e.g. unit tests, helper scripts)
  • Automated test(s) verify changes (e.g. unit test, autotest)
  • Tested manually, description below (e.g. SITL)
  • Tested on hardware
  • Logs attached
  • Logs available on request

Description

Adds infrastructure to run unit tests under asan and fixes bugs found...

peterbarker and others added 5 commits August 7, 2026 12:50
…ing test

The test explicitly called the destructor and then read the freed
buffer, and filled a 2048 byte array with 'a' with no terminator before
passing it to printf.  Both are found by address sanitizer.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The AP_Param constructor scans the table for AP_PARAM_NONE to count the
parameters, so an unterminated table is read past the end.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The index was advanced before the last two checks, so they tested the
following result and read past the end of the table on the final call.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
ArduPilot does not free its singletons, so leak checking reports a great
deal which is not a bug.  Tests which do not otherwise pull in
AP_Common/c++.cpp get operator new from the ASAN runtime rather than our
own calloc based one, so fill allocations with zero to match.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Adds a unit-tests-asan configuration which builds and runs the unit
tests with --asan.  Only clang is used as boards.py adds the sanitizer
link flag for clang alone, and --asan is only implemented for the sitl
board so the linux unit tests remain uninstrumented.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added CI github_actions Pull requests that update GitHub Actions code Python labels Aug 7, 2026

@khancyr khancyr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

looks like we don't have libclang-rt-18-dev on the container ...
do you prefer I update the container and we keep the same tag, or I create another tag and we change the tag version on the CI workflow ?

sitl
]
exclude:
# boards.py only adds the sanitizer link flag when building

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should we add support for asan on gcc ? from the docs it should be supported

@peterbarker

Copy link
Copy Markdown
Contributor Author

looks like we don't have libclang-rt-18-dev on the container ... do you prefer I update the container and we keep the same tag, or I create another tag and we change the tag version on the CI workflow ?

Maybe we should just take the test fixes for now?

I mean, 4 errors in all of the tests over how many years - and the errors were only in the tests.

So I think I should just archive the asan thing for later....

@khancyr

khancyr commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

well, did you try to run on some SITL test ? our unittests are far from covering significant part of the codebase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI github_actions Pull requests that update GitHub Actions code Python

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants