Skip to content

Commit

Permalink
test/unit: update unit test 60
Browse files Browse the repository at this point in the history
- make sipsak use localhost to avoid name lookup error
- kill Kamailio by using pid file
- do not pass -L to sipsak in order to have proper (CR LF) line ending
  • Loading branch information
mslehto committed Nov 16, 2016
1 parent 092ee82 commit 3690bce
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
17 changes: 9 additions & 8 deletions test/unit/60.sh
Expand Up @@ -20,26 +20,27 @@
. include/common
. include/require.sh

CFG=60.cfg
CFGFILE=60.cfg
TMPFILE=$(mktemp -t kamailio-test.XXXXXXXXXX)
SIPSAKOPTS="-H localhost -s sip:127.0.0.1 -v"

if ! (check_sipsak && check_kamailio && check_module "sdpops"); then
exit 0
fi

${BIN} -w . -f ${CFG} > /dev/null
${BIN} -w ${RUN_DIR} -Y ${RUN_DIR} -P ${PIDFILE} -f ${CFGFILE} > /dev/null
ret=$?

sleep 1
if [ "${ret}" -ne 0 ] ; then
echo "start fail"
${KILL}
kill_kamailio
exit ${ret}
fi

# Borken SDP should give 500 response
FILE="60-message-sdp0.sip"
sipsak -f ${FILE} -L -s sip:127.0.0.1 -v > ${TMPFILE}
sipsak ${SIPSAKOPTS} -f ${FILE} > ${TMPFILE}
ret=$?
if [ "${ret}" -eq 1 ] ; then
ret=0
Expand All @@ -55,7 +56,7 @@ for i in 1 2 3 4 5 6 7; do
TOTALBEFORE=$(awk '/^v=0/,/^$/ {total++; if ($0 ~ /^a=X-cap/ ) { prefix++;} else { other++} } END {if (prefix) {print other " + " prefix} else { print other " + 0"} }' ${FILE})
OTHERBEFORE=$(echo ${TOTALBEFORE}|cut -d+ -f1)

sipsak -f ${FILE} -L -s sip:127.0.0.1 -v > ${TMPFILE}
sipsak ${SIPSAKOPTS} -f ${FILE} > ${TMPFILE}
ret=$?
if [ "${ret}" -eq 0 ] ; then
TOTALAFTER=$(awk '/^v=0/,/^$/ {total++; if ($0 ~ /^a=X-cap/ ) { prefix++;} else { other++} } END {if (prefix) {print other " + " prefix} else { print other " + 0"} }' ${TMPFILE})
Expand All @@ -74,7 +75,7 @@ done

# Empty body should get 500 response
FILE="60-message-sdp8.sip"
sipsak -f ${FILE} -L -s sip:127.0.0.1 -v > ${TMPFILE}
sipsak ${SIPSAKOPTS} -f ${FILE} > ${TMPFILE}
ret=$?
if [ "${ret}" -eq 1 ] ; then
ret=0
Expand All @@ -84,7 +85,7 @@ else
exit ${ret}
fi

${KILL}

kill_kamailio
rm ${TMPFILE}
exit ${ret}

2 changes: 2 additions & 0 deletions test/unit/include/common
@@ -1,6 +1,7 @@
# all database modules
DB_ALL_MOD="acc|alias_db|auth_db|avpops|dialog|dialplan|dispatcher|domain|domainpolicy|group|imc|lcr|msilo|siptrace|speeddial|uri_db|usrloc|permissions|pdt|userblacklist"
# root directory relative to tests
RUN_DIR="."
SRC_DIR="../.."
CTL_DIR="$SRC_DIR/utils/kamctl"
CTLRC="$CTL_DIR/kamctlrc"
Expand All @@ -19,5 +20,6 @@ else
fi
fi
KILL="killall -15 $BNAME"
PIDFILE="${RUN_DIR}/kamailio.pid"
# test directory relative to root
TEST_DIR="test/unit"
4 changes: 4 additions & 0 deletions test/unit/include/require.sh
Expand Up @@ -63,3 +63,7 @@ check_sipsak() {
fi;
return 0
}

kill_kamailio() {
kill $(cat ${PIDFILE})
}

0 comments on commit 3690bce

Please sign in to comment.