From 619856ab22a84b323ad720a529a8b8cfa5fa032f Mon Sep 17 00:00:00 2001 From: ssdfasd <2156608475@qq.com> Date: Thu, 2 Apr 2026 02:49:27 +0800 Subject: [PATCH] test: add renderer phase regression entrypoint --- scripts/Run-RendererPhaseRegression.ps1 | 156 ++++++++++++++++++++++++ tests/CMakeLists.txt | 24 ++++ tests/Rendering/CMakeLists.txt | 24 ++++ 3 files changed, 204 insertions(+) create mode 100644 scripts/Run-RendererPhaseRegression.ps1 diff --git a/scripts/Run-RendererPhaseRegression.ps1 b/scripts/Run-RendererPhaseRegression.ps1 new file mode 100644 index 00000000..092f3889 --- /dev/null +++ b/scripts/Run-RendererPhaseRegression.ps1 @@ -0,0 +1,156 @@ +[CmdletBinding()] +param( + [string]$BuildDir = "build", + [string]$Config = "Debug", + [string]$RepoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path, + [int]$SmokeSeconds = 5, + [switch]$SkipBuild, + [switch]$SkipSmoke, + [switch]$CleanBuild +) + +Set-StrictMode -Version Latest +$ErrorActionPreference = "Stop" + +function Invoke-Step { + param( + [Parameter(Mandatory = $true)] + [string]$Label, + [Parameter(Mandatory = $true)] + [scriptblock]$Action + ) + + Write-Host "==> $Label" + & $Action +} + +function Invoke-Native { + param( + [Parameter(Mandatory = $true)] + [string]$FilePath, + [Parameter()] + [string[]]$Arguments = @(), + [string]$WorkingDirectory = $RepoRoot + ) + + Push-Location $WorkingDirectory + try { + & $FilePath @Arguments + if ($LASTEXITCODE -ne 0) { + throw ("Command failed with exit code {0}: {1} {2}" -f $LASTEXITCODE, $FilePath, ($Arguments -join ' ')) + } + } + finally { + Pop-Location + } +} + +function Get-ExePath { + param( + [Parameter(Mandatory = $true)] + [string[]]$Parts + ) + + $path = $BuildDir + foreach ($part in $Parts) { + $path = Join-Path $path $part + } + + $resolved = if ([System.IO.Path]::IsPathRooted($path)) { + $path + } + else { + Join-Path $RepoRoot $path + } + if (-not (Test-Path $resolved)) { + throw "Expected executable does not exist: $resolved" + } + + return $resolved +} + +$RepoRoot = [System.IO.Path]::GetFullPath($RepoRoot) +$BuildDir = if ([System.IO.Path]::IsPathRooted($BuildDir)) { + [System.IO.Path]::GetFullPath($BuildDir) +} +else { + [System.IO.Path]::GetFullPath((Join-Path $RepoRoot $BuildDir)) +} + +$msbuildArguments = @( + "--", "/m:1", + "/p:UseMultiToolTask=false", + "/p:CL_MPCount=1" +) + +if (-not $SkipBuild) { + if ($CleanBuild) { + Invoke-Step "Clean rebuild XCEngine" { + Invoke-Native -FilePath "cmake" -Arguments (@( + "--build", $BuildDir, + "--config", $Config, + "--target", "XCEngine", + "--clean-first" + ) + $msbuildArguments) + } + } + + Invoke-Step "Build rendering regression targets" { + Invoke-Native -FilePath "cmake" -Arguments (@( + "--build", $BuildDir, + "--config", $Config, + "--target", "rendering_phase_regression_build" + ) + $msbuildArguments) + } +} + +$executables = @( + (Get-ExePath -Parts @("tests", "Rendering", "unit", $Config, "rendering_unit_tests.exe")), + (Get-ExePath -Parts @("tests", "Rendering", "integration", "textured_quad_scene", $Config, "rendering_integration_textured_quad_scene.exe")), + (Get-ExePath -Parts @("tests", "Rendering", "integration", "backpack_scene", $Config, "rendering_integration_backpack_scene.exe")), + (Get-ExePath -Parts @("tests", "Rendering", "integration", "backpack_lit_scene", $Config, "rendering_integration_backpack_lit_scene.exe")), + (Get-ExePath -Parts @("tests", "Rendering", "integration", "camera_stack_scene", $Config, "rendering_integration_camera_stack_scene.exe")), + (Get-ExePath -Parts @("tests", "Rendering", "integration", "transparent_material_scene", $Config, "rendering_integration_transparent_material_scene.exe")), + (Get-ExePath -Parts @("tests", "Rendering", "integration", "cull_material_scene", $Config, "rendering_integration_cull_material_scene.exe")), + (Get-ExePath -Parts @("tests", "Rendering", "integration", "depth_sort_scene", $Config, "rendering_integration_depth_sort_scene.exe")), + (Get-ExePath -Parts @("tests", "Rendering", "integration", "material_state_scene", $Config, "rendering_integration_material_state_scene.exe")), + (Get-ExePath -Parts @("tests", "Rendering", "integration", "offscreen_scene", $Config, "rendering_integration_offscreen_scene.exe")), + (Get-ExePath -Parts @("tests", "Editor", $Config, "editor_tests.exe")) +) + +foreach ($executable in $executables) { + $label = [System.IO.Path]::GetFileName($executable) + $workingDirectory = Split-Path -Parent $executable + Invoke-Step "Run $label" { + Invoke-Native -FilePath $executable -WorkingDirectory $workingDirectory + } +} + +if (-not $SkipSmoke) { + $editorExe = Join-Path $RepoRoot "editor\bin\$Config\XCEngine.exe" + if (-not (Test-Path $editorExe)) { + throw "Expected editor executable does not exist: $editorExe" + } + + Invoke-Step "Smoke launch XCEditor ($SmokeSeconds seconds)" { + $process = Start-Process -FilePath $editorExe -WorkingDirectory $RepoRoot -PassThru + try { + Start-Sleep -Seconds $SmokeSeconds + if ($process.HasExited) { + if ($process.ExitCode -ne 0) { + throw "XCEditor exited early with code $($process.ExitCode)" + } + } + else { + Stop-Process -Id $process.Id -Force + } + } + finally { + if (-not $process.HasExited) { + Stop-Process -Id $process.Id -Force -ErrorAction SilentlyContinue + } + } + } +} + +Write-Host "Renderer phase regression passed." diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 4e92dd31..74ef68ef 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -44,6 +44,30 @@ add_subdirectory(Resources) add_subdirectory(Input) add_subdirectory(Editor) +if(WIN32) + find_program(XCENGINE_POWERSHELL_EXECUTABLE NAMES powershell pwsh REQUIRED) + + add_custom_target(rendering_phase_regression_build + DEPENDS + rendering_all_tests + editor_tests + XCEditor + ) + + add_custom_target(rendering_phase_regression + COMMAND "${XCENGINE_POWERSHELL_EXECUTABLE}" + -NoProfile + -ExecutionPolicy Bypass + -File "${CMAKE_SOURCE_DIR}/scripts/Run-RendererPhaseRegression.ps1" + -RepoRoot "${CMAKE_SOURCE_DIR}" + -BuildDir "${CMAKE_BINARY_DIR}" + -Config $ + -CleanBuild + USES_TERMINAL + COMMENT "Run renderer phase regression suite" + ) +endif() + # ============================================================ # Test Summary # ============================================================ diff --git a/tests/Rendering/CMakeLists.txt b/tests/Rendering/CMakeLists.txt index 948f04c4..87393569 100644 --- a/tests/Rendering/CMakeLists.txt +++ b/tests/Rendering/CMakeLists.txt @@ -4,3 +4,27 @@ project(XCEngine_RenderingTests) add_subdirectory(unit) add_subdirectory(integration) + +add_custom_target(rendering_unit_test_targets + DEPENDS + rendering_unit_tests +) + +add_custom_target(rendering_integration_tests + DEPENDS + rendering_integration_textured_quad_scene + rendering_integration_backpack_scene + rendering_integration_backpack_lit_scene + rendering_integration_camera_stack_scene + rendering_integration_transparent_material_scene + rendering_integration_cull_material_scene + rendering_integration_depth_sort_scene + rendering_integration_material_state_scene + rendering_integration_offscreen_scene +) + +add_custom_target(rendering_all_tests + DEPENDS + rendering_unit_test_targets + rendering_integration_tests +)