[asterisk-commits] rmudgett: branch rmudgett/srtp r1668 - in /asterisk/team/rmudgett/srtp/tests/...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jun 23 11:55:00 CDT 2011


Author: rmudgett
Date: Thu Jun 23 11:54:57 2011
New Revision: 1668

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=1668
Log:
Update the test to use the new hotness.

Modified:
    asterisk/team/rmudgett/srtp/tests/channels/SIP/sip_srtp/configs/ast1/extensions.conf
    asterisk/team/rmudgett/srtp/tests/channels/SIP/sip_srtp/configs/ast2/extensions.conf
    asterisk/team/rmudgett/srtp/tests/channels/SIP/sip_srtp/run-test

Modified: asterisk/team/rmudgett/srtp/tests/channels/SIP/sip_srtp/configs/ast1/extensions.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/rmudgett/srtp/tests/channels/SIP/sip_srtp/configs/ast1/extensions.conf?view=diff&rev=1668&r1=1667&r2=1668
==============================================================================
--- asterisk/team/rmudgett/srtp/tests/channels/SIP/sip_srtp/configs/ast1/extensions.conf (original)
+++ asterisk/team/rmudgett/srtp/tests/channels/SIP/sip_srtp/configs/ast1/extensions.conf Thu Jun 23 11:54:57 2011
@@ -7,3 +7,5 @@
 exten => 1000,1,Answer()
 exten => 1000,n,Set(TEST_RESULT=${CHANNEL} secure_media=${CHANNEL(secure_media)})
 exten => 1000,n,AGI(agi://127.0.0.1:4573)
+; Give the other side a chance to get its test result
+exten => 1000,n,Wait(5)

Modified: asterisk/team/rmudgett/srtp/tests/channels/SIP/sip_srtp/configs/ast2/extensions.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/rmudgett/srtp/tests/channels/SIP/sip_srtp/configs/ast2/extensions.conf?view=diff&rev=1668&r1=1667&r2=1668
==============================================================================
--- asterisk/team/rmudgett/srtp/tests/channels/SIP/sip_srtp/configs/ast2/extensions.conf (original)
+++ asterisk/team/rmudgett/srtp/tests/channels/SIP/sip_srtp/configs/ast2/extensions.conf Thu Jun 23 11:54:57 2011
@@ -7,3 +7,5 @@
 exten => 2000,1,Answer()
 exten => 2000,n,Set(TEST_RESULT=${CHANNEL} secure_media=${CHANNEL(secure_media)})
 exten => 2000,n,AGI(agi://127.0.0.1:4573)
+; Give the other side a chance to get its test result
+exten => 2000,n,Wait(5)

Modified: asterisk/team/rmudgett/srtp/tests/channels/SIP/sip_srtp/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/rmudgett/srtp/tests/channels/SIP/sip_srtp/run-test?view=diff&rev=1668&r1=1667&r2=1668
==============================================================================
--- asterisk/team/rmudgett/srtp/tests/channels/SIP/sip_srtp/run-test (original)
+++ asterisk/team/rmudgett/srtp/tests/channels/SIP/sip_srtp/run-test Thu Jun 23 11:54:57 2011
@@ -10,51 +10,32 @@
 import sys
 import os
 import time
-from optparse import OptionParser
-from twisted.application import service, internet
 from twisted.internet import reactor, defer
-from starpy import fastagi
 
 sys.path.append("lib/python")
-from asterisk.asterisk import Asterisk
-from asterisk.version import AsteriskVersion
+from asterisk.TestCase import TestCase
 
-workingdir = "/tmp/asterisk-testsuite/channels/SIP/sip_srtp"
-testdir = "tests/channels/SIP/sip_srtp"
+class SIPCallTest(TestCase):
+    def __init__(self, argv):
+        TestCase.__init__(self, argv)
 
-
-class SIPCallTest:
-    def __init__(self, argv):
         self.connected_chan1 = False
         self.connected_chan2 = False
         self.connected_srtp1 = False
         self.connected_srtp2 = False
 
-        self.f = fastagi.FastAGIFactory(self.fastagi_func)
-        reactor.listenTCP(4573, self.f, 50, '127.0.0.1')
-        reactor.callWhenRunning(self.run)
+        # Safe Reactor timeout values on my own machine could be as low as 1.
+        self.reactor_timeout = 10
 
-        parser = OptionParser()
-        parser.add_option("-v", "--version", dest="ast_version",
-                          help="Asterisk version string")
-        parser.add_option("-n", dest="test_name",
-                help="Test name")
+        # Create one AGI server
+        self.create_fastagi_factory()
 
-        (options, args) = parser.parse_args(argv)
-        self.ast_version = AsteriskVersion(options.ast_version)
+        # Create two Asterisk instances ...
+        self.create_asterisk(2)
 
-        print "Creating Asterisk instances ..."
-
-        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 fastagi_func(self, agi):
+    def fastagi_connect(self, agi):
         def get_test_result(val):
             print "Connection result '%s'" % val
-            #if val.split("-")[0] == "SIP/127.0.0.1:5061":
             if val.split("-")[0] == "SIP/2000":
                 # Outgoing call on Ast1
                 self.connected_chan1 = True
@@ -65,58 +46,40 @@
                 self.connected_chan2 = True
                 if val.split("=")[1] == "1":
                     self.connected_srtp2 = True
+            else:
+                print "Don't know which side is connected."
 
         agi.getVariable("TEST_RESULT").addCallback(get_test_result)
 
-        #def get_secure_media(val):
-        #    print "Secure media is '%s'" % val
-        #    if val == "1":
-        #        self.srtp_connected = True
-        #agi.getVariable("CHANNEL(secure_media)").addCallback(get_secure_media)
-        #
-        #sequence = fastagi.InSequence()
-        #sequence.append(agi.execute, "Wait", "2")
-        #sequence.append(agi.hangup)
-        #sequence.append(agi.finish)
-        #sequence()
+    def stop_asterisk(self):
+        TestCase.stop_asterisk(self)
 
-    def stop_reactor(self):
-        print "Stopping Reactor ..."
-        if reactor.running:
-            reactor.stop()
-
-    def start_asterisk(self):
-        print "Starting Asterisk instances ..."
-        self.ast1.start()
-        self.ast2.start()
-
-    def stop_asterisk(self):
-        print "Stopping Asterisk instances ..."
-        self.ast1.stop()
-        self.ast2.stop()
+        # Determine if the test passed
+        print "self.connected_chan1:%s" % (self.connected_chan1)
+        print "self.connected_srtp1:%s" % (self.connected_srtp1)
+        print "self.connected_chan2:%s" % (self.connected_chan2)
+        print "self.connected_srtp2:%s" % (self.connected_srtp2)
+        if self.connected_chan1 and self.connected_srtp1 and self.connected_chan2 and self.connected_srtp2:
+            print "Test passed"
+            self.passed = True
 
     def run(self):
-        self.start_asterisk()
+        TestCase.run(self)
 
-        reactor.callLater(20, self.stop_reactor)
-
-        #self.ast1.cli_exec("originate SIP/2000 extension 1000 at siptest1")
-        #self.ast1.cli_exec("originate SIP/2000!2000 extension 1000 at siptest1")
-        #self.ast1.cli_exec("originate SIP/2000 at 127.0.0.1:5061 extension 1000 at siptest1")
-        self.ast1.cli_exec("originate SIP/2000/2000 extension 1000 at siptest1")
-
+        print "Initiating test call"
+        self.ast[0].cli_exec(
+            "originate SIP/2000/2000 extension 1000 at siptest1")
 
 def main(argv=None):
     if argv is None:
         argv = sys.argv
     test = SIPCallTest(argv)
+    test.start_asterisk()
     reactor.run()
     test.stop_asterisk()
-    print "BUGBUG test.connected_chan1:%s test.connected_srtp1:%s test.connected_chan2:%s test.connected_srtp2:%s" % (test.connected_chan1, test.connected_srtp1, test.connected_chan2, test.connected_srtp2)
-    if test.connected_chan1 and test.connected_srtp1 and test.connected_chan2 and test.connected_srtp2:
+    if test.passed:
         return 0
     return 1
-
 
 if __name__ == "__main__":
     sys.exit(main() or 0)




More information about the asterisk-commits mailing list