fix(driver-abcip): resolve High code-review findings (Driver.AbCip-001, -002, -003, -008)
Driver.AbCip-001 — ReinitializeAsync silently discarded its config JSON. Extracted AbCipDriverFactoryExtensions.ParseOptions; InitializeAsync now re-parses a content-bearing driverConfigJson and replaces _options (and recreates the alarm projection), so a reinitialize with a changed config (new device/tag, changed timeout) actually takes effect. A blank or empty-object JSON keeps construction-time options for the unit-test seam. Driver.AbCip-002 — libplctag status mapping used wrong integer constants. MapLibplctagStatus now switches on the libplctag.NET Status enum members (Ok/Pending/ErrorTimeout/ErrorNotFound/ErrorNotAllowed/ErrorOutOfBounds/…) instead of hand-typed natives, so timeout/not-found/not-allowed/out-of-bounds get their specific OPC UA codes instead of all collapsing to BadCommunicationError. The int overload casts to Status to stay correct against the wrapper's contiguous renumbering. Driver.AbCip-003 — whole-UDT reads decoded members at declaration-order offsets, which Studio 5000 does not guarantee. Added the opt-in AbCipDriverOptions.EnableDeclarationOnlyUdtGrouping flag (default false); AbCipUdtReadPlanner.Build forms no groups when it is off, so by default every UDT member reads per-tag rather than at possibly-wrong offsets. Driver.AbCip-008 — probe loops were fire-and-forget and ShutdownAsync raced them. Each probe Task is stored on DeviceState.ProbeTask; ShutdownAsync now cancels every CTS, awaits each probe Task (10s timeout), then disposes the CTS and handles. DeviceState.Runtimes/ParentRuntimes are ConcurrentDictionary and the Ensure*RuntimeAsync paths use TryAdd, disposing the losing concurrent creator instead of leaking a native tag handle. Adds AbCipDriverCodeReviewRegressionTests and updates existing AbCip tests to the corrected status constants + opt-in grouping flag. AbCip driver + test project build clean; all 244 AbCip tests pass. (The full-solution build has pre-existing, unrelated Driver.Galaxy protobuf-generation errors in this worktree.) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using libplctag;
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.OtOpcUa.Driver.AbCip;
|
||||
@@ -25,17 +26,37 @@ public sealed class AbCipStatusMapperTests
|
||||
AbCipStatusMapper.MapCipGeneralStatus(status).ShouldBe(expected);
|
||||
}
|
||||
|
||||
// Driver.AbCip-002 — the integers here are the underlying values of the libplctag.NET
|
||||
// Status enum (what (int)Tag.GetStatus() actually returns), NOT raw native PLCTAG_ERR_*
|
||||
// constants. The libplctag.NET wrapper renumbers the native codes into a contiguous enum.
|
||||
[Theory]
|
||||
[InlineData(0, AbCipStatusMapper.Good)]
|
||||
[InlineData(1, AbCipStatusMapper.GoodMoreData)] // PLCTAG_STATUS_PENDING
|
||||
[InlineData(-5, AbCipStatusMapper.BadTimeout)]
|
||||
[InlineData(-7, AbCipStatusMapper.BadCommunicationError)]
|
||||
[InlineData(-14, AbCipStatusMapper.BadNodeIdUnknown)]
|
||||
[InlineData(-16, AbCipStatusMapper.BadNotWritable)]
|
||||
[InlineData(-17, AbCipStatusMapper.BadOutOfRange)]
|
||||
[InlineData(-99, AbCipStatusMapper.BadCommunicationError)] // unknown negative → generic comms failure
|
||||
public void MapLibplctagStatus_maps_known_codes(int status, uint expected)
|
||||
[InlineData(Status.Ok, AbCipStatusMapper.Good)]
|
||||
[InlineData(Status.Pending, AbCipStatusMapper.GoodMoreData)]
|
||||
[InlineData(Status.ErrorTimeout, AbCipStatusMapper.BadTimeout)]
|
||||
[InlineData(Status.ErrorNotFound, AbCipStatusMapper.BadNodeIdUnknown)]
|
||||
[InlineData(Status.ErrorNotAllowed, AbCipStatusMapper.BadNotWritable)]
|
||||
[InlineData(Status.ErrorOutOfBounds, AbCipStatusMapper.BadOutOfRange)]
|
||||
[InlineData(Status.ErrorBadConnection, AbCipStatusMapper.BadCommunicationError)]
|
||||
[InlineData(Status.ErrorBadGateway, AbCipStatusMapper.BadCommunicationError)]
|
||||
[InlineData(Status.ErrorUnsupported, AbCipStatusMapper.BadNotSupported)]
|
||||
[InlineData(Status.ErrorNoMem, AbCipStatusMapper.BadCommunicationError)] // unmapped → generic comms
|
||||
public void MapLibplctagStatus_maps_real_enum_members(Status status, uint expected)
|
||||
{
|
||||
AbCipStatusMapper.MapLibplctagStatus(status).ShouldBe(expected);
|
||||
// The int overload must agree — it is the seam IAbCipTagRuntime.GetStatus() drives.
|
||||
AbCipStatusMapper.MapLibplctagStatus((int)status).ShouldBe(expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MapLibplctagStatus_distinguishes_timeout_from_generic_comms_error()
|
||||
{
|
||||
// Regression for Driver.AbCip-002: a real timeout used to fall through to
|
||||
// BadCommunicationError because the code matched the wrong integer (-5).
|
||||
AbCipStatusMapper.MapLibplctagStatus((int)Status.ErrorTimeout)
|
||||
.ShouldBe(AbCipStatusMapper.BadTimeout);
|
||||
AbCipStatusMapper.MapLibplctagStatus((int)Status.ErrorNotFound)
|
||||
.ShouldBe(AbCipStatusMapper.BadNodeIdUnknown);
|
||||
AbCipStatusMapper.MapLibplctagStatus((int)Status.ErrorNotFound)
|
||||
.ShouldNotBe(AbCipStatusMapper.BadCommunicationError);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user