mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-26 01:51:41 +00:00
[wpilibc] Clean up integration tests (#3400)
The command and shuffleboard integration tests were removed because their unit tests counterparts already provide adequate coverage. Java already removed these.
This commit is contained in:
@@ -18,8 +18,6 @@
|
||||
#define EXPECT_NEAR_UNITS(val1, val2, eps) \
|
||||
EXPECT_LE(units::math::abs(val1 - val2), eps)
|
||||
|
||||
using namespace frc;
|
||||
|
||||
static constexpr auto kCounterTime = 1_ms;
|
||||
|
||||
static constexpr auto kDelayTime = 100_ms;
|
||||
@@ -33,20 +31,10 @@ static constexpr auto kSynchronousInterruptTimeTolerance = 10_ms;
|
||||
*/
|
||||
class DIOLoopTest : public testing::Test {
|
||||
protected:
|
||||
DigitalInput* m_input;
|
||||
DigitalOutput* m_output;
|
||||
frc::DigitalInput m_input{TestBench::kLoop1InputChannel};
|
||||
frc::DigitalOutput m_output{TestBench::kLoop1OutputChannel};
|
||||
|
||||
void SetUp() override {
|
||||
m_input = new DigitalInput(TestBench::kLoop1InputChannel);
|
||||
m_output = new DigitalOutput(TestBench::kLoop1OutputChannel);
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
delete m_input;
|
||||
delete m_output;
|
||||
}
|
||||
|
||||
void Reset() { m_output->Set(false); }
|
||||
void Reset() { m_output.Set(false); }
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -56,15 +44,15 @@ class DIOLoopTest : public testing::Test {
|
||||
TEST_F(DIOLoopTest, Loop) {
|
||||
Reset();
|
||||
|
||||
m_output->Set(false);
|
||||
Wait(kDelayTime);
|
||||
EXPECT_FALSE(m_input->Get()) << "The digital output was turned off, but "
|
||||
<< "the digital input is on.";
|
||||
m_output.Set(false);
|
||||
frc::Wait(kDelayTime);
|
||||
EXPECT_FALSE(m_input.Get()) << "The digital output was turned off, but "
|
||||
<< "the digital input is on.";
|
||||
|
||||
m_output->Set(true);
|
||||
Wait(kDelayTime);
|
||||
EXPECT_TRUE(m_input->Get()) << "The digital output was turned on, but "
|
||||
<< "the digital input is off.";
|
||||
m_output.Set(true);
|
||||
frc::Wait(kDelayTime);
|
||||
EXPECT_TRUE(m_input.Get()) << "The digital output was turned on, but "
|
||||
<< "the digital input is off.";
|
||||
}
|
||||
/**
|
||||
* Tests to see if the DIO PWM functionality works.
|
||||
@@ -72,43 +60,43 @@ TEST_F(DIOLoopTest, Loop) {
|
||||
TEST_F(DIOLoopTest, DIOPWM) {
|
||||
Reset();
|
||||
|
||||
m_output->Set(false);
|
||||
Wait(kDelayTime);
|
||||
EXPECT_FALSE(m_input->Get()) << "The digital output was turned off, but "
|
||||
<< "the digital input is on.";
|
||||
m_output.Set(false);
|
||||
frc::Wait(kDelayTime);
|
||||
EXPECT_FALSE(m_input.Get()) << "The digital output was turned off, but "
|
||||
<< "the digital input is on.";
|
||||
|
||||
// Set frequency to 2.0 Hz
|
||||
m_output->SetPWMRate(2.0);
|
||||
m_output.SetPWMRate(2.0);
|
||||
// Enable PWM, but leave it off
|
||||
m_output->EnablePWM(0.0);
|
||||
Wait(0.5_s);
|
||||
m_output->UpdateDutyCycle(0.5);
|
||||
m_input->RequestInterrupts();
|
||||
m_input->SetUpSourceEdge(false, true);
|
||||
InterruptableSensorBase::WaitResult result =
|
||||
m_input->WaitForInterrupt(3_s, true);
|
||||
m_output.EnablePWM(0.0);
|
||||
frc::Wait(0.5_s);
|
||||
m_output.UpdateDutyCycle(0.5);
|
||||
m_input.RequestInterrupts();
|
||||
m_input.SetUpSourceEdge(false, true);
|
||||
frc::InterruptableSensorBase::WaitResult result =
|
||||
m_input.WaitForInterrupt(3_s, true);
|
||||
|
||||
Wait(0.5_s);
|
||||
bool firstCycle = m_input->Get();
|
||||
Wait(0.5_s);
|
||||
bool secondCycle = m_input->Get();
|
||||
Wait(0.5_s);
|
||||
bool thirdCycle = m_input->Get();
|
||||
Wait(0.5_s);
|
||||
bool forthCycle = m_input->Get();
|
||||
Wait(0.5_s);
|
||||
bool fifthCycle = m_input->Get();
|
||||
Wait(0.5_s);
|
||||
bool sixthCycle = m_input->Get();
|
||||
Wait(0.5_s);
|
||||
bool seventhCycle = m_input->Get();
|
||||
m_output->DisablePWM();
|
||||
Wait(0.5_s);
|
||||
bool firstAfterStop = m_input->Get();
|
||||
Wait(0.5_s);
|
||||
bool secondAfterStop = m_input->Get();
|
||||
frc::Wait(0.5_s);
|
||||
bool firstCycle = m_input.Get();
|
||||
frc::Wait(0.5_s);
|
||||
bool secondCycle = m_input.Get();
|
||||
frc::Wait(0.5_s);
|
||||
bool thirdCycle = m_input.Get();
|
||||
frc::Wait(0.5_s);
|
||||
bool forthCycle = m_input.Get();
|
||||
frc::Wait(0.5_s);
|
||||
bool fifthCycle = m_input.Get();
|
||||
frc::Wait(0.5_s);
|
||||
bool sixthCycle = m_input.Get();
|
||||
frc::Wait(0.5_s);
|
||||
bool seventhCycle = m_input.Get();
|
||||
m_output.DisablePWM();
|
||||
frc::Wait(0.5_s);
|
||||
bool firstAfterStop = m_input.Get();
|
||||
frc::Wait(0.5_s);
|
||||
bool secondAfterStop = m_input.Get();
|
||||
|
||||
EXPECT_EQ(InterruptableSensorBase::WaitResult::kFallingEdge, result)
|
||||
EXPECT_EQ(frc::InterruptableSensorBase::WaitResult::kFallingEdge, result)
|
||||
<< "WaitForInterrupt was not falling.";
|
||||
|
||||
EXPECT_FALSE(firstCycle) << "Input not low after first delay";
|
||||
@@ -129,16 +117,16 @@ TEST_F(DIOLoopTest, DIOPWM) {
|
||||
TEST_F(DIOLoopTest, FakeCounter) {
|
||||
Reset();
|
||||
|
||||
Counter counter(m_input);
|
||||
frc::Counter counter{&m_input};
|
||||
|
||||
EXPECT_EQ(0, counter.Get()) << "Counter did not initialize to 0.";
|
||||
|
||||
/* Count 100 ticks. The counter value should be 100 after this loop. */
|
||||
for (int32_t i = 0; i < 100; i++) {
|
||||
m_output->Set(true);
|
||||
Wait(kCounterTime);
|
||||
m_output->Set(false);
|
||||
Wait(kCounterTime);
|
||||
for (int32_t i = 0; i < 100; ++i) {
|
||||
m_output.Set(true);
|
||||
frc::Wait(kCounterTime);
|
||||
m_output.Set(false);
|
||||
frc::Wait(kCounterTime);
|
||||
}
|
||||
|
||||
EXPECT_EQ(100, counter.Get()) << "Counter did not count up to 100.";
|
||||
@@ -152,40 +140,40 @@ TEST_F(DIOLoopTest, AsynchronousInterruptWorks) {
|
||||
int32_t param = 0;
|
||||
|
||||
// Given an interrupt handler that sets an int32_t to 12345
|
||||
m_input->RequestInterrupts(InterruptHandler, ¶m);
|
||||
m_input->EnableInterrupts();
|
||||
m_input.RequestInterrupts(InterruptHandler, ¶m);
|
||||
m_input.EnableInterrupts();
|
||||
|
||||
// If the voltage rises
|
||||
m_output->Set(false);
|
||||
m_output->Set(true);
|
||||
m_input->CancelInterrupts();
|
||||
m_output.Set(false);
|
||||
m_output.Set(true);
|
||||
m_input.CancelInterrupts();
|
||||
|
||||
// Then the int32_t should be 12345
|
||||
Wait(kDelayTime);
|
||||
frc::Wait(kDelayTime);
|
||||
EXPECT_EQ(12345, param) << "The interrupt did not run.";
|
||||
}
|
||||
|
||||
static void* InterruptTriggerer(void* data) {
|
||||
DigitalOutput* output = static_cast<DigitalOutput*>(data);
|
||||
output->Set(false);
|
||||
Wait(kSynchronousInterruptTime);
|
||||
output->Set(true);
|
||||
auto& output = *static_cast<frc::DigitalOutput*>(data);
|
||||
output.Set(false);
|
||||
frc::Wait(kSynchronousInterruptTime);
|
||||
output.Set(true);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
TEST_F(DIOLoopTest, SynchronousInterruptWorks) {
|
||||
// Given a synchronous interrupt
|
||||
m_input->RequestInterrupts();
|
||||
m_input.RequestInterrupts();
|
||||
|
||||
// If we have another thread trigger the interrupt in a few seconds
|
||||
pthread_t interruptTriggererLoop;
|
||||
pthread_create(&interruptTriggererLoop, nullptr, InterruptTriggerer,
|
||||
m_output);
|
||||
&m_output);
|
||||
|
||||
// Then this thread should pause and resume after that number of seconds
|
||||
Timer timer;
|
||||
frc::Timer timer;
|
||||
timer.Start();
|
||||
m_input->WaitForInterrupt(kSynchronousInterruptTime + 1_s);
|
||||
m_input.WaitForInterrupt(kSynchronousInterruptTime + 1_s);
|
||||
EXPECT_NEAR_UNITS(kSynchronousInterruptTime, timer.Get(),
|
||||
kSynchronousInterruptTimeTolerance);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user