From 76febb85fd3cbfa8daa76421f780d49107d1fd98 Mon Sep 17 00:00:00 2001 From: Konstantin Kostiuk Date: Thu, 20 Mar 2025 11:18:38 +0200 Subject: [PATCH 1/4] Add ability to zip test result logs by result instance id Signed-off-by: Konstantin Kostiuk --- lib/rtoolsHCK.rb | 26 +++++++++++++++----------- tools/toolsHCK.ps1 | 23 +++++++++++++++++++---- 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/lib/rtoolsHCK.rb b/lib/rtoolsHCK.rb index 106e480..33438a1 100755 --- a/lib/rtoolsHCK.rb +++ b/lib/rtoolsHCK.rb @@ -882,26 +882,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, + # +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) + 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) diff --git a/tools/toolsHCK.ps1 b/tools/toolsHCK.ps1 index b0c6068..49fbbd0 100644 --- a/tools/toolsHCK.ps1 +++ b/tools/toolsHCK.ps1 @@ -1916,7 +1916,16 @@ function listtestresults { # 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:" @@ -1952,7 +1961,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 @@ -2024,7 +2033,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") @@ -2033,7 +2048,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)!." From 0a59c7b9e3c60d766a57a32f4770cce0a07b3151 Mon Sep 17 00:00:00 2001 From: Konstantin Kostiuk Date: Mon, 31 Mar 2025 15:56:37 +0300 Subject: [PATCH 2/4] Use keyword arguments for zip_test_result_logs Signed-off-by: Konstantin Kostiuk --- lib/rtoolsHCK.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/rtoolsHCK.rb b/lib/rtoolsHCK.rb index 33438a1..5bde42c 100755 --- a/lib/rtoolsHCK.rb +++ b/lib/rtoolsHCK.rb @@ -892,12 +892,12 @@ def list_test_results(test, target, project, machine, pool) # 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, + def zip_test_result_logs(result_index:, + test:, + target:, + project:, + machine:, + pool:, index_instance_id: false) handle_action_exceptions(__method__) do cmd_line = [ From 5d277ea1c86d2ddc6bd55885a1a996ee3dad4c0c Mon Sep 17 00:00:00 2001 From: Konstantin Kostiuk Date: Thu, 20 Mar 2025 11:23:53 +0200 Subject: [PATCH 3/4] listtestresults: Allow test_id to be null In this case, all results will be listed. Signed-off-by: Konstantin Kostiuk --- lib/rtoolsHCK.rb | 13 +++- tools/toolsHCK.ps1 | 149 ++++++++++++++++++++++++--------------------- 2 files changed, 89 insertions(+), 73 deletions(-) diff --git a/lib/rtoolsHCK.rb b/lib/rtoolsHCK.rb index 5bde42c..0519d41 100755 --- a/lib/rtoolsHCK.rb +++ b/lib/rtoolsHCK.rb @@ -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 diff --git a/tools/toolsHCK.ps1 b/tools/toolsHCK.ps1 index 49fbbd0..54c00e9 100644 --- a/tools/toolsHCK.ps1 +++ b/tools/toolsHCK.ps1 @@ -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:" @@ -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." @@ -1834,81 +1834,90 @@ 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 ([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 ($WntdTest.GetTestResults().Count -ge 1)) { throw "The test hasen't been queued, can't find test results." } else { $WntdResults = $WntdTest.GetTestResults() } + $testresultlist = New-Object System.Collections.ArrayList + foreach ($WntdTest in $WntdTests) { + $WntdResults = $WntdTest.GetTestResults() - if (-Not $json) { - Write-Output "" - Write-Output "The requested project test's results:" - Write-Output "" - - 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 } } From cbcb2179b8484f6a814a3a9206ffce9a5a79b010 Mon Sep 17 00:00:00 2001 From: Konstantin Kostiuk Date: Thu, 20 Mar 2025 11:25:39 +0200 Subject: [PATCH 4/4] Bump rtoolsHCK version (0.6.0) Signed-off-by: Konstantin Kostiuk --- lib/version.rb | 2 +- tools/toolsHCK.ps1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/version.rb b/lib/version.rb index 7866fa2..2a45143 100644 --- a/lib/version.rb +++ b/lib/version.rb @@ -3,5 +3,5 @@ # rtoolsHCK version extend to class class RToolsHCK # Current rtoolsHCK version - VERSION = '0.5.3' + VERSION = '0.6.0' end diff --git a/tools/toolsHCK.ps1 b/tools/toolsHCK.ps1 index 54c00e9..9e1d91d 100644 --- a/tools/toolsHCK.ps1 +++ b/tools/toolsHCK.ps1 @@ -40,7 +40,7 @@ if ($env:WTTSTDIO -like "*\Hardware Certification Kit\*") { } ## -$Version = "0.5.3" +$Version = "0.6.0" $MaxJsonDepth = 6 ##