ci: make unit tests execution compatible with different versions of Boost

This commit also unifies the coding style of CI scripts.

Change-Id: Iae73f63d8a997dbfde9233b6ee7f53a3d9644ef6
Refs: #3750
diff --git a/.jenkins.d/00-deps.sh b/.jenkins.d/00-deps.sh
index 06b2ad5..4a4db28 100755
--- a/.jenkins.d/00-deps.sh
+++ b/.jenkins.d/00-deps.sh
@@ -4,20 +4,16 @@
 JDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
 source "$JDIR"/util.sh
 
-if has OSX $NODE_LABELS; then
-    if has OSX-10.8 $NODE_LABELS; then
-        EXTRA_FLAGS=--c++11
-    fi
+set -x
 
-    set -x
+if has OSX $NODE_LABELS; then
     brew update
     brew upgrade
-    brew install boost pkg-config cryptopp openssl $EXTRA_FLAGS
+    brew install boost pkg-config cryptopp openssl
     brew cleanup
 fi
 
 if has Ubuntu $NODE_LABELS; then
-    set -x
     sudo apt-get -qq update
     sudo apt-get -qq install build-essential pkg-config libboost-all-dev \
                              libcrypto++-dev libsqlite3-dev libssl-dev \
diff --git a/.jenkins.d/01-ndn-cxx.sh b/.jenkins.d/01-ndn-cxx.sh
index 2bc46fd..e5f7585 100755
--- a/.jenkins.d/01-ndn-cxx.sh
+++ b/.jenkins.d/01-ndn-cxx.sh
@@ -1,11 +1,12 @@
 #!/usr/bin/env bash
-set -x
 set -e
 
 JDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
 source "$JDIR"/util.sh
 
-pushd ${CACHE_DIR:-/tmp} >/dev/null
+set -x
+
+pushd "${CACHE_DIR:-/tmp}" >/dev/null
 
 INSTALLED_VERSION=$((cd ndn-cxx && git rev-parse HEAD) 2>/dev/null || echo NONE)
 
@@ -28,9 +29,9 @@
 
 pushd ndn-cxx >/dev/null
 
-./waf configure -j1 --color=yes --enable-shared --disable-static --without-osx-keychain
-./waf -j1 --color=yes
-sudo ./waf install -j1 --color=yes
+./waf -j1 --color=yes configure --enable-shared --disable-static --without-osx-keychain
+./waf -j1 --color=yes build
+sudo ./waf -j1 --color=yes install
 
 popd >/dev/null
 popd >/dev/null
diff --git a/.jenkins.d/10-build.sh b/.jenkins.d/10-build.sh
index fa7591a..3c975e0 100755
--- a/.jenkins.d/10-build.sh
+++ b/.jenkins.d/10-build.sh
@@ -1,7 +1,11 @@
 #!/usr/bin/env bash
-set -x
 set -e
 
+JDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
+source "$JDIR"/util.sh
+
+set -x
+
 git submodule init
 git submodule sync
 git submodule update
@@ -10,14 +14,14 @@
 sudo ./waf -j1 --color=yes distclean
 
 if [[ "$JOB_NAME" != *"limited-build" ]]; then
-  # Configure/build in optimized mode with tests and precompiled headers
+  # Configure/build in optimized mode with tests
   ./waf -j1 --color=yes configure --with-tests
   ./waf -j1 --color=yes build
 
   # Cleanup
   sudo ./waf -j1 --color=yes distclean
 
-  # Configure/build in optimized mode without tests and with precompiled headers
+  # Configure/build in optimized mode without tests
   ./waf -j1 --color=yes configure
   ./waf -j1 --color=yes build
 
@@ -25,7 +29,7 @@
   sudo ./waf -j1 --color=yes distclean
 fi
 
-# Configure/build in debug mode
+# Configure/build in debug mode with tests and without precompiled headers
 if [[ "$JOB_NAME" == *"code-coverage" ]]; then
     COVERAGE="--with-coverage"
 fi
diff --git a/.jenkins.d/20-tests.sh b/.jenkins.d/20-tests.sh
index 17419ce..88c9948 100755
--- a/.jenkins.d/20-tests.sh
+++ b/.jenkins.d/20-tests.sh
@@ -1,12 +1,13 @@
 #!/usr/bin/env bash
-set -x
 set -e
 
 JDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
 source "$JDIR"/util.sh
 
+set -x
+
 # Prepare environment
-rm -Rf ~/.ndnx ~/.ndn
+rm -Rf ~/.ndn
 
 if has OSX $NODE_LABELS; then
     security unlock-keychain -p named-data
@@ -14,37 +15,32 @@
 
 ndnsec-keygen "/tmp/jenkins/$NODE_NAME" | ndnsec-install-cert -
 
-count=0
+BOOST_VERSION=$(python -c "import sys; sys.path.append('build/c4che'); import _cache; print(_cache.BOOST_VERSION_NUMBER);")
 
-# Helper function
-run_tests() {
-    local sudo=
-    if [[ $1 == sudo ]]; then
-        sudo=$1
-        shift
-    fi
-
-    local module=$1
-    shift
-
-    if [[ -n $XUNIT ]]; then
-        ${sudo} ./build/unit-tests-${module} -l all "$@" -- --log_format2=XML --log_sink2="build/xunit-${count}-${module}${sudo:+-}${sudo}.xml"
-        ((count+=1))
+ut_log_args() {
+    ((ut_count+=1))
+    if (( BOOST_VERSION >= 106200 )); then
+        echo --logger=HRF,test_suite,stdout:XML,all,build/xunit-report-${ut_count}.xml
     else
-        ${sudo} ./build/unit-tests-${module} -l test_suite "$@"
+        if [[ -n $XUNIT ]]; then
+            echo --log_level=all $( (( BOOST_VERSION >= 106000 )) && echo -- ) \
+                 --log_format2=XML --log_sink2=build/xunit-report-${ut_count}.xml
+        else
+            echo --log_level=test_suite
+        fi
     fi
 }
 
 # First run all tests as unprivileged user
-run_tests core
-run_tests daemon
-run_tests rib
-run_tests tools
+./build/unit-tests-core $(ut_log_args)
+./build/unit-tests-daemon $(ut_log_args)
+./build/unit-tests-rib $(ut_log_args)
+./build/unit-tests-tools $(ut_log_args)
 
 # Then use sudo to run those tests that need superuser powers
-run_tests sudo core -t TestPrivilegeHelper
-run_tests sudo daemon -t Face/TestEthernetFactory,TestEthernetTransport
-run_tests sudo daemon -t Mgmt/TestGeneralConfigSection/UserAndGroupConfig,NoUserConfig
-run_tests sudo daemon -t Mgmt/TestFaceManager/ProcessConfig/ProcessSectionUdp,ProcessSectionUdpMulticastReinit,ProcessSectionEther,ProcessSectionEtherMulticastReinit
+sudo ./build/unit-tests-core -t TestPrivilegeHelper $(ut_log_args)
+sudo ./build/unit-tests-daemon -t Face/TestEthernetFactory,TestEthernetTransport $(ut_log_args)
+sudo ./build/unit-tests-daemon -t Mgmt/TestGeneralConfigSection/UserAndGroupConfig,NoUserConfig $(ut_log_args)
+sudo ./build/unit-tests-daemon -t Mgmt/TestFaceManager/ProcessConfig/ProcessSectionUdp,ProcessSectionUdpMulticastReinit,ProcessSectionEther,ProcessSectionEtherMulticastReinit $(ut_log_args)
 
-unset count
+unset ut_count
diff --git a/.jenkins.d/30-coverage.sh b/.jenkins.d/30-coverage.sh
index d09e270..a0e983e 100755
--- a/.jenkins.d/30-coverage.sh
+++ b/.jenkins.d/30-coverage.sh
@@ -1,10 +1,11 @@
 #!/usr/bin/env bash
-set -x
 set -e
 
 JDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
 source "$JDIR"/util.sh
 
+set -x
+
 if [[ $JOB_NAME == *"code-coverage" ]]; then
     gcovr --object-directory=build \
           --output=build/coverage.xml \
diff --git a/.jenkins.d/util.sh b/.jenkins.d/util.sh
index 81c8931..a89bc27 100644
--- a/.jenkins.d/util.sh
+++ b/.jenkins.d/util.sh
@@ -1,9 +1,18 @@
 has() {
+    local saved_xtrace
+    [[ $- == *x* ]] && saved_xtrace=-x || saved_xtrace=+x
+    set +x
+
     local p=$1
     shift
-    local x
-    for x in "$@"; do
-        [[ "${x}" == "${p}" ]] && return 0
+    local i ret=1
+    for i in "$@"; do
+        if [[ "${i}" == "${p}" ]]; then
+            ret=0
+            break
+        fi
     done
-    return 1
+
+    set ${saved_xtrace}
+    return ${ret}
 }
diff --git a/.travis.yml b/.travis.yml
index 6ed51f3..db62c24 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -7,18 +7,21 @@
   include:
     - os: linux
       dist: trusty
-      env: CXX=g++
+      env:
+        - CXX=g++
+        - NODE_LABELS="Linux Ubuntu Ubuntu-14.04"
     - os: linux
       dist: trusty
-      env: CXX=clang++
+      env:
+        - CXX=clang++
+        - NODE_LABELS="Linux Ubuntu Ubuntu-14.04"
     - os: osx
-      env: CXX=clang++
+      env:
+        - CXX=clang++
+        - NODE_LABELS="OSX OSX-10.9"
 notifications:
   email:
     on_success: always
     on_failure: always
 script:
-  - if [[ $TRAVIS_OS_NAME == linux ]]; then export NODE_LABELS="Linux Ubuntu Ubuntu-14.04"; fi
-  - if [[ $TRAVIS_OS_NAME == osx ]]; then export NODE_LABELS="OSX OSX-10.9"; fi
-  - echo $NODE_LABELS
   - ./.jenkins
diff --git a/tests/main.cpp b/tests/main.cpp
index 49c3e9c..01bb6b0 100644
--- a/tests/main.cpp
+++ b/tests/main.cpp
@@ -1,11 +1,12 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014  Regents of the University of California,
- *                     Arizona Board of Regents,
- *                     Colorado State University,
- *                     University Pierre & Marie Curie, Sorbonne University,
- *                     Washington University in St. Louis,
- *                     Beijing Institute of Technology
+ * Copyright (c) 2014-2016,  Regents of the University of California,
+ *                           Arizona Board of Regents,
+ *                           Colorado State University,
+ *                           University Pierre & Marie Curie, Sorbonne University,
+ *                           Washington University in St. Louis,
+ *                           Beijing Institute of Technology,
+ *                           The University of Memphis.
  *
  * This file is part of NFD (Named Data Networking Forwarding Daemon).
  * See AUTHORS.md for complete list of NFD authors and contributors.
@@ -20,13 +21,20 @@
  *
  * You should have received a copy of the GNU General Public License along with
  * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
- **/
+ */
 
-#define BOOST_TEST_NO_MAIN
 #define BOOST_TEST_DYN_LINK
 #define BOOST_TEST_ALTERNATIVE_INIT_API
 
+#include <boost/version.hpp>
+
+#if BOOST_VERSION >= 106200
+// Boost.Test v3.3 (Boost 1.62) natively supports multi-logger output
 #include "boost-test.hpp"
+#else
+#define BOOST_TEST_NO_MAIN
+#include "boost-test.hpp"
+
 #include "boost-multi-log-formatter.hpp"
 
 #include <boost/program_options/options_description.hpp>
@@ -103,3 +111,5 @@
 {
   return ::boost::unit_test::unit_test_main(&init_tests, argc, argv);
 }
+
+#endif // BOOST_VERSION >= 106200