Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'Adrien.Gougeon/simgrid-master'
[simgrid.git] / tools / jenkins / Coverage.sh
1 #!/usr/bin/env sh
2
3 set -e
4
5 BUILDFOLDER=$WORKSPACE/build
6
7 die() {
8     echo "$@"
9     exit 1
10 }
11
12 ### Check the node installation
13
14 pkg_check() {
15   for pkg
16   do
17     if command -v "$pkg"
18     then
19        echo "$pkg is installed. Good."
20     else
21        die "please install $pkg before proceeding"
22     fi
23   done
24 }
25
26 pkg_check xsltproc gcovr ant cover2cover.py
27
28 ### Cleanup previous runs
29
30 [ -n "$WORKSPACE" ] || die "No WORKSPACE"
31 [ -d "$WORKSPACE" ] || die "WORKSPACE ($WORKSPACE) does not exist"
32
33 do_cleanup() {
34   for d
35   do
36     if [ -d "$d" ]
37     then
38       rm -rf "$d" || die "Could not remove $d"
39     fi
40     mkdir "$d" || die "Could not create $d"
41   done
42 }
43
44 do_cleanup "$BUILDFOLDER"
45
46 NUMPROC="$(nproc)" || NUMPROC=1
47
48
49 cd "$BUILDFOLDER"
50 rm -rf java_cov*
51 rm -rf jacoco_cov*
52 rm -rf python_cov*
53 rm -rf xml_coverage.xml
54
55 ctest -D ExperimentalStart || true
56
57 cmake -Denable_documentation=OFF -Denable_lua=ON \
58       -Denable_compile_optimizations=OFF -Denable_compile_warnings=ON \
59       -Denable_jedule=ON -Denable_mallocators=ON \
60       -Denable_smpi=ON -Denable_smpi_MPICH3_testsuite=ON -Denable_model-checking=ON \
61       -Denable_smpi_papi=ON \
62       -Denable_memcheck=OFF -Denable_memcheck_xml=OFF -Denable_smpi_ISP_testsuite=ON \
63       -Denable_coverage=ON -DLTO_EXTRA_FLAG="auto" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON "$WORKSPACE"
64
65 #build with sonarqube scanner wrapper
66 /home/ci/build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir bw-outputs make -j$NUMPROC tests
67 JACOCO_PATH="/usr/local/share/jacoco"
68 export JAVA_TOOL_OPTIONS="-javaagent:${JACOCO_PATH}/lib/jacocoagent.jar"
69
70 export PYTHON_TOOL_OPTIONS="/usr/bin/python3-coverage run --parallel-mode --branch"
71
72 ctest --no-compress-output -D ExperimentalTest -j$NUMPROC || true
73 ctest -D ExperimentalCoverage || true
74
75 unset JAVA_TOOL_OPTIONS
76 if [ -f Testing/TAG ] ; then
77
78   files=$( find . -size +1c -name "jacoco.exec" )
79   i=0
80   for file in $files
81   do
82     sourcepath=$( dirname "$file" )
83     #convert jacoco reports in xml ones
84     ant -f "$WORKSPACE"/tools/jenkins/jacoco.xml -Dexamplesrcdir="$WORKSPACE" -Dbuilddir="$BUILDFOLDER"/"${sourcepath}" -Djarfile="$BUILDFOLDER"/simgrid.jar -Djacocodir=${JACOCO_PATH}/lib
85     #convert jacoco xml reports in cobertura xml reports
86     cover2cover.py "$BUILDFOLDER"/"${sourcepath}"/report.xml .. ../src/bindings/java src/bindings/java > "$BUILDFOLDER"/java_coverage_${i}.xml
87     #save jacoco xml report as sonar only allows it 
88     mv "$BUILDFOLDER"/"${sourcepath}"/report.xml "$BUILDFOLDER"/jacoco_cov_${i}.xml
89     i=$((i + 1))
90   done
91
92   #convert python coverage reports in xml ones
93   cd "$BUILDFOLDER"
94   find .. -size +1c -name ".coverage*" -exec mv {} . \;
95   /usr/bin/python3-coverage combine
96   /usr/bin/python3-coverage xml -i -o ./python_coverage.xml
97
98   cd "$WORKSPACE"
99   #convert all gcov reports to xml cobertura reports
100   gcovr -r . --xml-pretty -e teshsuite -e examples/smpi/NAS -e examples/smpi/mc -u -o "$BUILDFOLDER"/xml_coverage.xml
101   xsltproc "$WORKSPACE"/tools/jenkins/ctest2junit.xsl build/Testing/"$( head -n 1 < build/Testing/TAG )"/Test.xml > CTestResults_memcheck.xml
102
103   #generate sloccount report
104   sloccount --duplicates --wide --details "$WORKSPACE" | grep -v -e '.git' -e 'mpich3-test' -e 'sloccount.sc' -e 'isp/umpire' -e 'build/' -e 'xml_coverage.xml' -e 'CTestResults_memcheck.xml' -e 'DynamicAnalysis.xml' > "$WORKSPACE"/sloccount.sc
105
106   #generate PVS-studio report
107   EXCLUDEDPATH="-e $WORKSPACE/src/include/catch.hpp -e $WORKSPACE/src/include/xxhash.hpp -e $WORKSPACE/teshsuite/smpi/mpich3-test/ -e $WORKSPACE/teshsuite/smpi/isp/ -e *_dtd.c -e *_dtd.h -e *yy.c -e  $WORKSPACE/src/xbt/automaton/ -e $WORKSPACE/src/smpi/colls/ -e $WORKSPACE/examples/smpi/NAS/ -e $WORKSPACE/examples/smpi/gemm/gemm.c -e $WORKSPACE/src/msg/ -e $WORKSPACE/include/msg/ -e $WORKSPACE/examples/deprecated/ -e $WORKSPACE/teshsuite/msg/"
108   pvs-studio-analyzer analyze -f "$BUILDFOLDER"/compile_commands.json -o "$WORKSPACE"/pvs.log $EXCLUDEDPATH -j$NUMPROC
109   # Disable:
110   # V521 Such expressions using the ',' operator are dangerous. (-> commas in catch.hpp),
111   # V1042 This file is marked with copyleft license, which requires you to open the derived source code.
112   # V1056 The predefined identifier '__func__' always contains the string 'operator()' inside function body of the overloaded 'operator()'.
113   plog-converter -t xml -o "$WORKSPACE"/pvs.plog -d V521,V1042,V1056 "$WORKSPACE"/pvs.log
114
115 fi || exit 42