#!/bin/bash # Define test functions. # Create working dir as variable "dir" testnr=0 testname= # For memcheck #clixon_cli="valgrind --leak-check=full --show-leak-kinds=all clixon_cli" clixon_cli=clixon_cli # For memcheck / performance #clixon_netconf="valgrind --leak-check=full --show-leak-kinds=all clixon_netconf" #clixon_netconf="valgrind --tool=callgrind clixon_netconf" clixon_netconf=clixon_netconf # How to run restconf stand-alone and using valgrind #sudo su -c "/www-data/clixon_restconf -f $cfg -D" -s /bin/sh www-data #sudo su -c "valgrind --leak-check=full --show-leak-kinds=all /www-data/clixon_restconf -f $cfg -D" -s /bin/sh www-data clixon_backend=clixon_backend dir=/var/tmp/$0 if [ ! -d $dir ]; then mkdir $dir fi rm -rf $dir/* # error and exit, arg is optional extra errmsg err(){ echo -e "\e[31m\nError in Test$testnr [$testname]:" if [ $# -gt 0 ]; then echo "Expected: $1" fi if [ $# -gt 1 ]; then echo "Received: $2" fi echo -e "\e[0m:" echo "$ret"| od -t c > $dir/clixon-ret echo "$expect"| od -t c > $dir/clixon-expect diff $dir/clixon-ret $dir/clixon-expect exit $testnr } # Increment test number and print a nice string new(){ testnr=`expr $testnr + 1` testname=$1 >&2 echo "Test$testnr [$1]" } new2(){ testnr=`expr $testnr + 1` testname=$1 >&2 echo -n "Test$testnr [$1]" } # clixon tester. First arg is command and second is expected outcome expectfn(){ cmd=$1 expect=$2 if [ $# = 3 ]; then expect2=$3 else expect2= fi ret=$($cmd) # if [ $? -ne 0 ]; then # err "wrong args" # fi # Match if both are empty string if [ -z "$ret" -a -z "$expect" ]; then return fi if [ -z "$ret" -a "$expect" = "^$" ]; then return fi # grep extended grep match=`echo $ret | grep -EZo "$expect"` if [ -z "$match" ]; then err "$expect" "$ret" fi if [ -n "$expect2" ]; then match=`echo "$ret" | grep -EZo "$expect2"` if [ -z "$match" ]; then err $expect "$ret" fi fi } expecteq(){ ret=$1 expect=$2 if [ -z "$ret" -a -z "$expect" ]; then return fi if [[ "$ret" = "$expect" ]]; then echo else err "$expect" "$ret" fi } # clixon tester. First arg is command second is stdin and # third is expected outcome expecteof(){ cmd=$1 input=$2 expect=$3 # Do while read stuff ret=$($cmd<