[asterisk-commits] tilghman: branch tilghman/callparking_retrieval r821 - in /asterisk/team/tilg...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Nov 9 16:08:18 CST 2010


Author: tilghman
Date: Tue Nov  9 16:08:14 2010
New Revision: 821

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=821
Log:
Separate library functions out

Added:
    asterisk/team/tilghman/callparking_retrieval/lib/sh/library.sh   (with props)
Modified:
    asterisk/team/tilghman/callparking_retrieval/tests/pbx/call-files2/run-test

Added: asterisk/team/tilghman/callparking_retrieval/lib/sh/library.sh
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/tilghman/callparking_retrieval/lib/sh/library.sh?view=auto&rev=821
==============================================================================
--- asterisk/team/tilghman/callparking_retrieval/lib/sh/library.sh (added)
+++ asterisk/team/tilghman/callparking_retrieval/lib/sh/library.sh Tue Nov  9 16:08:14 2010
@@ -1,0 +1,175 @@
+#!/bin/bash
+
+set +e
+
+testdir=${0%%run-test}
+ASTERISK=/usr/sbin/asterisk
+debug=0
+
+case `uname -s` in
+	solaris*|sunos*)
+		PS="ps -ef"
+		KILLALL="pkill"
+		;;
+	*)
+		PS="ps auxwww"
+		KILLALL="killall"
+		;;
+esac
+
+case $2 in
+	*-1.4*)
+		ORIGINATE='originate'
+		CSC_HEADERS=3
+		;;
+	*-1.6.2*|*-1.4*)
+		ORIGINATE='originate'
+		CSC_HEADERS=4
+		;;
+	"")
+		echo "Usage: $0 -v asterisk-<version>"
+		exit 1
+		;;
+	*)
+		ORIGINATE='channel originate'
+		CSC_HEADERS=4
+		;;
+esac
+
+#
+# initialize():
+#   Parameters:  directories within the test to use for each instance of Asterisk needed in this test
+#
+initialize() {
+	# Save all initialized directories
+	lib_SYSDIRS=$@
+
+	# Local variables
+	local dst=""
+	local conf=""
+	local user=""
+	local i=""
+
+	for user in $@; do
+		echo " >>> Creating configuration directory for $user"
+		eval "${user}_tmpdir=`mktemp --tmpdir=/var/tmp -t -d spoolfile_$user.XXXXXX`"
+		# Shortcut for referral within this loop only
+		eval "conf=\${${user}_tmpdir}"
+
+		if test "$conf" = ""; then
+			echo " *** Unable to create temporary directory for $user"
+			cleanup
+			exit 1
+		fi
+
+		echo " >>> Creating files in configuration directory for $user"
+		for i in ../configs/*.sample; do
+			dst=$conf/`basename $i .sample`
+			install -m 644 $i $dst
+		done
+		for i in $testdir$user/*.conf; do
+			dst=$conf/`basename $i`
+			install -m 644 $i $dst
+		done
+		( echo "[directories]"; echo "astetcdir => $conf"; echo "astrundir => $conf"; echo "astlogdir => $testdir/$user"; echo "astspooldir => $conf/spool" ; echo "[options]"; echo "verbose = 10"; echo "documentation_language = en_US" ) > $conf/asterisk.conf
+		( echo "noload => pbx_lua.so" ; echo "noload => pbx_ael.so" ) >> $conf/modules.conf
+		mkdir -p $conf/spool/outgoing
+
+		# Verify that files got created properly
+		if test -s $conf/asterisk.conf ; then : ; else
+			echo " *** Unable to create test configuration files for $user in $conf"
+			cleanup
+			exit 1
+		fi
+		echo " >>> Starting Asterisk for $user"
+		$ASTERISK -g -C $conf/asterisk.conf
+		sleep 1
+		# Asterisk is running, right?
+		if $ASTERISK -C $conf/asterisk.conf -rx "core waitfullybooted" >/dev/null 2>&1; then :; else
+			echo " *** Unable to start asterisk for $user"
+			cleanup
+			exit 1
+		fi
+	done
+}
+
+#
+# cleanup()
+#   Parameters: none
+#
+cleanup() {
+	# Hide local exit values from other functions and the parent script
+	for a in $lib_SYSDIRS; do
+		eval "local $a=0"
+	done
+	local conf=""
+	local u=""
+	local avals=""
+	local bvals=""
+
+	for u in $lib_SYSDIRS; do
+		eval "conf=\${${u}_tmpdir}"
+		if test "x$conf" = "x"; then : ; else
+			$ASTERISK -C $conf/asterisk.conf -rx "core stop when convenient" >/dev/null 2>&1
+			let $u=$?
+		fi
+	done
+	sleep 1
+	for u in $lib_SYSDIRS; do
+		eval "conf=\${${u}_tmpdir}"
+		if test "x$conf" = "x"; then : ; else
+			$ASTERISK -C $conf/asterisk.conf -rx "core stop now" >/dev/null 2>&1
+			let $u=$?
+		fi
+	done
+	avals=""
+	bvals=""
+	for u in $lib_SYSDIRS; do
+		avals="1$avals"
+		eval "bvals=${bvals}\${$u}"
+	done
+	if test "$avals" != "$bvals"; then
+		$KILLALL asterisk >/dev/null 2>&1
+		for u in $lib_SYSDIRS; do
+			eval "conf=\${${u}_tmpdir}"
+			# This is a "nonsense" command.  If Asterisk is not running, it will exit non-zero.
+			$ASTERISK -C $conf/asterisk.conf -rx "core set verbose atleast 1" >/dev/null 2>&1
+			let $u=$?
+		done
+	fi
+	avals=""
+	bvals=""
+	for u in $lib_SYSDIRS; do
+		avals="1$avals"
+		eval "bvals=${bvals}\${$u}"
+	done
+	if test "$avals" != "$bvals"; then
+		$KILLALL -9 asterisk >/dev/null 2>&1
+	fi
+
+	rm -rf $userA_tmpdir $userB_tmpdir
+	set -e
+}
+
+#
+# verify_call()
+#   Parameters:
+#     1. Asterisk instance
+#     2. Number of channels expected to be up
+#
+verify_call() {
+	# Verify that the call is up
+	local count=`$ASTERISK -C $1/asterisk.conf -rx "core show channels" | wc -l`
+	if test $count != $(($CSC_HEADERS+$2)); then
+		echo -n " *** Call generation failed: got $count, but expected "
+		echo $(($CSC_HEADERS+$2))
+		if test "$debug" = "1"; then
+			echo ">>>>>$1>>>>>"
+			$ASTERISK -C $1/asterisk.conf -rx "core show channels"
+			echo "<<<<<$1<<<<<"
+		fi
+		cleanup
+		exit 1
+	fi
+}
+

Propchange: asterisk/team/tilghman/callparking_retrieval/lib/sh/library.sh
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/team/tilghman/callparking_retrieval/lib/sh/library.sh
------------------------------------------------------------------------------
    svn:keywords = 'Date Author Id Revision Yoyo'

Propchange: asterisk/team/tilghman/callparking_retrieval/lib/sh/library.sh
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: asterisk/team/tilghman/callparking_retrieval/tests/pbx/call-files2/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/tilghman/callparking_retrieval/tests/pbx/call-files2/run-test?view=diff&rev=821&r1=820&r2=821
==============================================================================
--- asterisk/team/tilghman/callparking_retrieval/tests/pbx/call-files2/run-test (original)
+++ asterisk/team/tilghman/callparking_retrieval/tests/pbx/call-files2/run-test Tue Nov  9 16:08:14 2010
@@ -1,57 +1,8 @@
 #!/bin/bash
 
-set +e
-debug=1
+. lib/sh/library.sh
 
 echo " >>> Starting spoolfile test"
-
-testdir=${0%%run-test}
-ASTERISK=/usr/sbin/asterisk
-
-case `uname -s` in
-	solaris*|sunos*)
-		PS="ps -ef"
-		KILLALL="pkill"
-		;;
-	*)
-		PS="ps auxwww"
-		KILLALL="killall"
-		;;
-esac
-
-case $2 in
-	*-1.4*)
-		ORIGINATE='originate'
-		CSC_HEADERS=3
-		;;
-	*-1.6.2*|*-1.4*)
-		ORIGINATE='originate'
-		CSC_HEADERS=4
-		;;
-	"")
-		echo "Usage: $0 -v asterisk-<version>"
-		exit 1
-		;;
-	*)
-		ORIGINATE='channel originate'
-		CSC_HEADERS=4
-		;;
-esac
-
-cleanup() {
-	if test "x$userA_tmpdir" = "x"; then : ; else
-		$ASTERISK -C $userA_tmpdir/asterisk.conf -rx "core stop now" >/dev/null 2>&1
-	fi
-	if test "x$userB_tmpdir" = "x"; then : ; else
-		$ASTERISK -C $userB_tmpdir/asterisk.conf -rx "core stop now" >/dev/null 2>&1
-	fi
-	sleep 2
-	$KILLALL asterisk >/dev/null 2>&1
-	sleep 1
-	$KILLALL -9 asterisk >/dev/null 2>&1
-	rm -rf $userA_tmpdir $userB_tmpdir
-	set -e
-}
 
 create_spool() {
 	( echo "Channel: $1"
@@ -65,20 +16,7 @@
 	)
 }
 
-verify_call() {
-	# Verify that the call is up
-	local count=`$ASTERISK -C $1/asterisk.conf -rx "core show channels" | wc -l`
-	if test "$debug" = "1"; then
-		echo ">>>>>$1>>>>>"
-		$ASTERISK -C $1/asterisk.conf -rx "core show channels"
-		echo "<<<<<$1<<<<<"
-	fi
-	if test $count != $(($CSC_HEADERS+$2)); then
-		echo " *** Call generation failed: $count"
-		cleanup
-		exit 1
-	fi
-}
+initialize userA userB
 
 for user in userA userB; do
 	# Clean logger output file, when we're testing
@@ -86,45 +24,9 @@
 		rm -f $testdir/$user/messages
 	fi
 
-	echo " >>> Creating configuration directory for $user"
-	eval "${user}_tmpdir=`mktemp --tmpdir=/var/tmp -t -d spoolfile_$user.XXXXXX`"
 	# Shortcut for referral within this loop only
 	eval "conf=\${${user}_tmpdir}"
-
-	if test "$conf" = ""; then
-		echo " *** Unable to create temporary directory for $user"
-		cleanup
-		exit 1
-	fi
-
-	echo " >>> Creating files in configuration directory"
-	for i in ../configs/*.sample; do
-		dst=$conf/`basename $i .sample`
-		install -m 644 $i $dst
-	done
-	for i in $testdir$user/*.conf; do
-		dst=$conf/`basename $i`
-		install -m 644 $i $dst
-	done
-	( echo "[directories]"; echo "astetcdir => $conf"; echo "astrundir => $conf"; echo "astlogdir => $testdir/$user"; echo "astspooldir => $conf/spool" ; echo "[options]"; echo "verbose = 10"; echo "documentation_language = en_US" ) > $conf/asterisk.conf
-	( echo "noload => pbx_lua.so" ; echo "noload => pbx_ael.so" ) >> $conf/modules.conf
 	mkdir -p $conf/spool/outgoing
-
-	# Verify that files got created properly
-	if test -s $conf/asterisk.conf ; then : ; else
-		echo " *** Unable to create test configuration files in $conf"
-		cleanup
-		exit 1
-	fi
-	echo "Starting Asterisk for $user"
-	$ASTERISK -g -C $conf/asterisk.conf
-	sleep 1
-	# Asterisk is running, right?
-	if test `$PS | grep $conf[/] | wc -l` = "0"; then
-		echo " *** Unable to start asterisk for $user"
-		cleanup
-		exit 1
-	fi
 
 	if test $debug -gt 1; then
 		$ASTERISK -C $conf/asterisk.conf -rx 'core set debug 1 pbx_spool'
@@ -146,7 +48,7 @@
 verify_call $userA_tmpdir 3
 
 # Enough time for 3 retries
-sleep 15
+sleep 18
 
 echo " >>> Spool files should be expired by now"
 verify_call $userA_tmpdir 0
@@ -159,7 +61,8 @@
 
 sleep 5
 
-# Count before cleanup, because cleanup removes the log
+# If grep finds nothing, it exits abnormally.  We therefore need to do this
+# before cleanup, or our actual success will be detected as failure.
 count=`grep -c 'No such file or directory, deleting' $testdir/userA/messages`
 
 cleanup




More information about the asterisk-commits mailing list