test-ndntraffic: test case for testing ndn-traffic-generator

Change-Id: I117f38a206f0ae2a9d1d994f17884ae22e2c2f12
refs: #1387
diff --git a/library_helpers/process_manager.py b/library_helpers/process_manager.py
index ebc4862..fa2fdf3 100644
--- a/library_helpers/process_manager.py
+++ b/library_helpers/process_manager.py
@@ -6,17 +6,23 @@
 # See COPYING for copyright and distribution information.
 #
 
+import time
 import errno
 import subprocess
 import multiprocessing as mp
 
-class process_manager:
+class ProcessManager:
 
     manager = mp.Manager()
     processes = dict()
     subprocesses = manager.dict()
     results = manager.dict()
 
+    def cleanupProcesses(self):
+        self.processes.clear()
+        self.subprocesses.clear()
+        self.results.clear()
+
     def runProcess(self, processKey, processCallFormat, message, subprocesses, results):
         print message
         process = subprocess.Popen(
@@ -63,8 +69,16 @@
         else:
             return "Error not available for processKey - " + processKey
 
+    def getProcessOutput(self, processKey):
+        if processKey in self.results:
+            (returnCode, stdout, stderr) = self.results[processKey]
+            return stdout
+        else:
+            return "Output not available for processKey - " + processKey
+
     def startNfd(self):
         self.startProcess("nfd", ["sudo", "nfd"], "-> Starting NFD")
 
     def killNfd(self):
         self.killProcess("nfd")
+        time.sleep(2)
diff --git a/test_ndntlvping/test_ndntlvping.py b/test_ndntlvping/test_ndntlvping.py
index fbe1690..8cc3c4d 100644
--- a/test_ndntlvping/test_ndntlvping.py
+++ b/test_ndntlvping/test_ndntlvping.py
@@ -10,7 +10,7 @@
 import unittest
 import process_manager
 
-class test_ndntlvping(unittest.TestCase, process_manager.process_manager):
+class test_ndntlvping(unittest.TestCase, process_manager.ProcessManager):
     """Test case for testing ndn-tlv-ping application"""
 
     def setUp(self):
@@ -21,6 +21,7 @@
         self.killNfd()
         self.killProcess("ndnpingserver")
         self.killProcess("ndnping")
+        self.cleanupProcesses()
 
     def test_ping(self):
         self.startNfd()
@@ -33,9 +34,6 @@
         time.sleep(1)
         self.waitForProcessCompletion("ndnping", 10)
         self.waitForProcessCompletion("ndnpingserver", 10)
-        self.killProcess("ndnping")
-        self.killProcess("ndnpingserver")
-        self.killNfd()
         if self.hasProcessCompleted("ndnping"):
             if self.getProcessReturnCode("ndnping") != 0:
                 print self.getProcessError("ndnping")
diff --git a/test_ndntraffic/README.md b/test_ndntraffic/README.md
new file mode 100644
index 0000000..7f95d2e
--- /dev/null
+++ b/test_ndntraffic/README.md
@@ -0,0 +1,12 @@
+Test Case - ndntraffic
+======================
+
+## Objective ##
+
+To test the ndn-traffic-generator application on a single host.
+
+## Description ##
+
+This test case will run the NFD, ndn-traffic and ndn-traffic-server binaries.
+This will report SUCCESS if one interest/data is successfully exchanged without any data inconsistency between the ndn-traffic and ndn-traffic-server.
+In all other scenarios, the test case will report FAILURE
diff --git a/test_ndntraffic/__init__.py b/test_ndntraffic/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test_ndntraffic/__init__.py
diff --git a/test_ndntraffic/test-traffic-client.conf b/test_ndntraffic/test-traffic-client.conf
new file mode 100644
index 0000000..9c7ff0e
--- /dev/null
+++ b/test_ndntraffic/test-traffic-client.conf
@@ -0,0 +1,4 @@
+TrafficPercentage=100
+Name=/test/ndntraffic
+ExpectedContent=ABCDEFGHIJKLMNOPQRSTUVWXYZ
+MustBeFresh=1
diff --git a/test_ndntraffic/test-traffic-server.conf b/test_ndntraffic/test-traffic-server.conf
new file mode 100644
index 0000000..0cfff54
--- /dev/null
+++ b/test_ndntraffic/test-traffic-server.conf
@@ -0,0 +1,2 @@
+Name=/test/ndntraffic
+Content=ABCDEFGHIJKLMNOPQRSTUVWXYZ
diff --git a/test_ndntraffic/test_ndntraffic.py b/test_ndntraffic/test_ndntraffic.py
new file mode 100644
index 0000000..632c4fe
--- /dev/null
+++ b/test_ndntraffic/test_ndntraffic.py
@@ -0,0 +1,54 @@
+#!/usr/bin/python2
+# -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+#
+# Copyright (C) 2014 University of Arizona
+# Author: Jerald Paul Abraham <jeraldabraham@email.arizona.edu>
+# See COPYING for copyright and distribution information.
+#
+
+import os
+import time
+import unittest
+import process_manager
+
+class test_ndntraffic(unittest.TestCase, process_manager.ProcessManager):
+    """Test case for testing ndn-traffic-generator application"""
+
+    def setUp(self):
+        print "\nTesting ndn-traffic-generator"
+        print "*****************************"
+
+    def tearDown(self):
+        self.killNfd()
+        self.killProcess("ndn-traffic-server")
+        self.killProcess("ndn-traffic")
+        self.cleanupProcesses()
+
+    def test_traffic(self):
+        self.startNfd()
+        time.sleep(1)
+        serverConfigurationFile = os.path.abspath("test_ndntraffic/test-traffic-server.conf")
+        self.startProcess("ndn-traffic-server",
+            ["ndn-traffic-server", "-c 1", serverConfigurationFile],
+            "-> Starting Traffic Server")
+        time.sleep(1)
+        clientConfigurationFile = os.path.abspath("test_ndntraffic/test-traffic-client.conf")
+        self.startProcess("ndn-traffic",
+            ["ndn-traffic", "-c 1", clientConfigurationFile],
+            "-> Starting Traffic Client")
+        time.sleep(1)
+        self.waitForProcessCompletion("ndn-traffic", 10)
+        self.waitForProcessCompletion("ndn-traffic-server", 10)
+        if self.hasProcessCompleted("ndn-traffic"):
+            if self.getProcessReturnCode("ndn-traffic") != 0:
+                print self.getProcessError("ndn-traffic")
+                self.fail(">> TEST FAILED - received non-zero return code from ndn-traffic")
+        else:
+            self.fail(">> TEST FAILED - ndn-traffic failed to complete")
+        if self.hasProcessCompleted("ndn-traffic-server"):
+            if self.getProcessReturnCode("ndn-traffic-server") != 0:
+                print self.getProcessError("ndn-traffic-server")
+                self.fail(">> TEST FAILED - received non-zero return code from ndn-traffic-server")
+        else:
+            self.fail(">> TEST FAILED - ndn-traffic-server failed to complete")
+        print ">> TEST SUCCESSFUL"