[Asterisk-code-review] fax/pjsip/gateway t38 g711 rx: Add new test. (testsuite[master])

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


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


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

fax/pjsip/gateway_t38_g711_rx: Add new test.

This test verifies proper gateway functionality when the calling leg is
t38 and the answering leg is g711.  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 ReceiveFax() on the calling leg and
SendFax() on the answering leg.  If the fax is successful, the test
passes.

ASTERISK-27657

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



  git pull ssh://gerrit.asterisk.org:29418/testsuite refs/changes/50/9350/1

diff --git a/tests/fax/pjsip/gateway_t38_g711_rx/configs/ast1/extensions.conf b/tests/fax/pjsip/gateway_t38_g711_rx/configs/ast1/extensions.conf
new file mode 100644
index 0000000..8d12a56
--- /dev/null
+++ b/tests/fax/pjsip/gateway_t38_g711_rx/configs/ast1/extensions.conf
@@ -0,0 +1,14 @@
+[receivefax]
+exten => 1234,1,noop
+exten => 1234,n,ReceiveFax(${ASTDATADIR}/receive.tiff)
+
+exten => h,1,noop
+exten => h,n,UserEvent(FaxStatus,operation: receive,status: ${FAXOPT(status)},statusstr: ${FAXOPT(statusstr)},error: ${FAXOPT(error)})
+
+[sendfax]
+exten => 1234,1,noop
+exten => 1234,n,SendFax(${ASTDATADIR}/send.tiff)
+
+exten => h,1,noop
+exten => h,n,UserEvent(FaxStatus,operation: send,status: ${FAXOPT(status)},statusstr: ${FAXOPT(statusstr)},error: ${FAXOPT(error)})
+
diff --git a/tests/fax/pjsip/gateway_t38_g711_rx/configs/ast1/pjsip.conf b/tests/fax/pjsip/gateway_t38_g711_rx/configs/ast1/pjsip.conf
new file mode 100644
index 0000000..d398b48
--- /dev/null
+++ b/tests/fax/pjsip/gateway_t38_g711_rx/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=sendfax
+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_t38_g711_rx/configs/ast2/extensions.conf b/tests/fax/pjsip/gateway_t38_g711_rx/configs/ast2/extensions.conf
new file mode 100644
index 0000000..85f818b
--- /dev/null
+++ b/tests/fax/pjsip/gateway_t38_g711_rx/configs/ast2/extensions.conf
@@ -0,0 +1,8 @@
+[gatewayfax]
+exten => 1234,1,noop
+exten => 1234,n,Set(FAXOPT(gateway)=yes)
+exten => 1234,n,Dial(PJSIP/ast1-g711/sip:1234 at 127.0.0.1)
+
+exten => h,1,noop
+exten => h,n,UserEvent(FaxStatus,operation: gateway,status: ${FAXOPT(status)},statusstr: ${FAXOPT(statusstr)},error: ${FAXOPT(error)})
+
diff --git a/tests/fax/pjsip/gateway_t38_g711_rx/configs/ast2/pjsip.conf b/tests/fax/pjsip/gateway_t38_g711_rx/configs/ast2/pjsip.conf
new file mode 100644
index 0000000..2a00ebf
--- /dev/null
+++ b/tests/fax/pjsip/gateway_t38_g711_rx/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_t38_g711_rx/run-test b/tests/fax/pjsip/gateway_t38_g711_rx/run-test
new file mode 100755
index 0000000..eab6cc2
--- /dev/null
+++ b/tests/fax/pjsip/gateway_t38_g711_rx/run-test
@@ -0,0 +1,115 @@
+#!/usr/bin/env python
+# vim: sw=3 et:
+'''
+Copyright (C) 2011, Digium, Inc.
+Matthew Nicholson <mnicholson 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-t38/sip:1234 at 127.0.0.2",
+                               "receivefax", "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_t38_g711_rx/send.tiff b/tests/fax/pjsip/gateway_t38_g711_rx/send.tiff
new file mode 100644
index 0000000..a5fb4fe
--- /dev/null
+++ b/tests/fax/pjsip/gateway_t38_g711_rx/send.tiff
Binary files differ
diff --git a/tests/fax/pjsip/gateway_t38_g711_rx/test-config.yaml b/tests/fax/pjsip/gateway_t38_g711_rx/test-config.yaml
new file mode 100644
index 0000000..d8df833
--- /dev/null
+++ b/tests/fax/pjsip/gateway_t38_g711_rx/test-config.yaml
@@ -0,0 +1,33 @@
+testinfo:
+    summary: 'Test the fax gateway.'
+    description: |
+        This test verifies proper gateway functionality when the calling leg
+        is t38 and the answering leg is g711. 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 ReceiveFax() on the
+        calling leg and SendFax() on the answering leg. If the fax is
+        successful, the test passes.
+
+        The call flow looks like this:
+         |receive     |
+         |t38      t38|
+         |----------->|
+         |     gateway|
+         |g711    g711|
+         |<-----------|
+        \|send        |/
+
+properties:
+    dependencies:
+        - python : 'twisted'
+        - python : 'starpy'
+        - custom : 'fax'
+        - asterisk : 'app_dial'
+        - asterisk : 'app_userevent'
+        - asterisk : 'chan_pjsip'
+        - 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 fab89a1..3e7dea4 100644
--- a/tests/fax/pjsip/tests.yaml
+++ b/tests/fax/pjsip/tests.yaml
@@ -4,6 +4,7 @@
     - test: 'directmedia_reinvite_t38'
     - test: 'gateway_g711_t38'
     - test: 'gateway_native_t38'
+    - test: 'gateway_t38_g711_rx'
     - test: 'gateway_t38_g711_tx'
     - test: 't38'
     - test: 't38_1xx_response'

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

Gerrit-Project: testsuite
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie12ef47afaa6a0cfba13d24cc3f78ed678b81cbf
Gerrit-Change-Number: 9350
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/2aa4037f/attachment-0001.html>


More information about the asterisk-code-review mailing list