|
- $ErrorActionPreference = 'Stop'
-
- $workspacePath = (Resolve-Path (Join-Path $PSScriptRoot '..\..')).Path
- $compiler = Get-Command gcc.exe -ErrorAction SilentlyContinue
- if ($null -eq $compiler)
- {
- throw 'gcc.exe was not found; PLSR host tests cannot run.'
- }
-
- $outputDirectory = Join-Path $workspacePath 'tmp'
- if (-not (Test-Path -LiteralPath $outputDirectory))
- {
- New-Item -ItemType Directory -Path $outputDirectory | Out-Null
- }
-
- $tests = @(
- @{
- Name = 'test_plc_device'
- Sources = @(
- "$workspacePath\PLSR\Src\plc_device.c"
- "$workspacePath\PLSR\Src\plsr_persistence.c"
- "$workspacePath\PLSR\Test\test_plc_device.c"
- )
- },
- @{
- Name = 'test_plsr_core'
- Sources = @(
- "$workspacePath\PLSR\Src\plc_device.c"
- "$workspacePath\PLSR\Src\plsr_persistence.c"
- "$workspacePath\PLSR\Src\plsr_resource.c"
- "$workspacePath\PLSR\Src\plsr_job.c"
- "$workspacePath\PLSR\Src\plsr_path.c"
- "$workspacePath\PLSR\Src\plsr_core.c"
- "$workspacePath\PLSR\Test\test_plsr_core.c"
- )
- },
- @{
- Name = 'test_plsr_job'
- Sources = @(
- "$workspacePath\PLSR\Src\plc_device.c"
- "$workspacePath\PLSR\Src\plsr_persistence.c"
- "$workspacePath\PLSR\Src\plsr_resource.c"
- "$workspacePath\PLSR\Src\plsr_job.c"
- "$workspacePath\PLSR\Src\plsr_path.c"
- "$workspacePath\PLSR\Src\plsr_core.c"
- "$workspacePath\PLSR\Test\test_plsr_job.c"
- )
- },
- @{
- Name = 'test_plsr_path'
- Sources = @(
- "$workspacePath\PLSR\Src\plc_device.c"
- "$workspacePath\PLSR\Src\plsr_persistence.c"
- "$workspacePath\PLSR\Src\plsr_resource.c"
- "$workspacePath\PLSR\Src\plsr_job.c"
- "$workspacePath\PLSR\Src\plsr_path.c"
- "$workspacePath\PLSR\Src\plsr_core.c"
- "$workspacePath\PLSR\Test\test_plsr_path.c"
- )
- },
- @{
- Name = 'test_plsr_profile'
- Sources = @(
- "$workspacePath\PLSR\Src\plsr_profile.c"
- "$workspacePath\PLSR\Test\test_plsr_profile.c"
- )
- }
- )
-
- foreach ($test in $tests)
- {
- $outputPath = Join-Path $outputDirectory "$($test.Name).exe"
- $arguments = @(
- '-std=c11'
- '-Wall'
- '-Wextra'
- '-Werror'
- '-DPLSR_HOST_TEST'
- "-I$workspacePath\PLSR\Inc"
- ) + $test.Sources + @('-o', $outputPath, '-lm')
-
- try
- {
- & $compiler.Source @arguments
- if ($LASTEXITCODE -ne 0)
- {
- throw "$($test.Name) compilation failed with exit code $LASTEXITCODE."
- }
-
- & $outputPath
- if ($LASTEXITCODE -ne 0)
- {
- throw "$($test.Name) failed with exit code $LASTEXITCODE."
- }
- }
- finally
- {
- if (Test-Path -LiteralPath $outputPath)
- {
- Remove-Item -LiteralPath $outputPath -Force
- }
- }
- }
|