# Run cross-built test_*.exe inside the VM as the current user. # run_tests.ps1 BUNDLE [FILTER] # BUNDLE holds bin\ (exes, busybox.exe) and data\ (repo-relative fixtures). # Each run copies data\ into a per-user work dir and uses it as the cwd. param([Parameter(Mandatory = $true)][string]$Bundle, [string]$Filter = '*') $ErrorActionPreference = 'Stop' [Console]::OutputEncoding = [Text.UTF8Encoding]::new($false) $OutputEncoding = [Console]::OutputEncoding $work = Join-Path $env:TEMP ('cst-test-' + [guid]::NewGuid().ToString('N').Substring(0, 8)) New-Item -ItemType Directory -Force $work | Out-Null Copy-Item -Recurse -Force (Join-Path $Bundle 'data\*') $work $env:PATH = (Join-Path $Bundle 'bin') + ';' + $env:PATH $acp = [Text.Encoding]::Default.CodePage "== user=$env:USERNAME acp=$acp work=$work" $fail = 0 $pass = 0 foreach ($exe in Get-ChildItem (Join-Path $Bundle 'bin') -Filter "test_$Filter.exe" | Sort-Object Name) { $name = $exe.BaseName $out = Join-Path $work "$name.out" $err = Join-Path $work "$name.err" $sw = [Diagnostics.Stopwatch]::StartNew() $p = Start-Process -FilePath $exe.FullName -WorkingDirectory $work -NoNewWindow -PassThru ` -RedirectStandardOutput $out -RedirectStandardError $err $null = $p.Handle if (-not $p.WaitForExit(300000)) { & taskkill.exe /T /F /PID $p.Id | Out-Null $code = 'timeout' } else { $p.WaitForExit() $code = $p.ExitCode } $secs = [math]::Round($sw.Elapsed.TotalSeconds, 1) if ($code -eq 0) { $pass++ "PASS $name (${secs}s)" } else { $fail++ "FAIL $name (exit $code, ${secs}s)" foreach ($f in $out, $err) { if (Test-Path $f) { Get-Content -Path $f -Encoding UTF8 -Tail 25 | ForEach-Object { " $_" } } } } } "== $pass passed, $fail failed" Set-Location $env:TEMP Remove-Item -Recurse -Force $work -ErrorAction SilentlyContinue exit $fail