ci: correctly generate tests reports 24/37124/2
authorMauro Sardara <msardara@cisco.com>
Wed, 14 Sep 2022 14:17:22 +0000 (16:17 +0200)
committerMauro Sardara <msardara@cisco.com>
Wed, 14 Sep 2022 14:26:27 +0000 (16:26 +0200)
Do not use make test to run the tests after the build,
as it overwrites the report file for each single unit tests.

Signed-off-by: Mauro Sardara <msardara@cisco.com>
Change-Id: Icdc55b31c1e36b213f977b76f8518ac16c393afc

scripts/build-packages.sh
scripts/functions.sh
scripts/run-sonar.sh

index 598b3f6..dddc98d 100644 (file)
@@ -17,6 +17,20 @@ set -euxo pipefail
 SCRIPT_PATH=$( cd "$(dirname "${BASH_SOURCE}")" ; pwd -P )
 source ${SCRIPT_PATH}/functions.sh
 
+BUILD_PATH="${SCRIPT_PATH}/../packages"
+TEST_REPORT_DIR="${BUILD_PATH}/reports"
+BUILD_ROOT_DIR="${BUILD_PATH}/build-root/bin"
+MAKE_FOLDER="${SCRIPT_PATH}/.."
+
+function execute_tests() {
+    mkdir -p "${TEST_REPORT_DIR}"
+    pushd "${BUILD_ROOT_DIR}"
+      for component in "${TEST_COMPONENTS[@]}"; do
+        GTEST_OUTPUT="xml:${TEST_REPORT_DIR}/${component}-report.xml" "./${component}_tests"
+      done
+    popd
+}
+
 # Parameters:
 # $1 = Package name
 #
@@ -28,18 +42,11 @@ function build_package() {
     echo "*******************************************************************"
 
     # Run unit tests and make the package
-    export GTEST_OUTPUT="xml:report.xml"
-    make -C "${SCRIPT_PATH}/.." BUILD_PATH="${SCRIPT_PATH}/../packages" INSTALL_PREFIX=/usr test package-release
-
-    pushd ${SCRIPT_PATH}/../packages
-      # Find and collect reports
-      mkdir -p reports
-      REPORTS=($(find . -iname 'report.xml'))
-      echo "${REPORTS[@]}"
-      for report in "${REPORTS[@]}"; do
-        mv "${report}" "reports/$(echo ${report} | awk -F/ '{print $(2)"-"$(NF)}')"
-      done
+    make -C "${MAKE_FOLDER}" BUILD_PATH="${BUILD_PATH}" INSTALL_PREFIX=/usr package-release
+
+    execute_tests
 
+    pushd "${BUILD_PATH}"
       find . -not -name '*.deb' \
         -not -name '*.rpm' \
         -not -name 'reports' \
index d6d8bf8..544c283 100644 (file)
@@ -31,6 +31,14 @@ fi
 
 COLLECTD_SOURCE="https://github.com/collectd/collectd/releases/download/collectd-5.12.0/collectd-5.12.0.tar.bz2"
 
+declare -a TEST_COMPONENTS=(
+  "libtransport"
+  "lib"
+  "hicn_light"
+  "hicnplugin"
+  "libhicnctrl"
+)
+
 function install_collectd_headers() {
   curl -OL ${COLLECTD_SOURCE}
   tar -xf collectd-5.12.0.tar.bz2
index 3d386bb..87a94b5 100755 (executable)
@@ -6,6 +6,9 @@ set -euxo pipefail
 # PROJECT_KEY=fdio-hicn
 # PROJECT_ORGANIZATION=fdio
 
+SCRIPT_PATH=$( cd "$(dirname "${BASH_SOURCE}")" ; pwd -P )
+source "${SCRIPT_PATH}/functions.sh"
+
 export SONAR_TOKEN=$API_TOKEN
 export SONAR_SCANNER_VERSION=4.7.0.2747
 export SONAR_SCANNER_HOME=$HOME/.sonar/sonar-scanner-$SONAR_SCANNER_VERSION-linux
@@ -30,14 +33,6 @@ make SONAR_BUILD_WRAPPER=${HOME}/.sonar/build-wrapper-linux-x86/build-wrapper-li
 # Run tests to compute test coverage
 pushd ${BUILD_PATH}
 
-declare -a TEST_COMPONENTS=(
-  "libtransport"
-  "lib"
-  "hicn_light"
-  "hicnplugin"
-  "libhicnctrl"
-)
-
 # Save first test executable
 FIRST_COMPONENT="${TEST_COMPONENTS[0]}"
 FIRST_TEST="${TEST_PATH}/${FIRST_COMPONENT}_tests"