Skip to content

Commit de82494

Browse files
authored
pass asan (#26)
1 parent ff83471 commit de82494

4 files changed

Lines changed: 48 additions & 11 deletions

File tree

README.md

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,17 @@ Optimized as an execution engine for Machine Learning pipelines.
88

99
## Table of Contents
1010

11-
- [Features](#features)
12-
- [Requirements](#requirements)
13-
- [Installation](#installation)
14-
<!-- - [Quick Start](#quick-start)
15-
- [API Reference](#api-reference)
16-
- [PyManager](#pyschedulerpymanager)
17-
- [InvokeHandler](#pyschedulerpymanagerinvokehandler)
18-
- [Examples](#examples)
19-
- [Configuration](#configuration)
20-
- [Contributing](#contributing)
11+
- [Features](#features)
12+
- [Requirements](#requirements)
13+
- [Installation](#installation)
14+
- [Testing with AddressSanitizer](#testing-with-addresssanitizer)
15+
<!-- - [Quick Start](#quick-start)
16+
- [API Reference](#api-reference)
17+
- [PyManager](#pyschedulerpymanager)
18+
- [InvokeHandler](#pyschedulerpymanagerinvokehandler)
19+
- [Examples](#examples)
20+
- [Configuration](#configuration)
21+
- [Contributing](#contributing)
2122
- [License](#license) -->
2223

2324
## Features
@@ -204,3 +205,25 @@ for (int i = 0; i < 1000; i++)
204205
for (auto& f : rank_futures)
205206
std::cout << f.get() << "\n";
206207
```
208+
209+
## Testing with AddressSanitizer
210+
211+
Build the tests with ASan enabled:
212+
213+
```bash
214+
./configure.sh --tests --asan --build
215+
```
216+
217+
This adds `-fsanitize=address -fno-omit-frame-pointer -g` to the compile and link flags.
218+
219+
### LSAN suppressions
220+
221+
CPython's embedded interpreter and extension modules (e.g. numpy) intentionally leak interned strings, type caches, and method tables at shutdown. These are not bugs in pyscheduler but will be reported by LeakSanitizer. A suppressions file (`lsan_supressions.txt`) in the project root filters them out.
222+
223+
The build system automatically symlinks this file into the test binary directory. To use it:
224+
225+
```bash
226+
LSAN_OPTIONS=suppressions=lsan_suppressions.txt PYTHONMALLOC=malloc ./build/debug/tests/pyscheduler_tests
227+
```
228+
229+
`PYTHONMALLOC=malloc` is required so that Python's allocations go through the system malloc, which ASan can track. Without it, CPython uses its own arena allocator and ASan cannot see individual allocations.

configure.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ to_preset(){ case "$1" in Debug) echo debug;; Release) echo release;; RelWithDeb
2424

2525
command -v cmake >/dev/null 2>&1 || die "cmake not found in PATH"
2626

27-
PRESET="debug" BUILD_EXAMPLES=OFF BUILD_TESTS=OFF
27+
MODE="debug" BUILD_EXAMPLES=OFF BUILD_TESTS=OFF
2828
ENABLE_ASAN=OFF ENABLE_TSAN=OFF ENABLE_FP=OFF
2929
RUN_BUILD=OFF RUN_INSTALL=OFF JOBS=""
3030
PYTHON_UDL_INTERFACE_PREFIX="${PYTHON_UDL_INTERFACE_PREFIX:-/usr/local}"

lsan_supressions.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
leak:PyUnicode_New
2+
leak:PyObject_Malloc
3+
leak:PyFloat_FromDouble
4+
leak:PyArrayMethod_FromSpec_int

tests/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ if(TEST_SOURCES)
88
Catch2::Catch2WithMain
99
)
1010

11+
# Symlink LSAN suppressions file into test binary directory
12+
set(_lsan_src "${CMAKE_SOURCE_DIR}/lsan_supressions.txt")
13+
set(_lsan_dst "$<TARGET_FILE_DIR:pyscheduler_tests>/lsan_suppressions.txt")
14+
if(EXISTS "${_lsan_src}")
15+
add_custom_command(TARGET pyscheduler_tests POST_BUILD
16+
COMMAND ${CMAKE_COMMAND} -E create_symlink "${_lsan_src}" "${_lsan_dst}"
17+
COMMENT "Symlinking lsan_suppressions.txt into test directory"
18+
)
19+
endif()
20+
1121
include(CTest)
1222
include(Catch)
1323
catch_discover_tests(pyscheduler_tests)

0 commit comments

Comments
 (0)