@ -26,6 +26,7 @@ SKIP_DELDOMAIN=false
SKIP_TESTS = false
SKIP_PARSE = false
SKIP_RUNSIPP = false
FIX_RETRANS = false
GRAPH = false
GRAPH_FAIL = false
JSON_KAM = false
@ -85,17 +86,48 @@ check_test() {
kam_type = "--json"
fi
echo -n " $( date) - Testing $( basename " $1 " ) againts $( basename " $2 " ) -> $( basename " $3 " ) "
if ! " ${ BIN_DIR } /check.py " ${ kam_type } " $1 " " $2 " > " $3 " ; then
echo " NOT ok"
ERR_FLAG = 1
if ( ! " ${ GRAPH } " ) && " ${ GRAPH_FAIL } " ; then
echo " $( date) - Generating flow image: ${ dest } .png "
graph " $msg " " ${ dest } .png "
echo " $( date) - Done "
fi
else
echo -n " $( date) - Testing $( basename " $1 " ) against $( basename " $2 " ) -> $( basename " $3 " ) "
if " ${ BIN_DIR } /check.py " ${ kam_type } " $1 " " $2 " > " $3 " ; then
echo " ok"
return
fi
echo " NOT ok"
if " ${ FIX_RETRANS } " ; then
echo " $( date) - Fix retransmissions enabled: try to test the next json file "
local next_msg
local next_tap
next_test_filepath " $1 "
next_tap = ${ 3 /_test.tap/_test_retry.tap }
if [ -a " $next_msg " ] ; then
echo -n " $( date) - Testing $( basename " $1 " ) against $( basename " $next_msg " ) -> $( basename " $next_tap " ) "
if " ${ BIN_DIR } /check.py " ${ kam_type } " $1 " " $next_msg " > " $next_tap " ; then
# Test using the next json file was fine. That means that, with high probability, there was a retransmission.
# Next step is to backup the failed tap test and overwrite it with the working one
mv " ${ 3 } " " ${ 3 } _retrans "
mv " ${ next_tap } " " ${ 3 } "
echo " ok"
return
fi
if [ -a " $next_tap " ] ; then
# Test using the next json file was a failure.
# Next step is remove $next_tap file to don't create confusion during the additional checks
rm " ${ next_tap } "
fi
fi
echo " NOT ok"
fi
ERR_FLAG = 1
if ( ! " ${ GRAPH } " ) && " ${ GRAPH_FAIL } " ; then
echo " $( date) - Generating flow image: ${ dest } .png "
# In any failure case only the graph related to the original json file will be created
graph " $msg " " ${ dest } .png "
echo " $( date) - Done "
fi
}
@ -495,6 +527,26 @@ test_filepath() {
msg = " ${ LOG_DIR } / $( basename " $msg_name " ) "
}
next_test_filepath( ) {
local msg_name
local old_json
local new_json
if ! " ${ JSON_KAM } " ; then
msg_name = ${ 1 /_test.yml/.yml }
else
msg_name = ${ 1 /_test.yml/.json }
fi
msg_name = $( basename " ${ msg_name } " )
old_json = " ${ msg_name : 0 : 4 } "
new_json = $(( ( 10# $old_json ) + 1 ))
new_json = $( printf %04d ${ new_json } )
msg_name = " ${ new_json } ${ msg_name : 4 } "
next_msg = " ${ LOG_DIR } / ${ msg_name } "
}
usage( ) {
echo "Usage: check.sh [-hCDRTGgJKm] [-d DOMAIN ] [-p PROFILE ] -s [GROUP] check_name"
echo "Options:"
@ -505,6 +557,7 @@ usage() {
echo -e "\t-P: skip parse"
echo -e "\t-G: creation of graphviz image"
echo -e "\t-g: creation of graphviz image only if test fails"
echo -e "\t-r: fix retransmission issues"
echo -e "\t-d: DOMAIN"
echo -e "\t-p CE|PRO default is CE"
echo -e "\t-J kamailio json output ON. PARSE skipped"
@ -515,7 +568,7 @@ usage() {
echo -e "\tcheck_name. Scenario name to check. This is the name of the directory on GROUP dir."
}
while getopts 'hCd:p:Rs:DTPGg JKm' opt; do
while getopts 'hCd:p:Rs:DTPGg r JKm' opt; do
case $opt in
h) usage; exit 0; ;
C) SKIP = true; ;
@ -529,6 +582,7 @@ while getopts 'hCd:p:Rs:DTPGgJKm' opt; do
K) CAPTURE = true; ;
G) GRAPH = true; ;
g) GRAPH_FAIL = true; ;
r) FIX_RETRANS = true; ;
J) JSON_KAM = true; ;
m) MEMDBG = true; ;
esac
@ -630,6 +684,42 @@ if ! "$SKIP_RUNSIPP" ; then
echo " $( date) - No json files found "
fi
fi
if " ${ FIX_RETRANS } " ; then
echo " $( date) - Checking retransmission issues "
RETRANS_ISSUE = false
file_find = ( $( find " ${ LOG_DIR } " -maxdepth 1 -name '*.json' | sort) )
for json_file in " ${ file_find [@] } " ; do
file_find = ( " ${ file_find [@] : 1 } " )
if ! [ -a " ${ json_file } " ] ; then
continue
fi
for next_json_file in " ${ file_find [@] } " ; do
if ! [ -a " ${ next_json_file } " ] ; then
continue
fi
if ( diff -q -u <( tail -n3 " ${ json_file } " ) <( tail -n3 " ${ next_json_file } " ) & > /dev/null ) ; then
echo " $( basename " ${ next_json_file } " ) seems a retransmission of $( basename " ${ json_file } " ) ---> renaming the file in ${ next_json_file } _retransmission "
mv -f " ${ next_json_file } " " ${ next_json_file } _retransmission "
RETRANS_ISSUE = true
fi
done
done
if " ${ RETRANS_ISSUE } " ; then
echo " $( date) - Reordering kamailio json files "
file_find = ( $( find " ${ LOG_DIR } " -maxdepth 1 -name '*.json' | sort) )
a = 1
for json_file in " ${ file_find [@] } " ; do
new_name = $( printf "%04d.json" " ${ a } " )
mv -n " ${ json_file } " " ${ LOG_DIR } / ${ new_name } " & > /dev/null
let a = a+1
done
fi
echo " $( date) - Done "
fi
fi