From 203f62cb2f895327ffb316a99459016c73b23822 Mon Sep 17 00:00:00 2001 From: Joe Peterson Date: Mon, 14 Oct 2024 17:01:57 -0600 Subject: [PATCH] Add memleak check to github ci --- .github/scripts/prep_valgrind_test.sh | 16 ++++++++++++++++ .github/workflows/ContinuousIntegration.yml | 15 ++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 .github/scripts/prep_valgrind_test.sh diff --git a/.github/scripts/prep_valgrind_test.sh b/.github/scripts/prep_valgrind_test.sh new file mode 100644 index 0000000..4549a44 --- /dev/null +++ b/.github/scripts/prep_valgrind_test.sh @@ -0,0 +1,16 @@ +#! /bin/bash +echo " +check_return_code() { + if [ \$? -ne 0 ]; then + echo \"Memory leak detected. Test Failed...\" + exit 1 + fi +} + +" > test_valgrind.sh + +find . -iname "*.test" -type f | while IFS= read -r line; do + dirname=$(dirname "$line") + realname=$(basename "$line") + echo "cd ${dirname}; valgrind --leak-check=full --show-leak-kinds=all --errors-for-leak-kinds=all --error-exitcode=1 ./${realname}; check_return_code; cd -" >> test_valgrind.sh +done diff --git a/.github/workflows/ContinuousIntegration.yml b/.github/workflows/ContinuousIntegration.yml index 8d5f6b4..4fade33 100644 --- a/.github/workflows/ContinuousIntegration.yml +++ b/.github/workflows/ContinuousIntegration.yml @@ -29,7 +29,7 @@ jobs: - name: mkdir bin run: mkdir bin - name: cmake - run: cmake -DPYTHON_EXECUTABLE=$(which python3) -D CMAKE_CXX_COMPILER=`which ${{matrix.cxx}}` -D CMAKE_BUILD_TYPE=${{matrix.build_type}} -D tools.tests=ON .. + run: cmake -DCMAKE_CXX_FLAGS="-gdwarf-4" -DPYTHON_EXECUTABLE=$(which python3) -D CMAKE_CXX_COMPILER=`which ${{matrix.cxx}}` -D CMAKE_BUILD_TYPE=${{matrix.build_type}} -D tools.tests=ON .. working-directory: ./bin - name: make run: make -j2 @@ -37,3 +37,16 @@ jobs: - name: ctest run: ctest -j2 working-directory: ./bin + + - name: Setup Valgrind on Ubuntu + if: ${{matrix.os == 'ubuntu-22.04'}} + run: | + sudo apt-get install valgrind; + bash .github/scripts/prep_valgrind_test.sh + working-directory: . + + - name: Run tests with Valgrind + if: ${{matrix.os == 'ubuntu-22.04'}} + run: | + bash test_valgrind.sh + working-directory: .