Files
lmxopcua/scripts/e2e/test-all.ps1
Joseph Doherty 5fc596a9a1 E2E test script — Galaxy (MXAccess) driver: read / write / subscribe / alarms / history
Seven-stage e2e script covering every Galaxy-specific capability surface:
IReadable + IWritable + ISubscribable + IAlarmSource + IHistoryProvider.
Unlike the other drivers there is no per-protocol CLI — Galaxy's proxy
lives in-process with the server + talks to OtOpcUaGalaxyHost over a
named pipe (MXAccess COM is 32-bit-only), so every stage runs through
`otopcua-cli` against the published OPC UA address space.

## Stages

1. Probe                   — otopcua-cli read on the source NodeId
2. Source read             — capture value for downstream comparison
3. Virtual-tag bridge      — Phase 7 VirtualTag (source × 2) through
                             CachedTagUpstreamSource
4. Subscribe-sees-change   — data-change events propagate
5. Reverse bridge          — opc-ua write → Galaxy; soft-passes if the
                             attribute's Galaxy-side ACL forbids writes
                             (`BadUserAccessDenied` / `BadNotWritable`)
6. Alarm fires             — scripted-alarm Condition fires with Active
                             state when source crosses threshold
7. History read            — historyread returns samples from the Aveva
                             Historian → IHistoryProvider path

## Two new helpers in _common.ps1

- `Test-AlarmFiresOnThreshold` — start `otopcua-cli alarms --refresh`
  in the background on a Condition NodeId, drive the source change,
  assert captured stdout contains `ALARM` + `Active`. Uses the same
  Start-Process + temp-file pattern as `Test-SubscribeSeesChange` since
  the alarms command runs until Ctrl+C (no built-in --duration).
- `Test-HistoryHasSamples` — call `otopcua-cli historyread` over a
  configurable lookback window, parse `N values returned.` marker, fail
  if below MinSamples. Works for driver-sourced, virtual, or scripted-
  alarm historized nodes.

## Wiring

- `test-all.ps1` picks up the optional `galaxy` sidecar section and
  runs the script with the configured NodeIds + wait windows.
- `e2e-config.sample.json` adds a `galaxy` section seeded with the
  Phase 7 defaults (`p7-smoke-tag-source` / `-vt-derived` /
  `-al-overtemp`) — matches `scripts/smoke/seed-phase-7-smoke.sql`.
- `scripts/e2e/README.md` expected-matrix gains a Galaxy row.

## Prereqs

- OtOpcUaGalaxyHost running (NSSM-wrapped) with the Galaxy + MXAccess
  runtime available
- `seed-phase-7-smoke.sql` applied with a live Galaxy attribute
  substituted into `dbo.Tag.TagConfig`
- OtOpcUa server running against the `p7-smoke` cluster
- Non-elevated shell (Galaxy.Host pipe ACL denies Admins)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-21 12:59:06 -04:00

229 lines
8.2 KiB
PowerShell

#Requires -Version 7.0
<#
.SYNOPSIS
Runs every scripts/e2e/test-*.ps1 and tallies PASS / FAIL / SKIP.
.DESCRIPTION
The per-protocol scripts require protocol-specific NodeIds that depend on
your server's config DB seed. This runner expects a JSON sidecar at
scripts/e2e/e2e-config.json (not checked in — see README) with one entry
per driver giving the NodeIds + endpoints to pass through. Any driver
missing from the sidecar is skipped with a clear message rather than
failing hard.
.PARAMETER ConfigFile
Path to the sidecar JSON. Default: scripts/e2e/e2e-config.json.
.PARAMETER OpcUaUrl
Default OPC UA endpoint passed to each per-driver script. Default
opc.tcp://localhost:4840. Individual entries in the config file can override.
#>
param(
[string]$ConfigFile = "$PSScriptRoot/e2e-config.json",
[string]$OpcUaUrl = "opc.tcp://localhost:4840"
)
$ErrorActionPreference = "Stop"
. "$PSScriptRoot/_common.ps1"
if (-not (Test-Path $ConfigFile)) {
Write-Fail "no config at $ConfigFile — copy e2e-config.sample.json + fill in your NodeIds first (see README)"
exit 2
}
# -AsHashtable + Get-Or below keeps access tolerant of missing keys even under
# Set-StrictMode -Version 3.0 (inherited from _common.ps1). Without this a
# missing "$config.ablegacy" throws "property cannot be found on this object".
$config = Get-Content $ConfigFile -Raw | ConvertFrom-Json -AsHashtable
$summary = [ordered]@{}
# Return $Table[$Key] if present, else $Default. Nested tables are themselves
# hashtables so this composes: (Get-Or $config modbus)['opcUaUrl'].
function Get-Or {
param($Table, [string]$Key, $Default = $null)
if ($Table -and $Table.ContainsKey($Key)) { return $Table[$Key] }
return $Default
}
function Run-Suite {
param(
[string]$Name,
[scriptblock]$Action
)
try {
& $Action
$summary[$Name] = if ($LASTEXITCODE -eq 0) { "PASS" } else { "FAIL" }
}
catch {
Write-Fail "$Name runner crashed: $_"
$summary[$Name] = "FAIL"
}
}
# ---------------------------------------------------------------------------
# Modbus
# ---------------------------------------------------------------------------
$modbus = Get-Or $config "modbus"
if ($modbus) {
Write-Header "== MODBUS =="
Run-Suite "modbus" {
& "$PSScriptRoot/test-modbus.ps1" `
-ModbusHost $modbus["endpoint"] `
-OpcUaUrl (Get-Or $modbus "opcUaUrl" $OpcUaUrl) `
-BridgeNodeId $modbus["bridgeNodeId"]
}
}
else { $summary["modbus"] = "SKIP (no config entry)" }
# ---------------------------------------------------------------------------
# AB CIP
# ---------------------------------------------------------------------------
$abcip = Get-Or $config "abcip"
if ($abcip) {
Write-Header "== AB CIP =="
Run-Suite "abcip" {
& "$PSScriptRoot/test-abcip.ps1" `
-Gateway $abcip["gateway"] `
-Family (Get-Or $abcip "family" "ControlLogix") `
-TagPath (Get-Or $abcip "tagPath" "TestDINT") `
-OpcUaUrl (Get-Or $abcip "opcUaUrl" $OpcUaUrl) `
-BridgeNodeId $abcip["bridgeNodeId"]
}
}
else { $summary["abcip"] = "SKIP (no config entry)" }
# ---------------------------------------------------------------------------
# AB Legacy
# ---------------------------------------------------------------------------
$ablegacy = Get-Or $config "ablegacy"
if ($ablegacy) {
Write-Header "== AB LEGACY =="
Run-Suite "ablegacy" {
& "$PSScriptRoot/test-ablegacy.ps1" `
-Gateway $ablegacy["gateway"] `
-PlcType (Get-Or $ablegacy "plcType" "Slc500") `
-Address (Get-Or $ablegacy "address" "N7:5") `
-OpcUaUrl (Get-Or $ablegacy "opcUaUrl" $OpcUaUrl) `
-BridgeNodeId $ablegacy["bridgeNodeId"]
}
}
else { $summary["ablegacy"] = "SKIP (no config entry)" }
# ---------------------------------------------------------------------------
# S7
# ---------------------------------------------------------------------------
$s7 = Get-Or $config "s7"
if ($s7) {
Write-Header "== S7 =="
Run-Suite "s7" {
& "$PSScriptRoot/test-s7.ps1" `
-S7Host $s7["endpoint"] `
-Cpu (Get-Or $s7 "cpu" "S71500") `
-Slot (Get-Or $s7 "slot" 0) `
-Address (Get-Or $s7 "address" "DB1.DBW0") `
-OpcUaUrl (Get-Or $s7 "opcUaUrl" $OpcUaUrl) `
-BridgeNodeId $s7["bridgeNodeId"]
}
}
else { $summary["s7"] = "SKIP (no config entry)" }
# ---------------------------------------------------------------------------
# FOCAS
# ---------------------------------------------------------------------------
$focas = Get-Or $config "focas"
if ($focas) {
Write-Header "== FOCAS =="
Run-Suite "focas" {
& "$PSScriptRoot/test-focas.ps1" `
-CncHost $focas["host"] `
-CncPort (Get-Or $focas "port" 8193) `
-Address (Get-Or $focas "address" "R100") `
-OpcUaUrl (Get-Or $focas "opcUaUrl" $OpcUaUrl) `
-BridgeNodeId $focas["bridgeNodeId"]
}
}
else { $summary["focas"] = "SKIP (no config entry)" }
# ---------------------------------------------------------------------------
# TwinCAT
# ---------------------------------------------------------------------------
$twincat = Get-Or $config "twincat"
if ($twincat) {
Write-Header "== TWINCAT =="
Run-Suite "twincat" {
& "$PSScriptRoot/test-twincat.ps1" `
-AmsNetId $twincat["amsNetId"] `
-AmsPort (Get-Or $twincat "amsPort" 851) `
-SymbolPath (Get-Or $twincat "symbolPath" "MAIN.iCounter") `
-OpcUaUrl (Get-Or $twincat "opcUaUrl" $OpcUaUrl) `
-BridgeNodeId $twincat["bridgeNodeId"]
}
}
else { $summary["twincat"] = "SKIP (no config entry)" }
# ---------------------------------------------------------------------------
# Phase 7 virtual tags + scripted alarms
# ---------------------------------------------------------------------------
$galaxy = Get-Or $config "galaxy"
if ($galaxy) {
Write-Header "== GALAXY =="
Run-Suite "galaxy" {
& "$PSScriptRoot/test-galaxy.ps1" `
-OpcUaUrl (Get-Or $galaxy "opcUaUrl" $OpcUaUrl) `
-SourceNodeId $galaxy["sourceNodeId"] `
-VirtualNodeId (Get-Or $galaxy "virtualNodeId" "") `
-AlarmNodeId (Get-Or $galaxy "alarmNodeId" "") `
-AlarmTriggerValue (Get-Or $galaxy "alarmTriggerValue" "75") `
-ChangeWaitSec (Get-Or $galaxy "changeWaitSec" 10) `
-AlarmWaitSec (Get-Or $galaxy "alarmWaitSec" 10) `
-HistoryLookbackSec (Get-Or $galaxy "historyLookbackSec" 3600)
}
}
else { $summary["galaxy"] = "SKIP (no config entry)" }
$phase7 = Get-Or $config "phase7"
if ($phase7) {
Write-Header "== PHASE 7 virtual tags + scripted alarms =="
Run-Suite "phase7" {
$defaultModbus = if ($modbus) { $modbus["endpoint"] } else { $null }
& "$PSScriptRoot/test-phase7-virtualtags.ps1" `
-ModbusHost (Get-Or $phase7 "modbusEndpoint" $defaultModbus) `
-OpcUaUrl (Get-Or $phase7 "opcUaUrl" $OpcUaUrl) `
-InputNodeId $phase7["inputNodeId"] `
-VirtualNodeId $phase7["virtualNodeId"] `
-AlarmNodeId (Get-Or $phase7 "alarmNodeId" $null)
}
}
else { $summary["phase7"] = "SKIP (no config entry)" }
# ---------------------------------------------------------------------------
# Final matrix
# ---------------------------------------------------------------------------
Write-Host ""
Write-Host "==================== FINAL MATRIX ====================" -ForegroundColor Cyan
$summary.GetEnumerator() | ForEach-Object {
$color = switch -Wildcard ($_.Value) {
"PASS" { "Green" }
"FAIL" { "Red" }
"SKIP*" { "Yellow" }
default { "Gray" }
}
Write-Host (" {0,-10} {1}" -f $_.Key, $_.Value) -ForegroundColor $color
}
$failed = ($summary.Values | Where-Object { $_ -eq "FAIL" }).Count
if ($failed -gt 0) {
Write-Host "$failed suite(s) failed." -ForegroundColor Red
exit 1
}
Write-Host "All present suites passed." -ForegroundColor Green