[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:
Tyler Veness
2021-05-31 10:21:34 -07:00
committed by GitHub
parent 4f7a4464df
commit 93523d572e
38 changed files with 662 additions and 2232 deletions

View File

@@ -12,41 +12,23 @@
#include "frc/Timer.h"
#include "gtest/gtest.h"
using namespace frc;
static constexpr auto kDelayTime = 10_ms;
/**
* A fixture with an analog input and an analog output wired together
*/
class AnalogLoopTest : public testing::Test {
protected:
AnalogInput* m_input;
AnalogOutput* m_output;
void SetUp() override {
m_input = new AnalogInput(TestBench::kFakeAnalogOutputChannel);
m_output = new AnalogOutput(TestBench::kAnalogOutputChannel);
}
void TearDown() override {
delete m_input;
delete m_output;
}
};
/**
* Test analog inputs and outputs by setting one and making sure the other
* matches.
*/
TEST_F(AnalogLoopTest, AnalogInputWorks) {
TEST(AnalogLoopTest, AnalogInputWorks) {
frc::AnalogInput input{TestBench::kFakeAnalogOutputChannel};
frc::AnalogOutput output{TestBench::kAnalogOutputChannel};
// Set the output voltage and check if the input measures the same voltage
for (int32_t i = 0; i < 50; i++) {
m_output->SetVoltage(i / 10.0);
output.SetVoltage(i / 10.0);
Wait(kDelayTime);
frc::Wait(kDelayTime);
EXPECT_NEAR(m_output->GetVoltage(), m_input->GetVoltage(), 0.01);
EXPECT_NEAR(output.GetVoltage(), input.GetVoltage(), 0.01);
}
}
@@ -54,26 +36,29 @@ TEST_F(AnalogLoopTest, AnalogInputWorks) {
* Test if we can use an analog trigger to check if the output is within a
* range correctly.
*/
TEST_F(AnalogLoopTest, AnalogTriggerWorks) {
AnalogTrigger trigger(m_input);
TEST(AnalogLoopTest, AnalogTriggerWorks) {
frc::AnalogInput input{TestBench::kFakeAnalogOutputChannel};
frc::AnalogOutput output{TestBench::kAnalogOutputChannel};
frc::AnalogTrigger trigger{&input};
trigger.SetLimitsVoltage(2.0, 3.0);
m_output->SetVoltage(1.0);
Wait(kDelayTime);
output.SetVoltage(1.0);
frc::Wait(kDelayTime);
EXPECT_FALSE(trigger.GetInWindow())
<< "Analog trigger is in the window (2V, 3V)";
EXPECT_FALSE(trigger.GetTriggerState()) << "Analog trigger is on";
m_output->SetVoltage(2.5);
Wait(kDelayTime);
output.SetVoltage(2.5);
frc::Wait(kDelayTime);
EXPECT_TRUE(trigger.GetInWindow())
<< "Analog trigger is not in the window (2V, 3V)";
EXPECT_FALSE(trigger.GetTriggerState()) << "Analog trigger is on";
m_output->SetVoltage(4.0);
Wait(kDelayTime);
output.SetVoltage(4.0);
frc::Wait(kDelayTime);
EXPECT_FALSE(trigger.GetInWindow())
<< "Analog trigger is in the window (2V, 3V)";
@@ -84,18 +69,21 @@ TEST_F(AnalogLoopTest, AnalogTriggerWorks) {
* Test if we can count the right number of ticks from an analog trigger with
* a counter.
*/
TEST_F(AnalogLoopTest, AnalogTriggerCounterWorks) {
AnalogTrigger trigger(m_input);
TEST(AnalogLoopTest, AnalogTriggerCounterWorks) {
frc::AnalogInput input{TestBench::kFakeAnalogOutputChannel};
frc::AnalogOutput output{TestBench::kAnalogOutputChannel};
frc::AnalogTrigger trigger{&input};
trigger.SetLimitsVoltage(2.0, 3.0);
Counter counter(trigger);
frc::Counter counter{trigger};
// Turn the analog output low and high 50 times
for (int32_t i = 0; i < 50; i++) {
m_output->SetVoltage(1.0);
Wait(kDelayTime);
m_output->SetVoltage(4.0);
Wait(kDelayTime);
output.SetVoltage(1.0);
frc::Wait(kDelayTime);
output.SetVoltage(4.0);
frc::Wait(kDelayTime);
}
// The counter should be 50
@@ -107,24 +95,27 @@ static void InterruptHandler(uint32_t interruptAssertedMask, void* param) {
*reinterpret_cast<int32_t*>(param) = 12345;
}
TEST_F(AnalogLoopTest, AsynchronusInterruptWorks) {
TEST(AnalogLoopTest, AsynchronusInterruptWorks) {
frc::AnalogInput input{TestBench::kFakeAnalogOutputChannel};
frc::AnalogOutput output{TestBench::kAnalogOutputChannel};
int32_t param = 0;
AnalogTrigger trigger(m_input);
frc::AnalogTrigger trigger{&input};
trigger.SetLimitsVoltage(2.0, 3.0);
// Given an interrupt handler that sets an int32_t to 12345
std::shared_ptr<AnalogTriggerOutput> triggerOutput =
trigger.CreateOutput(AnalogTriggerType::kState);
std::shared_ptr<frc::AnalogTriggerOutput> triggerOutput =
trigger.CreateOutput(frc::AnalogTriggerType::kState);
triggerOutput->RequestInterrupts(InterruptHandler, &param);
triggerOutput->EnableInterrupts();
// If the analog output moves from below to above the window
m_output->SetVoltage(0.0);
Wait(kDelayTime);
m_output->SetVoltage(5.0);
output.SetVoltage(0.0);
frc::Wait(kDelayTime);
output.SetVoltage(5.0);
triggerOutput->CancelInterrupts();
// Then the int32_t should be 12345
Wait(kDelayTime);
frc::Wait(kDelayTime);
EXPECT_EQ(12345, param) << "The interrupt did not run.";
}