[Asterisk-code-review] fax/pjsip/gateway g711 t31: Add new test. (testsuite[13])

Richard Mudgett asteriskteam at digium.com
Thu Jul 5 15:20:00 CDT 2018


Richard Mudgett has uploaded this change for review. ( https://gerrit.asterisk.org/9338


Change subject: fax/pjsip/gateway_g711_t31: Add new test.
......................................................................

fax/pjsip/gateway_g711_t31: Add new test.

This test verifies proper gateway functionality when the calling leg is
g711 and the answering leg is t38.  Two asterisk instances are started and
a call is made from ast1 to ast2.  Ast2 will start a fax gateway and send
the call back to ast1.  Ast1 runs SendFax() on the calling side and
ReceiveFax() on the answering side.  If the fax is successful, the test
passes.

ASTERISK-27657

Change-Id: Ic88e132a3ce5af1bc7640eba8b9ed17cfdcd620f
---
A tests/fax/pjsip/gateway_g711_t38/configs/ast1/extensions.conf
A tests/fax/pjsip/gateway_g711_t38/configs/ast1/pjsip.conf
A tests/fax/pjsip/gateway_g711_t38/configs/ast2/extensions.conf
A tests/fax/pjsip/gateway_g711_t38/configs/ast2/pjsip.conf
A tests/fax/pjsip/gateway_g711_t38/run-test
A tests/fax/pjsip/gateway_g711_t38/send.tiff
A tests/fax/pjsip/gateway_g711_t38/test-config.yaml
M tests/fax/pjsip/tests.yaml
8 files changed, 228 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/testsuite refs/changes/38/9338/1

diff --git a/tests/fax/pjsip/gateway_g711_t38/configs/ast1/extensions.conf b/tests/fax/pjsip/gateway_g711_t38/configs/ast1/extensions.conf
new file mode 100644
index 0000000..d2c1909
--- /dev/null
+++ b/tests/fax/pjsip/gateway_g711_t38/configs/ast1/extensions.conf
@@ -0,0 +1,18 @@
+[receivefax]
+exten = 1234,1,NoOp()
+same = n,ReceiveFax(${ASTDATADIR}/receive.tiff)
+same = n,Hangup()
+
+exten = h,1,NoOp()
+same = n,UserEvent(FaxStatus,operation: receive,status: ${FAXOPT(status)},statusstr: ${FAXOPT(statusstr)},error: ${FAXOPT(error)})
+same = n,Hangup()
+
+[sendfax]
+exten = 1234,1,NoOp()
+same = n,SendFax(${ASTDATADIR}/send.tiff)
+same = n,Hangup()
+
+exten = h,1,NoOp()
+same = n,UserEvent(FaxStatus,operation: send,status: ${FAXOPT(status)},statusstr: ${FAXOPT(statusstr)},error: ${FAXOPT(error)})
+same = n,Hangup()
+
diff --git a/tests/fax/pjsip/gateway_g711_t38/configs/ast1/pjsip.conf b/tests/fax/pjsip/gateway_g711_t38/configs/ast1/pjsip.conf
new file mode 100644
index 0000000..c2ce7f7
--- /dev/null
+++ b/tests/fax/pjsip/gateway_g711_t38/configs/ast1/pjsip.conf
@@ -0,0 +1,22 @@
+[global]
+type=global
+debug=yes
+
+[local-transport]
+type=transport
+protocol=udp
+bind=127.0.0.1
+
+[endpoint-template](!)
+type=endpoint
+allow=!all,ulaw,alaw
+context=receivefax
+media_address=127.0.0.1
+
+[ast2-t38](endpoint-template)
+t38_udptl=yes
+from_user=ast1-t38
+
+[ast2-g711](endpoint-template)
+t38_udptl=no
+from_user=ast1-g711
diff --git a/tests/fax/pjsip/gateway_g711_t38/configs/ast2/extensions.conf b/tests/fax/pjsip/gateway_g711_t38/configs/ast2/extensions.conf
new file mode 100644
index 0000000..679b24e
--- /dev/null
+++ b/tests/fax/pjsip/gateway_g711_t38/configs/ast2/extensions.conf
@@ -0,0 +1,14 @@
+[gatewayfax]
+exten = 1234,1,NoOp()
+same = n,Dial(PJSIP/ast1-t38/sip:1234 at 127.0.0.1,,b(setup^1))
+same = n,Hangup()
+
+exten = setup,1,NoOp()
+same = n,Set(FAXOPT(gateway)=yes)
+same = n,Set(CHANNEL(hangup_handler_push)=hangup,1)
+same = n,Return()
+
+exten = hangup,1,NoOp()
+same = n,UserEvent(FaxStatus,operation: gateway,status: ${FAXOPT(status)},statusstr: ${FAXOPT(statusstr)},error: ${FAXOPT(error)})
+same = n,Return()
+
diff --git a/tests/fax/pjsip/gateway_g711_t38/configs/ast2/pjsip.conf b/tests/fax/pjsip/gateway_g711_t38/configs/ast2/pjsip.conf
new file mode 100644
index 0000000..2a00ebf
--- /dev/null
+++ b/tests/fax/pjsip/gateway_g711_t38/configs/ast2/pjsip.conf
@@ -0,0 +1,22 @@
+[global]
+type=global
+debug=yes
+
+[local-transport]
+type=transport
+protocol=udp
+bind=127.0.0.2
+
+[endpoint-template](!)
+type=endpoint
+allow=!all,ulaw,alaw
+context=gatewayfax
+media_address=127.0.0.2
+
+[ast1-t38](endpoint-template)
+t38_udptl=yes
+from_user=ast2-t38
+
+[ast1-g711](endpoint-template)
+t38_udptl=no
+from_user=ast2-g711
diff --git a/tests/fax/pjsip/gateway_g711_t38/run-test b/tests/fax/pjsip/gateway_g711_t38/run-test
new file mode 100755
index 0000000..7e43d4e
--- /dev/null
+++ b/tests/fax/pjsip/gateway_g711_t38/run-test
@@ -0,0 +1,116 @@
+#!/usr/bin/env python
+# vim: sw=3 et:
+'''
+Copyright (C) 2018, Digium, Inc.
+Matthew Nicholson <mnicholson at digium.com>
+Richard Mudgett <rmudgett at digium.com>
+
+This program is free software, distributed under the terms of
+the GNU General Public License Version 2.
+'''
+
+import sys
+import logging
+import os
+import re
+import shutil
+
+from twisted.internet import reactor
+
+sys.path.append("lib/python")
+from asterisk.asterisk import Asterisk
+from asterisk.test_case import TestCase
+
+logger = logging.getLogger(__name__)
+
+
+class GatewayTest(TestCase):
+    event_count = 0
+    success_count = 0
+
+    def __init__(self):
+        TestCase.__init__(self)
+        self.reactor_timeout = 120
+        self.create_asterisk(2)
+
+        # copy the tiff file we are going to send to a good known location
+        shutil.copy("%s/send.tiff" % (os.path.dirname(os.path.realpath(__file__)),),
+                    "%s%s" % (self.ast[0].base, self.ast[0].directories['astdatadir']))
+
+    def ami_connect(self, ami):
+        if ami.id == 0:
+
+            logger.info("sending a call from ast1 to ast2")
+
+            ami.registerEvent('UserEvent', self.fax_result)
+            df = ami.originate("PJSIP/ast2-g711/sip:1234 at 127.0.0.2",
+                               "sendfax", "1234", 1)
+
+            def handle_failure(reason):
+                logger.error("error sending originate:")
+                logger.error(reason.getTraceback())
+                self.stop_reactor()
+
+                return reason
+
+            df.addErrback(handle_failure)
+        else:
+            ami.registerEvent('UserEvent', self.fax_gateway_result)
+
+    def fax_gateway_result(self, ami, event):
+        if event['userevent'] != 'FaxStatus':
+            return
+
+        self.event_count += 1
+
+        if event['status'] == "SUCCESS":
+            logger.info("successful gateway operation")
+            self.success_count += 1
+        else:
+            logger.error("gateway error:")
+            logger.error("status: %s" % (event['status'],))
+            logger.error("error: %s" % (event['error'],))
+            logger.error("statusstr: %s" % (event['statusstr'],))
+
+        self.are_we_there_yet()
+
+    def fax_result(self, ami, event):
+        if event['userevent'] != 'FaxStatus':
+            return
+
+        self.event_count += 1
+
+        if event['status'] == "SUCCESS":
+            logger.info("successful %s through gateway" % (event['operation'],))
+            self.success_count += 1
+        else:
+            logger.error("error sending fax through gateway:")
+            logger.error("operation: %s" % (event['operation'],))
+            logger.error("status: %s" % (event['status'],))
+            logger.error("error: %s" % (event['error'],))
+            logger.error("statusstr: %s" % (event['statusstr'],))
+
+        self.are_we_there_yet()
+
+    def are_we_there_yet(self):
+        if self.event_count == 3:
+            if self.success_count == 3:
+                self.passed = True
+            self.stop_reactor()
+
+    def run(self):
+        TestCase.run(self)
+        self.create_ami_factory(2)
+
+
+def main():
+    test = GatewayTest()
+    reactor.run()
+
+    if not test.passed:
+        return 1
+
+    return 0
+
+if __name__ == "__main__":
+    sys.exit(main() or 0)
diff --git a/tests/fax/pjsip/gateway_g711_t38/send.tiff b/tests/fax/pjsip/gateway_g711_t38/send.tiff
new file mode 100644
index 0000000..a5fb4fe
--- /dev/null
+++ b/tests/fax/pjsip/gateway_g711_t38/send.tiff
Binary files differ
diff --git a/tests/fax/pjsip/gateway_g711_t38/test-config.yaml b/tests/fax/pjsip/gateway_g711_t38/test-config.yaml
new file mode 100644
index 0000000..15a597b
--- /dev/null
+++ b/tests/fax/pjsip/gateway_g711_t38/test-config.yaml
@@ -0,0 +1,35 @@
+testinfo:
+    summary: 'Test the fax gateway.'
+    description: |
+        This test verifies proper gateway functionality when the calling leg
+        is g711 and the answering leg is t38. Two asterisk instances are
+        started and a call is made from ast1 to ast2. Ast2 will start a fax
+        gateway and send the call back to ast1. Ast1 runs SendFax() on the
+        calling side and ReceiveFax() on the answering side. If the fax is
+        successful, the test passes.
+
+        The call flow looks like this:
+         |send        |
+         |g711    g711|
+         |----------->|
+         |     gateway|
+         |t38      t38|
+         |<-----------|
+        \|receive     |/
+
+properties:
+    dependencies:
+        - python : 'twisted'
+        - python : 'starpy'
+        - custom : 'fax'
+        - asterisk : 'app_dial'
+        - asterisk : 'app_stack'
+        - asterisk : 'app_userevent'
+        - asterisk : 'chan_pjsip'
+        - asterisk : 'func_channel'
+        - asterisk : 'res_fax'
+        - asterisk : 'res_pjsip_t38'
+    tags:
+        - pjsip
+        - fax
+        - fax_gateway
diff --git a/tests/fax/pjsip/tests.yaml b/tests/fax/pjsip/tests.yaml
index 66822c2..0cee9ab 100644
--- a/tests/fax/pjsip/tests.yaml
+++ b/tests/fax/pjsip/tests.yaml
@@ -2,6 +2,7 @@
 tests:
     - test: 'ast-2016-003'
     - test: 'directmedia_reinvite_t38'
+    - test: 'gateway_g711_t38'
     - test: 'gateway_native_t38'
     - test: 'gateway_t38_g711'
     - test: 't38'

-- 
To view, visit https://gerrit.asterisk.org/9338
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: testsuite
Gerrit-Branch: 13
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic88e132a3ce5af1bc7640eba8b9ed17cfdcd620f
Gerrit-Change-Number: 9338
Gerrit-PatchSet: 1
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180705/6e331fdd/attachment-0001.html>


More information about the asterisk-code-review mailing list