From 73f2b9ae31b4aaf84d9277da284c55781445c841 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 12 Mar 2026 16:47:09 +0000 Subject: [PATCH 1/3] Initial plan From 6e08950207c430b9dd1349d6163df8b98303d937 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 12 Mar 2026 16:56:31 +0000 Subject: [PATCH 2/3] Fix EnableDisableTests flakiness by replacing static shared state with per-device instances Co-authored-by: krwq <660048+krwq@users.noreply.github.com> --- .../Mcp23xxx/tests/EnableDisableTests.cs | 45 +++++++++++-------- src/devices/Mcp23xxx/tests/Mcp23xxxTest.cs | 10 +++++ 2 files changed, 37 insertions(+), 18 deletions(-) diff --git a/src/devices/Mcp23xxx/tests/EnableDisableTests.cs b/src/devices/Mcp23xxx/tests/EnableDisableTests.cs index 8e8e38b562..a857ae89e4 100644 --- a/src/devices/Mcp23xxx/tests/EnableDisableTests.cs +++ b/src/devices/Mcp23xxx/tests/EnableDisableTests.cs @@ -10,21 +10,20 @@ namespace Iot.Device.Mcp23xxx.Tests { public class EnableDisableTests : Mcp23xxxTest { - private static readonly GpioDriverMock s_driverMock = new GpioDriverMock(); - private static readonly GpioController s_gpioMock = new GpioController(s_driverMock); - [Theory] [MemberData(nameof(ResetTestDevices))] public void InitialResetState(TestDevice testDevice) { - s_gpioMock.OpenPin(1, PinMode.Input); - Assert.Equal(PinValue.Low, s_gpioMock.Read(1)); - s_gpioMock.SetPinMode(1, PinMode.Output); + GpioDriverMock driverMock = testDevice.ResetDriverMock!; + GpioController gpioMock = new GpioController(driverMock); + gpioMock.OpenPin(1, PinMode.Input); + Assert.Equal(PinValue.Low, gpioMock.Read(1)); + gpioMock.SetPinMode(1, PinMode.Output); testDevice.Device.Enable(); - s_gpioMock.SetPinMode(1, PinMode.Input); - Assert.Equal(PinValue.High, s_gpioMock.Read(1)); - s_gpioMock.ClosePin(1); - s_driverMock.Reset(); + gpioMock.SetPinMode(1, PinMode.Input); + Assert.Equal(PinValue.High, gpioMock.Read(1)); + gpioMock.ClosePin(1); + driverMock.Reset(); } [Theory] @@ -84,23 +83,33 @@ public static TheoryData ResetTestDevices TheoryData devices = new TheoryData(); // Don't want to use the same bus mock for each + GpioDriverMock driverMock; + + driverMock = new GpioDriverMock(); I2cDeviceMock i2c = new I2cDeviceMock(1); - devices.Add(new TestDevice(new Mcp23008(i2c, reset: 1, controller: new GpioController(s_driverMock)), i2c.DeviceMock)); + devices.Add(new TestDevice(new Mcp23008(i2c, reset: 1, controller: new GpioController(driverMock)), i2c.DeviceMock, driverMock)); + driverMock = new GpioDriverMock(); i2c = new I2cDeviceMock(1); - devices.Add(new TestDevice(new Mcp23009(i2c, reset: 1, controller: new GpioController(s_driverMock)), i2c.DeviceMock)); + devices.Add(new TestDevice(new Mcp23009(i2c, reset: 1, controller: new GpioController(driverMock)), i2c.DeviceMock, driverMock)); + driverMock = new GpioDriverMock(); i2c = new I2cDeviceMock(2); - devices.Add(new TestDevice(new Mcp23017(i2c, reset: 1, controller: new GpioController(s_driverMock)), i2c.DeviceMock)); + devices.Add(new TestDevice(new Mcp23017(i2c, reset: 1, controller: new GpioController(driverMock)), i2c.DeviceMock, driverMock)); + driverMock = new GpioDriverMock(); i2c = new I2cDeviceMock(2); - devices.Add(new TestDevice(new Mcp23018(i2c, reset: 1, controller: new GpioController(s_driverMock)), i2c.DeviceMock)); + devices.Add(new TestDevice(new Mcp23018(i2c, reset: 1, controller: new GpioController(driverMock)), i2c.DeviceMock, driverMock)); + driverMock = new GpioDriverMock(); SpiDeviceMock spi = new SpiDeviceMock(1); - devices.Add(new TestDevice(new Mcp23s08(spi, 0x20, reset: 1, controller: new GpioController(s_driverMock)), spi.DeviceMock)); + devices.Add(new TestDevice(new Mcp23s08(spi, 0x20, reset: 1, controller: new GpioController(driverMock)), spi.DeviceMock, driverMock)); + driverMock = new GpioDriverMock(); spi = new SpiDeviceMock(1); - devices.Add(new TestDevice(new Mcp23s09(spi, reset: 1, controller: new GpioController(s_driverMock)), spi.DeviceMock)); + devices.Add(new TestDevice(new Mcp23s09(spi, reset: 1, controller: new GpioController(driverMock)), spi.DeviceMock, driverMock)); + driverMock = new GpioDriverMock(); spi = new SpiDeviceMock(2); - devices.Add(new TestDevice(new Mcp23s17(spi, 0x20, reset: 1, controller: new GpioController(s_driverMock)), spi.DeviceMock)); + devices.Add(new TestDevice(new Mcp23s17(spi, 0x20, reset: 1, controller: new GpioController(driverMock)), spi.DeviceMock, driverMock)); + driverMock = new GpioDriverMock(); spi = new SpiDeviceMock(2); - devices.Add(new TestDevice(new Mcp23s18(spi, reset: 1, controller: new GpioController(s_driverMock)), spi.DeviceMock)); + devices.Add(new TestDevice(new Mcp23s18(spi, reset: 1, controller: new GpioController(driverMock)), spi.DeviceMock, driverMock)); return devices; } } diff --git a/src/devices/Mcp23xxx/tests/Mcp23xxxTest.cs b/src/devices/Mcp23xxx/tests/Mcp23xxxTest.cs index d787000d44..85adb8c1fd 100644 --- a/src/devices/Mcp23xxx/tests/Mcp23xxxTest.cs +++ b/src/devices/Mcp23xxx/tests/Mcp23xxxTest.cs @@ -47,12 +47,22 @@ public struct TestDevice public Mcp23xxx Device { get; } public Mcp23xxxChipMock ChipMock { get; } public GpioController Controller { get; } + public GpioDriverMock? ResetDriverMock { get; } public TestDevice(Mcp23xxx device, Mcp23xxxChipMock chipMock) { Device = device; ChipMock = chipMock; Controller = new GpioController(Device); + ResetDriverMock = null; + } + + public TestDevice(Mcp23xxx device, Mcp23xxxChipMock chipMock, GpioDriverMock resetDriverMock) + { + Device = device; + ChipMock = chipMock; + Controller = new GpioController(Device); + ResetDriverMock = resetDriverMock; } } From 1613a83fdfac48bf9b95d9a60a7dd4076780f0bd Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 12 Mar 2026 17:00:29 +0000 Subject: [PATCH 3/3] Minor: combine declaration and initialization of driverMock variable Co-authored-by: krwq <660048+krwq@users.noreply.github.com> --- src/devices/Mcp23xxx/tests/EnableDisableTests.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/devices/Mcp23xxx/tests/EnableDisableTests.cs b/src/devices/Mcp23xxx/tests/EnableDisableTests.cs index a857ae89e4..144e98de93 100644 --- a/src/devices/Mcp23xxx/tests/EnableDisableTests.cs +++ b/src/devices/Mcp23xxx/tests/EnableDisableTests.cs @@ -83,9 +83,7 @@ public static TheoryData ResetTestDevices TheoryData devices = new TheoryData(); // Don't want to use the same bus mock for each - GpioDriverMock driverMock; - - driverMock = new GpioDriverMock(); + GpioDriverMock driverMock = new GpioDriverMock(); I2cDeviceMock i2c = new I2cDeviceMock(1); devices.Add(new TestDevice(new Mcp23008(i2c, reset: 1, controller: new GpioController(driverMock)), i2c.DeviceMock, driverMock)); driverMock = new GpioDriverMock();