Skip to content

Commit e18529f

Browse files
Merge pull request #844 from weslleyspereira/try-valgrind
Uses Valgrind for ExperimentalMemCheck in ctest
2 parents 7a29cfe + cfe1114 commit e18529f

File tree

6 files changed

+82
-5
lines changed

6 files changed

+82
-5
lines changed

.github/workflows/cmake.yml

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,14 @@ jobs:
130130
- name: Checkout LAPACK
131131
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
132132

133+
- name: Install ninja-build tool
134+
uses: seanmiddleditch/gha-setup-ninja@16b940825621068d98711680b6c3ff92201f8fc0 # v3
135+
133136
- name: Configure CMake
134137
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
135138
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
136139
run: >
137-
cmake -B build
140+
cmake -B build -G Ninja
138141
-D CMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
139142
-D CMAKE_INSTALL_PREFIX=${{github.workspace}}/lapack_install
140143
-D CBLAS:BOOL=ON
@@ -181,4 +184,57 @@ jobs:
181184
-D BUILD_SHARED_LIBS:BOOL=ON
182185
183186
- name: Install
184-
run: cmake --build build --target install -j2
187+
run: cmake --build build --target install -j2
188+
189+
memory-check:
190+
runs-on: ubuntu-latest
191+
env:
192+
BUILD_TYPE: Debug
193+
194+
steps:
195+
196+
- name: Checkout LAPACK
197+
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
198+
199+
- name: Install ninja-build tool
200+
uses: seanmiddleditch/gha-setup-ninja@16b940825621068d98711680b6c3ff92201f8fc0 # v3
201+
202+
- name: Install APT packages
203+
run: |
204+
sudo apt update
205+
sudo apt install -y cmake valgrind gfortran
206+
207+
- name: Configure CMake
208+
run: >
209+
cmake -B build -G Ninja
210+
-D CMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
211+
-D CBLAS:BOOL=ON
212+
-D LAPACKE:BOOL=ON
213+
-D BUILD_TESTING:BOOL=ON
214+
-D LAPACKE_WITH_TMG:BOOL=ON
215+
-D BUILD_SHARED_LIBS:BOOL=ON
216+
-D LAPACK_TESTING_USE_PYTHON:BOOL=OFF
217+
218+
- name: Build
219+
run: cmake --build build --config ${{env.BUILD_TYPE}}
220+
221+
- name: Test
222+
working-directory: ${{github.workspace}}/build
223+
run: |
224+
ctest -C ${{env.BUILD_TYPE}} --schedule-random -j2 -T memcheck > memcheck.out
225+
cat memcheck.out
226+
if tail -n 1 memcheck.out | grep -q "Memory checking results:"; then
227+
exit 0
228+
else
229+
for f in Testing/Temporary/MemoryChecker.*.log; do
230+
if tail -n 1 $f | grep -q "ERROR SUMMARY: 0 errors"; then
231+
tail -n 1 $f
232+
continue
233+
else
234+
echo "Memory check failed in $f"
235+
cat $f
236+
exit 1
237+
fi
238+
done
239+
exit 0
240+
fi

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ if(_is_coverage_build)
4545
find_package(codecov)
4646
endif()
4747

48+
# Use valgrind if it is found
49+
option( LAPACK_TESTING_USE_PYTHON "Use Python for testing. Disable it on memory checks." ON )
50+
find_program( MEMORYCHECK_COMMAND valgrind )
51+
if( MEMORYCHECK_COMMAND )
52+
message( STATUS "Found valgrind: ${MEMORYCHECK_COMMAND}" )
53+
set( MEMORYCHECK_COMMAND_OPTIONS "--leak-check=full --show-leak-kinds=all --track-origins=yes" )
54+
endif()
55+
4856
# By default test Fortran compiler complex abs and complex division
4957
option(TEST_FORTRAN_COMPILER "Test Fortran compiler complex abs and complex division" OFF)
5058
if( TEST_FORTRAN_COMPILER )

CTestCustom.cmake.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ set(CTEST_CUSTOM_WARNING_EXCEPTION
4848

4949
# Only run post test if suitable python interpreter was found
5050
set(PYTHON_EXECUTABLE @PYTHON_EXECUTABLE@)
51-
if(PYTHON_EXECUTABLE)
51+
set(LAPACK_TESTING_USE_PYTHON @LAPACK_TESTING_USE_PYTHON@)
52+
if(PYTHON_EXECUTABLE AND LAPACK_TESTING_USE_PYTHON)
5253
set(CTEST_CUSTOM_POST_TEST "${PYTHON_EXECUTABLE} ./lapack_testing.py -s -d TESTING")
5354
endif()
5455

LAPACKE/example/example_DGESV_colmajor.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ int main(int argc, char **argv) {
103103
print_matrix_colmajor( "Details of LU factorization", n, n, A, lda );
104104
/* Print pivot indices */
105105
print_vector( "Pivot indices", n, ipiv );
106+
107+
/* Free matrices and vectors */
108+
free(A);
109+
free(b);
110+
free(ipiv);
111+
106112
exit( 0 );
107113
} /* End of LAPACKE_dgesv Example */
108114

LAPACKE/example/example_DGESV_rowmajor.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ int main(int argc, char **argv) {
100100
print_matrix_rowmajor( "Details of LU factorization", n, n, A, lda );
101101
/* Print pivot indices */
102102
print_vector( "Pivot indices", n, ipiv );
103+
104+
/* Free matrices and vectors */
105+
free(A);
106+
free(b);
107+
free(ipiv);
108+
103109
exit( 0 );
104110
} /* End of LAPACKE_dgesv Example */
105111

TESTING/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ add_subdirectory(EIG)
1515

1616

1717
# Only run this test if python 3 is found
18-
if(PYTHON_EXECUTABLE)
18+
if(PYTHON_EXECUTABLE AND LAPACK_TESTING_USE_PYTHON)
1919
message(STATUS "Enabling LAPACK test summary (see TESTING/testing_results.txt)")
2020
file(COPY ${LAPACK_SOURCE_DIR}/lapack_testing.py DESTINATION ${LAPACK_BINARY_DIR})
2121
add_test(
@@ -38,7 +38,7 @@ function(add_lapack_test output input target)
3838
-DINTDIR=${CMAKE_CFG_INTDIR}
3939
-P "${LAPACK_SOURCE_DIR}/TESTING/runtest.cmake")
4040

41-
if(PYTHON_EXECUTABLE)
41+
if(PYTHON_EXECUTABLE AND LAPACK_TESTING_USE_PYTHON)
4242
set_property(
4343
TEST LAPACK_Test_Summary
4444
APPEND PROPERTY DEPENDS LAPACK-${testName}

0 commit comments

Comments
 (0)