Running Net-SNMP Regression Tests under Valgrind

From Net-SNMP Wiki
Jump to: navigation, search

Introduction

When testing changes of core Net-SNMP code one should not only test these changes functionally but one should also test these with Valgrind. Since Valgrind is a dynamic analysis tool, it is important to trigger as much Net-SNMP code as possible during testing. One way to do that is to run all Net-SNMP regression tests under Valgrind.

Additional Memcheck Suppressions

You will need the memcheck suppression patterns below in addition to those included in the Valgrind distribution. Save these in a file called e.g. net-snmp-memcheck.supp.

{
   ldap1
   Memcheck:Value8
   ...
   obj:/usr/lib64/libnss_ldap-264.so
   obj:/usr/lib64/libnss_ldap-264.so
}
{
   ldap2
   Memcheck:Param
   ...
   obj:/usr/lib64/libnss_ldap-264.so
   obj:/usr/lib64/libnss_ldap-264.so
}
{
   OpenSSL1
   Memcheck:Leak
   ...
   fun:CRYPTO_malloc
}
{
   OpenSSL2
   Memcheck:Leak
   ...
   fun:CRYPTO_realloc
}
{
   OpenSSL3
   Memcheck:Value4
   ...
   fun:generate_key
   fun:DH_generate_key
}
{
   OpenSSL4
   Memcheck:Cond
   ...
   fun:generate_key
   fun:DH_generate_key
}
{
   rpmReadConfigFiles-leak
   Memcheck:Leak
   ...
   fun:rpmReadConfigFiles
}

Running Regression Tests under Valgrind

Once you have compiled the Net-SNMP source code and once you have installed Valgrind 3.6.0 or later, the Net-SNMP regression tests can be run under Valgrind with the script below.

#!/bin/bash

rm -rf /tmp/snmp-*
make -s
export SNMP_SAVE_TMPDIR=yes DYNAMIC_ANALYZER="$HOME/software/valgrind/vg-in-place --trace-children=yes --trace-children-skip=/usr/bin/env,/bin/sed,/bin/ls,/bin/sh --track-origins=no --leak-check=full --suppressions=$HOME/path-to-net-snmp-memcheck-suppression-file/net-snmp-memcheck.supp --gen-suppressions=all"
make -s test
cd testing || exit $?
./RUNFULLTESTS -g unit-tests
echo
echo 'Output files with Valgrind complaints:'
if grep -rEl 'Invalid | uninitialised |Invalid free|Mismatched free|Source and destination overlap' /tmp/snmp-*; then
  exit 1
else
  exit 0
fi