XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

AshfallFrontier

【Unity】灰烬边境,一款生存策略游戏

公开
关注 0 Fork 0 Star 0
UTF-8
param([string]$BuildPath = '', [string]$OutputPath = '')
$ErrorActionPreference = 'Stop'
$projectRoot = Split-Path -Parent $PSScriptRoot
if (!$BuildPath) { $BuildPath = Join-Path $projectRoot 'Builds/Windows/AshfallFrontier.exe' }
if (!$OutputPath) { $OutputPath = Join-Path $projectRoot ('TestResults/Network-' + (Get-Date -Format 'yyyyMMdd-HHmmss')) }
$gameExecutable = (Resolve-Path -LiteralPath $BuildPath).Path
$resultDirectory = [IO.Path]::GetFullPath($OutputPath)
if ((Test-Path -LiteralPath $resultDirectory) -and @(Get-ChildItem -LiteralPath $resultDirectory -Filter 'smoke-*.txt').Count -gt 0) {
    throw 'Choose a fresh result directory so stale reports cannot make a failed run pass.'
}
New-Item -ItemType Directory -Path $resultDirectory -Force | Out-Null
$processes = @()
try {
    foreach ($index in 0..3) {
        $role = if ($index -eq 0) { 'host' } else { 'client' }
        $profile = 'smoke' + $index
        $log = Join-Path $resultDirectory ($profile + '.log')
        $arguments = @('--mode', $role, '--profile', $profile, '--smoke', '--smoke-output', ('"' + $resultDirectory + '"'), '-logFile', ('"' + $log + '"'), '-screen-width', '1280', '-screen-height', '800', '-screen-fullscreen', '0')
        $processes += Start-Process -FilePath $gameExecutable -ArgumentList $arguments -WindowStyle Hidden -PassThru
        if ($index -eq 0) { Start-Sleep -Seconds 3 }
    }
    $deadline = (Get-Date).AddSeconds(110)
    while (($processes | Where-Object { !$_.HasExited }).Count -gt 0 -and (Get-Date) -lt $deadline) { Start-Sleep -Seconds 1 }
    $reports = @(Get-ChildItem -LiteralPath $resultDirectory -Filter 'smoke-*.txt')
    foreach ($report in $reports) { Get-Content -LiteralPath $report.FullName }
    if ($reports.Count -ne 4 -or ($reports | Where-Object { (Get-Content -LiteralPath $_.FullName -Raw) -notlike 'PASS*' }).Count -gt 0 -or
        ($processes | Where-Object { !$_.HasExited -or $_.ExitCode -ne 0 }).Count -gt 0) {
        throw "Network smoke failed; inspect $resultDirectory"
    }
    Write-Output "Four-process smoke passed. Reports: $resultDirectory"
} finally {
    foreach ($process in $processes) { if (!$process.HasExited) { Stop-Process -Id $process.Id } }
}