Skip to content

Commit

Permalink
Add TestCategory and MachineName to JUnitReport
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhishek Tiwari authored and snipex111 committed Jan 2, 2025
1 parent e94713a commit 8775898
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 42 deletions.
2 changes: 1 addition & 1 deletion LISAv2-Framework.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ function Start-LISAv2 {
}
}

if (($failedCount -eq 0 -and $errorCount -eq 0 -and $testCount -gt 0) -or (-not $RunInParallel -and $TestIdInParallel)) {
if (($failedCount -eq 0 -and $errorCount -eq 0 -and $testCount -ge 0) -or (-not $RunInParallel -and $TestIdInParallel)) {
$ExitCode = 0
} else {
$ExitCode = 1
Expand Down
12 changes: 10 additions & 2 deletions Libraries/TestReport.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,18 @@ Class JUnitReportGenerator
[System.Xml.XmlElement] $ReportRootNode
[object] $TestSuiteLogTable
[object] $TestSuiteCaseLogTable

JUnitReportGenerator([string]$ReportPath)
[string] $TestCategory
[string] $ovlname
JUnitReportGenerator([string]$ReportPath,[string]$TestCategory,[string]$ovlname)
{
$this.JunitReportPath = $ReportPath
$this.JunitReport = New-Object System.Xml.XmlDocument
$newElement = $this.JunitReport.CreateElement("testsuites")
$this.ReportRootNode = $this.JunitReport.AppendChild($newElement)
$this.TestSuiteLogTable = @{}
$this.TestSuiteCaseLogTable = @{}
$this.TestCategory=$TestCategory
$this.ovlname=$ovlname
}

[void] SaveLogReport()
Expand All @@ -156,6 +159,11 @@ Class JUnitReportGenerator
$newElement.SetAttribute("errors", 0)
$newElement.SetAttribute("skipped", 0)
$newElement.SetAttribute("time", 0)
$newElement.SetAttribute("TestCategory", $this.TestCategory)
$newElement.SetAttribute("ovlname", $this.ovlname)
if ( $global:BaseOSVHD ) {
$newElement.SetAttribute("ImageUnderTest", $global:BaseOSVHD )
}
$testsuiteNode = $this.ReportRootNode.AppendChild($newElement)

$testsuite = [ReportNode]::New($testsuiteNode)
Expand Down
86 changes: 47 additions & 39 deletions TestControllers/TestController.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Class TestController {
[string] $RGIdentifier
[string] $OsVHD
[string] $TestCategory
[string] $ovlname
[string] $TestNames
[string] $TestArea
[string] $TestTag
Expand Down Expand Up @@ -270,6 +271,7 @@ Class TestController {
$this.SetupTypeToTestCases = @{}
$this.SetupTypeTable = @{}
$allTests = $null
$this.ovlname=""
$SetupTypeXMLs = Get-ChildItem -Path "$WorkingDirectory\XML\VMConfigurations\*.xml"
foreach ($file in $SetupTypeXMLs.FullName) {
$setupXml = [xml]( Get-Content -Path $file)
Expand Down Expand Up @@ -302,11 +304,16 @@ Class TestController {
foreach ($CustomParameter in $CustomTestParameters) {
$ReplaceThis = $CustomParameter.Split("=")[0]
$ReplaceWith = $CustomParameter.Substring($CustomParameter.IndexOf("=") + 1)
$OldValue = ($ReplaceableTestParameters.ReplaceableTestParameters.Parameter | Where-Object `
{ $_.ReplaceThis -eq $ReplaceThis }).ReplaceWith
($ReplaceableTestParameters.ReplaceableTestParameters.Parameter | Where-Object `
{ $_.ReplaceThis -eq $ReplaceThis }).ReplaceWith = $ReplaceWith
Write-LogInfo "Custom Parameter: $ReplaceThis=$OldValue --> $ReplaceWith"
if($ReplaceThis -eq "ovlname") {
$this.ovlname=$ReplaceWith
}
else {
$OldValue = ($ReplaceableTestParameters.ReplaceableTestParameters.Parameter | Where-Object `
{ $_.ReplaceThis -eq $ReplaceThis }).ReplaceWith
($ReplaceableTestParameters.ReplaceableTestParameters.Parameter | Where-Object `
{ $_.ReplaceThis -eq $ReplaceThis }).ReplaceWith = $ReplaceWith
Write-LogInfo "Custom Parameter: $ReplaceThis=$OldValue --> $ReplaceWith"
}
}
Write-LogInfo "Custom parameter(s) are ready to be injected along with default parameters, if any."
}
Expand All @@ -323,47 +330,48 @@ Class TestController {
}
}
if (!$allTests) {
Throw "Not able to collect any test cases from XML files"
Write-LogWarn "Not able to collect any test cases from XML files"
}
else {
$collectedTCCount = $allTests.Count
Write-LogInfo "$collectedTCCount Test Cases have been collected"
}
$this.PrepareSetupTypeToTestCases($this.SetupTypeToTestCases, $allTests)
if (($this.TotalCaseNum -eq 0) -or ($allTests.Count -eq 0)) {
Write-LogWarn "All collected test cases are skipped, because the test case has native SetupConfig that conflicts with current Run-LISAv2 parameters, or LISAv2 needs more specific parameters to run against selected test cases, please check again"
}
elseif ($collectedTCCount -ne $allTests.Count) {
Write-LogInfo "$($allTests.Count) Test Cases have been selected or expanded to be run in this LISAv2 execution, other test cases may have been skipped due to test case native SetupConfig conflicts with current Run-LISAv2 parameters"
}

if ($this.RunInParallel -and !$this.TestIdInParallel) {
if ($this.TotalCountInParallel -ge $allTests.Count) {
$this.TotalCountInParallel = $allTests.Count

$this.PrepareSetupTypeToTestCases($this.SetupTypeToTestCases, $allTests)
if (($this.TotalCaseNum -eq 0) -or ($allTests.Count -eq 0)) {
Write-LogWarn "All collected test cases are skipped, because the test case has native SetupConfig that conflicts with current Run-LISAv2 parameters, or LISAv2 needs more specific parameters to run against selected test cases, please check again"
}
for ($pIndex = 1; $pIndex -le $this.TotalCountInParallel; $pIndex++) {
$index = 0..$($allTests.Count - 1) | Where-Object { [int]($_ + 1) % $this.TotalCountInParallel -eq $($pIndex % $this.TotalCountInParallel)}
$parallelTest = $allTests | Select-Object -Index $index
$targetTestsFolder = Join-Path -Path $env:TEMP -ChildPath "$global:TestId-$pIndex"
if (!(Test-Path -Path $targetTestsFolder)) {
New-Item -Force -Path $targetTestsFolder -ItemType Directory
}
$parallelTestsFilePath = Join-Path -Path $targetTestsFolder -ChildPath "AllTests.xml"
if (Test-Path -Path $parallelTestsFilePath) {
Remove-Item -Force -Path $parallelTestsFilePath
elseif ($collectedTCCount -ne $allTests.Count) {
Write-LogInfo "$($allTests.Count) Test Cases have been selected or expanded to be run in this LISAv2 execution, other test cases may have been skipped due to test case native SetupConfig conflicts with current Run-LISAv2 parameters"
}

if ($this.RunInParallel -and !$this.TestIdInParallel) {
if ($this.TotalCountInParallel -ge $allTests.Count) {
$this.TotalCountInParallel = $allTests.Count
}
[xml]$parallelTestsDoc = New-Object System.Xml.XmlDocument
$dec = $parallelTestsDoc.CreateXmlDeclaration("1.0", "UTF-8", $null)
$null = $parallelTestsDoc.AppendChild($dec)
#$parallelTests.AppendChild($parallelTests.CreateComment($text))
$tcNode = $parallelTestsDoc.CreateElement("TestCases")
$parallelTest | ForEach-Object {
$null = $tcNode.AppendChild($parallelTestsDoc.ImportNode($_, $true))
for ($pIndex = 1; $pIndex -le $this.TotalCountInParallel; $pIndex++) {
$index = 0..$($allTests.Count - 1) | Where-Object { [int]($_ + 1) % $this.TotalCountInParallel -eq $($pIndex % $this.TotalCountInParallel)}
$parallelTest = $allTests | Select-Object -Index $index
$targetTestsFolder = Join-Path -Path $env:TEMP -ChildPath "$global:TestId-$pIndex"
if (!(Test-Path -Path $targetTestsFolder)) {
New-Item -Force -Path $targetTestsFolder -ItemType Directory
}
$parallelTestsFilePath = Join-Path -Path $targetTestsFolder -ChildPath "AllTests.xml"
if (Test-Path -Path $parallelTestsFilePath) {
Remove-Item -Force -Path $parallelTestsFilePath
}
[xml]$parallelTestsDoc = New-Object System.Xml.XmlDocument
$dec = $parallelTestsDoc.CreateXmlDeclaration("1.0", "UTF-8", $null)
$null = $parallelTestsDoc.AppendChild($dec)
#$parallelTests.AppendChild($parallelTests.CreateComment($text))
$tcNode = $parallelTestsDoc.CreateElement("TestCases")
$parallelTest | ForEach-Object {
$null = $tcNode.AppendChild($parallelTestsDoc.ImportNode($_, $true))
}
$null = $parallelTestsDoc.AppendChild($tcNode)
$parallelTestsDoc.Save("$parallelTestsFilePath")
}
$null = $parallelTestsDoc.AppendChild($tcNode)
$parallelTestsDoc.Save("$parallelTestsFilePath")
}
}
}
}

[void] PrepareTestImage() {}
Expand Down Expand Up @@ -903,7 +911,7 @@ Class TestController {

Write-LogInfo "Prepare test log structure and start testing now ..."
# Start JUnit XML report logger.
$this.JunitReport = [JUnitReportGenerator]::New($TestReportXmlPath)
$this.JunitReport = [JUnitReportGenerator]::New($TestReportXmlPath,$this.TestCategory,$this.ovlname)
$this.JunitReport.StartLogTestSuite("LISAv2Test-$($this.TestPlatform)")
$this.TestSummary = [TestSummary]::New($this.TestCategory, $this.TestArea, $this.TestNames, $this.TestTag, $this.TestPriority, $this.TotalCaseNum)

Expand Down

0 comments on commit 8775898

Please sign in to comment.