Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Don't get tied to a version, this one needed an upgrade
[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 do_cleanup() {
13   for d in "$BUILDFOLDER"
14   do
15     if [ -d "$d" ]
16     then
17       rm -rf "$d" || die "Could not remote $d"
18     fi
19   done
20 }
21
22 ### Check the node installation
23
24 for pkg in xsltproc gcovr ant cover2cover.py
25 do
26    if command -v $pkg
27    then
28       echo "$pkg is installed. Good."
29    else
30       die "please install $pkg before proceeding"
31    fi
32 done
33
34 ### Cleanup previous runs
35
36 ! [ -z "$WORKSPACE" ] || die "No WORKSPACE"
37 [ -d "$WORKSPACE" ] || die "WORKSPACE ($WORKSPACE) does not exist"
38
39 do_cleanup
40
41 for d in "$BUILDFOLDER"
42 do
43   mkdir "$d" || die "Could not create $d"
44 done
45
46 NUMPROC="$(nproc)" || NUMPROC=1
47
48
49 cd $BUILDFOLDER
50 rm -rf java_cov*
51 rm -rf xml_coverage.xml
52
53 ctest -D ExperimentalStart || true
54
55 cmake -Denable_documentation=OFF -Denable_lua=ON -Denable_java=ON \
56       -Denable_compile_optimizations=OFF -Denable_compile_warnings=ON \
57       -Denable_jedule=ON -Denable_mallocators=ON \
58       -Denable_smpi=ON -Denable_smpi_MPICH3_testsuite=ON -Denable_model-checking=ON \
59       -Denable_smpi_papi=ON \
60       -Denable_memcheck=OFF -Denable_memcheck_xml=OFF -Denable_smpi_ISP_testsuite=ON -Denable_coverage=ON $WORKSPACE
61
62 #build with sonarqube scanner wrapper
63 /home/ci/build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir bw-outputs make -j$NUMPROC
64 JACOCO_PATH="/usr/local/share/jacoco"
65 export JAVA_TOOL_OPTIONS="-javaagent:${JACOCO_PATH}/lib/jacocoagent.jar"
66
67 ctest --no-compress-output -D ExperimentalTest -j$NUMPROC || true
68 ctest -D ExperimentalCoverage || true
69
70 unset JAVA_TOOL_OPTIONS
71 if [ -f Testing/TAG ] ; then
72
73   files=$( find . -size +1c -name "jacoco.exec" )
74   i=0
75   for file in $files
76   do
77     sourcepath=$( dirname $file )
78     #convert jacoco reports in xml ones
79     ant -f $WORKSPACE/tools/jenkins/jacoco.xml -Dexamplesrcdir=$WORKSPACE -Dbuilddir=$BUILDFOLDER/${sourcepath} -Djarfile=$BUILDFOLDER/simgrid.jar -Djacocodir=${JACOCO_PATH}/lib
80     #convert jacoco xml reports in cobertura xml reports
81     cover2cover.py $BUILDFOLDER/${sourcepath}/report.xml .. ../src/bindings/java src/bindings/java > $WORKSPACE/java_coverage_${i}.xml
82     i=$((i + 1))
83   done
84
85    cd $WORKSPACE
86    #convert all gcov reports to xml cobertura reports
87    gcovr -r . --xml-pretty -e teshsuite -u -o $WORKSPACE/xml_coverage.xml
88    xsltproc $WORKSPACE/tools/jenkins/ctest2junit.xsl build/Testing/$( head -n 1 < build/Testing/TAG )/Test.xml > CTestResults_memcheck.xml
89
90    #generate sloccount report
91    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
92
93    #upload files to codacy. CODACY_PROJECT_TOKEN must be setup !
94    if ! [ -z $CODACY_PROJECT_TOKEN ]
95    then 
96      for report in $WORKSPACE/java_cov*
97      do
98        if [ ! -e "$report" ]; then continue; fi
99        java -jar /home/ci/codacy-coverage-reporter-*-assembly.jar report -l Java -r $report --partial
100      done
101      java -jar /home/ci/codacy-coverage-reporter-*-assembly.jar final
102      java -jar /home/ci/codacy-coverage-reporter-*-assembly.jar report -l C -f -r $WORKSPACE/xml_coverage.xml
103      java -jar /home/ci/codacy-coverage-reporter-*-assembly.jar report -l CPP -f -r $WORKSPACE/xml_coverage.xml
104    fi
105 fi