How to run the regression tests with valgrind

This page explains how to run the regression tests with valgrind to enable memory access error checking.

Configure the build system to run tests with valgrind

To clone, configure the build system to run the regression tests with valgrind, build, and execute the tests do

git clone https://codeberg.org/xyst/xyst.git && cd xyst
mkdir build && cd build
cmake -DENABLE_VALGRIND=true ../src
make && ctest -j4 --output-on-failure

All regression test executables will be prefixed by valgrind's memory checker which can detect memory access problems, uninitialized values, memory leaks, bad heap management (double frees and mismatched frees), or overlapping source and destination memory blocks.

How to update the valgrind suppression file

Some false positives are listed in tests/regression/valgrind.sup. If this file needs to be updated, it can be done by temporarily changing VALGRIND_CMD in tests/regression/CMakeLists.txt to instruct valgrind to generate and output suppression information to a log file. The procedure to update the valgrind suppression file is described below.

Start by running the single test that failes

ctest -R <test-triggering-new-valgrind-errors> -V

Upon examining the valgrind output if the decision is made to suppress this new error from future valgrind checks, change the valgrind command in cmake as below:

diff --git a/tests/regression/CMakeLists.txt b/tests/regression/CMakeLists.txt
index 43e8118..e8eafb4 100644
--- a/tests/regression/CMakeLists.txt
+++ b/tests/regression/CMakeLists.txt
@@ -26,8 +26,8 @@ if (ENABLE_VALGRIND)
   find_program(VALGRIND valgrind)
   if (VALGRIND)
     set(sup "${PROJECT_SOURCE_DIR}/../tests/regression/valgrind.sup")
-    set(VALGRIND_CMD "${VALGRIND} --tool=memcheck --suppressions=${sup}")
-    #set(VALGRIND_CMD "${VALGRIND} --tool=memcheck --suppressions=${sup} --gen-suppressions=all --log-file=${sup}.log")
+    #set(VALGRIND_CMD "${VALGRIND} --tool=memcheck --suppressions=${sup}")
+    set(VALGRIND_CMD "${VALGRIND} --tool=memcheck --suppressions=${sup} --gen-suppressions=all --log-file=${sup}.log")
     message(STATUS "Will run all regression tests prefixed by '${VALGRIND_CMD}'")
   else()
     message(WARNING "Valgrind was enabled but NOT found")

Now rebuild (which should trigger a cmake update) and run the test again that triggered a new valgrind problem to save the valgrind suppression output into a log file:

make
ctest -R <test-triggering-new-valgrind-errors> -V

Now the suppression blocks based on the newly written tests/regression/valgrind.sup.log can be appended to tests/regression/valgrind.sup.

After updating the suppression file tests/regression/valgrind.sup, do not forget to not commit the above patch to tests/regression/CMakeLists.txt.