您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

125 行
3.8 KiB

  1. $ErrorActionPreference = 'Stop'
  2. $workspacePath = (Resolve-Path (Join-Path $PSScriptRoot '..\..')).Path
  3. $compiler = Get-Command gcc.exe -ErrorAction SilentlyContinue
  4. if ($null -eq $compiler)
  5. {
  6. throw 'gcc.exe was not found; PLSR host tests cannot run.'
  7. }
  8. $outputDirectory = Join-Path $workspacePath 'tmp'
  9. if (-not (Test-Path -LiteralPath $outputDirectory))
  10. {
  11. New-Item -ItemType Directory -Path $outputDirectory | Out-Null
  12. }
  13. $tests = @(
  14. @{
  15. Name = 'test_plc_device'
  16. Sources = @(
  17. "$workspacePath\PLSR\Src\plc_device.c"
  18. "$workspacePath\PLSR\Src\plsr_persistence.c"
  19. "$workspacePath\PLSR\Test\test_plc_device.c"
  20. )
  21. },
  22. @{
  23. Name = 'test_plsr_core'
  24. Sources = @(
  25. "$workspacePath\PLSR\Src\plc_device.c"
  26. "$workspacePath\PLSR\Src\plsr_persistence.c"
  27. "$workspacePath\PLSR\Src\plsr_resource.c"
  28. "$workspacePath\PLSR\Src\plsr_job.c"
  29. "$workspacePath\PLSR\Src\plsr_path.c"
  30. "$workspacePath\PLSR\Src\plsr_profile.c"
  31. "$workspacePath\PLSR\Src\plsr_hal_f407.c"
  32. "$workspacePath\PLSR\Src\plsr_core.c"
  33. "$workspacePath\PLSR\Test\test_plsr_core.c"
  34. )
  35. },
  36. @{
  37. Name = 'test_plsr_job'
  38. Sources = @(
  39. "$workspacePath\PLSR\Src\plc_device.c"
  40. "$workspacePath\PLSR\Src\plsr_persistence.c"
  41. "$workspacePath\PLSR\Src\plsr_resource.c"
  42. "$workspacePath\PLSR\Src\plsr_job.c"
  43. "$workspacePath\PLSR\Src\plsr_path.c"
  44. "$workspacePath\PLSR\Src\plsr_profile.c"
  45. "$workspacePath\PLSR\Src\plsr_hal_f407.c"
  46. "$workspacePath\PLSR\Src\plsr_core.c"
  47. "$workspacePath\PLSR\Test\test_plsr_job.c"
  48. )
  49. },
  50. @{
  51. Name = 'test_plsr_path'
  52. Sources = @(
  53. "$workspacePath\PLSR\Src\plc_device.c"
  54. "$workspacePath\PLSR\Src\plsr_persistence.c"
  55. "$workspacePath\PLSR\Src\plsr_resource.c"
  56. "$workspacePath\PLSR\Src\plsr_job.c"
  57. "$workspacePath\PLSR\Src\plsr_path.c"
  58. "$workspacePath\PLSR\Src\plsr_profile.c"
  59. "$workspacePath\PLSR\Src\plsr_hal_f407.c"
  60. "$workspacePath\PLSR\Src\plsr_core.c"
  61. "$workspacePath\PLSR\Test\test_plsr_path.c"
  62. )
  63. },
  64. @{
  65. Name = 'test_plsr_profile'
  66. Sources = @(
  67. "$workspacePath\PLSR\Src\plsr_profile.c"
  68. "$workspacePath\PLSR\Test\test_plsr_profile.c"
  69. )
  70. },
  71. @{
  72. Name = 'test_plsr_hal'
  73. Sources = @(
  74. "$workspacePath\PLSR\Src\plc_device.c"
  75. "$workspacePath\PLSR\Src\plsr_persistence.c"
  76. "$workspacePath\PLSR\Src\plsr_resource.c"
  77. "$workspacePath\PLSR\Src\plsr_job.c"
  78. "$workspacePath\PLSR\Src\plsr_path.c"
  79. "$workspacePath\PLSR\Src\plsr_profile.c"
  80. "$workspacePath\PLSR\Src\plsr_hal_f407.c"
  81. "$workspacePath\PLSR\Src\plsr_core.c"
  82. "$workspacePath\PLSR\Src\plsr_self_test.c"
  83. "$workspacePath\PLSR\Test\test_plsr_hal.c"
  84. )
  85. }
  86. )
  87. foreach ($test in $tests)
  88. {
  89. $outputPath = Join-Path $outputDirectory "$($test.Name).exe"
  90. $arguments = @(
  91. '-std=c11'
  92. '-Wall'
  93. '-Wextra'
  94. '-Werror'
  95. '-DPLSR_HOST_TEST'
  96. "-I$workspacePath\PLSR\Inc"
  97. ) + $test.Sources + @('-o', $outputPath, '-lm')
  98. try
  99. {
  100. & $compiler.Source @arguments
  101. if ($LASTEXITCODE -ne 0)
  102. {
  103. throw "$($test.Name) compilation failed with exit code $LASTEXITCODE."
  104. }
  105. & $outputPath
  106. if ($LASTEXITCODE -ne 0)
  107. {
  108. throw "$($test.Name) failed with exit code $LASTEXITCODE."
  109. }
  110. }
  111. finally
  112. {
  113. if (Test-Path -LiteralPath $outputPath)
  114. {
  115. Remove-Item -LiteralPath $outputPath -Force
  116. }
  117. }
  118. }