From 1f5b070af5b81a6cfd248c3854a0848b26b549f3 Mon Sep 17 00:00:00 2001 From: Gold856 <117957790+Gold856@users.noreply.github.com> Date: Sun, 28 Jul 2024 21:51:51 -0400 Subject: [PATCH] [wpilib] Wait 0.5s after enabling interrupt in tests If the interrupt edge tests are running while under heavy CPU load (like building wpilib,) they are prone to failure since the interrupt thread doesn't have enough time to set up callbacks. The interrupt edge tests now copy the original AsynchronousInterrupt test, which has a 0.5s delay after the interrupt is enabled. Running the new interrupt tests while building allwpilib causes far less failures than the old tests. --- wpilibc/src/test/native/cpp/InterruptTest.cpp | 6 ++---- .../src/test/java/edu/wpi/first/wpilibj/InterruptTest.java | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/wpilibc/src/test/native/cpp/InterruptTest.cpp b/wpilibc/src/test/native/cpp/InterruptTest.cpp index d0cc2c08222..8b054d75f59 100644 --- a/wpilibc/src/test/native/cpp/InterruptTest.cpp +++ b/wpilibc/src/test/native/cpp/InterruptTest.cpp @@ -57,9 +57,8 @@ TEST(InterruptTest, RisingEdge) { interrupt.SetInterruptEdges(true, true); DIOSim digitalSim{di}; digitalSim.SetValue(false); - frc::Wait(0.5_s); interrupt.Enable(); - frc::Wait(20_ms); + frc::Wait(0.5_s); digitalSim.SetValue(true); frc::Wait(20_ms); @@ -87,9 +86,8 @@ TEST(InterruptTest, FallingEdge) { interrupt.SetInterruptEdges(true, true); DIOSim digitalSim{di}; digitalSim.SetValue(true); - frc::Wait(0.5_s); interrupt.Enable(); - frc::Wait(20_ms); + frc::Wait(0.5_s); digitalSim.SetValue(false); frc::Wait(20_ms); diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/InterruptTest.java b/wpilibj/src/test/java/edu/wpi/first/wpilibj/InterruptTest.java index a392fc6c8e7..7855d89753e 100644 --- a/wpilibj/src/test/java/edu/wpi/first/wpilibj/InterruptTest.java +++ b/wpilibj/src/test/java/edu/wpi/first/wpilibj/InterruptTest.java @@ -62,9 +62,8 @@ void testRisingEdge() { interrupt.setInterruptEdges(true, true); DIOSim digitalSim = new DIOSim(di); digitalSim.setValue(false); - Timer.delay(0.5); interrupt.enable(); - Timer.delay(0.02); + Timer.delay(0.5); digitalSim.setValue(true); Timer.delay(0.02); @@ -99,9 +98,8 @@ void testFallingEdge() { interrupt.setInterruptEdges(true, true); DIOSim digitalSim = new DIOSim(di); digitalSim.setValue(true); - Timer.delay(0.5); interrupt.enable(); - Timer.delay(0.02); + Timer.delay(0.5); digitalSim.setValue(false); Timer.delay(0.02);