Skip to content

Commit 8671892

Browse files
kostyanf14YanVugenfirer
authored andcommitted
listtestresults: Allow test_id to be null
In this case, all results will be listed. Signed-off-by: Konstantin Kostiuk <[email protected]>
1 parent 5d0157a commit 8671892

File tree

2 files changed

+89
-73
lines changed

2 files changed

+89
-73
lines changed

lib/rtoolsHCK.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -857,16 +857,23 @@ def apply_test_result_filters(result,
857857
#
858858
# == Params:
859859
#
860-
# +test+:: The id of the test, use list_tests action to get it
860+
# +test_id+:: The id of the test, use list_tests action to get it
861+
# If id is nil, all tests results will be listed
861862
# +target+:: The key of the target, use list_machine_targets to get it
862863
# +project+:: The name of the project
863864
# +machine+:: The name of the machine as registered with the HCK\HLK
864865
# controller
865866
# +pool+:: The name of the pool
866-
def list_test_results(test, target, project, machine, pool)
867+
def list_test_results(test_id, target, project, machine, pool)
868+
test_id = if test_id.nil?
869+
'$null'
870+
else
871+
"'#{test_id}'"
872+
end
873+
867874
handle_action_exceptions(__method__) do
868875
cmd_line = [
869-
"listtestresults '#{test}' '#{target}' '#{project}' '#{machine}' " \
876+
"listtestresults #{test_id} '#{target}' '#{project}' '#{machine}' " \
870877
"'#{pool}'"
871878
]
872879
cmd_line << 'json' if @json

tools/toolsHCK.ps1

Lines changed: 79 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1740,12 +1740,20 @@ function applytestresultfilters {
17401740
# ListTestResults
17411741
function listtestresults {
17421742
[CmdletBinding()]
1743-
param([Switch]$help, [Parameter(Position=1)][String]$test, [Parameter(Position=2)][String]$target, [Parameter(Position=3)][String]$project, [Parameter(Position=4)][String]$machine, [Parameter(Position=5)][String]$pool)
1743+
param(
1744+
[Switch]$help,
1745+
[Parameter(Position=1)][AllowNull()][String]$testid,
1746+
[Parameter(Position=2)][String]$target,
1747+
[Parameter(Position=3)][String]$project,
1748+
[Parameter(Position=4)][String]$machine,
1749+
[Parameter(Position=5)][String]$pool
1750+
)
17441751

17451752
function Usage {
17461753
Write-Output "listtestresults:"
17471754
Write-Output ""
1748-
Write-Output "A script that lists all of the test results and lists them and their info."
1755+
Write-Output "A script that lists all of the test results (if testid specified) or "
1756+
Write-Output "lists all of the results for all tests (if testid '$null') and lists them and their info."
17491757
Write-Output "These tasks are done by using the HCK\HLK API provided with the Windows HCK\HLK Studio."
17501758
Write-Output ""
17511759
Write-Output "Usage:"
@@ -1774,14 +1782,6 @@ function listtestresults {
17741782
if (-Not $json) { Usage; return } else { throw "Help requested, ignoring..." }
17751783
}
17761784

1777-
if ([String]::IsNullOrEmpty($test)) {
1778-
if (-Not $json) {
1779-
Write-Output "WARNING: Please provide a test's id."
1780-
Usage; return
1781-
} else {
1782-
throw "Please provide a test's id."
1783-
}
1784-
}
17851785
if ([String]::IsNullOrEmpty($target)) {
17861786
if (-Not $json) {
17871787
Write-Output "WARNING: Please provide a target's key."
@@ -1834,81 +1834,90 @@ function listtestresults {
18341834
}
18351835

18361836
$WntdTests = New-Object System.Collections.ArrayList
1837-
$WntdPITargets | foreach { $WntdTests.AddRange($_.GetTests()) }
18381837

1839-
if (-Not ($WntdTest = $WntdTests | Where-Object { $_.Id -eq $test })) { throw "Didn't find a test with the id given." }
1838+
if ([String]::IsNullOrEmpty($testid)) {
1839+
$WntdPITargets | foreach { $WntdTests.AddRange($_.GetTests()) }
1840+
} else {
1841+
$WntdPITargets | foreach { $_.GetTests() } | Where-Object { $_.Id -eq $testid } | foreach { $WntdTests.Add($_) | Out-Null }
1842+
if ($WntdTests.Count -lt 1) { throw "Didn't find a test with the id given." }
1843+
if ($WntdTests[0].GetTestResults().Count -lt 1) { throw "The test hasen't been queued, can't find test results." }
1844+
}
18401845

1841-
if (-Not ($WntdTest.GetTestResults().Count -ge 1)) { throw "The test hasen't been queued, can't find test results." } else { $WntdResults = $WntdTest.GetTestResults() }
1846+
$testresultlist = New-Object System.Collections.ArrayList
1847+
foreach ($WntdTest in $WntdTests) {
1848+
$WntdResults = $WntdTest.GetTestResults()
18421849

1843-
if (-Not $json) {
1844-
Write-Output ""
1845-
Write-Output "The requested project test's results:"
1846-
Write-Output ""
1847-
1848-
foreach ($tTestResult in $WntdResults) {
1849-
$tTestResult.Refresh()
1850-
Write-Output "============================================="
1851-
Write-Output "Test result index : $($WntdResults.IndexOf($tTestResult))"
1850+
if (-Not $json) {
18521851
Write-Output ""
1853-
Write-Output " Test name : $($tTestResult.Test.Name)"
1854-
Write-Output " Completion time : $($tTestResult.CompletionTime)"
1855-
Write-Output " Schedule time : $($tTestResult.ScheduleTime)"
1856-
Write-Output " Start time : $($tTestResult.StartTime)"
1857-
Write-Output " Status : $($tTestResult.Status)"
1858-
Write-Output " Are filters applied : $($tTestResult.AreFiltersApplied)"
1859-
Write-Output " Target name : $($tTestResult.Target.Name)"
1860-
Write-Output " Tasks :"
1861-
foreach ($tTask in $tTestResult.GetTasks()) {
1862-
Write-Output " $($tTask.Name):"
1863-
Write-Output " Stage : $($tTask.Stage)"
1864-
Write-Output " Status : $($tTask.Status)"
1865-
if (-Not [String]::IsNullOrEmpty($tTask.TaskErrorMessage)) {
1866-
Write-Output " Task error message : $($tTask.TaskErrorMessage)"
1867-
}
1868-
Write-Output " Task type : $($tTask.TaskType)"
1869-
if ($tTask.GetChildTasks()) {
1870-
Write-Output " Sub tasks :"
1871-
1872-
foreach ($subtTask in $tTask.GetChildTasks()) {
1873-
Write-Output " $($subtTask.Name):"
1874-
Write-Output " Stage : $($subtTask.Stage)"
1875-
Write-Output " Status : $($subtTask.Status)"
1876-
if (-Not [String]::IsNullOrEmpty($subtTask.TaskErrorMessage)) {
1877-
Write-Output " Task error message : $($subtTask.TaskErrorMessage)"
1878-
}
1879-
Write-Output " Task type : $($subtTask.TaskType)"
1880-
if (-Not ($subtTask -eq $tTask.GetChildTasks()[-1])) {
1881-
Write-Output ""
1852+
Write-Output "The requested project test's results:"
1853+
Write-Output "Test name: $($WntdTest.Name)"
1854+
Write-Output ""
1855+
1856+
foreach ($tTestResult in $WntdResults) {
1857+
$tTestResult.Refresh()
1858+
Write-Output "============================================="
1859+
Write-Output "Test result index : $($WntdResults.IndexOf($tTestResult))"
1860+
Write-Output ""
1861+
Write-Output " Test name : $($tTestResult.Test.Name)"
1862+
Write-Output " Completion time : $($tTestResult.CompletionTime)"
1863+
Write-Output " Schedule time : $($tTestResult.ScheduleTime)"
1864+
Write-Output " Start time : $($tTestResult.StartTime)"
1865+
Write-Output " Status : $($tTestResult.Status)"
1866+
Write-Output " Are filters applied : $($tTestResult.AreFiltersApplied)"
1867+
Write-Output " Target name : $($tTestResult.Target.Name)"
1868+
Write-Output " Tasks :"
1869+
foreach ($tTask in $tTestResult.GetTasks()) {
1870+
Write-Output " $($tTask.Name):"
1871+
Write-Output " Stage : $($tTask.Stage)"
1872+
Write-Output " Status : $($tTask.Status)"
1873+
if (-Not [String]::IsNullOrEmpty($tTask.TaskErrorMessage)) {
1874+
Write-Output " Task error message : $($tTask.TaskErrorMessage)"
1875+
}
1876+
Write-Output " Task type : $($tTask.TaskType)"
1877+
if ($tTask.GetChildTasks()) {
1878+
Write-Output " Sub tasks :"
1879+
1880+
foreach ($subtTask in $tTask.GetChildTasks()) {
1881+
Write-Output " $($subtTask.Name):"
1882+
Write-Output " Stage : $($subtTask.Stage)"
1883+
Write-Output " Status : $($subtTask.Status)"
1884+
if (-Not [String]::IsNullOrEmpty($subtTask.TaskErrorMessage)) {
1885+
Write-Output " Task error message : $($subtTask.TaskErrorMessage)"
1886+
}
1887+
Write-Output " Task type : $($subtTask.TaskType)"
1888+
if (-Not ($subtTask -eq $tTask.GetChildTasks()[-1])) {
1889+
Write-Output ""
1890+
}
18821891
}
18831892
}
1893+
Write-Output ""
18841894
}
1885-
Write-Output ""
1895+
Write-Output "============================================="
18861896
}
1887-
Write-Output "============================================="
1888-
}
1889-
} else {
1890-
$testresultlist = New-Object System.Collections.ArrayList
1891-
1892-
foreach ($tTestResult in $WntdResults) {
1893-
$tTestResult.Refresh()
1894-
$taskslist = New-Object System.Collections.ArrayList
1897+
} else {
1898+
foreach ($tTestResult in $WntdResults) {
1899+
$tTestResult.Refresh()
1900+
$taskslist = New-Object System.Collections.ArrayList
18951901

1896-
foreach ($tTask in $tTestResult.GetTasks()) {
1897-
$subtaskslist = New-Object System.Collections.ArrayList
1902+
foreach ($tTask in $tTestResult.GetTasks()) {
1903+
$subtaskslist = New-Object System.Collections.ArrayList
18981904

1899-
if ($tTask.GetChildTasks()) {
1900-
foreach ($subtTask in $tTask.GetChildTasks()) {
1901-
$subtasktype = (New-Task $subtTask.Name $subtTask.Stage $subtTask.Status.ToString() $subtTask.TaskErrorMessage $subtTask.TaskType (New-Object System.Collections.ArrayList))
1902-
$subtaskslist.Add($subtasktype) | Out-Null
1905+
if ($tTask.GetChildTasks()) {
1906+
foreach ($subtTask in $tTask.GetChildTasks()) {
1907+
$subtasktype = (New-Task $subtTask.Name $subtTask.Stage $subtTask.Status.ToString() $subtTask.TaskErrorMessage $subtTask.TaskType (New-Object System.Collections.ArrayList))
1908+
$subtaskslist.Add($subtasktype) | Out-Null
1909+
}
19031910
}
1911+
$tasktype = (New-Task $tTask.Name $tTask.Stage $tTask.Status.ToString() $tTask.TaskErrorMessage $tTask.TaskType $subtaskslist)
1912+
$taskslist.Add($tasktype) | Out-Null
19041913
}
1905-
$tasktype = (New-Task $tTask.Name $tTask.Stage $tTask.Status.ToString() $tTask.TaskErrorMessage $tTask.TaskType $subtaskslist)
1906-
$taskslist.Add($tasktype) | Out-Null
1907-
}
19081914

1909-
$testresultlist.Add((New-TestResult $tTestResult.Test.Name $tTestResult.CompletionTime.ToString() $tTestResult.ScheduleTime.ToString() $tTestResult.StartTime.ToString() $tTestResult.Status.ToString() $tTestResult.InstanceId.ToString() $tTestResult.AreFiltersApplied.ToString() $tTestResult.Target.Name $taskslist)) | Out-Null
1915+
$testresultlist.Add((New-TestResult $tTestResult.Test.Name $tTestResult.CompletionTime.ToString() $tTestResult.ScheduleTime.ToString() $tTestResult.StartTime.ToString() $tTestResult.Status.ToString() $tTestResult.InstanceId.ToString() $tTestResult.AreFiltersApplied.ToString() $tTestResult.Target.Name $taskslist)) | Out-Null
1916+
}
19101917
}
1918+
}
19111919

1920+
if ($json) {
19121921
ConvertTo-Json @($testresultlist) -Depth $MaxJsonDepth -Compress
19131922
}
19141923
}

0 commit comments

Comments
 (0)