Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 29 additions & 18 deletions lib/rtoolsHCK.rb
Original file line number Diff line number Diff line change
Expand Up @@ -857,16 +857,23 @@ def apply_test_result_filters(result,
#
# == Params:
#
# +test+:: The id of the test, use list_tests action to get it
# +test_id+:: The id of the test, use list_tests action to get it
# If id is nil, all tests results will be listed
# +target+:: The key of the target, use list_machine_targets to get it
# +project+:: The name of the project
# +machine+:: The name of the machine as registered with the HCK\HLK
# controller
# +pool+:: The name of the pool
def list_test_results(test, target, project, machine, pool)
def list_test_results(test_id, target, project, machine, pool)
test_id = if test_id.nil?
'$null'
else
"'#{test_id}'"
end

handle_action_exceptions(__method__) do
cmd_line = [
"listtestresults '#{test}' '#{target}' '#{project}' '#{machine}' " \
"listtestresults #{test_id} '#{target}' '#{project}' '#{machine}' " \
"'#{pool}'"
]
cmd_line << 'json' if @json
Expand All @@ -882,26 +889,30 @@ def list_test_results(test, target, project, machine, pool)
#
# == Params:
#
# +result+:: The index of the test result, use list_test_results action
# to get it
# +test+:: The id of the test, use list_tests action to get it
# +target+:: The key of the target, use list_machine_targets to get it
# +project+:: The name of the project
# +machine+:: The name of the machine as registered with the HCK\HLK
# controller
# +pool+:: The name of the pool
def zip_test_result_logs(result,
test,
target,
project,
machine,
pool)
# +result_index+:: If index_instance_id is false the index of the test result,
# use list_test_results action to get it
# If index_instance_id is true the instance id of the test result
# +test+:: The id of the test, use list_tests action to get it
# +target+:: The key of the target, use list_machine_targets to get it
# +project+:: The name of the project
# +machine+:: The name of the machine as registered with the HCK\HLK
# controller
# +pool+:: The name of the pool
# +index_instance_id+:: If true, the result_index is treated as an instance id
def zip_test_result_logs(result_index:,
test:,
target:,
project:,
machine:,
pool:,
index_instance_id: false)
handle_action_exceptions(__method__) do
cmd_line = [
"ziptestresultlogs '#{result}' '#{test}' '#{target}' " \
"ziptestresultlogs '#{result_index}' '#{test}' '#{target}' " \
"'#{project}' '#{machine}' '#{pool}'"
]
cmd_line << 'json' if @json
cmd_line << '-indexinstanceid' if index_instance_id

stream = @toolshck_ether.cmd(cmd_line.join(' '))
test_results = handle_return(stream)
Expand Down
2 changes: 1 addition & 1 deletion lib/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
# rtoolsHCK version extend to class
class RToolsHCK
# Current rtoolsHCK version
VERSION = '0.5.3'
VERSION = '0.6.0'
end
174 changes: 99 additions & 75 deletions tools/toolsHCK.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ if ($env:WTTSTDIO -like "*\Hardware Certification Kit\*") {
}

##
$Version = "0.5.3"
$Version = "0.6.0"
$MaxJsonDepth = 6
##

Expand Down Expand Up @@ -1740,12 +1740,20 @@ function applytestresultfilters {
# ListTestResults
function listtestresults {
[CmdletBinding()]
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)
param(
[Switch]$help,
[Parameter(Position=1)][AllowNull()][String]$testid,
[Parameter(Position=2)][String]$target,
[Parameter(Position=3)][String]$project,
[Parameter(Position=4)][String]$machine,
[Parameter(Position=5)][String]$pool
)

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

if ([String]::IsNullOrEmpty($test)) {
if (-Not $json) {
Write-Output "WARNING: Please provide a test's id."
Usage; return
} else {
throw "Please provide a test's id."
}
}
if ([String]::IsNullOrEmpty($target)) {
if (-Not $json) {
Write-Output "WARNING: Please provide a target's key."
Expand Down Expand Up @@ -1834,89 +1834,107 @@ function listtestresults {
}

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

if (-Not ($WntdTest = $WntdTests | Where-Object { $_.Id -eq $test })) { throw "Didn't find a test with the id given." }

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

if (-Not $json) {
Write-Output ""
Write-Output "The requested project test's results:"
Write-Output ""
$testresultlist = New-Object System.Collections.ArrayList
foreach ($WntdTest in $WntdTests) {
$WntdResults = $WntdTest.GetTestResults()

foreach ($tTestResult in $WntdResults) {
$tTestResult.Refresh()
Write-Output "============================================="
Write-Output "Test result index : $($WntdResults.IndexOf($tTestResult))"
if (-Not $json) {
Write-Output ""
Write-Output " Test name : $($tTestResult.Test.Name)"
Write-Output " Completion time : $($tTestResult.CompletionTime)"
Write-Output " Schedule time : $($tTestResult.ScheduleTime)"
Write-Output " Start time : $($tTestResult.StartTime)"
Write-Output " Status : $($tTestResult.Status)"
Write-Output " Are filters applied : $($tTestResult.AreFiltersApplied)"
Write-Output " Target name : $($tTestResult.Target.Name)"
Write-Output " Tasks :"
foreach ($tTask in $tTestResult.GetTasks()) {
Write-Output " $($tTask.Name):"
Write-Output " Stage : $($tTask.Stage)"
Write-Output " Status : $($tTask.Status)"
if (-Not [String]::IsNullOrEmpty($tTask.TaskErrorMessage)) {
Write-Output " Task error message : $($tTask.TaskErrorMessage)"
}
Write-Output " Task type : $($tTask.TaskType)"
if ($tTask.GetChildTasks()) {
Write-Output " Sub tasks :"

foreach ($subtTask in $tTask.GetChildTasks()) {
Write-Output " $($subtTask.Name):"
Write-Output " Stage : $($subtTask.Stage)"
Write-Output " Status : $($subtTask.Status)"
if (-Not [String]::IsNullOrEmpty($subtTask.TaskErrorMessage)) {
Write-Output " Task error message : $($subtTask.TaskErrorMessage)"
}
Write-Output " Task type : $($subtTask.TaskType)"
if (-Not ($subtTask -eq $tTask.GetChildTasks()[-1])) {
Write-Output ""
Write-Output "The requested project test's results:"
Write-Output "Test name: $($WntdTest.Name)"
Write-Output ""

foreach ($tTestResult in $WntdResults) {
$tTestResult.Refresh()
Write-Output "============================================="
Write-Output "Test result index : $($WntdResults.IndexOf($tTestResult))"
Write-Output ""
Write-Output " Test name : $($tTestResult.Test.Name)"
Write-Output " Completion time : $($tTestResult.CompletionTime)"
Write-Output " Schedule time : $($tTestResult.ScheduleTime)"
Write-Output " Start time : $($tTestResult.StartTime)"
Write-Output " Status : $($tTestResult.Status)"
Write-Output " Are filters applied : $($tTestResult.AreFiltersApplied)"
Write-Output " Target name : $($tTestResult.Target.Name)"
Write-Output " Tasks :"
foreach ($tTask in $tTestResult.GetTasks()) {
Write-Output " $($tTask.Name):"
Write-Output " Stage : $($tTask.Stage)"
Write-Output " Status : $($tTask.Status)"
if (-Not [String]::IsNullOrEmpty($tTask.TaskErrorMessage)) {
Write-Output " Task error message : $($tTask.TaskErrorMessage)"
}
Write-Output " Task type : $($tTask.TaskType)"
if ($tTask.GetChildTasks()) {
Write-Output " Sub tasks :"

foreach ($subtTask in $tTask.GetChildTasks()) {
Write-Output " $($subtTask.Name):"
Write-Output " Stage : $($subtTask.Stage)"
Write-Output " Status : $($subtTask.Status)"
if (-Not [String]::IsNullOrEmpty($subtTask.TaskErrorMessage)) {
Write-Output " Task error message : $($subtTask.TaskErrorMessage)"
}
Write-Output " Task type : $($subtTask.TaskType)"
if (-Not ($subtTask -eq $tTask.GetChildTasks()[-1])) {
Write-Output ""
}
}
}
Write-Output ""
}
Write-Output ""
Write-Output "============================================="
}
Write-Output "============================================="
}
} else {
$testresultlist = New-Object System.Collections.ArrayList

foreach ($tTestResult in $WntdResults) {
$tTestResult.Refresh()
$taskslist = New-Object System.Collections.ArrayList
} else {
foreach ($tTestResult in $WntdResults) {
$tTestResult.Refresh()
$taskslist = New-Object System.Collections.ArrayList

foreach ($tTask in $tTestResult.GetTasks()) {
$subtaskslist = New-Object System.Collections.ArrayList
foreach ($tTask in $tTestResult.GetTasks()) {
$subtaskslist = New-Object System.Collections.ArrayList

if ($tTask.GetChildTasks()) {
foreach ($subtTask in $tTask.GetChildTasks()) {
$subtasktype = (New-Task $subtTask.Name $subtTask.Stage $subtTask.Status.ToString() $subtTask.TaskErrorMessage $subtTask.TaskType (New-Object System.Collections.ArrayList))
$subtaskslist.Add($subtasktype) | Out-Null
if ($tTask.GetChildTasks()) {
foreach ($subtTask in $tTask.GetChildTasks()) {
$subtasktype = (New-Task $subtTask.Name $subtTask.Stage $subtTask.Status.ToString() $subtTask.TaskErrorMessage $subtTask.TaskType (New-Object System.Collections.ArrayList))
$subtaskslist.Add($subtasktype) | Out-Null
}
}
$tasktype = (New-Task $tTask.Name $tTask.Stage $tTask.Status.ToString() $tTask.TaskErrorMessage $tTask.TaskType $subtaskslist)
$taskslist.Add($tasktype) | Out-Null
}
$tasktype = (New-Task $tTask.Name $tTask.Stage $tTask.Status.ToString() $tTask.TaskErrorMessage $tTask.TaskType $subtaskslist)
$taskslist.Add($tasktype) | Out-Null
}

$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
$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
}
}
}

if ($json) {
ConvertTo-Json @($testresultlist) -Depth $MaxJsonDepth -Compress
}
}
#
# ZipTestResultLogs
function ziptestresultlogs {
[CmdletBinding()]
param([Switch]$help, [Parameter(Position=1)][String]$result, [Parameter(Position=2)][String]$test, [Parameter(Position=3)][String]$target, [Parameter(Position=4)][String]$project, [Parameter(Position=5)][String]$machine, [Parameter(Position=6)][String]$pool)
param(
[Switch]$help,
[Switch]$indexinstanceid,
[Parameter(Position=1)][String]$resultindex,
[Parameter(Position=2)][String]$test,
[Parameter(Position=3)][String]$target,
[Parameter(Position=4)][String]$project,
[Parameter(Position=5)][String]$machine,
[Parameter(Position=6)][String]$pool
)

function Usage {
Write-Output "ziptestresultlogs:"
Expand Down Expand Up @@ -1952,7 +1970,7 @@ function ziptestresultlogs {
if (-Not $json) { Usage; return } else { throw "Help requested, ignoring..." }
}

if ([String]::IsNullOrEmpty($result)) {
if ([String]::IsNullOrEmpty($resultindex)) {
if (-Not $json) {
Write-Output "WARNING: Please provide a test result's index."
Usage; return
Expand Down Expand Up @@ -2024,7 +2042,13 @@ function ziptestresultlogs {

if (-Not ($WntdTest = $WntdTests | Where-Object { $_.Id -eq $test })) { throw "Didn't find a test with the id given." }

if (-Not ($WntdResult = $WntdTest.GetTestResults()[$result])) { throw "Invalid test result index, can't find the test result." } else { $WntdLogs = $WntdResult.GetLogs() }
if ($indexinstanceid) {
if (-Not ($WntdResult = $WntdTest.GetTestResults() | Where-Object { $_.InstanceId -eq $resultindex }))
{ throw "Invalid test result instance id, can't find the test result." } else { $WntdLogs = $WntdResult.GetLogs() }
} else {
if (-Not ($WntdResult = $WntdTest.GetTestResults()[$resultindex]))
{ throw "Invalid test result index, can't find the test result." } else { $WntdLogs = $WntdResult.GetLogs() }
}
if (-Not ($WntdLogs.Count -ge 1)) { throw "There are no logs to be zipped in the test result." }

$DayStamp = $(get-date).ToString("dd-MM-yyyy")
Expand All @@ -2033,7 +2057,7 @@ function ziptestresultlogs {
$SafeTestName = ($WntdTest.Name -replace '[^\w\-\.]', '_').Trim('_')

$LogsDir = $env:TEMP + "\prometheus_test_logs\$DayStamp\[$TimeStamp]" + $WntdTest.Id
$ZipPath = $env:TEMP + "\prometheus_test_logs\$DayStamp\$DayStamp" + "_" + $TimeStamp + "_" + $SafeTestName + ".zip"
$ZipPath = $env:TEMP + "\prometheus_test_logs\$DayStamp\$DayStamp" + "_" + $TimeStamp + "_" + $WntdResult.InstanceId + "_" + $SafeTestName + ".zip"

if (-Not $json) {
Write-Output "The test has $($WntdResult.Status)!."
Expand Down