mem.sh with more than one target

This commit is contained in:
Olof Hagsand 2019-03-28 21:57:28 +01:00
parent a269e26c0d
commit 38991084a5
3 changed files with 85 additions and 63 deletions

View file

@ -73,7 +73,7 @@ RUN make
RUN make install RUN make install
# Build and install the clixon example # Build and install the clixon example
WORKDIR /clixon/clixon/example WORKDIR /clixon/clixon/example/main
RUN make RUN make
RUN make install RUN make install
RUN install example.xml /clixon/build/etc/clixon.xml RUN install example.xml /clixon/build/etc/clixon.xml

View file

@ -52,12 +52,10 @@ Run all tests but continue after errors and only print a summary test output ide
``` ```
## Memory leak test ## 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 # All components
mem.sh netconf mem.sh restconf backend # Only backend and cli
mem.sh backend
mem.sh restconf
``` ```
## Site.sh ## Site.sh

View file

@ -1,27 +1,27 @@
#!/bin/bash #!/bin/bash
# Run valgrind leak test for cli, restconf, netconf or background. # Run valgrind leak test for cli, restconf, netconf or background.
# Stop on first error # Stop on first error
#
if [ $# -ne 1 ]; then
echo "usage: $0 cli|netconf|restconf|backend" # valgrind memleak checks
exit -1
fi
PROGRAM=$1
valgrindfile=$(mktemp)
echo "valgrindfile:$valgrindfile"
case "$PROGRAM" in # Run valgrindtest once, args:
# what: cli|netconf|restconf|backend
memonce(){
what=$1
valgrindfile=$(mktemp)
echo "valgrindfile:$valgrindfile"
case "$what" in
'cli') 'cli')
valgrindtest=1 valgrindtest=1
RCWAIT=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" 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') 'netconf')
valgrindtest=1 valgrindtest=1
RCWAIT=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" 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') 'backend')
valgrindtest=2 # This means backend valgrind test valgrindtest=2 # This means backend valgrind test
RCWAIT=10 # valgrind backend needs some time to get up RCWAIT=10 # valgrind backend needs some time to get up
@ -29,7 +29,7 @@ case "$PROGRAM" in
perfreq=10 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" 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') 'restconf')
valgrindtest=3 # This means backend valgrind test valgrindtest=3 # This means backend valgrind test
sudo chmod 660 $valgrindfile sudo chmod 660 $valgrindfile
@ -37,17 +37,18 @@ case "$PROGRAM" in
RCWAIT=5 # valgrind restconf needs some time to get up 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" 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 echo "usage: $0 cli|netconf|restconf|backend" # valgrind memleak checks
rm -f $valgrindfile rm -f $valgrindfile
exit -1 exit -1
;; ;;
esac esac
err=0 err=0
testnr=0 testnr=0
for test in test_*.sh; do for test in test_*.sh; do
if [ $testnr != 0 ]; then echo; fi
testfile=$test testfile=$test
. ./$test . ./$test
errcode=$? errcode=$?
@ -57,9 +58,32 @@ for test in test_*.sh; do
echo -ne "\e[0m" echo -ne "\e[0m"
exit $errcode exit $errcode
fi fi
done done
if [ $valgrindtest -eq 1 ]; then if [ $valgrindtest -eq 1 ]; then
checkvalgrind checkvalgrind
sudo rm -f $valgrindfile sudo rm -f $valgrindfile
fi
}
if [ -z "$*" ]; then
cmds="backend restconf cli netconf"
else
cmds=$*
fi fi
# 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
# Then actual run
for c in $cmds; do
echo "Mem test for $c"
echo "================="
memonce $c
done