[Pkg-voip-commits] [asterisk] 07/09: test script to run test modules of asterisk

tzafrir at debian.org tzafrir at debian.org
Thu Aug 17 16:50:42 UTC 2017


This is an automated email from the git hooks/post-receive script.

tzafrir pushed a commit to branch master
in repository asterisk.

commit ab0f30b1ee64f2791b122650efd3ba2f0c57f3b4
Author: Tzafrir Cohen <tzafrir at debian.org>
Date:   Sat Dec 24 03:00:05 2016 +0200

    test script to run test modules of asterisk
    
    Adds a test spec and script for usage with autopkgtest
---
 debian/.gitignore              |  3 ++
 debian/README.source           | 17 +++++++++++
 debian/tests/asttestmods       | 64 ++++++++++++++++++++++++++++++++++++++++++
 debian/tests/control           |  3 ++
 debian/tests/testmods/asterisk | 18 ++++++++++++
 5 files changed, 105 insertions(+)

diff --git a/debian/.gitignore b/debian/.gitignore
index f9c0add..2da07dd 100644
--- a/debian/.gitignore
+++ b/debian/.gitignore
@@ -21,4 +21,7 @@ autoreconf.after
 autoreconf.before
 debhelper-build-stamp
 files
+tests/testmods/asterisk.conf
+tests/testmods/output/
 tmp/
+
diff --git a/debian/README.source b/debian/README.source
index 9071ff4..7d51e38 100644
--- a/debian/README.source
+++ b/debian/README.source
@@ -6,3 +6,20 @@ at http://honk.sigxcpu.org/projects/git-buildpackage/manual-html/gbp.html
 
 You find that doc also in /usr/share/doc/git-buildpackage/manual-html/gbp.html
 after installing the package  git-buildpackage
+
+== Tests ==
+Tests should be run with autopkgtest. If you have a local setup. As it
+needs to run an indeppendent instance of Asterisk, which may need to use
+its own ports, a schroot instance will not do.
+
+After a build use something along the lines of:
+
+  autopkgtest asterisk_13.13.1~dfsg-1_amd64.changes -- virt-server [whatever]
+
+If you want to run the tests manually: this should work. It requires
+installing the packages (including asterisk-tests) you built on the
+system, and from the same system, running
+
+  ./debian/tests/asttestmods
+
+Note that it needs to be run as root.
diff --git a/debian/tests/asttestmods b/debian/tests/asttestmods
new file mode 100755
index 0000000..82de7cd
--- /dev/null
+++ b/debian/tests/asttestmods
@@ -0,0 +1,64 @@
+#!/bin/sh
+
+base_dir="debian/tests/testmods"
+asterisk="$base_dir/asterisk"
+output_dir="$base_dir/output" # Writable by Asterisk
+conf_dir="$output_dir/conf"
+results_file="$PWD/$output_dir/results.txt"
+
+# test_message: some tests still fail. See
+#   https://issues.asterisk.org/jira/browse/ASTERISK-27172
+disable_mods='
+	test_message
+'
+
+setup() {
+	service asterisk stop
+
+	rm -rf "$output_dir"
+	mkdir -p "$output_dir/lib" "$output_dir/logs" \
+		"$output_dir/spool/voicemail/default/1234/INBOX"
+	cp -a configs/samples "$output_dir/conf"
+	for file in "$output_dir/conf/"*.conf.sample; do
+		new_name=${file%.sample}
+		mv "$file" "$new_name"
+	done
+	sed -i -e '/;enabled=/s/^;//' "$conf_dir/http.conf"
+	for mod in $disable_mods; do
+		sed -i -e "/^\[modules\]/anoload => $mod.so" "$conf_dir/modules.conf"
+	done
+	chown -R asterisk "$output_dir"
+	$asterisk -U asterisk
+	sleep 1
+	$asterisk -rx 'core waitfullybooted'
+}
+
+run() {
+	$asterisk -rx 'test execute all' 2>&1
+	$asterisk -rx "test generate results txt $results_file"
+	$asterisk -rx 'module show like test_' | awk '/Running/ {print $1}' \
+		| sort  > "$output_dir/mods_loaded"
+	ls /usr/lib/asterisk/modules/ | sort | grep ^test_ > "$output_dir/mods_all"
+	if ! cmp -s "$output_dir/mods_loaded" "$output_dir/mods_all"; then
+		echo >&2 "Some test modules were not loaded:"
+		diff "$output_dir/mods_loaded" "$output_dir/mods_all" >&2
+	fi
+	header=`cat "$results_file" | sed -e '/^$/,$d' `
+	failed=`echo "$header" | awk '/^Passed/ {print $3}'`
+	test_in_source=`grep AST_TEST_REGISTER tests/test_*.c | wc -l`
+	if [ "$failed" != '0' ]; then
+		echo >&2 "Some tests failed:"
+		echo >&2 "$header"
+		$asterisk -rx "test show results failed" >&2
+	fi
+}
+
+teardown() {
+	$asterisk -rx 'core stop now'
+	service asterisk start
+}
+
+setup
+run
+teardown
+
diff --git a/debian/tests/control b/debian/tests/control
new file mode 100644
index 0000000..57b32b2
--- /dev/null
+++ b/debian/tests/control
@@ -0,0 +1,3 @@
+Tests: asttestmods
+Restrictions: needs-root, isolation-container
+Depends: asterisk, asterisk-voicemail, asterisk-tests, asterisk-core-sounds-en-gsm, realpath
diff --git a/debian/tests/testmods/asterisk b/debian/tests/testmods/asterisk
new file mode 100755
index 0000000..6c7c49a
--- /dev/null
+++ b/debian/tests/testmods/asterisk
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+# Run Asterisk using the local configuration directory:
+
+my_dir=$(realpath `dirname $0`)
+dir="$my_dir/output"
+ast_conf="$dir/asterisk.conf"
+if [ ! -r "$ast_conf" ]; then
+	(
+		echo "; File generated by $0"
+		echo "[directories]"
+		echo "astetcdir     => $dir/conf"
+		echo "astlogdir     => $dir/logs"
+		echo "astlibdir     => $dir/lib"
+		echo "astspooldir   => $dir/spool"
+	) > "$ast_conf"
+fi
+exec /usr/sbin/asterisk -C "$ast_conf" "$@"

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-voip/asterisk.git



More information about the Pkg-voip-commits mailing list