rewrite Python tests as Bash tests
correct University of Arizona copyright statements
refs #4410
Change-Id: I2e34b28698336d39b64030f68984b711f4bdbd0d
diff --git a/test_interest_aggregation/README.md b/test_interest_aggregation/README.md
index 33f9551..df57f8e 100644
--- a/test_interest_aggregation/README.md
+++ b/test_interest_aggregation/README.md
@@ -1,22 +1,24 @@
-Test Case - interest-aggregation
+Test Case - interest_aggregation
================================
## Objective ##
-To test NFD's interest aggregation on a single host.
+Test NFD's Interest aggregation mechanism on a single host.
## Description ##
-This test case will run NFD, ndnpeek and ndn-traffic-server to check aggregation of interests by NFD. The following steps will be followed:
+This test case will run NFD, ndnpeek, and ndn-traffic-server to check for the proper aggregation of Interests by NFD.
-1. Start NFD.
-2. Set NFD to use the best-route v1 strategy.
-3. Start ndn-traffic-server to serve ndn:/test-agg, with -d 2000 flag to delay response for 2000ms.
-4. Start two instances of ndnpeek to request ndn:/test-agg/A. Wait until they terminate. Fail if either is unanswered.
-5. Stop ndn-traffic-server. Fail if total served Interest does not equal 1.
-6. Start ndn-traffic-server to serve ndn:/test-agg, with -d 2000 flag to delay response for 2000ms.
-7. Start ndnpeek to request ndn:/test-agg/B ChildSelector=leftmost, and another instance to request ndn:/test-agg/B ChildSelector=rightmost. Wait until they terminate. Fail if either is unanswered.
-8. Stop ndn-traffic-server. Fail if total served Interest does not equal 2.
-9. Start ndn-traffic-server to serve ndn:/test-agg, with -d 2000 flag to delay response for 2000ms.
-10. Start ndnpeek to request ndn:/test-agg/C InterestLifetime=6000ms, and another instance to request ndn:/test-agg/C InterestLifetime=8000ms. Wait until they terminate. Fail if either is unanswered.
-11. Stop ndn-traffic-server. Fail if total served Interest does not equal 1.
+## Steps ##
+
+1. Start NFD.
+2. Set NFD to use the best-route v1 strategy on the / prefix.
+3. Start ndn-traffic-server to serve /test-agg, with -d 2000 flag to delay response for 2000ms.
+4. Start two instances of ndnpeek to request /test-agg/A. Fail if either instance fails to exit or if either Interest goes unanswered.
+5. Stop ndn-traffic-server. Fail if total number of served Interests does not equal 1.
+6. Start ndn-traffic-server to serve /test-agg, with -d 2000 flag to delay response for 2000ms.
+7. Start ndnpeek to request /test-agg/B with CanBePrefix=false, and another instance to request /test-agg/B with CanBePrefix=true. Fail if either instance fails to exit or if either Interest goes unanswered.
+8. Stop ndn-traffic-server. Fail if total number of served Interests does not equal 2.
+9. Start ndn-traffic-server to serve /test-agg, with -d 2000 flag to delay response for 2000ms.
+10. Start ndnpeek to request /test-agg/C with InterestLifetime=6000ms, and another instance to request /test-agg/C with InterestLifetime=8000ms. Fail if either is instance fails to exit or if either Interest goes unanswered.
+11. Stop ndn-traffic-server. Fail if total number of served Interests does not equal 1.
diff --git a/test_interest_aggregation/__init__.py b/test_interest_aggregation/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/test_interest_aggregation/__init__.py
+++ /dev/null
diff --git a/test_interest_aggregation/interest-aggregation-test.sh b/test_interest_aggregation/interest-aggregation-test.sh
new file mode 100755
index 0000000..c0e3935
--- /dev/null
+++ b/test_interest_aggregation/interest-aggregation-test.sh
@@ -0,0 +1,140 @@
+#!/bin/bash
+source ../multi-host.conf
+
+clean_up() {
+ r=$(sudo killall ndn-traffic-server 2>&1)
+ r=$(sudo killall ndnpeek 2>&1)
+ r=$(sudo killall nfd 2>&1)
+}
+
+check_peek_exit() {
+ ps -p $2 > /dev/null
+ if [[ $? -ne 1 ]]; then
+ echo "Peek Client $1 did not exit"
+ clean_up
+ exit 1
+ fi
+}
+
+check_peek_output() {
+ local out=$(cat $2)
+ if [[ "$out" != "$3" ]]; then
+ echo "Peek Client $1 did not receive a Data containing '$3'. Actual: $out"
+ clean_up
+ exit 2
+ fi
+}
+
+check_server_receive_count() {
+ local actual=$(cat $2 | grep "Total Interests Received" | head -1 | cut -d"=" -f2 | tr -d " ")
+ if [[ $actual -ne $3 ]]; then
+ echo "Traffic Server $1 did not received expected $3 Interests. Actual: $actual"
+ clean_up
+ exit 3
+ fi
+}
+
+# A: Start NFD
+workdir=$(pwd)
+echo "Starting nfd on A..."
+mkdir -p $workdir/logs; sudo nfd &> $workdir/logs/nfd.log &
+sleep 1
+
+# A: Set NFD to use best-route v1 strategy
+echo "Setting strategy to best-route v1"
+nfdc strategy set / /localhost/nfd/strategy/best-route/%FD%01
+sleep 1
+
+# A: Start ndn-traffic-server (Prefix=/text-agg, ContentDelay=2000ms)
+echo "Starting Traffic Server 1 (Prefix=/test-agg, ContentDelay=2000ms)..."
+ndn-traffic-server $workdir/test-traffic-server.conf &> $workdir/logs/test-server-output-1.txt &
+sleep 1
+
+# A: Start two instances of ndnpeek to request /test-agg/A
+echo "Starting Peek Client 1 (Prefix=/test-agg/A)..."
+ndnpeek -p /test-agg/A &> $workdir/logs/test-peek-output-1.txt &
+peek1pid=$!
+echo "Starting Peek Client 2 (Prefix=/test-agg/A)..."
+ndnpeek -p /test-agg/A &> $workdir/logs/test-peek-output-2.txt &
+peek2pid=$!
+sleep 1
+
+# A: Stop ndn-traffic-server instance
+echo "Stopping Traffic Server 1..."
+sudo killall ndn-traffic-server 2>&1
+sleep 2
+
+# A: Ensure ndnpeek instances have quit
+check_peek_exit 1 $peek1pid
+check_peek_exit 2 $peek2pid
+
+# A: Ensure ndnpeek instances both received Data packets with correct payloads in response to their Interests
+check_peek_output 1 $workdir/logs/test-peek-output-1.txt AAAAAAAA
+check_peek_output 2 $workdir/logs/test-peek-output-2.txt AAAAAAAA
+
+# A: Ensure that Traffic Server 1 received only one Interest
+check_server_receive_count 1 $workdir/logs/test-server-output-1.txt 1
+
+# A: Start ndn-traffic-server (Prefix=/test-agg, ContentDelay=2000ms)
+echo "Starting Traffic Server 2 (Prefix=/test-agg, ContentDelay=2000ms)..."
+ndn-traffic-server $workdir/test-traffic-server.conf &> $workdir/logs/test-server-output-2.txt &
+sleep 1
+
+# A: Start two instances of ndnpeek to request /test-agg/B, with one setting CanBePrefix=false and
+# the other setting CanBePrefix=true
+echo "Starting Peek Client 3 (Prefix=/test-agg/B, CanBePrefix=false)..."
+ndnpeek -p /test-agg/B &> $workdir/logs/test-peek-output-3.txt &
+peek3pid=$!
+echo "Starting Peek Client 4 (Prefix=/test-agg/B, CanBePrefix=true)..."
+ndnpeek -P -p /test-agg/B &> $workdir/logs/test-peek-output-4.txt &
+peek4pid=$!
+sleep 1
+
+# A: Stop ndn-traffic-server instance
+echo "Stopping Traffic Server 2..."
+sudo killall ndn-traffic-server 2>&1
+sleep 2
+
+# A: Ensure ndnpeek instances have quit
+check_peek_exit 3 $peek3pid
+check_peek_exit 4 $peek4pid
+
+# A: Ensure ndnpeek instances both received Data packets with correct payload in response to their interests
+check_peek_output 3 $workdir/logs/test-peek-output-3.txt AAAAAAAA
+check_peek_output 4 $workdir/logs/test-peek-output-4.txt AAAAAAAA
+
+# A: Ensure that Traffic Server 2 received two Interests
+check_server_receive_count 2 $workdir/logs/test-server-output-2.txt 2
+
+# A: Start ndn-traffic-server (Prefix=/test-agg, ContentDelay=2000ms)
+echo "Starting Traffic Server 3 (Prefix=/test-agg, ContentDelay=2000ms)..."
+ndn-traffic-server $workdir/test-traffic-server.conf &> $workdir/logs/test-server-output-3.txt &
+sleep 1
+
+# A: Start two instances of ndnpeek to request /test-agg/C, with one setting InterestLifetime=6000ms
+# and the other setting InterestLifetime=8000ms
+echo "Starting Peek Client 5 (Prefix=/test-agg/C, InterestLifetime=6000ms)"
+ndnpeek --lifetime 6000 -p /test-agg/C > $workdir/logs/test-peek-output-5.txt &
+peek5pid=$!
+echo "Starting Peek Client 6 (Prefix=/test-agg/C, InterestLifetime=8000ms)..."
+ndnpeek --lifetime 8000 -p /test-agg/C > $workdir/logs/test-peek-output-6.txt &
+peek6pid=$!
+sleep 1
+
+# A: Stop ndn-traffic-server instance
+echo "Stopping Traffic Server 3..."
+sudo killall ndn-traffic-server 2>&1
+sleep 2
+
+# A: Ensure ndnpeek instances have quit
+check_peek_exit 5 $peek5pid
+check_peek_exit 6 $peek6pid
+
+# A: Ensure ndnpek instances both received Data packets with correct payload in response to their Interests
+check_peek_output 5 $workdir/logs/test-peek-output-5.txt AAAAAAAA
+check_peek_output 6 $workdir/logs/test-peek-output-6.txt AAAAAAAA
+
+# A: Ensure that Traffic Server 3 received only one Interest
+check_server_receive_count 3 $workdir/logs/test-server-output-3.txt 1
+
+clean_up
diff --git a/test_interest_aggregation/test-traffic-server.conf b/test_interest_aggregation/test-traffic-server.conf
index 4fd7531..b3ff461 100644
--- a/test_interest_aggregation/test-traffic-server.conf
+++ b/test_interest_aggregation/test-traffic-server.conf
@@ -1,2 +1,3 @@
Name=ndn:/test-agg
ContentDelay=2000
+Content=AAAAAAAA
diff --git a/test_interest_aggregation/test_interest_aggregation.py b/test_interest_aggregation/test_interest_aggregation.py
index 4b1fbe2..ed54fe9 100644
--- a/test_interest_aggregation/test_interest_aggregation.py
+++ b/test_interest_aggregation/test_interest_aggregation.py
@@ -1,169 +1,35 @@
#!/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_interest_aggregation(unittest.TestCase, process_manager.ProcessManager):
- """Test case for testing interest aggregation"""
+class test_interest_aggregation(unittest.TestCase):
+ """Test case for testing Interest aggregation"""
def setUp(self):
print "\nTesting Interest Aggregation"
print "****************************"
- self.logFolder = "test_interest_aggregation/logs/"
- if not os.path.exists(self.logFolder):
- os.system("mkdir " + self.logFolder)
+ os.chdir("test_interest_aggregation")
def tearDown(self):
- self.killNfd()
- self.killProcess("ndn-traffic-server-1")
- self.killProcess("ndnpeek-1")
- self.killProcess("ndnpeek-2")
- self.killProcess("ndn-traffic-server-2")
- self.killProcess("ndnpeek-3")
- self.killProcess("ndnpeek-4")
- self.killProcess("ndn-traffic-server-3")
- self.killProcess("ndnpeek-5")
- self.killProcess("ndnpeek-6")
- self.cleanupProcesses()
-
- def checkAndReportFailure(self, processKey, processName):
- if self.hasProcessCompleted(processKey):
- if self.getProcessReturnCode(processKey) != 0:
- print self.getProcessOutput(processKey)
- print self.getProcessError(processKey)
- self.fail(">> TEST FAILED - received non-zero return code from " + processName)
- else:
- self.fail(">> TEST FAILED - " + processName + " failed to complete")
-
-
- def checkServerReceiveCount(self, processKey, processName, expectedCount):
- serverOutput = self.getProcessOutput(processKey).splitlines()
- isTestSuccessful = False
- receivedCount = 0
- for logLine in serverOutput:
- if "Total Interests Received" in logLine:
- for value in logLine.split():
- if value.isdigit():
- receivedCount = int(value)
- break
- if receivedCount == expectedCount:
- isTestSuccessful = True
- break
- if not isTestSuccessful:
- self.fail(">> TEST FAILED - " + processName +
- " expected to receive only " + str(expectedCount) +
- " interest(s) but received " + str(receivedCount) + " interest(s)" )
- else:
- print "-> " + processName + " received " + str(receivedCount) + " interest(s)"
+ print "****************************"
+ os.chdir("..")
def test_aggregation(self):
-
- #Start NFD
- self.startNfd()
- time.sleep(1)
-
- #Set NFD to use best-route v1 strategy
- self.startProcess("nfdc",
- ["nfdc", "strategy", "set", "/", "/localhost/nfd/strategy/best-route/%FD%01"],
- "-> Setting strategy to best-route v1")
- time.sleep(1)
-
- #Start ndn-traffic-server to serve /test-agg, with content delay set to 2000ms
- serverConfigurationFile = os.path.abspath(
- "test_interest_aggregation/test-traffic-server.conf")
- self.startProcess("ndn-traffic-server-1",
- ["ndn-traffic-server", serverConfigurationFile],
- "-> Starting Traffic Server 1 (Prefix=/test-agg, ContentDelay=2000ms)")
- time.sleep(1)
-
- #Start two instances of ndnpeek to request /test-agg/A. Wait until they
- #terminate. Fail if either is unanswered.
- peekOutputFile = os.path.abspath(self.logFolder + "test-peek-output-1.txt")
- self.startProcess("ndnpeek-1",
- ["ndnpeek", "/test-agg/A"],
- "-> Starting Peek Client 1 (Prefix=/test-agg/A)",
- outputFile=peekOutputFile)
- peekOutputFile = os.path.abspath(self.logFolder + "test-peek-output-2.txt")
- self.startProcess("ndnpeek-2",
- ["ndnpeek", "/test-agg/A"],
- "-> Starting Peek Client 2 (Prefix=/test-agg/A)",
- outputFile=peekOutputFile)
- self.waitForProcessCompletion("ndnpeek-1", 10)
- self.waitForProcessCompletion("ndnpeek-2", 10)
-
- #Stop ndn-traffic-server. Fail if total served Interest does not equal 1.
- self.killProcess("ndn-traffic-server-1")
- time.sleep(1)
- print "-> Stopping Traffic Server 1"
- self.checkAndReportFailure("ndnpeek-1", "Peek Client 1")
- self.checkAndReportFailure("ndnpeek-2", "Peek Client 2")
- self.checkServerReceiveCount("ndn-traffic-server-1", "Traffic Server 1", 1)
-
- #Start ndn-traffic-server to serve /test-agg, with content delay set to 2000ms
- self.startProcess("ndn-traffic-server-2",
- ["ndn-traffic-server", serverConfigurationFile],
- "-> Starting Traffic Server 2 (Prefix=/test-agg, ContentDelay=2000ms)")
- time.sleep(1)
-
- #Start ndnpeek to request /test-agg/B ChildSelector=leftmost, and another
- #instance to request /test-agg/B ChildSelector=rightmost. Wait until they terminate.
- #Fail if either is unanswered.
- peekOutputFile = os.path.abspath(self.logFolder + "test-peek-output-3.txt")
- self.startProcess("ndnpeek-3",
- ["ndnpeek", "/test-agg/B"],
- "-> Starting Peek Client 3 (Prefix=/test-agg/B, ChildSelector=leftmost)",
- outputFile=peekOutputFile)
- peekOutputFile = os.path.abspath(self.logFolder + "test-peek-output-4.txt")
- self.startProcess("ndnpeek-4",
- ["ndnpeek", "-r", "/test-agg/B"],
- "-> Starting Peek Client 4 (Prefix=/test-agg/B, ChildSelector=rightmost)",
- outputFile=peekOutputFile)
- self.waitForProcessCompletion("ndnpeek-3", 10)
- self.waitForProcessCompletion("ndnpeek-4", 10)
-
- #Stop ndn-traffic-server. Fail if total served Interest does not equal 2.
- self.killProcess("ndn-traffic-server-2")
- time.sleep(1)
- print "-> Stopping Traffic Server 2"
- self.checkAndReportFailure("ndnpeek-3", "Peek Client 3")
- self.checkAndReportFailure("ndnpeek-4", "Peek Client 4")
- self.checkServerReceiveCount("ndn-traffic-server-2", "Traffic Server 2", 2)
-
- #Start ndn-traffic-server to serve /test-agg, with content delay set to 2000ms
- self.startProcess("ndn-traffic-server-3",
- ["ndn-traffic-server", serverConfigurationFile],
- "-> Starting Traffic Server 3 (Prefix=/test-agg, ContentDelay=2000ms)")
- time.sleep(1)
-
- #Start ndnpeek to request /test-agg/C InterestLifetime=6000ms, and another
- #instance to request /test-agg/C. InterestLifetime=8000ms. Wait until they terminate.
- #Fail if either is unanswered.
- peekOutputFile = os.path.abspath(self.logFolder + "test-peek-output-5.txt")
- self.startProcess("ndnpeek-5",
- ["ndnpeek", "--lifetime", "6000", "/test-agg/C"],
- "-> Starting Peek Client 5 (Prefix=/test-agg/C, InterestLifetime=6000ms)",
- outputFile=peekOutputFile)
- peekOutputFile = os.path.abspath(self.logFolder + "test-peek-output-6.txt")
- self.startProcess("ndnpeek-6",
- ["ndnpeek", "--lifetime", "8000", "/test-agg/C"],
- "-> Starting Peek Client 6 (Prefix=/test-agg/C, InterestLifetime=8000ms)",
- outputFile=peekOutputFile)
- self.waitForProcessCompletion("ndnpeek-5", 10)
- self.waitForProcessCompletion("ndnpeek-6", 10)
-
- #Stop ndn-traffic-server. Fail if total served Interest does not equal 1.
- self.killProcess("ndn-traffic-server-3")
- time.sleep(1)
- print "-> Stopping Traffic Server 3"
- self.checkAndReportFailure("ndnpeek-5", "Peek Client 5")
- self.checkAndReportFailure("ndnpeek-6", "Peek Client 6")
- self.checkServerReceiveCount("ndn-traffic-server-3", "Traffic Server 3", 1)
- print ">> TEST SUCCESSFUL"
+ ret = subprocess.call(["./interest-aggregation-test.sh"], shell=True)
+ print "Test script return value:", ret
+ errormsg = {
+ 1 : "Peek Client did not exit",
+ 2 : "Peek Client did not Data packet or received Data packet containing incorrect content",
+ 3 : "Traffic Server did not received correct count of Interests",
+ }
+ if (ret != 0):
+ self.fail(errormsg[ret])