NA-MIC-kit-curriculum/Testing-Based Programming/How to run Dynamic Analysis
Dynamic Analysis focuses on detecting defects at run time, particularly: Uninitialized variables and Memory leaks.
Contents
Introduction
This tutorial illustrates how to run dynamic analysis in a small project.
Requisites
You should have completed first the tutorials:
Installing Valgrind
Valgrind is the applications that will check your tests at run time and will report their defects.
In Ubuntu and Debian GNU/Linux you can install Valgrind by doing
sudo apt-get install valgrind
Configuring the Project
Rerun CMake and verify that the variable MEMORYCHECK_COMMAND is set properly:
cd ${BINARY_DIR} make edit_cache
- Hit the "t" key to go to the advanced mode
- Hit the "/" key to search for MEMORYCHECK_COMMAND
- Verify that it points to the valgrind executable that you installed
- Hit the "c" key to configure
- Hit the "g" key to generate and quit
Running the Tests
We present here two methods for running dynamic tests.
Method 1 is best suited for being used with a CDash Dashboard
Method 2 is best suited for being run locally and for tracking specific problems.
Method 1
Run the following commands:
cd ${BINARY_DIR} make ExperimentalStart make ExperimentalConfigure make ExperimentalBuild make ExperimentalTest make ExperimentalMemCheck
Method 2
Run the command locally:
cd ${BINARY_DIR} valgrind -v --leak-check=yes TestMain 5
The final part of the output will look like:
==27817== HEAP SUMMARY: ==27817== in use at exit: 0 bytes in 0 blocks ==27817== total heap usage: 1 allocs, 1 frees, 352 bytes allocated ==27817== ==27817== All heap blocks were freed -- no leaks are possible ==27817== ==27817== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 19 from 8) --27817-- --27817-- used_suppression: 19 dl-hack3-cond-1 ==27817== ==27817== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 19 from 8)