From 366b1cb42f95d7422df26d9519df932be31225da Mon Sep 17 00:00:00 2001 From: Kristofer Hallin Date: Wed, 27 Apr 2022 21:03:47 +0200 Subject: [PATCH] Valgrind tests for clixon_snmp. --- test/lib.sh | 24 ++++++++++++++++++++++++ test/mem.sh | 16 ++++++++++++---- test/test_snmp.sh | 17 ++++------------- 3 files changed, 40 insertions(+), 17 deletions(-) diff --git a/test/lib.sh b/test/lib.sh index b8fa2a4c..9213f539 100755 --- a/test/lib.sh +++ b/test/lib.sh @@ -415,6 +415,30 @@ function chunked_framing() printf "\n#%s\n%s\n##\n" ${length} "${str}" } +# Start clixon_snmp +function start_snmp(){ + cfg=$1 + + $clixon_snmp -f $cfg -D $DBG -l s & + + if [ $? -ne 0 ]; then + err + fi + + if [ $valgrindtest != 0 ]; then + checkvalgrind + fi +} + +# Stop clixon_snmp and Valgrind if needed +function stop_snmp(){ + if [ $valgrindtest != 0 ]; then + kill `ps aux | grep [v]algrind | awk '{print $2}' | tail -n1` + else + killall clixon_snmp + fi +} + # Start backend with all varargs. # If valgrindtest == 2, start valgrind function start_backend(){ diff --git a/test/mem.sh b/test/mem.sh index ed493d78..5d5c9a87 100755 --- a/test/mem.sh +++ b/test/mem.sh @@ -18,6 +18,7 @@ function memonce(){ clixon_netconf= clixon_backend= clixon_restconf= + clixon_snmp= case "$what" in 'cli') valgrindtest=1 @@ -43,8 +44,15 @@ function memonce(){ clixon_restconf="/usr/bin/valgrind --num-callers=50 --leak-check=full --show-leak-kinds=all --suppressions=./valgrind-clixon.supp --track-fds=yes --trace-children=no --child-silent-after-fork=yes --log-file=$valgrindfile clixon_restconf" ;; + 'snmp') + valgrindtest=1 # This means snmp valgrind test + sudo chmod 660 $valgrindfile + : ${DEMWAIT:=15} # valgrind backend needs some time to get up + clixon_snmp="/usr/bin/valgrind --num-callers=50 --leak-check=full --show-leak-kinds=all --suppressions=./valgrind-clixon.supp --track-fds=yes --trace-children=no --child-silent-after-fork=yes --log-file=$valgrindfile /usr/local/sbin/clixon_snmp" + ;; + *) - echo "usage: $0 cli|netconf|restconf|backend" # valgrind memleak checks + echo "usage: $0 cli|netconf|restconf|backend|snmp" # valgrind memleak checks rm -f $valgrindfile exit -1 ;; @@ -86,16 +94,16 @@ function println(){ } if [ -z "$*" ]; then - cmds="backend restconf cli netconf" + cmds="backend restconf cli netconf snmp" else cmds=$* fi # First run sanity for c in $cmds; do - if [ $c != cli -a $c != netconf -a $c != restconf -a $c != backend ]; then + if [ $c != cli -a $c != netconf -a $c != restconf -a $c != backend -a $c != snmp ]; then echo "c:$c" - echo "usage: $0 [cli|netconf|restconf|backend]+" + echo "usage: $0 [cli|netconf|restconf|backend|snmp]+" echo " with no args run all" exit -1 fi diff --git a/test/test_snmp.sh b/test/test_snmp.sh index 694391e6..5d7e1d40 100755 --- a/test/test_snmp.sh +++ b/test/test_snmp.sh @@ -5,12 +5,6 @@ s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi APPNAME=snmp -# Dont run this test with valgrind -if [ $valgrindtest -ne 0 ]; then - echo "...skipped " - return 0 # skip -fi - if [ ${WITH_NETSNMP} != "yes" ]; then echo "Skipping test, Net-SNMP support not enabled." if [ "$s" = $0 ]; then exit 0; else return 0; fi @@ -76,18 +70,15 @@ function testinit(){ sudo killall clixon_snmp new "Starting clixon_snmp" - $clixon_snmp -f $cfg -D $DBG -l s & + start_snmp $cfg & - sleep 1 - - pgrep clixon_snmp - if [ $? != 0 ]; then - err "Failed to start clixon_snmp" - fi + # Wait for things to settle + sleep 3 } function testexit(){ sudo killall snmpd + stop_snmp } new "SNMP tests"