From d99eab709adf42d2c5504e5da511d88508ce15a0 Mon Sep 17 00:00:00 2001 From: Abhishek Tiwari Date: Tue, 13 Aug 2024 16:10:23 +0530 Subject: [PATCH] Add TestCategory and MachineName to JUnitReport --- LISAv2-Framework.psm1 | 2 +- Libraries/TestReport.psm1 | 12 ++++++++++-- TestControllers/TestController.psm1 | 30 ++++++++++++++++++----------- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/LISAv2-Framework.psm1 b/LISAv2-Framework.psm1 index 398bf24879..b815434b4a 100644 --- a/LISAv2-Framework.psm1 +++ b/LISAv2-Framework.psm1 @@ -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 diff --git a/Libraries/TestReport.psm1 b/Libraries/TestReport.psm1 index a65f6ce8f2..0382c2cf87 100644 --- a/Libraries/TestReport.psm1 +++ b/Libraries/TestReport.psm1 @@ -123,8 +123,9 @@ Class JUnitReportGenerator [System.Xml.XmlElement] $ReportRootNode [object] $TestSuiteLogTable [object] $TestSuiteCaseLogTable - - JUnitReportGenerator([string]$ReportPath) + [string] $TestCategory + [string] $MachineName + JUnitReportGenerator([string]$ReportPath,[string]$TestCategory,[string]$MachineName) { $this.JunitReportPath = $ReportPath $this.JunitReport = New-Object System.Xml.XmlDocument @@ -132,6 +133,8 @@ Class JUnitReportGenerator $this.ReportRootNode = $this.JunitReport.AppendChild($newElement) $this.TestSuiteLogTable = @{} $this.TestSuiteCaseLogTable = @{} + $this.TestCategory=$TestCategory + $this.MachineName=$MachineName } [void] SaveLogReport() @@ -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("MachineName", $this.MachineName) + if ( $global:BaseOSVHD ) { + $newElement.SetAttribute("ImageUnderTest", $global:BaseOSVHD ) + } $testsuiteNode = $this.ReportRootNode.AppendChild($newElement) $testsuite = [ReportNode]::New($testsuiteNode) diff --git a/TestControllers/TestController.psm1 b/TestControllers/TestController.psm1 index 26d3937a0e..afcae798eb 100644 --- a/TestControllers/TestController.psm1 +++ b/TestControllers/TestController.psm1 @@ -53,6 +53,7 @@ Class TestController { [string] $RGIdentifier [string] $OsVHD [string] $TestCategory + [string] $MachineName [string] $TestNames [string] $TestArea [string] $TestTag @@ -270,6 +271,7 @@ Class TestController { $this.SetupTypeToTestCases = @{} $this.SetupTypeTable = @{} $allTests = $null + $this.MachineName="" $SetupTypeXMLs = Get-ChildItem -Path "$WorkingDirectory\XML\VMConfigurations\*.xml" foreach ($file in $SetupTypeXMLs.FullName) { $setupXml = [xml]( Get-Content -Path $file) @@ -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 "MachineName") { + $this.MachineName=$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." } @@ -323,12 +330,13 @@ Class TestController { } } if (!$allTests) { - Throw "Not able to collect any test cases from XML files" - } - else { - $collectedTCCount = $allTests.Count - Write-LogInfo "$collectedTCCount Test Cases have been collected" + Write-LogWarn "Not able to collect any test cases from XML files" + return } + + $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" @@ -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.MachineName) $this.JunitReport.StartLogTestSuite("LISAv2Test-$($this.TestPlatform)") $this.TestSummary = [TestSummary]::New($this.TestCategory, $this.TestArea, $this.TestNames, $this.TestTag, $this.TestPriority, $this.TotalCaseNum)