removed unnecessary strerror() in clixon_err() calls; added 'function' keyword in all function declarations in the test scripts

This commit is contained in:
Olof hagsand 2021-02-04 12:04:48 +01:00
parent 73414e2ece
commit 1f0147f996
42 changed files with 95 additions and 84 deletions

View file

@ -221,7 +221,7 @@ fi
# error and exit,
# arg1: expected
# arg2: errmsg[optional]
err(){
function err(){
echo -e "\e[31m\nError in Test$testnr [$testname]:"
if [ $# -gt 0 ]; then
echo "Expected: $1"
@ -240,7 +240,7 @@ err(){
}
# Test is previous test had valgrind errors if so quit
checkvalgrind(){
function checkvalgrind(){
if [ -f $valgrindfile ]; then
res=$(cat $valgrindfile | grep -e "Invalid" |awk '{print $4}' | grep -v '^0$')
if [ -n "$res" ]; then
@ -260,7 +260,7 @@ checkvalgrind(){
# Start backend with all varargs.
# If valgrindtest == 2, start valgrind
start_backend(){
function start_backend(){
if [ $valgrindtest -eq 2 ]; then
# Start in background since daemon version creates two traces: parent,
# child. If background then only the single relevant.
@ -273,7 +273,7 @@ start_backend(){
fi
}
stop_backend(){
function stop_backend(){
sudo clixon_backend -z $*
if [ $? -ne 0 ]; then
err "kill backend"
@ -286,7 +286,7 @@ stop_backend(){
}
# Wait for restconf to stop sending 502 Bad Gateway
wait_backend(){
function wait_backend(){
reply=$(echo '<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="101"><ping xmlns="http://clicon.org/lib"/></rpc>]]>]]>' | $clixon_netconf -qef $cfg 2> /dev/null)
let i=0;
while [[ $reply != "<rpc-reply"* ]]; do
@ -304,7 +304,7 @@ wait_backend(){
# Start restconf daemon
# @see wait_restconf
start_restconf(){
function start_restconf(){
# Start in background
echo "sudo -u $wwwstartuser -s $clixon_restconf $RCLOG -D $DBG $*"
sudo -u $wwwstartuser -s $clixon_restconf $RCLOG -D $DBG $* &
@ -314,7 +314,7 @@ start_restconf(){
}
# Stop restconf daemon before test
stop_restconf_pre(){
function stop_restconf_pre(){
sudo pkill -f clixon_restconf
}
@ -322,7 +322,7 @@ stop_restconf_pre(){
# Two caveats in pkill:
# 1) Dont use $clixon_restconf (dont work in valgrind)
# 2) Dont use -u $WWWUSER since clixon_restconf may drop privileges.
stop_restconf(){
function stop_restconf(){
# sudo pkill -u $wwwuser -f clixon_restconf # Dont use $clixon_restoconf doesnt work in valgrind
sudo pkill -f clixon_restconf
if [ $valgrindtest -eq 3 ]; then
@ -335,7 +335,7 @@ stop_restconf(){
# @see start_restconf
# Reasons for not working: if you run evhtp is nginx running?
# @note assumes port=80 if RCPROTO=http and port=443 if RCPROTO=https
wait_restconf(){
function wait_restconf(){
# echo "curl $CURLOPTS $* $RCPROTO://localhost/restconf"
hdr=$(curl $CURLOPTS $* $RCPROTO://localhost/restconf) 2> /dev/null
# echo "hdr:\"$hdr\""
@ -355,7 +355,7 @@ wait_restconf(){
fi
}
endtest()
function endtest()
{
if [ $valgrindtest -eq 1 ]; then
checkvalgrind
@ -363,7 +363,7 @@ endtest()
}
# Increment test number and print a nice string
new(){
function new(){
endtest # finalize previous test
testnr=`expr $testnr + 1`
testi=`expr $testi + 1`
@ -381,7 +381,7 @@ new(){
# Example:
# expectpart "$(a-shell-cmd arg)" 0 'expected match 1' 'expected match 2' --not-- 'not expected 1'
# @note need to escape \[\]
expectpart(){
function expectpart(){
r=$?
ret=$1
retval=$2
@ -435,7 +435,7 @@ expectpart(){
# - stdin input
# - expected stdout outcome
# Use this if you want regex eg ^foo$
expecteof(){
function expecteof(){
cmd=$1
retval=$2
input=$3
@ -482,7 +482,7 @@ EOF
# - expected command return value (0 if OK)
# - stdin input
# - expected stdout outcome
expecteofx(){
function expecteofx(){
cmd=$1
retval=$2
input=$3
@ -528,7 +528,7 @@ EOF
# - expected command return value (0 if OK)
# - stdin input
# - expected stdout outcome
expecteofeq(){
function expecteofeq(){
cmd=$1
retval=$2
input=$3
@ -567,7 +567,7 @@ EOF
# - Command
# - Filename to pipe to stdin
# - expected stdout outcome
expecteof_file(){
function expecteof_file(){
cmd=$1
retval=$2
file=$3
@ -601,7 +601,7 @@ expecteof_file(){
# - not expected stdout outcome*
#
# XXX do expectwait like expectpart with multiple matches
expectwait(){
function expectwait(){
cmd=$1
input=$2
expect=$3
@ -632,7 +632,7 @@ expectwait(){
fi
}
expectmatch(){
function expectmatch(){
ret=$1
r=$2
expret=$3

View file

@ -8,12 +8,16 @@
# Run valgrindtest once, args:
# what: (cli|netconf|restconf|backend)* # no args means all
memonce(){
function memonce(){
what=$1
valgrindfile=$(mktemp)
echo "valgrindfile:$valgrindfile"
clixon_cli=
clixon_netconf=
clixon_backend=
clixon_restconf=
case "$what" in
'cli')
valgrindtest=1
@ -32,7 +36,7 @@ memonce(){
clixon_backend="/usr/bin/valgrind --num-callers=50 --leak-check=full --show-leak-kinds=all --suppressions=./valgrind-clixon.supp --track-fds=yes --trace-children=no --log-file=$valgrindfile clixon_backend"
;;
'restconf')
valgrindtest=3 # This means backend valgrind test
valgrindtest=3 # This means restconf valgrind test
sudo chmod 660 $valgrindfile
sudo chown www-data $valgrindfile
: ${DEMWAIT:=15} # valgrind backend needs some time to get up
@ -66,7 +70,7 @@ memonce(){
}
# Print a line with ==== under
println(){
function println(){
str=$1
echo "$str"
length=$(echo "$str" | wc -c)

View file

@ -89,7 +89,7 @@ EOF
# Generate file with n entries
# argument: <n> <proto>
genfile(){
function genfile(){
if [ $2 = netconf ]; then
echo -n "<rpc><edit-config><target><candidate/></target><default-operation>replace</default-operation><config><x xmlns=\"urn:example:clixon\">" > $fxml
for (( i=0; i<$1; i++ )); do
@ -114,7 +114,7 @@ genfile(){
# netconf, restconf
# where op is one of:
# get put delete commit
runnet(){
function runnet(){
op=$1
nr=$2 # Number of entries in DB (keep diff from n due to shell dynamic binding)
reqs=$3
@ -165,7 +165,7 @@ done | $clixon_netconf -qf $cfg -y $fyang; } 2>&1 | awk '/real/ {print $2}' | tr
# netconf, restconf
# where op is one of:
# get put delete
runrest(){
function runrest(){
op=$1
nr=$2 # Number of entries in DB
reqs=$3
@ -210,12 +210,12 @@ runrest(){
}
commit(){
function commit(){
# commit to running
expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "<rpc><commit/></rpc>]]>]]>" "^<rpc-reply><ok/></rpc-reply>]]>]]>$"
}
reset(){
function reset(){
# delete all in candidate
expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "<rpc><edit-config><target><candidate/></target><default-operation>none</default-operation><config operation='delete'/></edit-config></rpc>]]>]]>" '^<rpc-reply><ok/></rpc-reply>]]>]]>$'
# commit to running
@ -224,7 +224,7 @@ reset(){
# Load n entries into candidate
# Args: <n>
load(){
function load(){
# Generate file ($fxml)
genfile $1 netconf
# Write it to backend in one chunk
@ -236,7 +236,7 @@ load(){
# args: <op> <protocol> <from> <step> <to> <reqs> <cand> <run>
# <reqs>=0 means all in one go
# <cand> <run> means a priori loaded into datastore
plot(){
function plot(){
op=$1
proto=$2
from=$3
@ -275,7 +275,7 @@ plot(){
# Each operation do <reqs> times
# args: <op> <protocol> <from> <step> <to> <reqs> <cand> <run>
# <reqs>=0 means all in one go
startup(){
function startup(){
from=$1
step=$2
to=$3

View file

@ -117,7 +117,7 @@ EOF
# Arguments
# - expected config
# - expected state
testrun()
function testrun()
{
config=$1
state=$2

View file

@ -133,7 +133,7 @@ if [ $BE -ne 0 ]; then
wait_backend
fi
testparam()
function testparam()
{
# Try hidden parameter list
@ -149,7 +149,7 @@ EOF
}
testvalue()
function testvalue()
{
# Try not hidden parameter list
new "query table parameter hidden"

View file

@ -117,7 +117,7 @@ fi
# then deleting it, and reloading it
# 1. mode - either VARS Keywords on non-key variables: a <x> y <y> or
# ALL Keywords on all variables: a x <x> y <y>
testrun()
function testrun()
{
mode=$1
if [ $mode = ALL ]; then

View file

@ -80,7 +80,7 @@ AFTER=$(cat <<EOF
EOF
)
testrun(){
function testrun(){
new "test params: -f $cfg -- -U"
# Bring your own backend
if [ $BE -ne 0 ]; then

View file

@ -124,7 +124,7 @@ EOF
# Run netconf feature test
# 1: syntax node
# 2: disabled or enabled
testrun()
function testrun()
{
node=$1
enabled=$2

View file

@ -50,7 +50,7 @@ EOF
# Args:
# 1: base tree
# 2: sub tree
testrun(){
function testrun(){
x0=$1
xi="<c xmlns=\"urn:example:example\">$2</c>"
xp=c

View file

@ -103,7 +103,7 @@ EOF
# - socket family
# - socket file/addr
# - precommand /(eg sudo to raise to root)
testrun(){
function testrun(){
mode=$1
username=$2
family=$3

View file

@ -164,7 +164,7 @@ EOF
# - read other in same module
# - read table
# - read parameter
testrun(){
function testrun(){
readdefault=$1
module=$2
table=$3

View file

@ -142,7 +142,7 @@ EOF
# - read
# - update
# - delete
testrun(){
function testrun(){
writedefault=$1
paramaccess=$2
paramaction=$3

View file

@ -64,7 +64,7 @@ EOF
# 6: expected return value of test2
# 7: expected return value of test3
# 8: startup mode: startup or init
testrun(){
function testrun(){
enablenacm=$1
readdefault=$2
writedefault=$3

View file

@ -161,7 +161,7 @@ if [ $RC -ne 0 ]; then
fi
# Set nacm from scratch
nacm(){
function nacm(){
new "auth set authentication config"
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc $DEFAULTNS><edit-config><target><candidate/></target><config operation='replace'>$RULES</config></edit-config></rpc>]]>]]>" "^<rpc-reply $DEFAULTNS><ok/></rpc-reply>]]>]]>$"

View file

@ -51,7 +51,7 @@ DEFAULT='<nacm xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-acm"><enable-nacm
# recovery: recovery user
# getp: true: get works; false: get does not work
# putp: true: expected to work; false: not work
testrun()
function testrun()
{
cred=$1
realuser=$2

View file

@ -379,7 +379,7 @@ EOF
# 1: leaf tag in yang
# 2: expected match(true) or fail(false)
# 3: match string
testrun(){
function testrun(){
leaf="$1" # leaf tag under <c> with pattern to test
mat="$2" # expected match (1) or fail (0)
str0="$3" # content string (to match against)

View file

@ -64,7 +64,7 @@ EOF
# Test function
# Arguments:
# 1: nr size of large list
testrun(){
function testrun(){
nr=$1
new "test params: -f $cfg"

View file

@ -40,7 +40,7 @@ EOF
# 3: expected user: Expected user after drop (or no drop then startuser)
# 4: privileged mode (none, drop_perm, drop_temp)
# 5: expect error: 0 or 1
testrun(){
function testrun(){
startuser=$1
beuser=$2
expectuser=$3

View file

@ -106,7 +106,7 @@ fi
# Restconf test routine with arguments:
# 1. proto:http/https
# 2: addr: 127.0.0.1/::1 # IPv4 or IPv6
testrun()
function testrun()
{
proto=$1 # http/https
addr=$2 # 127.0.0.1/::1

View file

@ -13,6 +13,11 @@ if [ "${WITH_RESTCONF}" != "evhtp" ]; then
if [ "$s" = $0 ]; then exit 0; else return 0; fi # skip
fi
# Skip if valgrind restconf (actually valgrind version < 3.16 27 May 2020)
if [ $valgrindtest -eq 3 ]; then
if [ "$s" = $0 ]; then exit 0; else return 0; fi # skip
fi
APPNAME=example
cfg=$dir/conf.xml

View file

@ -44,7 +44,7 @@ EOF
# Args:
# 1: operation
# 2: expectret 0: means expect pi 0 as return, else something else
testrpc()
function testrpc()
{
operation=$1
expectret=$2

View file

@ -48,7 +48,7 @@ cat <<EOF > $cfg
</clixon-config>
EOF
testrun(){
function testrun(){
option=$1
new "test params: -f $cfg -y $fyang $option"

View file

@ -22,7 +22,7 @@ fyang=$dir/socket.yang
# 1: UNIX|IPv4|IPv6
# 2: unix file or ipv4 address or ipv6 address
# 3: session-id
testrun(){
function testrun(){
family=$1
sock=$2
id=$3

View file

@ -156,7 +156,7 @@ cat <<EOF > $cfg
EOF
# Run The test, ssl config is in local config
testrun()
function testrun()
{
cat <<EOF > $dir/startup_db
<config>

View file

@ -61,7 +61,7 @@ brokenvar='<interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces"><inte
# The configs are identified by an interface called run, startup, extra.
# Depending on startup mode (init, none, running, or startup)
# expect different output of an initial get-config of running
testrun(){
function testrun(){
mode=$1
rdb=$2 # running db at start
sdb=$3 # startup db at start
@ -110,7 +110,7 @@ testrun(){
# The backend should fail with 255 and all db:s should be unaffected
testfail(){
function testfail(){
mode=$1
rdb=$2 # running db at start
sdb=$3 # startup db at start

View file

@ -81,7 +81,7 @@ EOF
# Check statements in log
# arg1: a statement to look for
# arg2: expected line number
checklog(){
function checklog(){
s=$1 # statement
l0=$2 # linenr
new "Check $s in log"

View file

@ -58,7 +58,7 @@ EOF
# Check statements in log
# arg1: a statement to look for
# arg2: expected line number
checklog(){
function checklog(){
s=$1 # statement
l0=$2 # linenr
new "Check $s in log"

View file

@ -210,7 +210,7 @@ EOF
# Type tests.
# Parameters:
# 1: dbcache: cache, nocache, cache-zerocopy
testrun(){
function testrun(){
dbcache=$1
new "test params: -f $cfg # dbcache: $dbcache"

View file

@ -192,7 +192,7 @@ EOF
# 3: min value (for errmsg)
# 4: max value (for errmsg)
# 5: post (eg .000 - special for decimal64, others should have "") (NYI)
testbuiltin(){
function testbuiltin(){
t=$1
val=$2
rmin=$3
@ -218,7 +218,7 @@ testbuiltin(){
# 2: val OK
# 3: eval Invalid value
# 4: post (eg .000 - special for decimal64, others should have "")
testrange(){
function testrange(){
t=$1
val=$2
eval=$3

View file

@ -250,7 +250,7 @@ cat <<EOF > $cfg
EOF
# Start from startup and upgrade, check running
testrun(){
function testrun(){
runxml=$1
# -u means trigger example upgrade

View file

@ -75,7 +75,7 @@ EOF
# Create 5 startup files 1-5 according to the 5 cases above (columns in the matrix)
# Argument:
# 1: payload, eg whats in the config apart from modstate
createstartups()
function createstartups()
{
payload=$1
@ -150,7 +150,7 @@ EOF
# Check statements in log
# arg1: a statement to look for
# arg2: expected line number
checklog(){
function checklog(){
s=$1 # statement
l0=$2 # linenr
new "Check $s in log on line $l0"
@ -178,7 +178,7 @@ checklog(){
# Check statements are not in log
# arg1: a statement to look for
checknolog(){
function checknolog(){
s=$1 # statement
new "Check $s not in log"
# echo "grep -n "$s" $log"
@ -200,7 +200,7 @@ checknolog(){
# 2: v: verb: true or false. The next statement should be there or not
# 3: what to look for in log (if v=true it should be there, if v=false it should not be there)
# 4: Linenr in log
testrun(){
function testrun(){
i=$1
flag=$2
match=$3
@ -248,7 +248,7 @@ testrun(){
# Arguments:
# 1 : payload with loaded YANG
# 2 : payload without loaded YANG
testall()
function testall()
{
payload1=$1
payload2=$2

View file

@ -56,7 +56,7 @@ EOF
# 4: xpath
# 5: retval
# 6: result
testrun(){
function testrun(){
op=$1
x0=$2
x1=$3

View file

@ -103,7 +103,7 @@ STATE1='<sa xmlns="urn:example:any"><sb><k>22</k><u5>55</u5></sb><u4><u5>a strin
# Args:
# 1: bool: startup (or not)
# 2: bool: treat unknown as anydata (or not)
testrun()
function testrun()
{
startup=$1
unknown=$2

View file

@ -70,7 +70,7 @@ cat <<EOF > $fyang
EOF
# No args
testrun(){
function testrun(){
# Initial data (default y not given)
XML='<a xmlns="urn:example:default"><b><c>0</c></b></a>'