ctest2junit.xsl 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  2. <xsl:param name="pass" select="'this'"/>
  3. <xsl:output method="xml" indent="yes"/>
  4. <!-- convert ctest output to junit format -->
  5. <!--
  6. Inspired by https://stackoverflow.com/questions/6329215/how-to-get-ctest-results-in-hudson-jenkins
  7. Based on https://github.com/zanata/zanata-tests/blob/master/scripts/CTest2JUnit.xsl
  8. Extended by providing total Start date, total time, total test stats
  9. -->
  10. <xsl:template match="/Site">
  11. <xsl:variable name="StartDate"><xsl:value-of select="Testing/StartDateTime"/></xsl:variable>
  12. <xsl:variable name="DoTime"><xsl:value-of select="Testing/EndTestTime - Testing/StartTestTime"/></xsl:variable>
  13. <xsl:variable name="TotalTests"><xsl:value-of select="count(Testing/Test)"/></xsl:variable>
  14. <xsl:variable name="Skipped"><xsl:value-of select="count(Testing/Test[@Status='notrun'])"/></xsl:variable>
  15. <xsl:variable name="Disabled"><xsl:value-of select="count(Testing/Test/Results/Measurement[Value='Disabled'])"/></xsl:variable>
  16. <xsl:variable name="Failed"><xsl:value-of select="count(Testing/Test[@Status='failed'])"/></xsl:variable>
  17. <testsuite time="{$DoTime}" timestamp="{$StartDate}" tests="{$TotalTests}" failures="{$Failed}" skipped="{$Skipped}" disabled="{$Disabled}">
  18. <xsl:variable name="BuildName"><xsl:value-of select="@BuildName"/></xsl:variable>
  19. <xsl:variable name="BuildStamp"><xsl:value-of select="@BuildStamp"/></xsl:variable>
  20. <xsl:variable name="Name"><xsl:value-of select="@Name"/></xsl:variable>
  21. <xsl:variable name="Generator"><xsl:value-of select="@Generator"/></xsl:variable>
  22. <xsl:variable name="CompilerName"><xsl:value-of select="@CompilerName"/></xsl:variable>
  23. <xsl:variable name="OSName"><xsl:value-of select="@OSName"/></xsl:variable>
  24. <xsl:variable name="Hostname"><xsl:value-of select="@Hostname"/></xsl:variable>
  25. <xsl:variable name="OSRelease"><xsl:value-of select="@OSRelease"/></xsl:variable>
  26. <xsl:variable name="OSVersion"><xsl:value-of select="@OSVersion"/></xsl:variable>
  27. <xsl:variable name="OSPlatform"><xsl:value-of select="@OSPlatform"/></xsl:variable>
  28. <xsl:variable name="Is64Bits"><xsl:value-of select="@Is64Bits"/></xsl:variable>
  29. <xsl:variable name="VendorString"><xsl:value-of select="@VendorString"/></xsl:variable>
  30. <xsl:variable name="VendorID"><xsl:value-of select="@VendorID"/></xsl:variable>
  31. <xsl:variable name="FamilyID"><xsl:value-of select="@FamilyID"/></xsl:variable>
  32. <xsl:variable name="ModelID"><xsl:value-of select="@ModelID"/></xsl:variable>
  33. <xsl:variable name="ProcessorCacheSize"><xsl:value-of select="@ProcessorCacheSize"/></xsl:variable>
  34. <xsl:variable name="NumberOfLogicalCPU"><xsl:value-of select="@NumberOfLogicalCPU"/></xsl:variable>
  35. <xsl:variable name="NumberOfPhysicalCPU"><xsl:value-of select="@NumberOfPhysicalCPU"/></xsl:variable>
  36. <xsl:variable name="TotalVirtualMemory"><xsl:value-of select="@TotalVirtualMemory"/></xsl:variable>
  37. <xsl:variable name="TotalPhysicalMemory"><xsl:value-of select="@TotalPhysicalMemory"/></xsl:variable>
  38. <xsl:variable name="LogicalProcessorsPerPhysical"><xsl:value-of select="@LogicalProcessorsPerPhysical"/></xsl:variable>
  39. <xsl:variable name="ProcessorClockFrequency"><xsl:value-of select="@ProcessorClockFrequency"/></xsl:variable>
  40. <properties>
  41. <property name="BuildName" value="{$BuildName} {$DoTime}" />
  42. <property name="BuildStamp" value="{$BuildStamp}" />
  43. <property name="Name" value="{$Name}" />
  44. <property name="Generator" value="{$Generator}" />
  45. <property name="CompilerName" value="{$CompilerName}" />
  46. <property name="OSName" value="{$OSName}" />
  47. <property name="Hostname" value="{$Hostname}" />
  48. <property name="OSRelease" value="{$OSRelease}" />
  49. <property name="OSVersion" value="{$OSVersion}" />
  50. <property name="OSPlatform" value="{$OSPlatform}" />
  51. <property name="Is64Bits" value="{$Is64Bits}" />
  52. <property name="VendorString" value="{$VendorString}" />
  53. <property name="VendorID" value="{$VendorID}" />
  54. <property name="FamilyID" value="{$FamilyID}" />
  55. <property name="ModelID" value="{$ModelID}" />
  56. <property name="ProcessorCacheSize" value="{$ProcessorCacheSize}" />
  57. <property name="NumberOfLogicalCPU" value="{$NumberOfLogicalCPU}" />
  58. <property name="NumberOfPhysicalCPU" value="{$NumberOfPhysicalCPU}" />
  59. <property name="TotalVirtualMemory" value="{$TotalVirtualMemory}" />
  60. <property name="TotalPhysicalMemory" value="{$TotalPhysicalMemory}" />
  61. <property name="LogicalProcessorsPerPhysical" value="{$LogicalProcessorsPerPhysical}" />
  62. <property name="ProcessorClockFrequency" value="{$ProcessorClockFrequency}" />
  63. </properties>
  64. <xsl:apply-templates select="Testing/Test"/>
  65. <system-out>
  66. BuildName: <xsl:value-of select="$BuildName" />
  67. BuildStamp: <xsl:value-of select="$BuildStamp" />
  68. Name: <xsl:value-of select="$Name" />
  69. Generator: <xsl:value-of select="$Generator" />
  70. CompilerName: <xsl:value-of select="$CompilerName" />
  71. OSName: <xsl:value-of select="$OSName" />
  72. Hostname: <xsl:value-of select="$Hostname" />
  73. OSRelease: <xsl:value-of select="$OSRelease" />
  74. OSVersion: <xsl:value-of select="$OSVersion" />
  75. OSPlatform: <xsl:value-of select="$OSPlatform" />
  76. Is64Bits: <xsl:value-of select="$Is64Bits" />
  77. VendorString: <xsl:value-of select="$VendorString" />
  78. VendorID: <xsl:value-of select="$VendorID" />
  79. FamilyID: <xsl:value-of select="$FamilyID" />
  80. ModelID: <xsl:value-of select="$ModelID" />
  81. ProcessorCacheSize: <xsl:value-of select="$ProcessorCacheSize" />
  82. NumberOfLogicalCPU: <xsl:value-of select="$NumberOfLogicalCPU" />
  83. NumberOfPhysicalCPU: <xsl:value-of select="$NumberOfPhysicalCPU" />
  84. TotalVirtualMemory: <xsl:value-of select="$TotalVirtualMemory" />
  85. TotalPhysicalMemory: <xsl:value-of select="$TotalPhysicalMemory" />
  86. LogicalProcessorsPerPhysical: <xsl:value-of select="$LogicalProcessorsPerPhysical" />
  87. ProcessorClockFrequency: <xsl:value-of select="$ProcessorClockFrequency" />
  88. </system-out>
  89. </testsuite>
  90. </xsl:template>
  91. <xsl:template match="Testing/Test">
  92. <xsl:variable name="testcasename"><xsl:value-of select="Name"/></xsl:variable>
  93. <xsl:variable name="testclassname"><xsl:value-of select="concat($pass, substring(Path,2))"/></xsl:variable>
  94. <xsl:variable name="exectime">
  95. <xsl:for-each select="Results/NamedMeasurement">
  96. <xsl:if test="@name='Execution Time'">
  97. <xsl:value-of select="Value"/>
  98. </xsl:if>
  99. </xsl:for-each>
  100. </xsl:variable>
  101. <testcase name="{$testcasename}" classname="{$testclassname}" time="{$exectime}">
  102. <xsl:if test="@Status = 'passed'">
  103. <system-out><xsl:value-of select="Results/Measurement/Value/text()"/></system-out>
  104. </xsl:if>
  105. <xsl:if test="@Status = 'failed'">
  106. <xsl:variable name="failtype">
  107. <xsl:for-each select="Results/NamedMeasurement">
  108. <xsl:if test="@name = 'Exit Code'">
  109. <xsl:value-of select="Value"/>
  110. </xsl:if>
  111. </xsl:for-each>
  112. </xsl:variable>
  113. <xsl:variable name="failcode">
  114. <xsl:for-each select="Results/NamedMeasurement">
  115. <xsl:if test="@name = 'Exit Value'">
  116. <xsl:value-of select="Value"/>
  117. </xsl:if>
  118. </xsl:for-each>
  119. </xsl:variable>
  120. <failure message="{$failtype} ({$failcode})"><xsl:value-of select="Results/Measurement/Value/text()" /></failure>
  121. </xsl:if>
  122. <xsl:if test="@Status = 'notrun'">
  123. <skipped><xsl:value-of select="Results/Measurement/Value/text()" /></skipped>
  124. </xsl:if>
  125. </testcase>
  126. </xsl:template>
  127. </xsl:stylesheet>