Add CI to run pytest under AddressSanitizer - #323
Open
take-cheeze wants to merge 5 commits into
Open
Conversation
take-cheeze
force-pushed
the
claude/pytest-address-sanitizer-ci-ff9549
branch
from
July 27, 2026 07:53
f53230b to
cb07962
Compare
take-cheeze
commented
Jul 29, 2026
Build the native extension (and the bundled onnx/protobuf) with -fsanitize=address and run the existing pytest suite with the ASan runtime preloaded, so memory errors (heap-buffer-overflow, use-after-free, ...) in onnxoptimizer's C++ passes are caught in CI. CPython is not built with ASan, so libasan is LD_PRELOADed and detect_leaks=0 suppresses leaks from the uninstrumented interpreter and third-party libraries. onnxruntime is omitted from the test dependencies because its uninstrumented C++ throws exceptions that trip ASan's __cxa_throw interceptor; it is only used for optional numerical comparison, so every optimize() call is still exercised. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GewbTty3fkFT4G9u6J1JJn Signed-off-by: Takeshi Watanabe <take-cheeze@users.noreply.github.com> Signed-off-by: take-cheeze <takechi101010@gmail.com>
The job aborted with "AddressSanitizer: CHECK failed ... real___cxa_throw != 0" on the first checker.check_model call. The cause is not onnxruntime (already omitted) but the uninstrumented `onnx` Python wheel: its C++ extension throws C++ exceptions from checker.check_model / shape inference, which the tests exercise constantly. With only libasan preloaded, ASan's __cxa_throw interceptor cannot resolve the real symbol at init and aborts the process on the first raised exception. Preload libstdc++ alongside libasan (libasan still first, as ASan requires) so the interceptor finds the real __cxa_throw and exceptions unwind normally; only genuine memory errors now fail CI. Update the stale comment that attributed the abort solely to onnxruntime. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GewbTty3fkFT4G9u6J1JJn Signed-off-by: Takeshi Watanabe <take-cheeze@users.noreply.github.com> Signed-off-by: take-cheeze <takechi101010@gmail.com>
Signed-off-by: Takeshi Watanabe <take-cheeze@users.noreply.github.com> Signed-off-by: take-cheeze <takechi101010@gmail.com>
take-cheeze
force-pushed
the
claude/pytest-address-sanitizer-ci-ff9549
branch
from
July 29, 2026 12:13
73e0dc5 to
a959cf7
Compare
The Pytest (ASan) job failed at collection with:
ModuleNotFoundError: No module named 'onnxoptimizer.onnx_opt_cpp2py_export'
`pip install .` puts the compiled extension only in site-packages, but the
test step runs `pytest onnxoptimizer/test/` from the repo root. Because the
test modules live inside the onnxoptimizer package, importing them puts the
repo root on sys.path, so `import onnxoptimizer` resolves to the in-tree
source package -- which has the .py sources but no compiled
onnx_opt_cpp2py_export extension -- and collection fails before any test runs.
Build the extension in place as well (reusing the cmake build the pip install
just produced) so the compiled module sits next to the source package pytest
imports. This is orthogonal to the ASan flags; the extension itself builds and
imports correctly under ASan once it is present in the source tree.
Signed-off-by: take-cheeze <takechi101010@gmail.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GewbTty3fkFT4G9u6J1JJn
take-cheeze
marked this pull request as ready for review
July 29, 2026 13:29
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Build the native extension (and the bundled onnx/protobuf) with -fsanitize=address and run the existing pytest suite with the ASan runtime preloaded, so memory errors (heap-buffer-overflow, use-after-free, ...) in onnxoptimizer's C++ passes are caught in CI.
CPython is not built with ASan, so libasan is LD_PRELOADed and detect_leaks=0 suppresses leaks from the uninstrumented interpreter and third-party libraries. onnxruntime is omitted from the test dependencies because its uninstrumented C++ throws exceptions that trip ASan's __cxa_throw interceptor; it is only used for optional numerical comparison, so every optimize() call is still exercised.
Claude-Session: https://claude.ai/code/session_01GewbTty3fkFT4G9u6J1JJn