Logo AND Algorithmique Numérique Distribuée

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