GCovr does not generate a valid report - objective-c

I want to set up my Jenkins with Cobertura to track code coverage.
Unfortunately I can not generate a valid xml.
I'm using:
gcovr 2.5-prerelease (r2774)
Xcode 4.6.1 Build version 4H512
My project is generating code coverage files correctly, but the report created with gcovr is not useful.
The command I use to generate the report is:
gcovr -r /Users/Shared/Jenkins/Home/jobs/CodeCoverage/workspace
--object-directory /Users/Shared/Jenkins/Home/Library/Developer/Xcode/DerivedData/myProject-aooceqwwovrizceerghqvhflcfty//Build/Intermediates/myProject.build/Development/myProject.build/Objects-normal/x86_64
--exclude '.*Developer.*'
--exclude '.*Tests.*'
--xml
This will create me this output:
<?xml version="1.0" ?>
<!DOCTYPE coverage SYSTEM 'http://cobertura.sourceforge.net/xml/coverage-03.dtd'>
<coverage branch-rate="0.0" line-rate="0.0" timestamp="1364322914" version="gcovr 2.5-prerelease (r2774)">
<sources>
<source>
/Users/Shared/Jenkins/Home/jobs/CodeCoverage/workspace/Project/myProject/
</source>
</sources>
<packages/>
</coverage>
Additional Informations:
If I remove --object-directory and -r and then I execute the command from the derived data directory a valid report is generated. This report can be read from cobertura but can not show any detailed information about the source files.

When working with XCode, I've found that using $WORKSPACE/build as the build directory helps with this problem. This keeps the Derived Data directory out of it, and also neatly keeps my object files in the build directory. It also prevents two builds from interfering with each other.
If using the Xcode build tool, set SYMROOT to $WORKSPACE/build in the Tool's build configuration. If you're building from the command line, set it manually on the command line or in the environment.
Then a gcovr script such as:
/your/path/to/gcovr -r . --object-directory build/YourApp.build/Coverage-iphonesimulator/YourApp.build/Objects-normal/i386 --xml > build/coverage.xml
(your path may vary slightly depending on what you call your build style, etc.)
And finally in the Cobertura config, point at build/coverage.xml, and you should get annotated source when you use the tool within Jenkins.
Should do the trick. I've been really happy with that configuration on our small farm of Mac Minis.

gcovr should be executed from the folder where the .gcda and .gcno files exist. And the root path is the folder where the source files(.c or .cpp) exist.
With this, the command looks like something as shown below.
rr-mac:gcdaFolder$ gcovr -r /path_to_C_sourceFiles/ .
For output html file below command works
rr-mac:gcdaFolder$ gcovr --html -o Filename_rp.html -r /path_to_C_sourceFiles/ .
Note: The dot(.) at the end is mandatory

The gcovr python script does not appear to supports out of source tree builds.
I raised a bug report about this here https://github.com/gcovr/gcovr/issues/61

Related

How to convert llvm profraw to cobertura

I need to switch a cmake based project from g++ to clang for some reasons. I've made the switch to llvm-11 on Ubuntu 20.04. I got the project itself compile, unit tests work as well. Though, getting coverage reporting working again seems tough.
I need to create a cobertura xml file in order to integrate it into the existing CI/CD infrastructure (Jenkins and Gitlab). I've been using an older version of [1] for cmake cobertura reporting.
I thought 'llvm-cov gcov' should do the trick for me already to do the switch, but I just end up with an empty xml file with no error reported.
Next to the empty xml there is a new default.profraw file generated by llvm-cov that ends up in the build directory. I got so far as to figure out that the .profdata file format which llvm-profdata can convert to seems to be more promising as intermediate format for conversion than the raw data format. So I've generated a .profdata file for testing from that using:
llvm-profdata-11 merge -sparse default.profraw -o default.profdata
And I can generate an HTML file from this as well which actually contains expected coverage:
llvm-cov show my-unit-tests -instr-profile=default.profdata ../src/*.cpp -path-equivalence -use-color --format html > coverage.html
Here is also the related snippet from the CMake file:
append_coverage_compiler_flags()
setup_target_for_coverage_gcovr_xml(
NAME coveragereports
EXECUTABLE my-unit-tests
DEPENDENCIES my-unit-tests my-app-lib-testing
#BASE_DIRECTORY "coverage"
#BASE_DIRECTORY "../"
EXCLUDE "${CMAKE_SOURCE_DIR}/libraries/*" "${CMAKE_SOURCE_DIR}/test/*" "/Library/*"
)
What tools / options do I have to convert the coverage data generated by clang(11) to cobertura xml?
[1] https://github.com/bilke/cmake-modules/blob/master/CodeCoverage.cmake

buildtime.sh “Permission denied” when building in Xcode - Native Project generated by WL Ant Task

Please refer the below post.
IBM Worklight - "Permission denied" when building in Xcode
I am using the Worklight 6.1. I build the environment with Ant Task. Ant task creates my Native folder for android and iPhone environment. I try to build the iPhone native which has been generated by Ant Task is giving the below error. Tried giving read & right permission manually. no fix.
Running a custom build phase script: buildtime.sh
/Users/prasanna/Library/Developer/Xcode/DerivedData/MobileAppIphone-coksdtlrretmihenzyztxxxdcuss/Build/Intermediates/MobileAppIphone.build/Debug-iphonesimulator/MobileAppIphone.build/Script-427B829D1393724500F223DC.sh: line 7: /Volumes/DataHD/ST/Mobile_Client/temp/PROD/iPhone/buildtime.sh: Permission denied
DONE with script: buildtime.sh (exitStatus=126)\n\n
Verify the following:
Create the project in Eclipse
Build it using Worklight Studio
Right-click on the generated iphone\native\buildtime.sh file
Check if it has the required permissions
Do the same with Ant
Check if it has the required permissions
If the result differs then this is a defect in Worklight 6.1.0.x
That said, following one of the options from the answer you've linked to should work, however you do not mention which option did you follow...
Given you are using a command line, I'd opt to following the second option to use CHMOD.
It could be that you have given it the wrong path.
Experiment with the path and come back with results.
you can also change the permission using [CHMOD][3]:
Copy the path to the folder holding the buildtime.sh file
Open the Terminal app
Run the following command (but use your own path from 1 above): chmod 755
/Users/idan/Documents/Worklight/workspace-6001/TestProject/apps/TestApp/iphone/native/buildtime.sh
buildtime.sh is executable file, you need to give it executable permissions, not just r&w
Adding the CHMOD 755 in my Ant Script for all files and folder will solve this permission issue.
<target name="set-permission"> <echo level="info">Setting Read / Write / Execute Permissions to all files and .sh files</echo> <chmod perm="755" includes="/*.sh"> <fileset dir="${basedir}/temp/QA/iphone"> <exclude name="**/trial/"/> </fileset> </chmod> </target>

Getting error Could not find or load main class org.testng.TestNG

I'm trying to run TestNG from command line, but it's giving me error.
Can someone tell me where am I going wrong?
java -cp C:/TestNG directory/testng-6.2.jar;C:\project directory\src\com\suites\suite\shop org.testng.TestNG testng.xml
Error: Could not find or load main class org.testng.TestNG
My scripts runs fine when I ran them from eclipse testng plugin.
Copy the below commands in a text file.
Edit the location.
Save it as yourtext.bat
Now, double click on the batch file created.
cd C:\Workspace\projectname
java -cp C:\Workspace\projectname\lib*;C:\Workspace\projectname\bin org.testng.TestNG testng.xml
Path of TestNG.jar file was not set up.
Follow instructions of following site to set up. It worked for me:
http://qtp-automate.blogspot.com/2011/10/running-selenium-testng-test-from.html
Try above answers.
If still not work, then you might have downloaded the wrong version of testng.jar. From link testng.org, please click "here for ant users" to download a full testng.jar(11 mega bytes), not a "Maven Central" version(no more than 100k).
I have tested those two versions on centos following testng tutorial point
Possibly your testng.jar file is not in the lib folder that C:\Workspace\projectname\lib.
You should find testng.jar first in your computer and move it manually to C:\Workspace\projectname\lib. Then it will work
Check that the lib folder contains testng-6.8.jar(or any other version) file because testng.xml even executes successfully without testng-6.8.jar (or any other version) with the jars that gets added when we add TestNG library.
My Assumptions:
You are trying to run test file from command prompt
libs folder generated under Project/tagret upon using "mvn clean package -DskipTests"
class file generated under Project/target/test-classes/package-name
With above assumptions in mind, you can follow below process.
Setting class path in command prompt:
1. Open project location in command prompt
2. set classpath=C:\User\SeleniumTestProject\target\test-classes;C:\User\SeleniumTestProject\target\libs\*
3. java org.testng.TestNG C:\User\SeleniumTestProject\testng.xml

How can I execute programs in my %PATH% with MSBuild?

Note: I'm using Mercurial as an example here, because that's what I'm trying to get to work with MSBuild right now.
But the problem is not limited to Mercurial, it happens with every external program that is somewhere in my %PATH% variable (I tried the same with PowerShell, for example).
So I didn't put the Mercurial tag on this question on purpose, because this is not about Mercurial!
What I actually want to do:
I want my build script to get the current revision number from my Mercurial repository and store it in a file.
The simplest way to do this from the command line is:
hg id -i >rev.txt
Mercurial is installed on my machine and the installation folder is in my %PATH% variable.
So I can run this line from anywhere on my machine (directly from the command line, or from a batch file), and it just works.
The problem occurs when I try to run this line from my build script.
I change the BeforeBuild (or AfterBuild) section of my .csproj file as follows:
<Target Name="AfterBuild">
<Exec Command="hg id -i >rev.txt"/>
</Target>
When I compile my solution with Visual Studio, it works and the rev.txt file is created in the folder where my .csproj is.
But when I compile the exact same solution from the command line with MSBuild, the build fails with the following error message:
The command "hg id -i >rev.txt" exited with code 9009.
I googled "msbuild code 9009" and found some solutions, but all of them propose to provide the full path to the executable.
When I do this, the build succeeds with MSBuild as well.
But this is not an acceptable solution for me, because I can't be sure that everyone using my project (including the build server) has installed Mercurial in the exact same folder.
That's exactly what %PATH% is for...
The same happens when I put the <Exec Command="... line directly into the build script.
If I specify the path to the executable, it works.
If I don't specify the path, it doesn't.
Is there any trick to make MSBuild execute programs in my %PATH% variable without specifying the complete folder?
EDIT:
#leppie:
Output redirection:
You mean the fact that I save the output of my command in a text file inside the command , instead of just running hg id -i as a command and using an output parameter or something like that to get the output?
Doesn't make any difference...the error is the same when I omit >rev.txt.
Command line args:
No, it throws the same error, even if I shorten the command to just hg (without any parameters).
Don't forget: if I run the exact same Exec command in the exact same .csproj file from Visual Studio, or if I just provide the path to the .exe file in the command, everything works.
So IMO output redirection and command line args can't be the problem.
Have you tried this extension pack for mercurial/msbuild?
http://msbuildhg.codeplex.com/documentation
Seems to have a task for returning revision id, which is what your trying to achieve no?
<HgVersion LocalPath="$(MSBuildProjectDirectory)" Timeout="5000">
<Output TaskParameter="Revision" PropertyName="AssemblyRevision" />
</HgVersion>
Okay, I found the solution.
I have to admit, it was a classic case of PEBKAC :-)
I'll explain it anyway, maybe it will help someone who made the same mistake:
Basically everything I have tried (plus what James Woolfenden suggested in his answer) would have been worked...if only the batch file that I use to run the build script wouldn't have looked like this:
path="%windir%\Microsoft.net\Framework\v4.0.30319"
msbuild build.proj
Yes, exactly.
I'm editing the %PATH% variable for the duration of this batch file, and I'm overwriting it with the path to MSBuild instead of just appending it.
So when my build script tries to call Mercurial, it can't find it anymore because its location is not in the %PATH% variable anymore.
No idea why I didn't see this before.
The correct way would be to append the MSBuild path, leaving the other paths intact:
path=%path%;%windir%\Microsoft.net\Framework\v4.0.30319

TeamCity + MSBuild: Tagging a deployment with a VCS build number

I am using TeamCity 4.5.1 to build and deploy an ASP.Net application to development.
This is working perfectly so far, however, my manager has asked that I tag the folder with the specific SVN Revision from which the source was compiled.
I am using an MSBuild script to do the build and deployment, however, I am unable to successfully retrieve the build number.
Here is the MSBuild command I'm using (sanitized):
<Exec Command=">\\server08\D$\Websites\MYPROJECT\version.txt echo %env.BUILD_VCS_NUMBER%,%env.BUILD_VCS_NUMBER.1%,%system.build.vcs.number%,%system.build.vcs.number.1%,%system.build.number.format%,%system.build.number.format.1%,%system.build.vcs.number.MYPROJECT_Web_Root%,%env.TEAMCITY_VCS_NUMBER_MYPROJECT_Web_Root%" />
Version.txt turns up like this:
,,,,,,,,
Aka, empty. What am I doing wrong? Any better way to do this?
%env.XYZ% is TeamCity's method of referring to the environment variables, if you want to use them in ITS settings anywhere.
In a batch file or via msbuild, you only want the XYZ part.
echo %BUILD_VCS_NUMBER% > \\path\to\version.txt