cs-freshness-test: Add test case for ContentStore and Data freshness

Refs: #1383

Change-Id: I69bf06dbb42b39ea8929bbd87a08d6f2723caeb7
diff --git a/test_cs_freshness/cs-freshness-test.sh b/test_cs_freshness/cs-freshness-test.sh
new file mode 100755
index 0000000..f1be323
--- /dev/null
+++ b/test_cs_freshness/cs-freshness-test.sh
@@ -0,0 +1,70 @@
+#!/usr/bin/env bash
+mkdir -p logs
+
+clean_up() {
+    r=$(killall ndn-traffic-server 2>&1)
+    r=$(sudo killall nfd 2>&1)
+}
+
+# Start NFD.
+sudo nfd > logs/nfd.log 2>&1 &
+sleep 1
+
+# Start ndn-traffic-server to serve `ndn:/test-caching`, FreshnessPeriod=2800ms
+ndn-traffic-server NDNTrafficServer.conf > logs/server.log 2>&1 &
+sleep 1
+
+# Invoke ndn-tlv-peek to send Interest `ndn:/test-caching/A`, MustBeFresh=yes. Fail if this Interest is unanswered.
+output=$(ndn-tlv-peek -fp ndn:/test-caching/A)
+if [[ $output != 'AAAAAAAA' ]]
+then
+    echo "FAIL: Expected data for first interest: 'AAAAAAAA', Actual: '$output'"
+    clean_up
+    exit 1
+fi
+
+# Pause 1000ms.
+sleep 1
+
+# Invoke ndn-tlv-peek to send Interest `ndn:/test-caching/A`, MustBeFresh=yes. Fail if this Interest is unanswered.
+output=$(ndn-tlv-peek -fp ndn:/test-caching/A)
+if [[ $output != 'AAAAAAAA' ]]
+then
+    echo "FAIL: Expected data for second interest: 'AAAAAAAA', Actual: '$output'"
+    clean_up
+    exit 2
+fi
+
+# Kill ndn-traffic-server. Check "total Interests received" equals 1.
+killall ndn-traffic-server
+sleep 5
+output=$(grep 'Total Interests Received' logs/server.log | head -1 | cut -d = -f2 | cut -d' ' -f2)
+if [[ $output != '1' ]]
+then
+    echo "FAIL: Expected ndn-traffic-server receives 1 interest. Actual: $output"
+    clean_up
+    exit 3
+fi
+
+# Invoke ndn-tlv-peek to send Interest `ndn:/test-caching/A`, MustBeFresh=yes. Fail if this Interest is answered.
+output=$(ndn-tlv-peek -fp ndn:/test-caching/A)
+if [[ ! -z $output ]]
+then
+    echo "FAIL: Expected no data received for third interest. Actual data received: '$output'"
+    clean_up
+    exit 4
+fi
+sleep 1
+
+# Invoke ndn-tlv-peek to send Interest `ndn:/test-caching/A` without MustBeFresh. Fail if this Interest is unanswered.
+output=$(ndn-tlv-peek -p ndn:/test-caching/A)
+if [[ $output != 'AAAAAAAA' ]]
+then
+    echo "FAIL: Expected data for fourth interest: 'AAAAAAAA', Actual: '$output'"
+    clean_up
+    exit 5
+fi
+
+# clean up
+clean_up
+echo "ContentStore and freshness test scenario PASSED"