ci: Enable coverage report and allow unit test output in XML format

Change-Id: I952654aa25d2bdfb5ba1885d1c7570cfdb7e3edf
diff --git a/.jenkins.d/20-ndns.sh b/.jenkins.d/20-ndns.sh
index ee128f5..d2552e7 100755
--- a/.jenkins.d/20-ndns.sh
+++ b/.jenkins.d/20-ndns.sh
@@ -2,7 +2,30 @@
 set -x
 set -e
 
-./waf distclean --color=yes
-./waf configure --debug --with-tests --color=yes
-./waf -j1 --color=yes
-sudo ./waf install --color=yes
+COVERAGE=$( python -c "print '--with-coverage --debug' if 'code-coverage' in '$JOB_NAME' else ''" )
+
+# Cleanup
+sudo ./waf -j1 --color=yes distclean
+
+# Configure/build in debug mode
+./waf -j1 --color=yes configure --with-tests --debug
+./waf -j1 --color=yes build
+
+# Cleanup
+sudo ./waf -j1 --color=yes distclean
+
+# Configure/build in optimized mode without tests
+./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 $COVERAGE
+./waf -j1 --color=yes build
+
+# (tests will be run against optimized version)
+
+# Install
+sudo ./waf -j1 --color=yes install
diff --git a/.jenkins.d/30-unit-tests.sh b/.jenkins.d/30-unit-tests.sh
index b05ec4a..4f8248b 100755
--- a/.jenkins.d/30-unit-tests.sh
+++ b/.jenkins.d/30-unit-tests.sh
@@ -8,9 +8,13 @@
 IS_OSX=$( python -c "print 'yes' if 'OSX' in '$NODE_LABELS'.strip().split(' ') else 'no'" )
 IS_LINUX=$( python -c "print 'yes' if 'Linux' in '$NODE_LABELS'.strip().split(' ') else 'no'" )
 
-if [ $IS_OSX = "yes" ]; then
+if [[ $IS_OSX == "yes" ]]; then
     security unlock-keychain -p "named-data"
 fi
 
 # Run unit tests
-./build/unit-tests -l test_suite
+if [[ -n "$XUNIT" ]]; then
+    ./build/unit-tests --log_format=XML --log_sink=build/xunit-report.xml --log_level=all --report_level=no
+else
+    ./build/unit-tests -l test_suite
+fi
diff --git a/.jenkins.d/40-coverage.sh b/.jenkins.d/40-coverage.sh
new file mode 100755
index 0000000..ccbb62e
--- /dev/null
+++ b/.jenkins.d/40-coverage.sh
@@ -0,0 +1,10 @@
+#!/usr/bin/env bash
+set -x
+set -e
+
+IS_COVR=$( python -c "print 'yes' if 'code-coverage' in '$JOB_NAME' else 'no'" )
+
+if [[ $IS_COVR == "yes" ]]; then
+  BASE="`pwd | sed -e 's|/|\\\/|g'`\\"
+  (cd build && gcovr -x -f $BASE/src -r ../ -o coverage.xml -b ./)
+fi