From 38991084a552def391b9845e8307f9cb85c4a254 Mon Sep 17 00:00:00 2001 From: Olof Hagsand Date: Thu, 28 Mar 2019 21:57:28 +0100 Subject: [PATCH] mem.sh with more than one target --- docker/system/Dockerfile | 2 +- test/README.md | 8 +-- test/mem.sh | 138 +++++++++++++++++++++++---------------- 3 files changed, 85 insertions(+), 63 deletions(-) diff --git a/docker/system/Dockerfile b/docker/system/Dockerfile index b99a71cc..a5065f89 100644 --- a/docker/system/Dockerfile +++ b/docker/system/Dockerfile @@ -73,7 +73,7 @@ RUN make RUN make install # Build and install the clixon example -WORKDIR /clixon/clixon/example +WORKDIR /clixon/clixon/example/main RUN make RUN make install RUN install example.xml /clixon/build/etc/clixon.xml diff --git a/test/README.md b/test/README.md index cb41e85f..27349b26 100644 --- a/test/README.md +++ b/test/README.md @@ -52,12 +52,10 @@ Run all tests but continue after errors and only print a summary test output ide ``` ## Memory leak test -These tests use valgrind to check for memory leaks: +The `mem.sh` runs memory checks using valgrind. Start it with no arguments to test all components (backend, restconf, cli, netconf), or specify which components to run: ``` - mem.sh cli - mem.sh netconf - mem.sh backend - mem.sh restconf + mem.sh # All components + mem.sh restconf backend # Only backend and cli ``` ## Site.sh diff --git a/test/mem.sh b/test/mem.sh index e570d96d..b5009775 100755 --- a/test/mem.sh +++ b/test/mem.sh @@ -1,65 +1,89 @@ #!/bin/bash # Run valgrind leak test for cli, restconf, netconf or background. # Stop on first error -# -if [ $# -ne 1 ]; then - echo "usage: $0 cli|netconf|restconf|backend" # valgrind memleak checks - exit -1 + + +# Run valgrindtest once, args: +# what: cli|netconf|restconf|backend +memonce(){ + what=$1 + + valgrindfile=$(mktemp) + echo "valgrindfile:$valgrindfile" + + case "$what" in + 'cli') + valgrindtest=1 + RCWAIT=1 + clixon_cli="/usr/bin/valgrind --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_cli" + ;; + 'netconf') + valgrindtest=1 + RCWAIT=1 + clixon_netconf="/usr/bin/valgrind --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_netconf" + ;; + 'backend') + valgrindtest=2 # This means backend valgrind test + RCWAIT=10 # valgrind backend needs some time to get up + perfnr=100 # test_perf.sh restconf put more or less stops + perfreq=10 + + clixon_backend="/usr/bin/valgrind --leak-check=full --show-leak-kinds=all --suppressions=./valgrind-clixon.supp --track-fds=yes --trace-children=yes --log-file=$valgrindfile clixon_backend" + ;; + 'restconf') + valgrindtest=3 # This means backend valgrind test + sudo chmod 660 $valgrindfile + sudo chown www-data $valgrindfile + RCWAIT=5 # valgrind restconf needs some time to get up + clixon_restconf="/usr/bin/valgrind --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 /www-data/clixon_restconf" + + ;; + *) + echo "usage: $0 cli|netconf|restconf|backend" # valgrind memleak checks + rm -f $valgrindfile + exit -1 + ;; + esac + + err=0 + testnr=0 + for test in test_*.sh; do + if [ $testnr != 0 ]; then echo; fi + testfile=$test + . ./$test + errcode=$? + if [ $errcode -ne 0 ]; then + err=1 + echo -e "\e[31mError in $test errcode=$errcode" + echo -ne "\e[0m" + exit $errcode + fi + done + if [ $valgrindtest -eq 1 ]; then + checkvalgrind + sudo rm -f $valgrindfile + fi +} + +if [ -z "$*" ]; then + cmds="backend restconf cli netconf" +else + cmds=$* fi -PROGRAM=$1 -valgrindfile=$(mktemp) -echo "valgrindfile:$valgrindfile" - -case "$PROGRAM" in - 'cli') - valgrindtest=1 - RCWAIT=1 - clixon_cli="/usr/bin/valgrind --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_cli" -;; - 'netconf') - valgrindtest=1 - RCWAIT=1 - clixon_netconf="/usr/bin/valgrind --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_netconf" -;; - 'backend') - valgrindtest=2 # This means backend valgrind test - RCWAIT=10 # valgrind backend needs some time to get up - perfnr=100 # test_perf.sh restconf put more or less stops - perfreq=10 - - clixon_backend="/usr/bin/valgrind --leak-check=full --show-leak-kinds=all --suppressions=./valgrind-clixon.supp --track-fds=yes --trace-children=yes --log-file=$valgrindfile clixon_backend" -;; - 'restconf') - valgrindtest=3 # This means backend valgrind test - sudo chmod 660 $valgrindfile - sudo chown www-data $valgrindfile - RCWAIT=5 # valgrind restconf needs some time to get up - clixon_restconf="/usr/bin/valgrind --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 /www-data/clixon_restconf" - -;; -*) - echo "usage: $0 cli|netconf|restconf|backend" # valgrind memleak checks - rm -f $valgrindfile - exit -1 -;; -esac - -err=0 -testnr=0 -for test in test_*.sh; do - testfile=$test - . ./$test - errcode=$? - if [ $errcode -ne 0 ]; then - err=1 - echo -e "\e[31mError in $test errcode=$errcode" - echo -ne "\e[0m" - exit $errcode +# First run sanity +for c in $cmds; do + if [ $c != cli -a $c != netconf -a $c != restconf -a $c != backend ]; then + echo "c:$c" + echo "usage: $0 [cli|netconf|restconf|backend]+" + echo " with no args run all" + exit -1 fi done -if [ $valgrindtest -eq 1 ]; then - checkvalgrind - sudo rm -f $valgrindfile -fi +# Then actual run +for c in $cmds; do + echo "Mem test for $c" + echo "=================" + memonce $c +done