Running Net-SNMP Regression Tests under Valgrind
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. This script works for the 5.5 and 5.6 branches and also for the trunk but not for the 5.4 or older branches.
#!/bin/bash scriptdir=$(dirname "$0") rm -rf /tmp/snmp-* export SNMP_SAVE_TMPDIR=yes DYNAMIC_ANALYZER="valgrind --trace-children=yes --trace-children-skip=/usr/bin/env,/bin/sed,/bin/ls,/bin/sh,/bin/bash,/usr/bin/sed,/usr/bin/ls,/usr/bin/make,/usr/bin/perl --track-origins=no --leak-check=full --show-leak-kinds=definite --suppressions=${scriptdir}/net-snmp-memcheck.supp --gen-suppressions=all -q" if [ "$($DYNAMIC_ANALYZER -q echo abc 2>&1)" != "abc" ]; then echo "Error: Valgrind not working properly" exit 1 fi export NOAUTODEPS=1 && { make -s && { ( export PATH="$PWD/agent/.libs:$PWD/apps/.libs:$PWD:$PATH" && cd testing && if [ -e RUNFULLTESTS ] && perl -e 'require TAP::Harness;' >/dev/null 2>&1; then ./RUNFULLTESTS -g all else make -s test fi ) ( export LD_LIBRARY_PATH="$( find . -name '*.so' | grep -v NetSNMP/agent/default_store | sed 's,^\./,'"$PWD/"',;s,/[^/]*$,,' | sort -u | tr '\n' :)" && cd perl && $DYNAMIC_ANALYZER make test ) } } 2>&1 | tee "../net-snmp-$(basename "$PWD")-build-log.txt" echo echo 'Output files with Valgrind complaints:' if grep -rEl ' Invalid | Uninitialised | Conditional jump or move depends on uninitialised value|Mismatched free|Source and destination overlap| UME ' /tmp/snmp-*; then exit 1 else exit 0 fi