test-unix-face: Add test case for unix face
Refs: #1377
Change-Id: I04273bc5b917b09b117f9e7222d840ddb0e7cc80
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..5cf7948
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+*.pyc
+*/logs
diff --git a/test_unixface/NDNTrafficClient.conf b/test_unixface/NDNTrafficClient.conf
new file mode 100644
index 0000000..5f6bf95
--- /dev/null
+++ b/test_unixface/NDNTrafficClient.conf
@@ -0,0 +1,9 @@
+##########
+TrafficPercentage=50
+Name=/example/A
+ExpectedContent=AAAAAAAA
+##########
+TrafficPercentage=50
+Name=/example/B
+ExpectedContent=BBBBBBBB
+##########
diff --git a/test_unixface/NDNTrafficServer.conf b/test_unixface/NDNTrafficServer.conf
new file mode 100644
index 0000000..1f4aab5
--- /dev/null
+++ b/test_unixface/NDNTrafficServer.conf
@@ -0,0 +1,7 @@
+##########
+Name=/example/A
+Content=AAAAAAAA
+##########
+Name=/example/B
+Content=BBBBBBBB
+##########
diff --git a/test_unixface/README.md b/test_unixface/README.md
new file mode 100644
index 0000000..01bb8ac
--- /dev/null
+++ b/test_unixface/README.md
@@ -0,0 +1,6 @@
+Test correctness of UNIX face and simple forwarding.
+
+1. Start NFD.
+2. Run traffic generator producer and consumer.
+3. Collect results.
+
diff --git a/test_unixface/__init__.py b/test_unixface/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test_unixface/__init__.py
diff --git a/test_unixface/test_unixface.py b/test_unixface/test_unixface.py
new file mode 100644
index 0000000..0dbfaeb
--- /dev/null
+++ b/test_unixface/test_unixface.py
@@ -0,0 +1,33 @@
+#!/usr/bin/python2
+# -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+#
+# Copyright (C) 2014 University of Arizona
+# Author: Yi Huang <ltr120@email.arizona.edu>
+# See COPYING for copyright and distribution information.
+#
+
+import os
+import unittest
+import subprocess
+
+class test_unixface(unittest.TestCase):
+ """Test case for testing unix face"""
+
+ def setUp(self):
+ print "\nTesting unix face"
+ print "*****************************"
+ os.chdir("test_unixface")
+
+ def tearDown(self):
+ print "*****************************"
+ os.chdir("..")
+
+ def test_unixface(self):
+ ret = subprocess.call(["./unix-face-test.sh"], shell=True)
+ print "Test script return value:", ret
+ errormsg = {
+ 1 : "ndn-traffic client does not end normally. See logs/client.log",
+ 2 : "Data loss detected",
+ }
+ if (ret != 0):
+ self.fail(errormsg[ret])
diff --git a/test_unixface/unix-face-test.sh b/test_unixface/unix-face-test.sh
new file mode 100755
index 0000000..0599a8f
--- /dev/null
+++ b/test_unixface/unix-face-test.sh
@@ -0,0 +1,26 @@
+#!/bin/bash
+mkdir -p logs
+clean_up() {
+ r=$(sudo killall ndn-traffic-server 2>&1)
+ r=$(sudo killall nfd 2>&1)
+}
+sudo nfd > logs/nfd.log 2>&1 &
+sleep 2
+ndn-traffic-server NDNTrafficServer.conf > logs/server.log 2>&1 &
+sleep 2
+echo "Sending interests..."
+ndn-traffic -i 100 -c 100 NDNTrafficClient.conf > logs/client.log 2>&1
+clean_up
+output=$(grep "Total Interest Loss" logs/client.log | head -1 | cut -d= -f2 | cut -d' ' -f2 | cut -d% -f1)
+if [[ -z $output ]]
+then
+ echo "ndn-traffic client does not end normally. See logs/client.log"
+ exit 1
+fi
+if [[ $output != '0' ]]
+then
+ echo "Expected no interest Loss. Actual: $output%"
+ echo "For more information, please examine the log at \"$(pwd)/logs\""
+ exit 2
+fi
+echo "Unix Face Test PASSED"