[Asterisk-code-review] runtests.py: Add the --pcap option (testsuite[master])

George Joseph asteriskteam at digium.com
Fri Aug 11 15:07:26 CDT 2017


George Joseph has uploaded this change for review. ( https://gerrit.asterisk.org/6224


Change subject: runtests.py:  Add the --pcap option
......................................................................

runtests.py:  Add the --pcap option

--pcap:  Capture all packets for each test in the test's log
directory as 'packet.pcap'

There was stub code in TestCase.__init__ that tried to do this but
it never worked.

N.B. This is completely separate from a test's use of pcap.

Change-Id: I008c2b71f155f919727bef7e1e59173b70065cc9
---
M lib/python/asterisk/test_case.py
M runtests.py
2 files changed, 15 insertions(+), 3 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/testsuite refs/changes/24/6224/1

diff --git a/lib/python/asterisk/test_case.py b/lib/python/asterisk/test_case.py
index dd5365b..815c4c8 100644
--- a/lib/python/asterisk/test_case.py
+++ b/lib/python/asterisk/test_case.py
@@ -169,9 +169,13 @@
 
         LOGGER.info("Executing " + self.test_name)
 
-        if PCAP_AVAILABLE and self.create_pcap:
-            self.pcapfilename = os.path.join(self.testlogdir, "dumpfile.pcap")
-            self.pcap = self.create_pcap_listener(dumpfile=self.pcapfilename)
+        if PCAP_AVAILABLE and os.getenv("PCAP", "no") == "yes":
+            # This PcapListener is from pcap_listener NOT from asterisk/pcap.
+            # The former is standalone, which we need here, while the latter
+            # is meant for use by tests.
+            # It's triggered by the --pcap command line.
+            dumpfile = os.path.join(self.testlogdir, "packet.pcap")
+            PcapListener("lo", dumpfile=dumpfile)
 
         self._setup_conditions()
 
diff --git a/runtests.py b/runtests.py
index a6a80f6..d057f09 100755
--- a/runtests.py
+++ b/runtests.py
@@ -128,6 +128,9 @@
             cmd = ["./lib/python/asterisk/test_runner.py",
                    "%s" % self.test_name]
         if os.path.exists(cmd[0]) and os.access(cmd[0], os.X_OK):
+            if self.options.pcap:
+                os.environ['PCAP'] = "yes"
+
             self.stdout_print("Running %s ..." % cmd)
             cmd.append(str(self.ast_version).rstrip())
             p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
@@ -439,6 +442,7 @@
 
     def _archive_pcap_dump(self, run_dir, archive_dir):
         self._archive_files(run_dir, archive_dir, 'dumpfile.pcap')
+        self._archive_files(run_dir, archive_dir, 'packet.pcap')
 
     def __check_can_run(self, ast_version):
         """Check tags and dependencies in the test config."""
@@ -854,6 +858,10 @@
     parser.add_option("--stop-on-error", action="store_true",
                       dest="stop_on_error", default=False,
                       help="Stops the testsuite when a test fails.")
+    parser.add_option("--pcap", action="store_true",
+                      dest="pcap", default=False,
+                      help="Capture packets. Output will be in "
+                      " the test's log directory as packet.pcap.")
     (options, args) = parser.parse_args(argv)
 
     # Install a signal handler for USR1/TERM, and use it to bail out of running

-- 
To view, visit https://gerrit.asterisk.org/6224
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: testsuite
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I008c2b71f155f919727bef7e1e59173b70065cc9
Gerrit-Change-Number: 6224
Gerrit-PatchSet: 1
Gerrit-Owner: George Joseph <gjoseph at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20170811/39785d19/attachment.html>


More information about the asterisk-code-review mailing list