Skip to content
Snippets Groups Projects
Commit 8399c8da authored by George Joseph's avatar George Joseph Committed by Gerrit Code Review
Browse files

Merge "CI: Allow runUnittests to use 'expect' to run the tests"

parents d2f784cc 8ff3435c
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env bash #!/usr/bin/env bash
CIDIR=$(dirname $(readlink -fn $0)) CIDIR=$(dirname $(readlink -fn $0))
NO_EXPECT=0
source $CIDIR/ci.functions source $CIDIR/ci.functions
ASTETCDIR=$DESTDIR/etc/asterisk ASTETCDIR=$DESTDIR/etc/asterisk
...@@ -14,9 +15,54 @@ asterisk_corefile_glob() { ...@@ -14,9 +15,54 @@ asterisk_corefile_glob() {
fi fi
} }
run_tests_expect() {
$EXPECT <<-EOF
spawn sudo $ASTERISK ${USER_GROUP:+-U ${USER_GROUP%%:*} -G ${USER_GROUP##*:}} -fcng -C $CONFFILE
match_max 512
set timeout 600
expect -notransfer "Asterisk Ready."
send "core show settings\r"
expect -notransfer "CLI>"
send "${UNITTEST_COMMAND:-test execute all}\r"
expect -notransfer -ex "Test(s) Executed"
expect -notransfer "CLI>"
send "test show results failed\r"
expect -notransfer "CLI>"
send "test generate results xml ${OUTPUTFILE}\r"
expect -notransfer "CLI>"
send "core stop now\r"
expect -notransfer "Executing last minute cleanups"
wait
EOF
}
run_tests_socket() {
sudo $ASTERISK ${USER_GROUP:+-U ${USER_GROUP%%:*} -G ${USER_GROUP##*:}} -gn -C $CONFFILE
for n in {1..5} ; do
sleep 3
$ASTERISK -rx "core waitfullybooted" -C $CONFFILE && break
done
sleep 1
$ASTERISK -rx "core show settings" -C $CONFFILE
$ASTERISK -rx "${UNITTEST_COMMAND:-test execute all}" -C $CONFFILE
$ASTERISK -rx "test show results failed" -C $CONFFILE
$ASTERISK -rx "test generate results xml $OUTPUTFILE" -C $CONFFILE
$ASTERISK -rx "core stop now" -C $CONFFILE
}
# If DESTDIR is used to install and run asterisk from non standard locations,
# the directory entries in asterisk.conf need to be munged to prepend DESTDIR.
ALTERED=$(head -10 ../tmp/DESTDIR/etc/asterisk/asterisk.conf | grep -q "DESTDIR" && echo yes)
if [ x"$ALTERED" = x ] ; then
# In the section that starts with [directories and ends with a blank line,
# replace "=> " with "=> ${DESTDIR}"
sed -i -r -e "/^\[directories/,/^$/ s@=>\s+@=> ${DESTDIR}@" "$ASTETCDIR/asterisk.conf"
fi
cat <<-EOF > "$ASTETCDIR/logger.conf" cat <<-EOF > "$ASTETCDIR/logger.conf"
[logfiles] [logfiles]
full => notice,warning,error,debug,verbose full => notice,warning,error,debug,verbose
console => notice,warning,error
EOF EOF
echo "[default]" > "$ASTETCDIR/extensions.conf" echo "[default]" > "$ASTETCDIR/extensions.conf"
...@@ -58,6 +104,7 @@ ASTERISK="$DESTDIR/usr/sbin/asterisk" ...@@ -58,6 +104,7 @@ ASTERISK="$DESTDIR/usr/sbin/asterisk"
CONFFILE=$ASTETCDIR/asterisk.conf CONFFILE=$ASTETCDIR/asterisk.conf
OUTPUTDIR=${OUTPUT_DIR:-tests/CI/output/} OUTPUTDIR=${OUTPUT_DIR:-tests/CI/output/}
OUTPUTFILE=${OUTPUT_XML:-${OUTPUTDIR}/unittests-results.xml} OUTPUTFILE=${OUTPUT_XML:-${OUTPUTDIR}/unittests-results.xml}
EXPECT="$(which expect 2>/dev/null || : )"
[ ! -d ${OUTPUTDIR} ] && mkdir -p $OUTPUTDIR [ ! -d ${OUTPUTDIR} ] && mkdir -p $OUTPUTDIR
[ x"$USER_GROUP" != x ] && sudo chown -R $USER_GROUP $OUTPUTDIR [ x"$USER_GROUP" != x ] && sudo chown -R $USER_GROUP $OUTPUTDIR
...@@ -65,16 +112,14 @@ OUTPUTFILE=${OUTPUT_XML:-${OUTPUTDIR}/unittests-results.xml} ...@@ -65,16 +112,14 @@ OUTPUTFILE=${OUTPUT_XML:-${OUTPUTDIR}/unittests-results.xml}
rm -rf $ASTETCDIR/extensions.{ael,lua} || : rm -rf $ASTETCDIR/extensions.{ael,lua} || :
set -x set -x
sudo $ASTERISK ${USER_GROUP:+-U ${USER_GROUP%%:*} -G ${USER_GROUP##*:}} -gn -C $CONFFILE if [ x"$EXPECT" != x -a $NO_EXPECT -eq 0 ] ; then
for n in {1..5} ; do run_tests_expect
sleep 3 else
$ASTERISK -rx "core waitfullybooted" -C $CONFFILE && break run_tests_socket
done fi
sleep 1
$ASTERISK -rx "${UNITTEST_COMMAND:-test execute all}" -C $CONFFILE # Cleanup "just in case"
$ASTERISK -rx "test show results failed" -C $CONFFILE sudo killall -qe -ABRT $ASTERISK
$ASTERISK -rx "test generate results xml $OUTPUTFILE" -C $CONFFILE
$ASTERISK -rx "core stop now" -C $CONFFILE
runner rsync -vaH $DESTDIR/var/log/asterisk/. $OUTPUTDIR runner rsync -vaH $DESTDIR/var/log/asterisk/. $OUTPUTDIR
set +x set +x
...@@ -86,6 +131,7 @@ do ...@@ -86,6 +131,7 @@ do
if [ -f $core ] if [ -f $core ]
then then
echo "*** Found a core file ($core) after running unit tests ***" echo "*** Found a core file ($core) after running unit tests ***"
set -x
sudo OUTPUTDIR=$OUTPUTDIR $DESTDIR/var/lib/asterisk/scripts/ast_coredumper --no-default-search $core sudo OUTPUTDIR=$OUTPUTDIR $DESTDIR/var/lib/asterisk/scripts/ast_coredumper --no-default-search $core
fi fi
done done
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment