Valgrind

From ASCEND
Jump to: navigation, search

Valgrind is a tool that can detect memory leaks and invalid attempts to access memory, or perform actions that depend on the contents of uninitialised memory.

When running ASCEND through valgrind, the following approach is suggested:

# enter your working directory
cd ~/ascend

# build the test suite, plus libascend (dependency)
scons -j2 test

# you might also need to build the solvers as another step
scons -j2 solvers

# set up your runtime environment
export ASCENDLIBRARY=~/ascend/models
export LD_LIBRARY_PATH=~/ascend:/usr/lib/coin:/usr/lib/coin/ThirdParty

# run the test suite through valgrind in 'memcheck' mode:
valgrind --suppressions=tools/valgrind/suppressions --tool=memcheck --leak-check=full --show-reachable=yes test/test TESTNAME

where in the above, TESTNAME is replaced by a valid test case or test suite, use test/test -l and test/test -tSUITENAME to list available options.

The above approach requires that you have CUnit installed on your system (see our notes on this), and that you have configured the 'scons' flags correctly so that it is detected on your system.

Valgrind can also be used with Python-based scripts, but you will need to be prepared to add suppressions for a large number of warnings/errors that Valgrind detects from Python itself.

As Ben Allan mentioned, a small amount of memory leakage from ASCEND is perfectly tolerable, providing it is fixed in magnitude, for example global variables that do not grow in time during an ASCEND process. We have a number of such 'leakages' in ASCEND resulting from dlopening of external relations and the like. Getting rid of these leakages is difficult and has not been prioritised at this stage.

The technique for adding items to the suppressions list is described in the Valgrind documention.