Import xunit tests for a C project

c
sonarcfamily

(Samuel) #1

Hello,

Must-share information:

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
    I am using sonaqube in version 6.7.1 (build 35068) with the C plugin.

  • what are you trying to achieve

I would want to import a xunit xml file generated by cmocka.
Here a short example of this kind of file (named tests.xml) :

<?xml version="1.0" encoding="UTF-8" ?>

< testsuites>
< testsuite name=“tests” time=“0.001” tests=“2” failures=“0” errors=“0” skipped=“0” >
< testcase name=“test_chargeFicEnvAppli” time=“0.000” >
</ testcase>
< testcase name=“test_initEnvAppli” time=“0.000” >
</ testcase>
</ testsuite>
</ testsuites>

  • what have you tried so far to achieve this

I used this option in my sonar.properties to anlayze the unit XML files “sonar.cfamily.cppunit.reportsPath”

I have a problem during the analysis, the scanner seems to not be able to read my XML file.
Here the log from scanner :

09:44:29.557 INFO: Parsing /opt/town-mill/skeleton/release/townskeleton-factoryskeleton-projectskeleton-BR_SPRINT_9-cov/unit_test_output/tests.xml
09:44:29.846 INFO: ------------------------------------------------------------------------
09:44:29.846 INFO: EXECUTION FAILURE
09:44:29.846 INFO: ------------------------------------------------------------------------
09:44:29.847 INFO: Total time: 13.174s
09:44:29.997 INFO: Final Memory: 34M/155M
09:44:29.997 INFO: ------------------------------------------------------------------------
09:44:29.997 ERROR: Error during SonarQube Scanner execution
java.lang.IllegalStateException: Can not iterate children: cursor does not point to a start element (state CLOSED)
at org.codehaus.staxmate.in.SMInputCursor.childCursor(SMInputCursor.java:1659)
at org.codehaus.staxmate.in.SMInputCursor.childCursor(SMInputCursor.java:1687)
at com.sonar.cpp.plugin.A.A$1.stream(na:541)
at org.sonar.api.utils.StaxParser.parse(StaxParser.java:115)
at org.sonar.api.utils.StaxParser.parse(StaxParser.java:95)
at org.sonar.api.utils.StaxParser.parse(StaxParser.java:85)
at com.sonar.cpp.plugin.A.A.A(na:1292)
at com.sonar.cpp.plugin.A.B.A(na:2609)
at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
at java.util.Iterator.forEachRemaining(Iterator.java:116)
at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)
at com.sonar.cpp.plugin.A.B.A(na:1760)
at com.sonar.cpp.plugin.A.B.execute(na:2382)
at org.sonar.scanner.sensor.SensorWrapper.analyse(SensorWrapper.java:53)
at org.sonar.scanner.phases.SensorsExecutor.executeSensor(SensorsExecutor.java:88)
at org.sonar.scanner.phases.SensorsExecutor.execute(SensorsExecutor.java:82)
at org.sonar.scanner.phases.SensorsExecutor.execute(SensorsExecutor.java:68)
at org.sonar.scanner.phases.AbstractPhaseExecutor.execute(AbstractPhaseExecutor.java:88)
at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:180)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:135)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:121)
at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:288)
at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:283)
at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:261)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:135)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:121)
at org.sonar.scanner.task.ScanTask.execute(ScanTask.java:48)
at org.sonar.scanner.task.TaskContainer.doAfterStart(TaskContainer.java:84)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:135)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:121)
at org.sonar.scanner.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:121)
at org.sonar.batch.bootstrapper.Batch.doExecuteTask(Batch.java:116)
at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:71)
at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
at com.sun.proxy.$Proxy0.execute(Unknown Source)
at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:171)
at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:128)
at org.sonarsource.scanner.cli.Main.execute(Main.java:111)
at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
at org.sonarsource.scanner.cli.Main.main(Main.java:61)

Is it possible and how to do to analyze a xunit file for a C project with the C plugin ?

Thank you


(Chris Williams) #2

I am having the same problem. Have you found a solution?


(Samuel) #3

No i am still looking for a solution


(Frank Lichtenheld) #4

The problem is that CPPUnit XML != XUnit XML. cmocka outputs xunit but the C/C++ plugin only supports cppunit format.