Files
lmxopcua/tests/Drivers/ZB.MOM.WW.OtOpcUa.Driver.AbLegacy.IntegrationTests/AbLegacyReadSmokeTests.cs
Joseph Doherty a25593a9c6 chore: organize solution into module folders (Core/Server/Drivers/Client/Tooling)
Group all 69 projects into category subfolders under src/ and tests/ so the
Rider Solution Explorer mirrors the module structure. Folders: Core, Server,
Drivers (with a nested Driver CLIs subfolder), Client, Tooling.

- Move every project folder on disk with git mv (history preserved as renames).
- Recompute relative paths in 57 .csproj files: cross-category ProjectReferences,
  the lib/ HintPath+None refs in Driver.Historian.Wonderware, and the external
  mxaccessgw refs in Driver.Galaxy and its test project.
- Rebuild ZB.MOM.WW.OtOpcUa.slnx with nested solution folders.
- Re-prefix project paths in functional scripts (e2e, compliance, smoke SQL,
  integration, install).

Build green (0 errors); unit tests pass. Docs left for a separate pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-17 01:55:28 -04:00

122 lines
5.6 KiB
C#

using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
using ZB.MOM.WW.OtOpcUa.Driver.AbLegacy.PlcFamilies;
namespace ZB.MOM.WW.OtOpcUa.Driver.AbLegacy.IntegrationTests;
/// <summary>
/// End-to-end smoke tests against the <c>ab_server</c> PCCC Docker container.
/// Promotes the AB Legacy driver from unit-only coverage (<c>FakeAbLegacyTag</c>)
/// to wire-level: real libplctag PCCC stack over real TCP against the ab_server
/// simulator. Parametrised over all three families (SLC 500 / MicroLogix / PLC-5)
/// via <c>[AbLegacyTheory]</c> + <c>[MemberData]</c>.
/// </summary>
[Collection(AbLegacyServerCollection.Name)]
[Trait("Category", "Integration")]
[Trait("Simulator", "ab_server-PCCC")]
public sealed class AbLegacyReadSmokeTests(AbLegacyServerFixture sim)
{
// Only one ab_server container binds :44818 at a time and `--plc=SLC500` only
// answers SLC-mode PCCC, etc. When `AB_LEGACY_COMPOSE_PROFILE` is set, the theory
// filters to that profile alone so the suite matches the running container. Unset
// (the default for real-hardware runs) parameterises across every family the driver
// supports.
public static IEnumerable<object[]> Profiles
{
get
{
var only = Environment.GetEnvironmentVariable("AB_LEGACY_COMPOSE_PROFILE");
var profiles = KnownProfiles.All.Where(p =>
string.IsNullOrEmpty(only) ||
string.Equals(p.ComposeProfile, only, StringComparison.OrdinalIgnoreCase));
return profiles.Select(p => new object[] { p });
}
}
[AbLegacyTheory]
[MemberData(nameof(Profiles))]
public async Task Driver_reads_seeded_N_file_from_ab_server_PCCC(AbLegacyServerProfile profile)
{
if (sim.SkipReason is not null) Assert.Skip(sim.SkipReason);
// PCCC semantics allow an empty cip-path (real SLC/PLC-5 hardware takes nothing
// after the `/`), but libplctag's ab_server requires a non-empty path at the
// CIP unconnected-send layer before the PCCC dispatcher runs. Default `1,0`
// against the Docker fixture; set AB_LEGACY_CIP_PATH= (empty) against real HW.
var deviceUri = $"ab://{sim.Host}:{sim.Port}/{sim.CipPath}";
await using var drv = new AbLegacyDriver(new AbLegacyDriverOptions
{
Devices = [new AbLegacyDeviceOptions(deviceUri, profile.Family)],
Tags = [
new AbLegacyTagDefinition(
Name: "IntCounter",
DeviceHostAddress: deviceUri,
Address: "N7:0",
DataType: AbLegacyDataType.Int),
],
Timeout = TimeSpan.FromSeconds(5),
Probe = new AbLegacyProbeOptions { Enabled = false },
}, driverInstanceId: $"ablegacy-smoke-{profile.Family}");
await drv.InitializeAsync("{}", TestContext.Current.CancellationToken);
var snapshots = await drv.ReadAsync(
["IntCounter"], TestContext.Current.CancellationToken);
snapshots.Single().StatusCode.ShouldBe(AbLegacyStatusMapper.Good,
$"N7:0 read must succeed against the {profile.Family} compose profile");
drv.GetHealth().State.ShouldBe(DriverState.Healthy);
}
[AbLegacyFact]
public async Task Slc500_write_then_read_round_trip_on_N7_scratch_register()
{
if (sim.SkipReason is not null) Assert.Skip(sim.SkipReason);
// Skip when the running compose profile isn't SLC500 — ab_server's `--plc=`
// flag selects exactly one family per process, so a write against a plc5-mode
// container with SLC500 semantics always fails at the wire.
var only = Environment.GetEnvironmentVariable("AB_LEGACY_COMPOSE_PROFILE");
if (!string.IsNullOrEmpty(only) &&
!string.Equals(only, "slc500", StringComparison.OrdinalIgnoreCase))
{
Assert.Skip($"Test targets the SLC500 compose profile; AB_LEGACY_COMPOSE_PROFILE='{only}'.");
}
// PCCC semantics allow an empty cip-path (real SLC/PLC-5 hardware takes nothing
// after the `/`), but libplctag's ab_server requires a non-empty path at the
// CIP unconnected-send layer before the PCCC dispatcher runs. Default `1,0`
// against the Docker fixture; set AB_LEGACY_CIP_PATH= (empty) against real HW.
var deviceUri = $"ab://{sim.Host}:{sim.Port}/{sim.CipPath}";
await using var drv = new AbLegacyDriver(new AbLegacyDriverOptions
{
Devices = [new AbLegacyDeviceOptions(deviceUri, AbLegacyPlcFamily.Slc500)],
Tags = [
new AbLegacyTagDefinition(
Name: "Scratch",
DeviceHostAddress: deviceUri,
Address: "N7:5",
DataType: AbLegacyDataType.Int,
Writable: true),
],
Timeout = TimeSpan.FromSeconds(5),
Probe = new AbLegacyProbeOptions { Enabled = false },
}, driverInstanceId: "ablegacy-smoke-rw");
await drv.InitializeAsync("{}", TestContext.Current.CancellationToken);
const short probe = 0x1234;
var writeResults = await drv.WriteAsync(
[new WriteRequest("Scratch", probe)],
TestContext.Current.CancellationToken);
writeResults.Single().StatusCode.ShouldBe(AbLegacyStatusMapper.Good,
"PCCC N7:5 write must succeed end-to-end");
var readResults = await drv.ReadAsync(
["Scratch"], TestContext.Current.CancellationToken);
readResults.Single().StatusCode.ShouldBe(AbLegacyStatusMapper.Good);
Convert.ToInt32(readResults.Single().Value).ShouldBe(probe);
}
}