Skip to content

Commit

Permalink
[wpilib] Wait 0.5s after enabling interrupt in tests
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Gold856 committed Jul 29, 2024
1 parent 4226d11 commit 1f5b070
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
6 changes: 2 additions & 4 deletions wpilibc/src/test/native/cpp/InterruptTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 1f5b070

Please sign in to comment.