tests+ci: Add and enable a partial unit test coverage

Change-Id: I6dbc5cf4d68679bd6f943322f572313884c8aef7
Refs: #2369
diff --git a/.jenkins.d/01-deps.sh b/.jenkins.d/01-deps.sh
index 6b9e10a..d05e767 100755
--- a/.jenkins.d/01-deps.sh
+++ b/.jenkins.d/01-deps.sh
@@ -1,11 +1,11 @@
 #!/usr/bin/env bash
-set -x
 set -e
 
-IS_OSX=$( python -c "print 'yes' if 'OSX' in '$NODE_LABELS'.strip().split(' ') else 'no'" )
-IS_UBUNTU=$( python -c "print 'yes' if 'Ubuntu' in '$NODE_LABELS'.strip().split(' ') else 'no'" )
+JDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
+source "$JDIR"/util.sh
 
-if [[ $IS_OSX == "yes" ]]; then
+if has OSX $NODE_LABELS; then
+    set -x
     brew update
     brew upgrade
     brew install boost cryptopp pkg-config libxml2
@@ -13,13 +13,13 @@
     brew cleanup
 fi
 
-if [[ $IS_UBUNTU == "yes" ]]; then
+if has Ubuntu $NODE_LABELS; then
+    set -x
     sudo apt-get update -qq -y
     sudo apt-get -qq -y install build-essential
     sudo apt-get -qq -y install libssl-dev libsqlite3-dev libcrypto++-dev
 
-    IS_12_04=$( python -c "print 'yes' if 'Ubuntu-12.04' in '$NODE_LABELS'.strip().split(' ') else 'no'" )
-    if [[ $IS_12_04 == "yes" ]]; then
+    if has Ubuntu-12.04 $NODE_LABELS; then
         sudo apt-get install -qq -y python-software-properties
         sudo add-apt-repository -y ppa:boost-latest/ppa
         sudo apt-get update -qq -y
diff --git a/.jenkins.d/02-deps-ndn-cxx.sh b/.jenkins.d/02-deps-ndn-cxx.sh
index 6e81cca..bcd5364 100755
--- a/.jenkins.d/02-deps-ndn-cxx.sh
+++ b/.jenkins.d/02-deps-ndn-cxx.sh
@@ -2,51 +2,43 @@
 set -x
 set -e
 
-if [[ $USE_NDN_PPA == "yes" ]]; then
-    sudo apt-get install -y python-software-properties
-    sudo add-apt-repository -qq -y ppa:named-data/ppa
-    sudo apt-get update -qq
-    sudo apt-get install -qq -y ndn-cxx-dev
-    exit 0
-fi
+JDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
+source "$JDIR"/util.sh
 
-cd /tmp
-BUILD="no"
-if [ ! -d ndn-cxx ]; then
-    git clone git://github.com/named-data/ndn-cxx
-    cd ndn-cxx
-    BUILD="yes"
+pushd /tmp >/dev/null
+
+INSTALLED_VERSION=$((cd ndn-cxx && git rev-parse HEAD) 2>/dev/null || echo NONE)
+
+sudo rm -Rf ndn-cxx-latest
+git clone --depth 1 git://github.com/named-data/ndn-cxx ndn-cxx-latest
+LATEST_VERSION=$((cd ndn-cxx-latest && git rev-parse HEAD) 2>/dev/null || echo UNKNOWN)
+
+if [[ $INSTALLED_VERSION != $LATEST_VERSION ]]; then
+    sudo rm -Rf ndn-cxx
+    mv ndn-cxx-latest ndn-cxx
 else
-    cd ndn-cxx
-    INSTALLED_VERSION=`git rev-parse HEAD || echo NONE`
-    sudo rm -Rf latest-version
-    git clone git://github.com/named-data/ndn-cxx latest-version
-    cd latest-version
-    LATEST_VERSION=`git rev-parse HEAD || echo UNKNOWN`
-    cd ..
-    rm -Rf latest-version
-    if [ "$INSTALLED_VERSION" != "$LATEST_VERSION" ]; then
-        cd ..
-        sudo rm -Rf ndn-cxx
-        git clone --depth 1 git://github.com/named-data/ndn-cxx
-        cd ndn-cxx
-        BUILD="yes"
-    fi
+    sudo rm -Rf ndn-cxx-latest
 fi
 
 sudo rm -Rf /usr/local/include/ndn-cxx
 sudo rm -f /usr/local/lib/libndn-cxx*
 sudo rm -f /usr/local/lib/pkgconfig/libndn-cxx*
 
-if [ "$BUILD" = "yes" ]; then
-    sudo ./waf distclean -j1 --color=yes
-fi
+pushd ndn-cxx >/dev/null
 
-IS_UBUNTU_12_04=$( python -c "print 'yes' if 'Ubuntu-12.04' in '$NODE_LABELS'.strip().split(' ') else 'no'" )
-if [[ $IS_UBUNTU_12_04 == "yes" ]]; then
+if has Ubuntu-12.04 $NODE_LABELS; then
     EXTRA_FLAGS=" --boost-libs=/usr/lib/x86_64-linux-gnu"
 fi
 
 ./waf configure -j1 --color=yes --enable-shared --disable-static --without-osx-keychain $EXTRA_FLAGS
 ./waf -j1 --color=yes
 sudo ./waf install -j1 --color=yes
+
+popd >/dev/null
+popd >/dev/null
+
+if has Linux $NODE_LABELS; then
+    sudo ldconfig
+elif has FreeBSD $NODE_LABELS; then
+    sudo ldconfig -a
+fi
diff --git a/.jenkins.d/10-build.sh b/.jenkins.d/10-build.sh
index 93e7d79..da977d5 100755
--- a/.jenkins.d/10-build.sh
+++ b/.jenkins.d/10-build.sh
@@ -2,38 +2,27 @@
 set -x
 set -e
 
-# git submodule init
-# git submodule sync
-# git submodule update
+JDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
+source "$JDIR"/util.sh
 
-# COVERAGE=$( python -c "print '--with-coverage' if 'code-coverage' in '$JOB_NAME' else ''" )
-IS_UBUNTU_12_04=$( python -c "print 'yes' if 'Ubuntu-12.04' in '$NODE_LABELS'.strip().split(' ') else 'no'" )
-if [[ $IS_UBUNTU_12_04 == "yes" ]]; then
-    EXTRA_FLAGS=" --boost-libs=/usr/lib/x86_64-linux-gnu"
-fi
+git submodule update --init
 
 # Cleanup
 sudo ./waf -j1 distclean
 
+if has Ubuntu-12.04 $NODE_LABELS; then
+    EXTRA_FLAGS=" --boost-libs=/usr/lib/x86_64-linux-gnu"
+fi
+
 # Configure/build in debug mode
-./waf -j1 configure --enable-modules=ndnSIM --enable-examples --enable-tests $EXTRA_FLAGS
+./waf -j1 configure -d debug --enable-modules=ndnSIM --enable-examples --enable-tests $EXTRA_FLAGS
 ./waf -j1 build
 
-# # Cleanup
-# sudo ./waf -j1 --color=yes distclean
+# Install
+sudo ./waf -j1 install
 
-# # Configure/build in optimized mode without tests with precompiled headers
-# ./waf -j1 --color=yes configure
-# ./waf -j1 --color=yes build
-
-# # Cleanup
-# sudo ./waf -j1 --color=yes distclean
-
-# # Configure/build in optimized mode
-# ./waf -j1 --color=yes configure --with-tests --without-pch $COVERAGE
-# ./waf -j1 --color=yes build
-
-# # (tests will be run against optimized version)
-
-# # Install
-# sudo ./waf -j1 --color=yes install
+if has Linux $NODE_LABELS; then
+    sudo ldconfig
+elif has FreeBSD $NODE_LABELS; then
+    sudo ldconfig -a
+fi
diff --git a/.jenkins.d/20-tests.sh b/.jenkins.d/20-tests.sh
new file mode 100755
index 0000000..01ce1a2
--- /dev/null
+++ b/.jenkins.d/20-tests.sh
@@ -0,0 +1,13 @@
+#!/usr/bin/env bash
+set -x
+set -e
+
+JDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
+source "$JDIR"/util.sh
+
+# Run unit tests
+if [[ -n "$XUNIT" ]]; then
+    ./build/src/ndnSIM/tests/ns3-dev-ndnSIM-unit-tests-debug --log_format=XML --log_sink=build/xunit-report.xml --log_level=all --report_level=no
+else
+    ./build/src/ndnSIM/tests/ns3-dev-ndnSIM-unit-tests-debug -l test_suite
+fi
diff --git a/.jenkins.d/util.sh b/.jenkins.d/util.sh
new file mode 100755
index 0000000..81c8931
--- /dev/null
+++ b/.jenkins.d/util.sh
@@ -0,0 +1,9 @@
+has() {
+    local p=$1
+    shift
+    local x
+    for x in "$@"; do
+        [[ "${x}" == "${p}" ]] && return 0
+    done
+    return 1
+}