Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Enable ns3 for coverage build and hope that it will be analyzed by sonar.
[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_ns3=ON \
61       -Denable_smpi=ON -Denable_smpi_MPICH3_testsuite=ON -Denable_model-checking=ON \
62       -Denable_smpi_papi=ON \
63       -Denable_memcheck=OFF -Denable_memcheck_xml=OFF -Denable_smpi_ISP_testsuite=ON \
64       -Denable_coverage=ON -DLTO_EXTRA_FLAG="auto" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON "$WORKSPACE"
65
66 #build with sonarqube scanner wrapper
67 /home/ci/build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir bw-outputs make -j$NUMPROC tests
68 JACOCO_PATH="/usr/local/share/jacoco"
69 export JAVA_TOOL_OPTIONS="-javaagent:${JACOCO_PATH}/lib/jacocoagent.jar"
70
71 export PYTHON_TOOL_OPTIONS="/usr/bin/python3-coverage run --parallel-mode --branch"
72
73 ctest --no-compress-output -D ExperimentalTest -j$NUMPROC || true
74 ctest -D ExperimentalCoverage || true
75
76 unset JAVA_TOOL_OPTIONS
77 if [ -f Testing/TAG ] ; then
78
79   files=$( find . -size +1c -name "jacoco.exec" )
80   i=0
81   for file in $files
82   do
83     sourcepath=$( dirname "$file" )
84     #convert jacoco reports in xml ones
85     ant -f "$WORKSPACE"/tools/jenkins/jacoco.xml -Dexamplesrcdir="$WORKSPACE" -Dbuilddir="$BUILDFOLDER"/"${sourcepath}" -Djarfile="$BUILDFOLDER"/simgrid.jar -Djacocodir=${JACOCO_PATH}/lib
86     #convert jacoco xml reports in cobertura xml reports
87     cover2cover.py "$BUILDFOLDER"/"${sourcepath}"/report.xml .. ../src/bindings/java src/bindings/java > "$BUILDFOLDER"/java_coverage_${i}.xml
88     #save jacoco xml report as sonar only allows it 
89     mv "$BUILDFOLDER"/"${sourcepath}"/report.xml "$BUILDFOLDER"/jacoco_cov_${i}.xml
90     i=$((i + 1))
91   done
92
93   #convert python coverage reports in xml ones
94   cd "$BUILDFOLDER"
95   find .. -size +1c -name ".coverage*" -exec mv {} . \;
96   /usr/bin/python3-coverage combine
97   /usr/bin/python3-coverage xml -i -o ./python_coverage.xml
98
99   cd "$WORKSPACE"
100   #convert all gcov reports to xml cobertura reports
101   gcovr -r . --xml-pretty -e teshsuite -u -o "$BUILDFOLDER"/xml_coverage.xml
102   xsltproc "$WORKSPACE"/tools/jenkins/ctest2junit.xsl build/Testing/"$( head -n 1 < build/Testing/TAG )"/Test.xml > CTestResults_memcheck.xml
103
104   #generate sloccount report
105   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
106
107   #generate PVS-studio report
108   EXCLUDEDPATH="-e $WORKSPACE/src/include/catch.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/"
109   pvs-studio-analyzer analyze -f "$BUILDFOLDER"/compile_commands.json -o "$WORKSPACE"/pvs.log $EXCLUDEDPATH -j$NUMPROC
110   #disable V1042 (copyleft), V521 (commas in catch.hpp)
111   plog-converter -t xml -o "$WORKSPACE"/pvs.plog -d V1042,V521 "$WORKSPACE"/pvs.log
112
113 fi || exit 42