[asterisk-commits] pabelanger: testsuite/asterisk/trunk r1480 - in /asterisk/trunk: ./ configs/ ...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu May 12 11:16:38 CDT 2011


Author: pabelanger
Date: Thu May 12 11:16:28 2011
New Revision: 1480

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=1480
Log:
Create TestCase python class.

This class now contains some common fuctions that most tests use.  I've also
2 tests to use the new class.  Moving forward, other tests will be converted
to use it.  Additionally, more documentation and examples will be added
providing more information about it.

Review: https://reviewboard.asterisk.org/r/1054/

Added:
    asterisk/trunk/configs/manager.conf
      - copied unchanged from r1479, asterisk/team/pabelanger/testClass/configs/manager.conf
    asterisk/trunk/configs/manager.general.conf.inc
      - copied unchanged from r1479, asterisk/team/pabelanger/testClass/configs/manager.general.conf.inc
    asterisk/trunk/lib/python/asterisk/TestCase.py
      - copied unchanged from r1479, asterisk/team/pabelanger/testClass/lib/python/asterisk/TestCase.py
    asterisk/trunk/tests/udptl/configs/ast1/manager.general.conf.inc
      - copied unchanged from r1479, asterisk/team/pabelanger/testClass/tests/udptl/configs/ast1/manager.general.conf.inc
    asterisk/trunk/tests/udptl/configs/ast2/manager.general.conf.inc
      - copied unchanged from r1479, asterisk/team/pabelanger/testClass/tests/udptl/configs/ast2/manager.general.conf.inc
Removed:
    asterisk/trunk/tests/udptl/configs/ast1/manager.conf
    asterisk/trunk/tests/udptl/configs/ast2/manager.conf
Modified:
    asterisk/trunk/configs/asterisk.options.conf.inc
    asterisk/trunk/lib/python/asterisk/__init__.py
    asterisk/trunk/lib/python/asterisk/asterisk.py
    asterisk/trunk/runtests.py
    asterisk/trunk/tests/manager/login/run-test
    asterisk/trunk/tests/udptl/run-test

Modified: asterisk/trunk/configs/asterisk.options.conf.inc
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/configs/asterisk.options.conf.inc?view=diff&rev=1480&r1=1479&r2=1480
==============================================================================
--- asterisk/trunk/configs/asterisk.options.conf.inc (original)
+++ asterisk/trunk/configs/asterisk.options.conf.inc Thu May 12 11:16:28 2011
@@ -4,3 +4,4 @@
 verbose = 15
 nocolor = yes
 dumpcore = yes
+execincludes = yes

Modified: asterisk/trunk/lib/python/asterisk/__init__.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/lib/python/asterisk/__init__.py?view=diff&rev=1480&r1=1479&r2=1480
==============================================================================
--- asterisk/trunk/lib/python/asterisk/__init__.py (original)
+++ asterisk/trunk/lib/python/asterisk/__init__.py Thu May 12 11:16:28 2011
@@ -1,1 +1,0 @@
-__all__ = [ "asterisk", "config", "version", "cdr", "utils" ]

Modified: asterisk/trunk/lib/python/asterisk/asterisk.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/lib/python/asterisk/asterisk.py?view=diff&rev=1480&r1=1479&r2=1480
==============================================================================
--- asterisk/trunk/lib/python/asterisk/asterisk.py (original)
+++ asterisk/trunk/lib/python/asterisk/asterisk.py Thu May 12 11:16:28 2011
@@ -43,24 +43,25 @@
     asterisk.conf.
     """
 
-    def __init__(self, base=None, ast_conf_options=None):
+    def __init__(self, base=None, ast_conf_options=None, host="127.0.0.1"):
         """Construct an Asterisk instance.
 
         Keyword Arguments:
         base -- This is the root of the files associated with this instance of
-        Asterisk.  By default, the base is "tmp/" within the current working
-        directory.  Given a base, a unique directory name will be generated to
-        hold all files.
-
-        Example Usage:
-        self.asterisk = Asterisk(base=os.path.join(os.getcwd(),
-                                                   "tests/ami-login/tmp"))
+        Asterisk.  By default, the base is "/tmp/asterisk-testsuite" directory.
+        Given a base, it will be appended to the default base directory.
+
+        Example Usage:
+        self.asterisk = Asterisk(base="manager/login")
         """
         self.directories = {}
         self.ast_version = AsteriskVersion()
 
+        self.base = "/tmp/asterisk-testsuite"
         self.astetcdir = "/etc/asterisk"
         self.ast_binary = utils.which("asterisk") or "/usr/sbin/asterisk"
+        self.host = host
+        self.valgrind = False
 
         # Find the system installed asterisk.conf
         ast_confs = [
@@ -76,10 +77,8 @@
             print "No asterisk.conf found on the system!"
             return
 
-        # Choose an install base
-        self.base = base
-        if self.base is None:
-            self.base = "%s/tmp" % os.getcwd()
+        if base is not None:
+            self.base = "%s/%s" % (self.base, base)
         i = 1
         while True:
             if not os.path.isdir("%s/ast%d" % (self.base, i)):
@@ -115,6 +114,8 @@
             "-f", "-g", "-q", "-m", "-n",
             "-C", "%s" % os.path.join(self.astetcdir, "asterisk.conf")
         ]
+        if self.valgrind:
+            cmd.insert(0, "valgrind")
         try:
             self.process = subprocess.Popen(cmd)
         except OSError:

Modified: asterisk/trunk/runtests.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/runtests.py?view=diff&rev=1480&r1=1479&r2=1480
==============================================================================
--- asterisk/trunk/runtests.py (original)
+++ asterisk/trunk/runtests.py Thu May 12 11:16:28 2011
@@ -109,7 +109,7 @@
             "res_fax_spandsp.so",
             "res_fax_digium.so",
         ]
-        ast = Asterisk(base="/tmp/asterisk-testsuite/runtests")
+        ast = Asterisk()
 
         if "astmoddir" not in ast.directories:
             return False
@@ -121,12 +121,13 @@
 
 
 class TestConfig:
-    def __init__(self, test_name, ast_version):
+    def __init__(self, test_name, ast_version, options):
         self.can_run = True
         self.did_run = False
         self.time = 0.0
         self.test_name = test_name
         self.ast_version = ast_version
+        self.options = options
         self.skip = None
         self.config = None
         self.summary = None
@@ -145,8 +146,11 @@
         start_time = time.time()
         cmd = [
             "%s/run-test" % self.test_name,
-            "-v", str(self.ast_version)
+            "-v", str(self.ast_version),
+            "--test-name", str(self.test_name)
         ]
+        if self.options.valgrind:
+            cmd.append("--valgrind")
         if os.path.exists(cmd[0]) and os.access(cmd[0], os.X_OK):
             print "Running %s ..." % cmd
             try:
@@ -281,7 +285,7 @@
             for val in t:
                 path = "%s/%s" % (test_dir, t[val])
                 if val == "test":
-                    tests.append(TestConfig(path, ast_version))
+                    tests.append(TestConfig(path, ast_version, self.options))
                 elif val == "dir":
                     tests += self._parse_test_yaml(path, ast_version)
 
@@ -401,6 +405,9 @@
     parser.add_option("-t", "--test",
             dest="test",
             help="Run a single specified test instead of all tests.")
+    parser.add_option("--valgrind", action="store_true",
+            dest="valgrind", default=False,
+            help="Run Asterisk under valgrind.")
     (options, args) = parser.parse_args(argv)
 
     # Check to see if this has been executed within a sub directory of an

Modified: asterisk/trunk/tests/manager/login/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/manager/login/run-test?view=diff&rev=1480&r1=1479&r2=1480
==============================================================================
--- asterisk/trunk/tests/manager/login/run-test (original)
+++ asterisk/trunk/tests/manager/login/run-test Thu May 12 11:16:28 2011
@@ -8,77 +8,35 @@
 '''
 
 import sys
-import os
-import shutil
-import time
-from twisted.application import service, internet
-from twisted.internet import reactor, defer
-from starpy import manager
+from twisted.internet import reactor
 
 sys.path.append("lib/python")
 from asterisk.asterisk import Asterisk
+from asterisk.TestCase import TestCase
 
-workingdir = "/tmp/asterisk-testsuite/manager/login"
-testdir = "tests/manager/login"
+class AMILoginTest(TestCase):
+    def __init__(self, argv):
+        TestCase.__init__(self, argv)
+        self.create_asterisk()
 
-
-class AMILoginTest:
-    def __init__(self):
-        self.passed = False
-        self.last_step = ""
-        self.ami = None
-
-        reactor.callWhenRunning(self.run)
-
-        print "Creating Asterisk instance ..."
-        self.ast1 = Asterisk(base=workingdir)
-        self.ast1.install_configs("%s/configs/ast1" % (testdir))
-
-    def stop_reactor(self):
-        print "Stopping Reactor ..."
-        if reactor.running:
-            reactor.stop()
-
-    def start_asterisk(self):
-        self.log_last_step("Starting Asterisk")
-        self.ast1.start()
-
-    def stop_asterisk(self):
-        self.ast1.stop()
-
-    def log_last_step(self, step):
-        print step
-        self.last_step = step
-
-    def on_error(self, ami):
-        print "ERROR, Last Step: %s" % self.last_step
-        self.stop_reactor()
-
-    def on_logoff(self, ami):
-        self.log_last_step("Logoff Successful")
+    def ami_logoff(self, ami):
         self.passed = True
         self.stop_reactor()
 
-    def on_connect(self, ami):
-        self.log_last_step("Connected to the AMI")
-        self.ami = ami
-        self.ami.logoff().addCallbacks(self.on_logoff, self.on_error)
-        self.log_last_step("Logging off")
+    def ami_connect(self, ami):
+        TestCase.ami_connect(self, ami)
+        self.ami[0].logoff().addCallbacks(self.ami_logoff, self.ami_login_error)
 
     def run(self):
-        self.start_asterisk()
+        TestCase.run(self)
+        self.create_ami_factory(1, "user", "mysecret")
 
-        # A timeout in case things hang and fail
-        reactor.callLater(20, self.stop_reactor)
+def main(argv=None):
+    if argv is None:
+        argv = sys.argv
 
-        self.log_last_step("Logging in to the AMI")
-        self.ami_factory = manager.AMIFactory("user", "mysecret")
-        self.ami_factory.login('127.0.0.1', 5038).addCallbacks(self.on_connect,
-                                                               self.on_error)
-
-
-def main():
-    test = AMILoginTest()
+    test = AMILoginTest(argv)
+    test.start_asterisk()
     reactor.run()
     test.stop_asterisk()
     if test.passed:

Modified: asterisk/trunk/tests/udptl/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/udptl/run-test?view=diff&rev=1480&r1=1479&r2=1480
==============================================================================
--- asterisk/trunk/tests/udptl/run-test (original)
+++ asterisk/trunk/tests/udptl/run-test Thu May 12 11:16:28 2011
@@ -7,60 +7,31 @@
 the GNU General Public License Version 2.
 '''
 import sys
-import os
-import signal
-import subprocess
-from optparse import OptionParser
-from twisted.application import service, internet
-from twisted.internet import reactor, defer
+from twisted.internet import reactor
 from starpy import manager
 
 sys.path.append("lib/python")
 from asterisk.asterisk import Asterisk
 from asterisk.version import AsteriskVersion
+from asterisk.TestCase import TestCase
 
-workingdir = "/tmp/asterisk-testsuite/udptl"
-testdir = "tests/udptl"
+class UdptlTest(TestCase):
+    def __init__(self, argv):
+        self.reactor_timeout = 60
 
-class UdptlTest:
-    def __init__(self, argv):
-        self.last_step = ""
-        self.passed = False
+        TestCase.__init__(self, argv)
+        self.create_asterisk(2)
 
-        parser = OptionParser()
-        parser.add_option("-v", "--version", dest="ast_version",
-                          help="Asterisk version string")
-        (options, args) = parser.parse_args(argv)
-        self.ast_version = AsteriskVersion(options.ast_version)
-
-        reactor.callWhenRunning(self.run)
-
-        self.ast1 = Asterisk(base=workingdir)
-        self.ast1.install_configs("%s/configs/ast1" % (testdir))
-
-        self.ast2 = Asterisk(base=workingdir)
-        self.ast2.install_configs("%s/configs/ast2" % (testdir))
-
-    def start_asterisk(self):
-        self.log_last_step("Starting Asterisk")
-        self.ast1.start()
-        self.ast1.cli_exec("fax set debug on")
-        self.ast2.start()
-        self.ast2.cli_exec("fax set debug on")
-
-    def stop_asterisk(self):
-        self.ast1.stop()
-        self.ast2.stop()
-
-    def ami_on_connect1(self, ami):
-        self.log_last_step("Connected to AMI 1")
-        self.ami1 = ami
-        self.ami1.originate(channel = "SIP/666 at receiver",
-                            application = "SendFax",
-                            data = "tests/udptl/1page.tif")
+    def ami_connect(self, ami):
+        TestCase.ami_connect(self, ami)
+        if ami.id == 0:
+            self.ami[0].originate(channel = "SIP/666 at receiver",
+                    application = "SendFax",
+                    data = "tests/udptl/1page.tif")
+        elif ami.id == 1:
+            self.ami[1].registerEvent("UserEvent", self.check_recv_fax_result)
 
     def check_recv_fax_result(self, ami, event):
-        self.log_last_step("Checking Userevent")
         if event.get("userevent").lower() != "recvstatus":
             return
         self.stop_reactor()
@@ -74,34 +45,12 @@
             self.passed = False
             print "UDPTL test failed!"
 
-    def ami_on_connect2(self, ami):
-        self.log_last_step("Connected to AMI 2")
-        self.ami2 = ami
-        self.ami2.registerEvent("UserEvent", self.check_recv_fax_result)
-
-    def ami_login_error(self, ami):
-        self.log_last_step("AMI login failed")
-        reactor.callLater(1, self.stop_reactor)
-
     def ami_login(self):
-        self.log_last_step("Logging in to the AMI")
-        self.ami_factory1 = manager.AMIFactory("user", "mysecret")
-        self.ami_factory2 = manager.AMIFactory("user", "mysecret")
-        self.ami_factory1.login('127.0.0.1', 5038).addCallbacks(self.ami_on_connect1, self.ami_login_error)
-        self.ami_factory2.login('127.0.0.1', 5039).addCallbacks(self.ami_on_connect2, self.ami_login_error)
-
-    def log_last_step(self, step):
-        print step
-        self.lastStep = step
-
-    def stop_reactor(self):
-        print "Stopping reactor"
-        if reactor.running:
-            reactor.stop()
+        self.create_ami_factory(2, "user", "mysecret")
 
     def run(self):
+        TestCase.run(self)
         self.ami_login()
-        self.shutdowncall = reactor.callLater(60, self.stop_reactor)
 
 
 def main(argv=None):
@@ -119,3 +68,5 @@
 
 if __name__ == "__main__":
     sys.exit(main() or 0)
+
+# vim:sw=4:ts=4:expandtab:textwidth=79




More information about the asterisk-commits mailing list