Code coverage missing when run on CI

I have CI running on Drone.io with macOS agents attached to it.
Made script to do scanning, see below. But thing is that script running fine on local machine and reporting code coverage, but not on Drone.io agent, always gets 0 code coverage. I think it has some specific with user and it has broken access to some local directories, so I added SONAR_USER_HOME. Is there anything else I need to define/add if user don’t have user folder or permissions to some defaul dirs?

#!/bin/bash

THIS_PWD=`pwd`
export SONAR_USER_HOME=$THIS_PWD

PATH=$PATH:/bin/local/bin:/usr/bin:/bin
PATH="/usr/local/opt/openjdk/bin:$PATH"

echo "Install SonarQube dependencies"

if ! command -v sonar-scanner &> /dev/null
then
   brew install sonar-scanner openjdk
fi

THIS_PWD=`pwd`

## note this have to be run once on runner because app not codesign.
if ! [[ -d build-wrapper-macosx-x86 ]]; then
curl -L https://__sonar_qube_websie___/static/cpp/build-wrapper-macosx-x86.zip  --output build-wrapper-macosx-x86.zip
unzip build-wrapper-macosx-x86.zip -d .
fi

export LLVM_PROFILE_FILE="code-%p.profraw"

# Build project

./build-wrapper-macosx-x86/build-wrapper-macosx-x86 --out-dir ../../build_wrapper_output_directory xcodebuild clean build -quiet \
-workspace "Project.xcworkspace" \
-scheme "AppName" \
-derivedDataPath "DerivedData" \
GCC_PREPROCESSOR_DEFINITIONS=$GCC_PREPROCESSOR_DEFINITIONS \
CODE_SIGN_IDENTITY="" \
CODE_SIGNING_REQUIRED=NO

DerivedData/Build/Products/Debug/AppName --gtest_output="xml:../results/report.xml"

echo "Generate coverage report"

xcrun llvm-profdata merge -output=code.profdata code-*.profraw
xcrun llvm-cov show DerivedData/Build/Products/Debug/AppName -instr-profile=code.profdata $THIS_PWD/include/* $THIS_PWD/src/* > coverage.txt

cd ../..

branch=$(git symbolic-ref --short HEAD)

sonar-scanner -Dproject.settings=.sonar-project.properties \
-Dsonar.cfamily.llvm-cov.reportPath="$THIS_PWD/coverage.txt" \
-Dsonar.login=$SONAR_LOGIN

SonarQube Version 7.9.1
Scanner 4.5 installed from homebrew on macOS

Hi @3d4m-vladimir,

did check if the content of coverage.txt is as expected on drone.io?

file exists and and has size:
-rw-r--r-- 1 user staff 15881472 Dec 18 19:03 coverage.txt

Hi @3d4m-vladimir,

would you be able to share coverage.txt and the output of the scanner in verbose mode by specifying sonar.verbose=true? I can send you a PM if you want to share privately.

Thanks
Now I realised that produced code coverage is 15Mb file. And I can see in logs that sonar-scanner fails to process it.
coverage.txt less then 1Mb on my local machine.

@mpaladin it fails to process coverage.txt but no errors, simply empty line between start and end, when on local machine it’s showing list of files.

INFO: Sensor llvm-cov [cpp]
1451	
1452	INFO: Parsing /private/var/folders/t3/bxthgw0n4w3bn99ff9mx36700000gn/T/drone-pfD8yhnrvgWo0UTS/drone/src/tests/macos/coverage.txt
1453	INFO: Sensor llvm-cov [cpp] (done) | time=293ms

For some reason on CI machine coverage.txt contains also other sources not included in xcrun llvm-cov show ...

@mpaladin problem with llvm-cov and location where drone.io by default executing builds.
I moved drone root directory to user folder and getting normal coverage.txt as on local machine.

Hi @3d4m-vladimir,

thank you for the notification, glad to know that you managed to solve the issue.

Hi @mpaladin,
by moving to user’s documents directory it did solve problem with llvm-cov, but I got problems with other CI integration setups. MacOS security has this thing that requires user to accept access to Documents directory, which is blocking launch of testing application… So, I’m at begging again. Probably going to go and see what llvm developers can suggest, gonna file issue there

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.