<# .SYNOPSIS Build the Windows slave example and optionally run host tests. .EXAMPLE ./scripts/build.ps1 -Test .EXAMPLE ./scripts/build.ps1 -Test -Suite Read -BuildName read-check #> param( [switch]$Test, [ValidateSet('All', 'Dtu', 'Common', 'Transport', 'Slave', 'Example', 'Command', 'Read', 'SystemCommand', 'Parameter', 'RemoteParameter', 'FileService', 'SoftwareUpgrade', 'FirmwareUpdate', 'Spontaneous', 'FaultEvent', 'Recording', 'History', 'UserLog', 'EnergyFreeze', 'PeriodicScan', 'Rules', 'Loopback')] [string]$Suite = 'All', [string]$Compiler = 'gcc', [ValidatePattern('^[A-Za-z0-9][A-Za-z0-9_-]*$')] [string]$BuildName = 'slave-example' ) $ErrorActionPreference = 'Stop' if ($PSBoundParameters.ContainsKey('Suite') -and -not $Test) { throw '-Suite requires -Test' } Get-Command $Compiler -ErrorAction Stop | Out-Null if ($Test -and $Suite -in @('All', 'Dtu', 'Loopback', 'History', 'UserLog', 'EnergyFreeze', 'FirmwareUpdate')) { Get-Command node -ErrorAction Stop | Out-Null } $projectRoot = Split-Path -Parent $PSScriptRoot $protocolInclude = Join-Path $projectRoot '104' $businessInclude = Join-Path $protocolInclude 'business' $commonInclude = Join-Path $projectRoot 'common' $exampleInclude = Join-Path $projectRoot 'examples' $exampleBuild = Join-Path (Join-Path $projectRoot '.build') $BuildName New-Item -ItemType Directory -Path $exampleBuild -Force | Out-Null # Shared dependencies; the example adds the actual TCP and Windows Net implementations. $libraryNames = @( '104/business/IEC104_Interrogation.c', '104/business/IEC104_GeneralInterrogation.c', '104/business/IEC104_CounterInterrogation.c', '104/business/IEC104_ClockSynchronization.c', '104/business/IEC104_Command.c', '104/business/IEC104_Read.c', '104/business/IEC104_SystemCommand.c', '104/business/IEC104_Startup.c', '104/business/IEC104_Parameter.c', '104/business/IEC104_RemoteParameter.c', '104/business/IEC104_FileService.c', '104/business/IEC104_SoftwareUpgrade.c', '104/business/IEC104_Spontaneous.c', '104/business/IEC104_PeriodicScan.c', '104/IEC104_Slave.c', 'common/IEC60870_Slave.c', 'common/IEC60870_Asdu.c', 'common/IEC60870_InformationObjects.c', 'common/IEC60870_Time.c', 'common/IEC60870_Clock.c', 'common/IEC60870_Codec.c', 'common/IEC60870_FaultEvent.c', 'common/IEC60870_FaultRecorder.c', 'common/IEC60870_Comtrade.c', 'common/IEC60870_History.c', 'common/IEC60870_HistoryFile.c', 'common/IEC60870_EnergyFreeze.c', 'common/IEC60870_EnergyFreezeFile.c', 'common/IEC60870_UserLog.c', 'common/IEC60870_UserLogFile.c', 'common/IEC60870_FirmwareUpdate.c', '104/IEC104_Connection.c', '104/IEC104_Receiver.c', '104/IEC104_SendManager.c', '104/IEC104_SendBuffer.c', '104/IEC104_AsduQueue.c', '104/IEC104_Codec.c', '104/IEC104_Link.c', '104/IEC104_Link_Slave_StartStop.c' ) $librarySources = @($libraryNames | ForEach-Object { Join-Path $projectRoot $_ }) $compileFlags = @('-std=c11', '-O2', '-Wall', '-Wextra', '-Werror', "-I$protocolInclude", "-I$businessInclude", "-I$commonInclude", "-I$exampleInclude") $exampleOutput = Join-Path $exampleBuild 'iec104_slave_example.exe' $exampleSources = @( (Join-Path $projectRoot 'examples/iec104_slave_example.c'), (Join-Path $projectRoot 'examples/iec104_example_config.c'), (Join-Path $projectRoot 'examples/iec104_example_recording.c'), (Join-Path $projectRoot 'examples/iec104_example_history.c'), (Join-Path $projectRoot 'examples/iec104_example_energy_freeze.c'), (Join-Path $projectRoot 'examples/iec104_example_energy_meter.c'), (Join-Path $projectRoot 'examples/iec104_example_user_log.c'), (Join-Path $projectRoot 'examples/iec104_example_upgrade.c'), (Join-Path $projectRoot '104/IEC104_TcpServer.c'), (Join-Path $projectRoot '104/IEC104_Net_Windows.c') ) + $librarySources # The runtime upgrade switch enables a module; capacity is fixed at build time. & $Compiler @compileFlags '-DIEC104_TCP_ACK_WATCH_CAPACITY=2' @exampleSources -o $exampleOutput -lws2_32 if ($LASTEXITCODE -ne 0) { throw 'Slave example build failed' } Write-Output "Built: $exampleOutput" Write-Output "Run: & '$exampleOutput' --ca 1" # Dedicated DTU profile; the generic eight-point example remains a protocol fixture. $dtuOutput = Join-Path $exampleBuild 'iec104_dtu_example.exe' $dtuSources = @( (Join-Path $projectRoot 'examples/iec104_dtu_example.c'), (Join-Path $projectRoot 'examples/iec104_dtu_settings.c'), (Join-Path $projectRoot 'examples/iec104_dtu_measurement.c'), (Join-Path $projectRoot 'examples/iec104_dtu_protection.c') ) + $exampleSources[1..($exampleSources.Count - 1)] & $Compiler @compileFlags '-DIEC104_EXAMPLE_DTU_PROFILE=1' '-DIEC104_TCP_ACK_WATCH_CAPACITY=2' @dtuSources -o $dtuOutput -lws2_32 if ($LASTEXITCODE -ne 0) { throw 'DTU example build failed' } Write-Output "Built: $dtuOutput" Write-Output "DTU 100V/1A demo: & '$dtuOutput' --ca 1" if ($Test) { $testBuild = Join-Path $exampleBuild 'tests' New-Item -ItemType Directory -Path $testBuild -Force | Out-Null $script:passedTests = 0 function Test-Suite([string]$Name) { return $Suite -eq 'All' -or $Suite -eq $Name } function Invoke-HostTest { param([string]$Name, [string[]]$Sources, [string[]]$ExtraFlags = @(), [string[]]$LinkFlags = @(), [string[]]$RunArgs = @()) $output = Join-Path $testBuild "$Name.exe" Write-Output "Testing: $Name" & $Compiler @compileFlags @ExtraFlags @Sources -o $output @LinkFlags # Never execute an old binary after a failed compilation. if ($LASTEXITCODE -ne 0) { throw "$Name build failed" } & $output @RunArgs if ($LASTEXITCODE -ne 0) { throw "$Name failed" } $script:passedTests++ } if (Test-Suite 'Dtu') { foreach ($model in @('settings_model', 'measurement', 'protection')) { $modelSources = @((Join-Path $projectRoot "test/iec104_dtu_${model}_test.c"), (Join-Path $projectRoot 'examples/iec104_dtu_settings.c')) if ($model -ne 'settings_model') { $modelSources += (Join-Path $projectRoot "examples/iec104_dtu_${model}.c") } Invoke-HostTest -Name "iec104_dtu_${model}_test" -Sources $modelSources -LinkFlags @('-lm') } $triggerSources = @('test/iec104_dtu_trigger_recording_test.c', 'examples/iec104_example_recording.c', 'common/IEC60870_FaultRecorder.c', 'common/IEC60870_Comtrade.c', 'common/IEC60870_Time.c') | ForEach-Object { Join-Path $projectRoot $_ } Invoke-HostTest -Name 'iec104_dtu_trigger_recording_test' -Sources $triggerSources ` -ExtraFlags @('-std=c99', '-pedantic', '-DIEC104_EXAMPLE_DTU_PROFILE=1', '-DIEC60870_TIME_USE_PLATFORM=0') -LinkFlags @('-lm') $gainSources = @('test/iec104_dtu_energy_settings_test.c', 'examples/iec104_example_energy_meter.c', 'common/IEC60870_EnergyFreeze.c', 'common/IEC60870_Time.c') | ForEach-Object { Join-Path $projectRoot $_ } Invoke-HostTest -Name 'iec104_dtu_energy_settings_test' -Sources $gainSources ` -ExtraFlags @('-std=c99', '-pedantic', '-DIEC104_EXAMPLE_DTU_PROFILE=1', '-DIEC60870_TIME_USE_PLATFORM=0') & node (Join-Path $projectRoot 'test/dtu_example_loopback_test.cjs') $dtuOutput if ($LASTEXITCODE -ne 0) { throw 'DTU XML/profile/TCP test failed' } & node (Join-Path $projectRoot 'test/dtu_settings_loopback_test.cjs') $dtuOutput if ($LASTEXITCODE -ne 0) { throw 'DTU settings/persistence TCP test failed' } & node (Join-Path $projectRoot 'test/dtu_features_loopback_test.cjs') $dtuOutput if ($LASTEXITCODE -ne 0) { throw 'DTU complete features TCP test failed' } & node (Join-Path $projectRoot 'test/dtu_process_loopback_test.cjs') $dtuOutput if ($LASTEXITCODE -ne 0) { throw 'DTU process/settings effect TCP test failed' } $dtuStorageDirectory = Join-Path $testBuild 'dtu-storage' New-Item -ItemType Directory -Path $dtuStorageDirectory -Force | Out-Null $dtuStorageSources = @('test/iec104_dtu_storage_test.c', 'examples/iec104_example_recording.c', 'examples/iec104_example_energy_meter.c', 'examples/iec104_example_energy_freeze.c', 'common/IEC60870_FaultRecorder.c', 'common/IEC60870_Comtrade.c', 'common/IEC60870_EnergyFreeze.c', 'common/IEC60870_EnergyFreezeFile.c', 'common/IEC60870_Time.c') | ForEach-Object { Join-Path $projectRoot $_ } Invoke-HostTest -Name 'iec104_dtu_storage_test' -Sources $dtuStorageSources ` -ExtraFlags @('-std=c99', '-pedantic', '-DIEC104_EXAMPLE_DTU_PROFILE=1', '-DIEC60870_TIME_USE_PLATFORM=0') ` -RunArgs @($dtuStorageDirectory) } $asduSources = @('common/IEC60870_Asdu.c', 'common/IEC60870_InformationObjects.c', 'common/IEC60870_Codec.c', 'common/IEC60870_Time.c') | ForEach-Object { Join-Path $projectRoot $_ } if (Test-Suite 'Common') { foreach ($name in @('iec60870_asdu_test', 'iec60870_asdu_extended_test')) { $sources = @((Join-Path $projectRoot "test/$name.c")) + $asduSources Invoke-HostTest -Name $name -Sources $sources Invoke-HostTest -Name "${name}_no_platform" -Sources $sources -ExtraFlags '-DIEC60870_TIME_USE_PLATFORM=0' } } if ((Test-Suite 'Common') -or $Suite -eq 'FaultEvent') { $faultCodecSources = @((Join-Path $projectRoot 'test/iec60870_fault_event_test.c'), (Join-Path $projectRoot 'common/IEC60870_FaultEvent.c')) + $asduSources Invoke-HostTest -Name 'iec60870_fault_event_test' -Sources $faultCodecSources Invoke-HostTest -Name 'iec60870_fault_event_no_platform' -Sources $faultCodecSources -ExtraFlags '-DIEC60870_TIME_USE_PLATFORM=0' } if ((Test-Suite 'Common') -or $Suite -eq 'Recording') { $recordingSources = @('common/IEC60870_FaultRecorder.c', 'common/IEC60870_Comtrade.c', 'common/IEC60870_Time.c') | ForEach-Object { Join-Path $projectRoot $_ } foreach ($name in @('iec60870_fault_recorder_test', 'iec60870_comtrade_test')) { Invoke-HostTest -Name $name -Sources (@((Join-Path $projectRoot "test/$name.c")) + $recordingSources) ` -ExtraFlags @('-std=c99', '-pedantic', '-DIEC60870_TIME_USE_PLATFORM=0') } $recordingDirectory = Join-Path $exampleBuild 'recording-adapter' New-Item -ItemType Directory -Path $recordingDirectory -Force | Out-Null Invoke-HostTest -Name 'iec104_example_recording_test' -Sources (@( (Join-Path $projectRoot 'test/iec104_example_recording_test.c'), (Join-Path $projectRoot 'examples/iec104_example_recording.c')) + $recordingSources) ` -ExtraFlags @('-std=c99', '-pedantic', '-DIEC60870_TIME_USE_PLATFORM=0') -RunArgs @($recordingDirectory) } # Historical storage and XML stay in independent C99 modules; the host adapter # additionally exercises real durable writes. The TCP peer checks the complete # integration without borrowing the library's encoders or changing host time. if (Test-Suite 'History') { $historySources = @('common/IEC60870_History.c', 'common/IEC60870_HistoryFile.c', 'common/IEC60870_Time.c') | ForEach-Object { Join-Path $projectRoot $_ } foreach ($name in @('iec60870_history_test', 'iec60870_history_file_test')) { Invoke-HostTest -Name $name -Sources (@((Join-Path $projectRoot "test/$name.c")) + $historySources) ` -ExtraFlags @('-std=c99', '-pedantic', '-DIEC60870_TIME_USE_PLATFORM=0') } $historyDirectory = Join-Path $exampleBuild 'history-adapter' New-Item -ItemType Directory -Path $historyDirectory -Force | Out-Null Invoke-HostTest -Name 'iec104_example_history_test' -Sources (@( (Join-Path $projectRoot 'test/iec104_example_history_test.c'), (Join-Path $projectRoot 'examples/iec104_example_history.c')) + $historySources) ` -ExtraFlags @('-std=c99', '-pedantic', '-DIEC60870_TIME_USE_PLATFORM=0', '-DIEC104_EXAMPLE_HISTORY_TEST') -RunArgs @($historyDirectory) # Reuse this build's executable, never an older default-directory binary. & node (Join-Path $projectRoot 'test/history_loopback_test.cjs') $exampleOutput if ($LASTEXITCODE -ne 0) { throw 'History TCP/XML/restart test failed' } } if (Test-Suite 'EnergyFreeze') { $energySources = @('common/IEC60870_EnergyFreeze.c', 'common/IEC60870_EnergyFreezeFile.c', 'common/IEC60870_Time.c') | ForEach-Object { Join-Path $projectRoot $_ } foreach ($name in @('iec60870_energy_freeze_test', 'iec60870_energy_freeze_file_test')) { Invoke-HostTest -Name $name -Sources (@((Join-Path $projectRoot "test/$name.c")) + $energySources) ` -ExtraFlags @('-std=c99', '-pedantic', '-DIEC60870_TIME_USE_PLATFORM=0') } Invoke-HostTest -Name 'iec104_example_energy_meter_test' -Sources (@( (Join-Path $projectRoot 'test/iec104_example_energy_meter_test.c'), (Join-Path $projectRoot 'examples/iec104_example_energy_meter.c')) + $energySources) ` -ExtraFlags @('-std=c99', '-pedantic', '-DIEC60870_TIME_USE_PLATFORM=0') $energyDirectory = Join-Path $exampleBuild 'energy-adapter' New-Item -ItemType Directory -Path $energyDirectory -Force | Out-Null Invoke-HostTest -Name 'iec104_example_energy_freeze_test' -Sources (@( (Join-Path $projectRoot 'test/iec104_example_energy_freeze_test.c'), (Join-Path $projectRoot 'examples/iec104_example_energy_freeze.c')) + $energySources) ` -ExtraFlags @('-std=c99', '-pedantic', '-DIEC60870_TIME_USE_PLATFORM=0', '-DIEC104_EXAMPLE_ENERGY_FREEZE_TEST') ` -RunArgs @($energyDirectory) Invoke-HostTest -Name 'iec104_energy_freeze_transitions_test' -Sources (@( (Join-Path $projectRoot 'test/iec104_energy_freeze_transitions_test.c'), (Join-Path $projectRoot 'examples/iec104_example_energy_freeze.c')) + $energySources) ` -ExtraFlags @('-std=c99', '-pedantic', '-DIEC60870_TIME_USE_PLATFORM=0', '-DIEC104_EXAMPLE_ENERGY_FREEZE_TEST') ` -RunArgs @($energyDirectory) & node (Join-Path $projectRoot 'test/energy_freeze_loopback_test.cjs') $exampleOutput if ($LASTEXITCODE -ne 0) { throw 'EnergyFreeze TCP/XML/restart test failed' } } # Annex C uses its own durable ring and XML schema; its restart test does not # depend on a third-party UI or on changing the host wall clock. # Core/XML fixtures use C99 and the integer calendar backend to expose hidden # host-time dependencies; they do not link the Windows storage adapter. if (Test-Suite 'UserLog') { $userLogSources = @('common/IEC60870_UserLog.c', 'common/IEC60870_UserLogFile.c', 'common/IEC60870_Time.c') | ForEach-Object { Join-Path $projectRoot $_ } foreach ($name in @('iec60870_user_log_test', 'iec60870_user_log_file_test')) { Invoke-HostTest -Name $name -Sources (@((Join-Path $projectRoot "test/$name.c")) + $userLogSources) ` -ExtraFlags @('-std=c99', '-pedantic', '-DIEC60870_TIME_USE_PLATFORM=0') } # Keep every real-file fixture beneath this build. The hook fails only # after a completed flush; production builds contain no fault injector. $userLogDirectory = Join-Path $exampleBuild 'user-log-adapter' New-Item -ItemType Directory -Path $userLogDirectory -Force | Out-Null Invoke-HostTest -Name 'iec104_example_user_log_test' -Sources (@( (Join-Path $projectRoot 'test/iec104_example_user_log_test.c'), (Join-Path $projectRoot 'examples/iec104_example_user_log.c')) + $userLogSources) ` -ExtraFlags @('-std=c99', '-pedantic', '-DIEC60870_TIME_USE_PLATFORM=0', '-DIEC104_EXAMPLE_USER_LOG_TEST') -RunArgs @($userLogDirectory) # Use the executable just built, so the real TCP/restart check cannot # silently exercise an older default-directory binary. & node (Join-Path $projectRoot 'test/user_log_loopback_test.cjs') $exampleOutput if ($LASTEXITCODE -ne 0) { throw 'UserLog TCP/XML/restart test failed' } } # Verify three layers: portable C99 state, durable Windows files, and real TCP. # Both C fixtures add pedantic checks even though the example uses C11. # Fault injection is linked only into the host fixture, never the example. # These tests install payload files; they do not execute the received bytes. if (Test-Suite 'FirmwareUpdate') { $firmwareSource = Join-Path $projectRoot 'common/IEC60870_FirmwareUpdate.c' Invoke-HostTest -Name 'iec60870_firmware_update_test' -Sources @( (Join-Path $projectRoot 'test/iec60870_firmware_update_test.c'), $firmwareSource) ` -ExtraFlags @('-std=c99', '-pedantic') # Isolate real-file fixtures under this build, away from other upgrade stores. $upgradeDirectory = Join-Path $exampleBuild 'upgrade-adapter' New-Item -ItemType Directory -Path $upgradeDirectory -Force | Out-Null Invoke-HostTest -Name 'iec104_example_upgrade_test' -Sources @( (Join-Path $projectRoot 'test/iec104_example_upgrade_test.c'), (Join-Path $projectRoot 'examples/iec104_example_upgrade.c'), $firmwareSource) ` -ExtraFlags @('-std=c99', '-pedantic', '-DIEC104_EXAMPLE_UPGRADE_TEST') -RunArgs @($upgradeDirectory) # Pass only this build's successful executable; Node constructs independent # package bytes, CRC expectations, and installed/backup file comparisons. & node (Join-Path $projectRoot 'test/firmware_update_loopback_test.cjs') $exampleOutput if ($LASTEXITCODE -ne 0) { throw 'Firmware installation TCP/restart test failed' } } if (Test-Suite 'Transport') { Invoke-HostTest -Name 'iec104_asdu_transport_test' -Sources (@( (Join-Path $projectRoot 'test/iec104_asdu_transport_test.c'), (Join-Path $projectRoot '104/IEC104_Codec.c')) + $asduSources) Invoke-HostTest -Name 'iec104_response_queue_test' -Sources @( (Join-Path $projectRoot 'test/iec104_response_queue_test.c'), (Join-Path $projectRoot '104/IEC104_AsduQueue.c')) Invoke-HostTest -Name 'iec104_strict_priority_queue_test' -Sources @( (Join-Path $projectRoot 'test/iec104_strict_priority_queue_test.c'), (Join-Path $projectRoot '104/IEC104_AsduQueue.c')) # These fixtures include TcpServer.c and a controlled Net backend themselves. foreach ($name in @('iec104_tcp_event_ring_test', 'iec104_tcp_scheduler_test', 'iec104_response_transport_test', 'iec104_ack_tracking_test', 'iec104_idle_transport_test', 'iec104_strict_priority_transport_test')) { Invoke-HostTest -Name $name -Sources (@((Join-Path $projectRoot "test/$name.c")) + $librarySources) } $ringSources = @((Join-Path $projectRoot 'test/iec104_tcp_event_ring_test.c')) + $librarySources Invoke-HostTest -Name 'iec104_tcp_event_ring_test_small' -Sources $ringSources -ExtraFlags @( '-DIEC104_TCP_RECORD_CAPACITY=3', '-DIEC104_TCP_EVENT_CAPACITY=12', '-DIEC104_TCP_EVENT_STATE_RESERVE=2') Invoke-HostTest -Name 'iec104_tcp_event_ring_test_large' -Sources $ringSources -ExtraFlags @( '-DIEC104_TCP_RECORD_CAPACITY=40', '-DIEC104_TCP_EVENT_CAPACITY=100', '-DIEC104_TCP_EVENT_STATE_RESERVE=6', '-DIEC104_TCP_RX_CAPACITY=4096') } foreach ($capacity in @(1, 2)) { $capacityFlag = "-DIEC104_TCP_SERVER_CAPACITY=$capacity" if (Test-Suite 'Slave') { Invoke-HostTest -Name "iec104_slave_test_$capacity" -Sources (@( (Join-Path $projectRoot 'test/iec104_slave_test.c')) + $librarySources) -ExtraFlags $capacityFlag } if (Test-Suite 'Example') { Invoke-HostTest -Name "iec104_slave_example_test_$capacity" -Sources (@( (Join-Path $projectRoot 'test/iec104_slave_example_test.c'), (Join-Path $projectRoot 'examples/iec104_example_recording.c'), (Join-Path $projectRoot 'examples/iec104_example_history.c'), (Join-Path $projectRoot 'examples/iec104_example_energy_freeze.c'), (Join-Path $projectRoot 'examples/iec104_example_energy_meter.c'), (Join-Path $projectRoot 'examples/iec104_example_user_log.c'), (Join-Path $projectRoot 'examples/iec104_example_upgrade.c'), (Join-Path $projectRoot 'examples/iec104_example_config.c')) + $librarySources) -ExtraFlags @( $capacityFlag, '-DIEC104_TCP_HIGH_CAPACITY=251', '-DIEC104_INTERROGATION_EVENT_CAPACITY=2', '-DIEC104_TCP_ACK_WATCH_CAPACITY=2') Invoke-HostTest -Name "iec104_slave_example_strict_test_$capacity" -Sources (@( (Join-Path $projectRoot 'test/iec104_slave_example_test.c'), (Join-Path $projectRoot 'examples/iec104_example_recording.c'), (Join-Path $projectRoot 'examples/iec104_example_history.c'), (Join-Path $projectRoot 'examples/iec104_example_energy_freeze.c'), (Join-Path $projectRoot 'examples/iec104_example_energy_meter.c'), (Join-Path $projectRoot 'examples/iec104_example_user_log.c'), (Join-Path $projectRoot 'examples/iec104_example_upgrade.c'), (Join-Path $projectRoot 'examples/iec104_example_config.c')) + $librarySources) -ExtraFlags @( $capacityFlag, '-DIEC104_TCP_HIGH_CAPACITY=1024', '-DIEC104_INTERROGATION_EVENT_CAPACITY=2', '-DIEC104_TCP_ACK_WATCH_CAPACITY=2', '-DIEC104_EXAMPLE_STRICT_TEST_ONLY=1') } if (Test-Suite 'Command') { foreach ($replyCapacity in @(1, 4)) { Invoke-HostTest -Name "iec104_command_test_${capacity}_${replyCapacity}" -Sources (@( (Join-Path $projectRoot 'test/iec104_command_test.c')) + $librarySources) -ExtraFlags @( $capacityFlag, "-DIEC104_COMMAND_REPLY_CAPACITY=$replyCapacity", '-DIEC104_TCP_HIGH_CAPACITY=251', '-DIEC104_COMMAND_TEST_HOOKS') } } if (Test-Suite 'Read') { foreach ($taskCapacity in @(1, 4)) { Invoke-HostTest -Name "iec104_read_test_${capacity}_${taskCapacity}" -Sources (@( (Join-Path $projectRoot 'test/iec104_read_test.c')) + $librarySources) -ExtraFlags @( $capacityFlag, "-DIEC104_READ_TASK_CAPACITY=$taskCapacity", '-DIEC104_TCP_HIGH_CAPACITY=251', '-DIEC104_READ_TEST_HOOKS') } } if (Test-Suite 'SystemCommand') { foreach ($taskCapacity in @(1, 4)) { Invoke-HostTest -Name "iec104_system_command_test_${capacity}_${taskCapacity}" -Sources (@( (Join-Path $projectRoot 'test/iec104_system_command_test.c')) + $librarySources) -ExtraFlags @( $capacityFlag, "-DIEC104_SYSTEM_COMMAND_TASK_CAPACITY=$taskCapacity", '-DIEC104_TCP_HIGH_CAPACITY=251', '-DIEC104_SYSTEM_COMMAND_TEST_HOOKS') } } if (Test-Suite 'RemoteParameter') { foreach ($taskCapacity in @(1, 2, 4)) { Invoke-HostTest -Name "iec104_remote_parameter_test_${capacity}_${taskCapacity}" -Sources (@( (Join-Path $projectRoot 'test/iec104_remote_parameter_test.c')) + $librarySources) -ExtraFlags @( $capacityFlag, "-DIEC104_REMOTE_PARAMETER_TASK_CAPACITY=$taskCapacity", '-DIEC104_TCP_HIGH_CAPACITY=251', '-DIEC104_REMOTE_PARAMETER_TEST_HOOKS') } } if (Test-Suite 'FileService') { foreach ($taskCapacity in @(1, 2)) { foreach ($segmentCapacity in @(1, 2, 4)) { Invoke-HostTest -Name "iec104_file_service_test_${capacity}_${taskCapacity}_${segmentCapacity}" -Sources (@( (Join-Path $projectRoot 'test/iec104_file_service_test.c')) + $librarySources) -ExtraFlags @( $capacityFlag, "-DIEC104_FILE_SERVICE_TASK_CAPACITY=$taskCapacity", "-DIEC104_FILE_SERVICE_SEGMENT_CAPACITY=$segmentCapacity", '-DIEC104_TCP_HIGH_CAPACITY=251', '-DIEC104_FILE_SERVICE_TEST_HOOKS') } } } if (Test-Suite 'SoftwareUpgrade') { foreach ($taskCapacity in @(1, 2)) { foreach ($policy in @(0, 1)) { Invoke-HostTest -Name "iec104_software_upgrade_test_${capacity}_${taskCapacity}_${policy}" -Sources (@( (Join-Path $projectRoot 'test/iec104_software_upgrade_test.c')) + $librarySources) -ExtraFlags @( $capacityFlag, "-DIEC104_SOFTWARE_UPGRADE_TASK_CAPACITY=$taskCapacity", "-DUPGRADE_TEST_POLICY=$policy", '-DIEC104_TCP_ACK_WATCH_CAPACITY=1', '-DIEC104_TCP_HIGH_CAPACITY=251', '-DIEC104_SOFTWARE_UPGRADE_TEST_HOOKS') } } } if (Test-Suite 'Parameter') { foreach ($taskCapacity in @(1, 4)) { Invoke-HostTest -Name "iec104_parameter_test_${capacity}_${taskCapacity}" -Sources (@( (Join-Path $projectRoot 'test/iec104_parameter_test.c')) + $librarySources) -ExtraFlags @( $capacityFlag, "-DIEC104_PARAMETER_TASK_CAPACITY=$taskCapacity", '-DIEC104_TCP_HIGH_CAPACITY=251', '-DIEC104_PARAMETER_TEST_HOOKS') } } } if (Test-Suite 'RemoteParameter') { # Boundary probes include the implementation to reach exhausted counters. $remoteLibrary = $librarySources | Where-Object { $_ -ne (Join-Path $projectRoot '104/business/IEC104_RemoteParameter.c') } Invoke-HostTest -Name 'iec104_remote_parameter_internal_test' -Sources (@( (Join-Path $projectRoot 'test/iec104_remote_parameter_internal_test.c')) + $remoteLibrary) -ExtraFlags @( '-DIEC104_TCP_HIGH_CAPACITY=251', '-DIEC104_REMOTE_PARAMETER_TEST_HOOKS') } if (Test-Suite 'FileService') { # Include the implementation once to reach non-wrapping identity/index boundaries. $fileLibrary = $librarySources | Where-Object { $_ -ne (Join-Path $projectRoot '104/business/IEC104_FileService.c') } Invoke-HostTest -Name 'iec104_file_service_internal_test' -Sources (@( (Join-Path $projectRoot 'test/iec104_file_service_internal_test.c')) + $fileLibrary) -ExtraFlags @( '-DIEC104_TCP_HIGH_CAPACITY=251', '-DIEC104_FILE_SERVICE_TEST_HOOKS') } if (Test-Suite 'Parameter') { Invoke-HostTest -Name 'iec104_parameter_edge_test' -Sources (@( (Join-Path $projectRoot 'test/iec104_parameter_edge_test.c')) + $librarySources) -ExtraFlags '-DIEC104_TCP_HIGH_CAPACITY=251' } if (Test-Suite 'SoftwareUpgrade') { $upgradeLibrary = $librarySources | Where-Object { $_ -ne (Join-Path $projectRoot '104/business/IEC104_SoftwareUpgrade.c') } Invoke-HostTest -Name 'iec104_software_upgrade_internal_test' -Sources (@( (Join-Path $projectRoot 'test/iec104_software_upgrade_internal_test.c')) + $upgradeLibrary) -ExtraFlags @( '-DIEC104_TCP_HIGH_CAPACITY=251', '-DIEC104_SOFTWARE_UPGRADE_TEST_HOOKS') } if (Test-Suite 'Spontaneous') { # This fixture also includes Spontaneous.c for failure injection. $spontaneousLibrary = $librarySources | Where-Object { $_ -ne (Join-Path $projectRoot '104/business/IEC104_Spontaneous.c') } $spontaneousSources = @((Join-Path $projectRoot 'test/iec104_spontaneous_test.c')) + $spontaneousLibrary foreach ($matrix in @(@(1, 4096), @(2, 4096), @(1, 272))) { Invoke-HostTest -Name "iec104_spontaneous_test_$($matrix[0])_$($matrix[1])" -Sources $spontaneousSources -ExtraFlags @( "-DIEC104_TCP_SERVER_CAPACITY=$($matrix[0])", "-DIEC104_TCP_NORMAL_CAPACITY=$($matrix[1])") } } if (Test-Suite 'FaultEvent') { # Fault-event publishing uses the real transport and injects submission failures. $faultLibrary = $librarySources | Where-Object { $_ -ne (Join-Path $projectRoot '104/business/IEC104_Spontaneous.c') } $faultSources = @((Join-Path $projectRoot 'test/iec104_fault_event_test.c')) + $faultLibrary foreach ($matrix in @(@(1, 4096), @(2, 4096), @(1, 272))) { Invoke-HostTest -Name "iec104_fault_event_test_$($matrix[0])_$($matrix[1])" -Sources $faultSources -ExtraFlags @( "-DIEC104_TCP_SERVER_CAPACITY=$($matrix[0])", "-DIEC104_TCP_NORMAL_CAPACITY=$($matrix[1])") } } if (Test-Suite 'PeriodicScan') { # The fixture includes PeriodicScan.c and TcpServer.c for controlled faults. $scanLibrary = $librarySources | Where-Object { $_ -ne (Join-Path $projectRoot '104/business/IEC104_PeriodicScan.c') } $scanSources = @((Join-Path $projectRoot 'test/iec104_periodic_scan_test.c')) + $scanLibrary foreach ($capacity in @(1, 2)) { foreach ($rows in @(256, 4)) { foreach ($groups in @(1, 4)) { Invoke-HostTest -Name "iec104_periodic_scan_${capacity}_${rows}_${groups}" -Sources $scanSources -ExtraFlags @( "-DIEC104_TCP_SERVER_CAPACITY=$capacity", "-DIEC104_PERIODIC_SCAN_ROW_BUDGET=$rows", "-DIEC104_PERIODIC_SCAN_GROUP_CAPACITY=$groups") } } } Invoke-HostTest -Name 'iec104_periodic_scan_budget14' -Sources $scanSources -ExtraFlags @( '-DIEC104_PERIODIC_SCAN_ROW_BUDGET=14', '-DIEC104_PERIODIC_SCAN_GROUP_CAPACITY=4') } if (Test-Suite 'Rules') { Invoke-HostTest -Name 'iec104_interrogation_rules_test' -Sources (@( (Join-Path $projectRoot 'test/iec104_interrogation_rules_test.c'), (Join-Path $projectRoot '104/IEC104_TcpServer.c'), (Join-Path $projectRoot '104/IEC104_Net_Windows.c')) + $librarySources) -LinkFlags '-lws2_32' } if (Test-Suite 'Loopback') { Invoke-HostTest -Name 'iec104_net_pending_input_test' -Sources @( (Join-Path $projectRoot 'test/iec104_net_pending_input_test.c'), (Join-Path $projectRoot '104/IEC104_Net_Windows.c')) -LinkFlags '-lws2_32' & node (Join-Path $projectRoot 'test/slave_example_loopback_test.cjs') $exampleOutput if ($LASTEXITCODE -ne 0) { throw 'Slave example TCP loopback test failed' } & node (Join-Path $projectRoot 'test/parameter_config_loopback_test.cjs') $exampleOutput if ($LASTEXITCODE -ne 0) { throw 'Parameter configuration persistence test failed' } & node (Join-Path $projectRoot 'test/periodic_scan_loopback_test.cjs') $exampleOutput if ($LASTEXITCODE -ne 0) { throw 'Periodic scan TCP loopback test failed' } & node (Join-Path $projectRoot 'test/remote_parameter_loopback_test.cjs') $exampleOutput if ($LASTEXITCODE -ne 0) { throw 'Remote parameter TCP loopback test failed' } & node (Join-Path $projectRoot 'test/software_upgrade_loopback_test.cjs') $exampleOutput if ($LASTEXITCODE -ne 0) { throw 'Software upgrade TCP loopback test failed' } $multiOutput = Join-Path $exampleBuild 'iec104_parameter_multi_master.exe' $multiSources = @( (Join-Path $projectRoot 'examples/iec104_parameter_multi_master.c'), (Join-Path $projectRoot '104/IEC104_TcpServer.c'), (Join-Path $projectRoot '104/IEC104_Net_Windows.c')) + $librarySources & $Compiler @compileFlags '-DIEC104_TCP_SERVER_CAPACITY=2' @multiSources -o $multiOutput -lws2_32 if ($LASTEXITCODE -ne 0) { throw 'Parameter multi-master example build failed' } & node (Join-Path $projectRoot 'test/parameter_multi_master_loopback_test.cjs') $multiOutput if ($LASTEXITCODE -ne 0) { throw 'Parameter multi-master loopback test failed' } } Write-Output "Passed: $script:passedTests C test executables (suite: $Suite)" }