run_windows_live.ps1 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. param([string]$ReleaseRoot = 'C:\Users\Administrator\delivery\XJKJ-STL-Qt-Clean-0.8.1.12')
  2. $ErrorActionPreference = 'Stop'
  3. $ProgressPreference = 'SilentlyContinue'
  4. $appRoot = Join-Path $ReleaseRoot 'app'
  5. $evidence = Join-Path $ReleaseRoot 'evidence'
  6. $utf8 = New-Object System.Text.UTF8Encoding($false)
  7. $env:PATH = "$env:SystemRoot\System32;$env:SystemRoot"
  8. $env:QT_QPA_PLATFORM = 'windows'
  9. $env:STL_QT_DISABLE_SERIAL = '1'
  10. $env:STL_QT_CONFIG_DIR = $appRoot
  11. $env:STL_QT_PLANS_FILE = Join-Path $appRoot 'qt-plans.json'
  12. Remove-Item Env:\QT_PLUGIN_PATH,Env:\QT_QPA_PLATFORM_PLUGIN_PATH,Env:\QTDIR,Env:\STL_QT_BACKEND_URL -ErrorAction SilentlyContinue
  13. $start = Get-Date
  14. $result = @{ passed=$false; started_utc=$start.ToUniversalTime().ToString('o');
  15. wrapper_session_id=(Get-Process -Id $PID).SessionId; platform='windows';
  16. uses_bundled_runtime_without_sdk_path=$true }
  17. try {
  18. $report = Join-Path $evidence 'windows-qt-live-host-on.json'
  19. $arguments = @('--mode','start','--url','ws://192.168.2.79:8080/ws?view=qt-clean',
  20. '--report',$report,'--screenshot',(Join-Path $evidence 'windows-qt-live-host-on.png'),
  21. '--expect-phase','mt','--timeout','900')
  22. # Own the Process handle directly: PowerShell 5.1 Start-Process can return a
  23. # Process object whose ExitCode is null after asynchronous redirection.
  24. $info = New-Object System.Diagnostics.ProcessStartInfo
  25. $info.FileName = Join-Path $appRoot 'QtCleanProbe.exe'
  26. $info.Arguments = ($arguments | ForEach-Object { '"' + $_ + '"' }) -join ' '
  27. $info.WorkingDirectory = $appRoot
  28. $info.UseShellExecute = $false
  29. $info.CreateNoWindow = $true
  30. $info.RedirectStandardOutput = $true
  31. $info.RedirectStandardError = $true
  32. $process = New-Object System.Diagnostics.Process
  33. $process.StartInfo = $info
  34. if (!$process.Start()) { throw 'Could not start the native Qt process.' }
  35. $stdoutTask = $process.StandardOutput.ReadToEndAsync()
  36. $stderrTask = $process.StandardError.ReadToEndAsync()
  37. $result.process_id = $process.Id
  38. $result.process_session_id = $process.SessionId
  39. [IO.File]::WriteAllText((Join-Path $evidence 'windows-live-process-start.json'), ($result | ConvertTo-Json -Depth 8), $utf8)
  40. if (!$process.WaitForExit(960000)) {
  41. Stop-Process -Id $process.Id -ErrorAction SilentlyContinue
  42. throw 'The Qt verification process exceeded its timeout.'
  43. }
  44. $result.exit_code = $process.ExitCode
  45. [IO.File]::WriteAllText((Join-Path $evidence 'windows-qt-live-host-on.stdout.log'), $stdoutTask.GetAwaiter().GetResult(), $utf8)
  46. [IO.File]::WriteAllText((Join-Path $evidence 'windows-qt-live-host-on.stderr.log'), $stderrTask.GetAwaiter().GetResult(), $utf8)
  47. if (!(Test-Path -LiteralPath $report)) { throw 'Qt verification did not produce its report.' }
  48. $verification = Get-Content -LiteralPath $report -Raw -Encoding utf8 | ConvertFrom-Json
  49. $result.qt_report_passed = $verification.pass
  50. $result.elapsed_ms = $verification.elapsed_ms
  51. $result.checks = @($verification.checks.PSObject.Properties).Count
  52. $result.command_boot_id = $verification.command_boot_id
  53. $result.passed = $process.ExitCode -eq 0 -and $verification.pass -eq $true -and $result.process_session_id -eq 1
  54. } catch {
  55. $result.error = $_.Exception.Message
  56. } finally {
  57. $result.completed_utc = (Get-Date).ToUniversalTime().ToString('o')
  58. [IO.File]::WriteAllText((Join-Path $evidence 'windows-live-process-result.json'), ($result | ConvertTo-Json -Depth 8), $utf8)
  59. }
  60. if (!$result.passed) { exit 1 }
  61. exit 0