File tree Expand file tree Collapse file tree 2 files changed +44
-1
lines changed Expand file tree Collapse file tree 2 files changed +44
-1
lines changed Original file line number Diff line number Diff line change @@ -370,10 +370,30 @@ endif()
370
370
string (REPLACE "test_" "${CMAKE_CURRENT_SOURCE_DIR} /test_" PYBIND11_ABS_PYTEST_FILES
371
371
"${PYBIND11_PYTEST_FILES} " )
372
372
373
+ if (NOT PYBIND11_MEMCHECK)
374
+ set (PYBIND11_TEST_PREFIX_COMMAND "" )
375
+ else ()
376
+ # cmake-format: off
377
+ set (PYBIND11_TEST_PREFIX_COMMAND
378
+ PYTHONMALLOC=malloc
379
+ valgrind
380
+ --leak-check=full
381
+ --show-leak-kinds=definite,indirect
382
+ --errors-for-leak-kinds=definite,indirect
383
+ --error-exitcode=1
384
+ --read-var-info=yes
385
+ --track-origins=yes
386
+ --suppressions="${CMAKE_CURRENT_SOURCE_DIR} /valgrind-python.supp"
387
+ --suppressions="${CMAKE_CURRENT_SOURCE_DIR} /valgrind-numpy-scipy.supp"
388
+ --gen-suppressions=all )
389
+ # cmake-format: on
390
+ endif ()
391
+
373
392
# A single command to compile and run the tests
374
393
add_custom_target (
375
394
pytest
376
- COMMAND ${PYTHON_EXECUTABLE} -m pytest ${PYBIND11_ABS_PYTEST_FILES}
395
+ COMMAND ${PYBIND11_TEST_PREFIX_COMMAND} ${PYTHON_EXECUTABLE} -m pytest
396
+ ${PYBIND11_ABS_PYTEST_FILES}
377
397
DEPENDS ${test_targets}
378
398
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
379
399
USES_TERMINAL )
@@ -386,6 +406,11 @@ if(PYBIND11_TEST_OVERRIDE)
386
406
"Note: not all tests run: -DPYBIND11_TEST_OVERRIDE is in effect" )
387
407
endif ()
388
408
409
+ add_custom_target (
410
+ memcheck
411
+ DEPENDS pytest
412
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} )
413
+
389
414
# Add a check target to run all the tests, starting with pytest (we add dependencies to this below)
390
415
add_custom_target (check DEPENDS pytest)
391
416
Original file line number Diff line number Diff line change 115
115
fun:_PyImport_FindSharedFuncptr
116
116
fun:_PyImport_LoadDynamicModuleWithSpec
117
117
}
118
+
119
+ # Not really CPython-specific, see link
120
+ {
121
+ dlopen leak (https://stackoverflow.com/questions/1542457/memory-leak-reported-by-valgrind-in-dlopen)
122
+ Memcheck:Leak
123
+ fun:malloc
124
+ ...
125
+ fun:dl_open_worker
126
+ fun:_dl_catch_exception
127
+ fun:_dl_open
128
+ fun:dlopen_doit
129
+ fun:_dl_catch_exception
130
+ fun:_dl_catch_error
131
+ fun:_dlerror_run
132
+ fun:dlopen@@GLIBC_2.2.5
133
+ fun:_PyImport_FindSharedFuncptr
134
+ fun:_PyImport_LoadDynamicModuleWithSpec
135
+ }
You can’t perform that action at this time.
0 commit comments