综合平台编程器项目的远程存储
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

97 lines
3.1 KiB

  1. [CmdletBinding()]
  2. param(
  3. [ValidateSet('Debug', 'Release')]
  4. [string]$Configuration = 'Debug',
  5. [ValidateSet('Functional', 'Performance', 'All')]
  6. [string]$Suite = 'Functional'
  7. )
  8. Set-StrictMode -Version Latest
  9. $ErrorActionPreference = 'Stop'
  10. $projectRoot = Split-Path -Parent $PSScriptRoot
  11. $qtRoot = 'D:\Qt5.15.2\5.15.2\mingw81_64'
  12. $mingwBin = 'D:\Qt5.15.2\Tools\mingw810_64\bin'
  13. $qmakePath = Join-Path $qtRoot 'bin\qmake.exe'
  14. $makePath = Join-Path $mingwBin 'mingw32-make.exe'
  15. $configurationName = $Configuration.ToLowerInvariant()
  16. $testSourceRoot = Join-Path $projectRoot 'app\tests'
  17. $buildRoot = Join-Path $projectRoot "build\tests\$configurationName"
  18. foreach ($requiredPath in @($qmakePath, $makePath, $testSourceRoot)) {
  19. if (-not (Test-Path -LiteralPath $requiredPath)) {
  20. throw "未找到必要文件:$requiredPath"
  21. }
  22. }
  23. $functionalTargets = @(
  24. 'domain_tests',
  25. 'alarm_service_tests',
  26. 'hmi_editor_service_tests',
  27. 'logic_editor_service_tests',
  28. 'offline_simulation_service_tests',
  29. 'project_management_tests',
  30. 'register_monitor_service_tests',
  31. 'runtime_mode_service_tests',
  32. 'plc_runtime_tests'
  33. )
  34. $performanceTargets = @('performance_tests')
  35. $targets = switch ($Suite) {
  36. 'Functional' { $functionalTargets }
  37. 'Performance' { $performanceTargets }
  38. 'All' { $functionalTargets + $performanceTargets }
  39. }
  40. $originalPath = $env:Path
  41. $env:Path = "$qtRoot\bin;$mingwBin;$env:Path"
  42. Write-Host "测试类型:$Suite"
  43. try {
  44. foreach ($target in $targets) {
  45. $projectFile = Join-Path $testSourceRoot "$target.pro"
  46. $buildDirectory = Join-Path $buildRoot $target
  47. $executablePath = Join-Path $buildDirectory "$configurationName\$target.exe"
  48. New-Item -ItemType Directory -Path $buildDirectory -Force | Out-Null
  49. Push-Location $buildDirectory
  50. try {
  51. & $qmakePath $projectFile "CONFIG+=$configurationName" "CONFIG-=$(if ($configurationName -eq 'debug') { 'release' } else { 'debug' })"
  52. if ($LASTEXITCODE -ne 0) {
  53. throw "qmake 失败:$target,退出码:$LASTEXITCODE"
  54. }
  55. & $makePath -j2
  56. if ($LASTEXITCODE -ne 0) {
  57. throw "构建失败:$target,退出码:$LASTEXITCODE"
  58. }
  59. if (-not (Test-Path -LiteralPath $executablePath)) {
  60. throw "未生成测试可执行文件:$executablePath"
  61. }
  62. Write-Host "运行 $target"
  63. if ($target -eq 'performance_tests') {
  64. $benchmarkResultPath = Join-Path $buildDirectory 'benchmark.csv'
  65. & $executablePath '-o' "$benchmarkResultPath,csv"
  66. } else {
  67. & $executablePath
  68. }
  69. if ($LASTEXITCODE -ne 0) {
  70. throw "测试失败:$target,退出码:$LASTEXITCODE"
  71. }
  72. if ($target -eq 'performance_tests') {
  73. Write-Host "性能结果:$benchmarkResultPath"
  74. Get-Content -LiteralPath $benchmarkResultPath -Encoding utf8
  75. }
  76. }
  77. finally {
  78. Pop-Location
  79. }
  80. }
  81. }
  82. finally {
  83. $env:Path = $originalPath
  84. }