ok cool,
This commit is contained in:
+19
-3
@@ -15,6 +15,22 @@ function Get-DefaultPassword {
|
|||||||
return (Get-Content -Raw $pwPath).Trim()
|
return (Get-Content -Raw $pwPath).Trim()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Normalize-LineEndings {
|
||||||
|
param([string]$Text)
|
||||||
|
if ($null -eq $Text) {
|
||||||
|
return $null
|
||||||
|
}
|
||||||
|
return ($Text -replace "`r`n", "`n" -replace "`r", "")
|
||||||
|
}
|
||||||
|
|
||||||
|
function Quote-ShArg {
|
||||||
|
param([AllowNull()][string]$Value)
|
||||||
|
if ($null -eq $Value) {
|
||||||
|
return "''"
|
||||||
|
}
|
||||||
|
return "'" + ($Value -replace "'", ("'" + '"' + "'" + '"' + "'")) + "'"
|
||||||
|
}
|
||||||
|
|
||||||
function Invoke-Ext {
|
function Invoke-Ext {
|
||||||
param($Exe, $Arguments, $Label)
|
param($Exe, $Arguments, $Label)
|
||||||
$displayArgs = $Arguments.Clone()
|
$displayArgs = $Arguments.Clone()
|
||||||
@@ -27,8 +43,8 @@ function Invoke-Ext {
|
|||||||
|
|
||||||
$out = & $Exe @Arguments 2>&1
|
$out = & $Exe @Arguments 2>&1
|
||||||
if ($LASTEXITCODE -ne 0) {
|
if ($LASTEXITCODE -ne 0) {
|
||||||
Write-Error ("{0} failed ({1}):`n{2}" -f $Label, $LASTEXITCODE, ($out -join "`n"))
|
Write-Error ("{0} exited with code {1}:`n{2}" -f $Label, $LASTEXITCODE, ($out -join "`n"))
|
||||||
throw ("{0} failed ({1})" -f $Label, $LASTEXITCODE)
|
throw ("{0} exited with code {1}" -f $Label, $LASTEXITCODE)
|
||||||
}
|
}
|
||||||
return $out
|
return $out
|
||||||
}
|
}
|
||||||
@@ -55,7 +71,7 @@ function Invoke-Scp {
|
|||||||
|
|
||||||
function Invoke-Ssh {
|
function Invoke-Ssh {
|
||||||
param($Cmd, $User, $Remote, $Pass, [switch]$Quiet)
|
param($Cmd, $User, $Remote, $Pass, [switch]$Quiet)
|
||||||
$Cmd = $Cmd -replace "`r`n", "`n" -replace "`r", ""
|
$Cmd = Normalize-LineEndings $Cmd
|
||||||
if ($plink = Get-Command plink.exe -ErrorAction SilentlyContinue) {
|
if ($plink = Get-Command plink.exe -ErrorAction SilentlyContinue) {
|
||||||
$arguments = @('-batch', '-ssh')
|
$arguments = @('-batch', '-ssh')
|
||||||
if ($Pass) { $arguments += @('-pw', $Pass) }
|
if ($Pass) { $arguments += @('-pw', $Pass) }
|
||||||
|
|||||||
+100
-34
@@ -3,14 +3,21 @@
|
|||||||
|
|
||||||
param(
|
param(
|
||||||
[string]$Package = "lda-ipjs",
|
[string]$Package = "lda-ipjs",
|
||||||
[string]$TestName = "",
|
[switch]$AllPackages,
|
||||||
|
[string]$Filter = "",
|
||||||
|
[switch]$Exact,
|
||||||
|
[switch]$List,
|
||||||
[ValidateSet("debug", "release")]
|
[ValidateSet("debug", "release")]
|
||||||
[string]$BuildProfile = "debug",
|
[string]$BuildProfile = "debug",
|
||||||
[string]$password,
|
[string]$password,
|
||||||
[switch]$Verbose,
|
[switch]$Verbose,
|
||||||
[string]$RemoteTestPath = "/root/.bin/test",
|
[string]$RemoteTestPath = "/root/.bin/test",
|
||||||
[string]$RemoteHost = "[email protected]",
|
[string]$RemoteHost = "[email protected]",
|
||||||
[switch]$Ignored
|
[switch]$Ignored,
|
||||||
|
[switch]$IncludeIgnored,
|
||||||
|
[switch]$NoCapture,
|
||||||
|
[switch]$ShowOutput,
|
||||||
|
[int]$Threads = 0
|
||||||
)
|
)
|
||||||
|
|
||||||
$ErrorActionPreference = "Stop"
|
$ErrorActionPreference = "Stop"
|
||||||
@@ -19,49 +26,108 @@ $ErrorActionPreference = "Stop"
|
|||||||
|
|
||||||
$password = Get-DefaultPassword $password
|
$password = Get-DefaultPassword $password
|
||||||
|
|
||||||
# Build tests and capture output
|
function Get-WorkspacePackages {
|
||||||
Write-Host "Building tests for $Package..." -ForegroundColor Cyan
|
$metadata = cargo metadata --no-deps --format-version 1 | ConvertFrom-Json
|
||||||
|
$workspaceMembers = [System.Collections.Generic.HashSet[string]]::new()
|
||||||
|
foreach ($member in $metadata.workspace_members) {
|
||||||
|
[void]$workspaceMembers.Add($member)
|
||||||
|
}
|
||||||
|
|
||||||
# Stream cargo output anc convert to text
|
@(
|
||||||
$cargoOutput = cargo test --no-run -p $Package --target armv7-unknown-linux-musleabihf $(if ($BuildProfile -eq "release") { "-r" }) 2>&1 |
|
$metadata.packages |
|
||||||
|
Where-Object { $workspaceMembers.Contains($_.id) } |
|
||||||
|
Select-Object -ExpandProperty name
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function Get-TestBinaryPaths {
|
||||||
|
param([string[]]$CargoOutput)
|
||||||
|
|
||||||
|
@(
|
||||||
|
$CargoOutput |
|
||||||
|
Select-String -Pattern "Executable.*\((.+)\)" |
|
||||||
|
ForEach-Object { $_.Matches.Groups[1].Value }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function Build-RemoteExecCommand {
|
||||||
|
param(
|
||||||
|
[string]$RemotePath,
|
||||||
|
[string[]]$Arguments
|
||||||
|
)
|
||||||
|
|
||||||
|
$quotedPath = Quote-ShArg $RemotePath
|
||||||
|
$quotedArgs = @($Arguments | ForEach-Object { Quote-ShArg "$_" })
|
||||||
|
$exec = (@($quotedPath) + $quotedArgs) -join " "
|
||||||
|
"chmod +x $quotedPath && $exec"
|
||||||
|
}
|
||||||
|
|
||||||
|
$packages = if ($AllPackages) { Get-WorkspacePackages } else { @($Package) }
|
||||||
|
$failures = New-Object System.Collections.Generic.List[string]
|
||||||
|
|
||||||
|
foreach ($packageName in $packages) {
|
||||||
|
Write-Host "Building tests for $packageName..." -ForegroundColor Cyan
|
||||||
|
|
||||||
|
# Stream cargo output and convert to text
|
||||||
|
$cargoOutput = cargo test --no-run -p $packageName --target armv7-unknown-linux-musleabihf $(if ($BuildProfile -eq "release") { "-r" }) 2>&1 |
|
||||||
ForEach-Object {
|
ForEach-Object {
|
||||||
$line = if ($_ -is [System.Management.Automation.ErrorRecord]) { $_.ToString() } else { $_ }
|
$line = if ($_ -is [System.Management.Automation.ErrorRecord]) { $_.ToString() } else { $_ }
|
||||||
if ($Verbose) {
|
if ($Verbose) {
|
||||||
Write-Host $line
|
Write-Host $line
|
||||||
}
|
}
|
||||||
$line # Pass through to capture
|
$line
|
||||||
}
|
}
|
||||||
|
|
||||||
# Parse test binary paths from cargo output
|
if ($LASTEXITCODE -ne 0) {
|
||||||
$testBinaries = $cargoOutput |
|
$failures.Add("$packageName (build failed)")
|
||||||
Select-String -Pattern "Executable.*\((.+)\)" |
|
Write-Warning "Build failed for $packageName"
|
||||||
ForEach-Object { $_.Matches.Groups[1].Value } |
|
continue
|
||||||
Get-Item
|
}
|
||||||
|
|
||||||
|
$testBinaryPaths = Get-TestBinaryPaths $cargoOutput
|
||||||
|
$testBinaries = @($testBinaryPaths | Get-Item)
|
||||||
|
|
||||||
if ($testBinaries.Count -eq 0) {
|
if ($testBinaries.Count -eq 0) {
|
||||||
Write-Error "No test binaries found! Exiting..."
|
Write-Host "Skipping ${packageName}: no test executables" -ForegroundColor DarkYellow
|
||||||
# Write-Host "Cargo output:" -ForegroundColor Yellow
|
continue
|
||||||
# $cargoOutput | ForEach-Object { Write-Host $_ }
|
}
|
||||||
|
|
||||||
|
Write-Host "Found $($testBinaries.Count) test $($testBinaries.Count -eq 1 ? "binary" : "binaries") for $packageName" -ForegroundColor Green
|
||||||
|
|
||||||
|
foreach ($testBinary in $testBinaries) {
|
||||||
|
Write-Host "`nTesting: $packageName / $($testBinary.Name)" -ForegroundColor Cyan
|
||||||
|
|
||||||
|
try {
|
||||||
|
# Copy and make executable
|
||||||
|
Invoke-Scp -Local $testBinary.FullName -Dest "${RemoteHost}:$RemoteTestPath" -Pass $password -Quiet
|
||||||
|
|
||||||
|
# Build test args
|
||||||
|
$parts = @()
|
||||||
|
if ($Filter) { $parts += $Filter }
|
||||||
|
if ($Exact) { $parts += "--exact" }
|
||||||
|
if ($List) { $parts += "--list" }
|
||||||
|
if ($Ignored) { $parts += "--ignored" }
|
||||||
|
if ($IncludeIgnored) { $parts += "--include-ignored" }
|
||||||
|
if ($ShowOutput -or $Verbose) { $parts += "--show-output" }
|
||||||
|
if ($NoCapture -or $Verbose) { $parts += "--nocapture" }
|
||||||
|
if ($Threads -gt 0) { $parts += "--test-threads"; $parts += $Threads }
|
||||||
|
$remoteCmd = Build-RemoteExecCommand -RemotePath $RemoteTestPath -Arguments $parts
|
||||||
|
|
||||||
|
# Run test binary (with chmod to ensure executable)
|
||||||
|
Invoke-Ssh -Cmd $remoteCmd -Remote $RemoteHost -Pass $password
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
$failures.Add("$packageName / $($testBinary.Name)")
|
||||||
|
Write-Warning "Test binary failed: $packageName / $($testBinary.Name)"
|
||||||
|
Write-Warning $_.Exception.Message
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($failures.Count -gt 0) {
|
||||||
|
Write-Error ("One or more test binaries failed: {0}" -f ($failures -join ", "))
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "Found $($testBinaries.Count) test $($testBinaries.Count -eq 1 ? "binary" : "binaries")" -ForegroundColor Green
|
|
||||||
|
|
||||||
# Run each test binary
|
|
||||||
foreach ($testBinary in $testBinaries) {
|
|
||||||
Write-Host "`nTesting: $($testBinary.Name)" -ForegroundColor Cyan
|
|
||||||
|
|
||||||
# Copy to target
|
|
||||||
Invoke-Scp -Local $testBinary.FullName -Dest "${RemoteHost}:$RemoteTestPath" -Pass $password -Quiet
|
|
||||||
|
|
||||||
# Run on target
|
|
||||||
$parts = @()
|
|
||||||
if ($TestName) { $parts += $TestName }
|
|
||||||
if ($Ignored) { $parts += "--ignored" }
|
|
||||||
if ($Verbose) { $parts += "--nocapture"; $parts += "--show-output" }
|
|
||||||
$testArgs = $parts -join " "
|
|
||||||
|
|
||||||
Invoke-Ssh -Cmd "chmod +x $RemoteTestPath && $RemoteTestPath $testArgs" -Remote $RemoteHost -Pass $password
|
|
||||||
}
|
|
||||||
|
|
||||||
Write-Host "`nDone!" -ForegroundColor Green
|
Write-Host "`nDone!" -ForegroundColor Green
|
||||||
|
|||||||
Reference in New Issue
Block a user