rewrite Python tests as Bash tests
correct University of Arizona copyright statements
refs #4410
Change-Id: I2e34b28698336d39b64030f68984b711f4bdbd0d
diff --git a/test_ndnpeekpoke/README.md b/test_ndnpeekpoke/README.md
index 145953c..9a652a8 100644
--- a/test_ndnpeekpoke/README.md
+++ b/test_ndnpeekpoke/README.md
@@ -3,10 +3,10 @@
## Objective ##
-To test the ndnpeek and ndnpoke applications on a single host.
+Test the ndnpeek and ndnpoke applications on a single host.
## Description ##
-This test case will run NFD, ndnpeek and ndnpoke.
-This will report SUCCESS if one interest/data is successfully exchanged between ndnpeek and ndnpoke.
-In all other scenarios, the test case will report FAILURE
+This test case will run NFD, ndnpeek, and ndnpoke.
+It will succeed if one Interest/Data exchange is completed between the instances of ndnpeek and ndnpoke.
+Otherwise, it will fail.
diff --git a/test_ndnpeekpoke/__init__.py b/test_ndnpeekpoke/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/test_ndnpeekpoke/__init__.py
+++ /dev/null
diff --git a/test_ndnpeekpoke/ndnpeekpoke-test.sh b/test_ndnpeekpoke/ndnpeekpoke-test.sh
new file mode 100755
index 0000000..9dff5b1
--- /dev/null
+++ b/test_ndnpeekpoke/ndnpeekpoke-test.sh
@@ -0,0 +1,44 @@
+#!/bin/bash
+source ../multi-host.conf
+
+clean_up() {
+ r=$(sudo killall ndnpeek 2>&1)
+ r=$(sudo killall ndnpoke 2>&1)
+ r=$(sudo killall nfd 2>&1)
+}
+
+# A: Start NFD
+workdir=$(pwd)
+echo "Starting nfd on A..."
+mkdir -p $workdir/logs; sudo nfd &> $workdir/logs/nfd.log &
+sleep 1
+
+# A: Start ndnpoke
+echo "Starting ndnpoke on A..."
+ndnpoke /test/peekpoke < $workdir/test-poke-input.txt &
+pokepid=$!
+sleep 1
+
+# A: Run ndnpeek
+echo "Running ndnpeek on A..."
+ndnpeek /test/peekpoke > $workdir/logs/test-peek-output.txt
+exitcode=$?
+
+if [[ $exitcode -ne 0 ]]; then
+ echo "Received non-zero exit code from ndnpeek - actual: $exitcode"
+ clean_up
+ exit 1
+fi
+
+sleep 1
+
+# Verify that ndnpoke has exited
+# ps -p returns 1 if no matching process is found
+ps -p $pokepid > /dev/null
+if [[ $? -ne 1 ]]; then
+ echo "ndnpoke did not exit"
+ clean_up
+ exit 2
+fi
+
+clean_up
diff --git a/test_ndnpeekpoke/test_ndnpeekpoke.py b/test_ndnpeekpoke/test_ndnpeekpoke.py
index 9f218e9..f2ea543 100644
--- a/test_ndnpeekpoke/test_ndnpeekpoke.py
+++ b/test_ndnpeekpoke/test_ndnpeekpoke.py
@@ -1,59 +1,34 @@
#!/usr/bin/python2
# -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
#
-# Copyright (C) 2014 University of Arizona
+# Copyright (C) 2014-2018 Arizona Board of Regents.
# Author: Jerald Paul Abraham <jeraldabraham@email.arizona.edu>
+# Author: Eric Newberry <enewberry@cs.arizona.edu>
# See COPYING for copyright and distribution information.
#
import os
-import time
import unittest
-import process_manager
+import subprocess
-class test_ndnpeekpoke(unittest.TestCase, process_manager.ProcessManager):
- """Test case for testing ndnpeek and ndnpoke applications"""
+class test_ndnpeekpoke(unittest.TestCase):
+ """Test case for the ndnpeek and ndnpoke applications"""
def setUp(self):
- print "\nTesting ndnpeek & ndnpoke"
- print "***********************************"
- os.system("mkdir -p test_ndnpeekpoke/logs/")
+ print "\nTesting ndnpeek and ndnpoke"
+ print "***************************"
+ os.chdir("test_ndnpeekpoke")
def tearDown(self):
- self.killNfd()
- self.killProcess("ndnpoke")
- self.killProcess("ndnpeek")
- self.cleanupProcesses()
+ print "***************************"
+ os.chdir("..")
- def test_peekpoke(self):
- self.startNfd()
- time.sleep(1)
- pokeInputFile = os.path.abspath("test_ndnpeekpoke/test-poke-input.txt")
- self.startProcess("ndnpoke",
- ["ndnpoke", "ndn:/test/peekpoke"],
- "-> Starting Poke",
- inputFile=pokeInputFile)
- time.sleep(1)
- peekOutputFile = os.path.abspath("test_ndnpeekpoke/logs/test-peek-output.txt")
- self.startProcess("ndnpeek",
- ["ndnpeek", "ndn:/test/peekpoke"],
- "-> Starting Peek",
- outputFile=peekOutputFile)
- time.sleep(1)
- self.waitForProcessCompletion("ndnpeek", 10)
- self.waitForProcessCompletion("ndnpoke", 10)
- if self.hasProcessCompleted("ndnpeek"):
- if self.getProcessReturnCode("ndnpeek") != 0:
- print self.getProcessReturnCode("ndnpeek")
- print self.getProcessError("ndnpeek")
- print self.getProcessOutput("ndnpeek")
- self.fail(">> TEST FAILED - received non-zero return code from ndnpeek")
- else:
- self.fail(">> TEST FAILED - ndnpeek failed to complete")
- if self.hasProcessCompleted("ndnpoke"):
- if self.getProcessReturnCode("ndnpoke") != 0:
- print self.getProcessError("ndnpoke")
- self.fail(">> TEST FAILED - received non-zero return code from ndnpoke")
- else:
- self.fail(">> TEST FAILED - ndnpoke failed to complete")
- print ">> TEST SUCCESSFUL"
+ def test_ndnpeekpoke(self):
+ ret = subprocess.call(["./ndnpeekpoke-test.sh"], shell=True)
+ print "Test script return value:", ret
+ errormsg = {
+ 1 : "ndnpeek did not receive a Data packet satisfying its Interest",
+ 2 : "ndnpoke did not exit after sending a Data packet",
+ }
+ if (ret != 0):
+ self.fail(errormsg[ret])