gpio unit tests (#2099)
* fix unregister api for gpio * consumers * guard with a critical section * index * guard less * unregister under lock * fix reinit * dead flag * fix most tests * initialize properly * initialize properly * assertions in tests * fix message * move gpio mocking * test gpios * we must lock earlier to be truly safe * this was using huge memory * devirtualize * test deinit
This commit is contained in:
parent
6168bcea80
commit
690ab7e917
|
@ -30,7 +30,6 @@ void setMockAfrVoltage(float voltage DECLARE_ENGINE_PARAMETER_SUFFIX);
|
|||
void setMockMafVoltage(float voltage DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||
void setMockIatVoltage(float voltage DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||
void setMockCltVoltage(float voltage DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||
void setMockState(brain_pin_e pin, bool state);
|
||||
|
||||
void printCurrentState(Logging *logging, int seconds, const char *engineTypeName, const char *firmwareBuildId);
|
||||
|
||||
|
|
|
@ -70,16 +70,6 @@ void setMockMapVoltage(float voltage DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
|||
void setMockVBattVoltage(float voltage DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||
setMockVoltage(engineConfiguration->vbattAdcChannel, voltage PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
}
|
||||
|
||||
void setMockState(brain_pin_e pin, bool state) {
|
||||
#if EFI_UNIT_TEST
|
||||
mockPinStates[static_cast<int>(pin)] = state;
|
||||
#else
|
||||
UNUSED(pin);
|
||||
UNUSED(state);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* EFI_ENABLE_MOCK_ADC */
|
||||
|
||||
#if EFI_PROD_CODE
|
||||
|
|
|
@ -133,4 +133,9 @@ bool mockPinStates[BRAIN_PIN_COUNT];
|
|||
bool efiReadPin(brain_pin_e pin) {
|
||||
return mockPinStates[static_cast<int>(pin)];
|
||||
}
|
||||
|
||||
void setMockState(brain_pin_e pin, bool state) {
|
||||
mockPinStates[static_cast<int>(pin)] = state;
|
||||
}
|
||||
|
||||
#endif /* EFI_PROD_CODE */
|
||||
|
|
|
@ -35,4 +35,6 @@ EXTERNC void efiIcuStart(const char *msg, ICUDriver *icup, const ICUConfig *conf
|
|||
#if ! EFI_PROD_CODE
|
||||
#define BRAIN_PIN_COUNT (1 << 8 * sizeof(brain_pin_e))
|
||||
extern bool mockPinStates[BRAIN_PIN_COUNT];
|
||||
|
||||
void setMockState(brain_pin_e pin, bool state);
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,97 @@
|
|||
#include "efi_gpio.h"
|
||||
#include "engine_test_helper.h"
|
||||
#include "unit_test_framework.h"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(gpio, testPinInitNonInverted) {
|
||||
WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
|
||||
|
||||
OutputPin dut;
|
||||
|
||||
// Set the "hardware" pin to on initially
|
||||
setMockState(GPIOA_6, true);
|
||||
ASSERT_TRUE(efiReadPin(GPIOA_6));
|
||||
|
||||
// this should turn it off
|
||||
pin_output_mode_e mode = OM_DEFAULT;
|
||||
dut.initPin("test", GPIOA_6, &mode);
|
||||
|
||||
EXPECT_FALSE(efiReadPin(GPIOA_6));
|
||||
}
|
||||
|
||||
TEST(gpio, testPinInitInverted) {
|
||||
WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
|
||||
|
||||
OutputPin dut;
|
||||
|
||||
// Set the "hardware" pin to off initially
|
||||
setMockState(GPIOA_6, false);
|
||||
ASSERT_FALSE(efiReadPin(GPIOA_6));
|
||||
|
||||
// this should turn it off
|
||||
pin_output_mode_e mode = OM_INVERTED;
|
||||
dut.initPin("test", GPIOA_6, &mode);
|
||||
|
||||
EXPECT_TRUE(efiReadPin(GPIOA_6));
|
||||
}
|
||||
|
||||
TEST(gpio, multipleInit) {
|
||||
OutputPin dut;
|
||||
|
||||
// Initial setup should be ok
|
||||
EXPECT_NO_FATAL_ERROR(dut.initPin("testPin", GPIOA_6));
|
||||
|
||||
// Reinit with the same pin should be ok
|
||||
EXPECT_NO_FATAL_ERROR(dut.initPin("testPin", GPIOA_6));
|
||||
|
||||
// Reinit with DIFFERENT pin should fail
|
||||
EXPECT_FATAL_ERROR(dut.initPin("testPin", GPIOB_5));
|
||||
}
|
||||
|
||||
TEST(gpio, deInit) {
|
||||
OutputPin dut;
|
||||
|
||||
// Initial setup should be ok
|
||||
EXPECT_NO_FATAL_ERROR(dut.initPin("testPin", GPIOA_6));
|
||||
|
||||
dut.deInit();
|
||||
|
||||
// Reinit with DIFFERENT pin should work after deinit
|
||||
EXPECT_NO_FATAL_ERROR(dut.initPin("testPin", GPIOB_5));
|
||||
}
|
||||
|
||||
TEST(gpio, pinSetNotInverted) {
|
||||
OutputPin dut;
|
||||
|
||||
pin_output_mode_e mode = OM_DEFAULT;
|
||||
dut.initPin("test", GPIOA_6, &mode);
|
||||
|
||||
// Initial state should be logic 0
|
||||
EXPECT_FALSE(efiReadPin(GPIOA_6));
|
||||
|
||||
dut.setValue(true);
|
||||
EXPECT_TRUE(efiReadPin(GPIOA_6));
|
||||
EXPECT_TRUE(dut.getLogicValue());
|
||||
|
||||
dut.setValue(false);
|
||||
EXPECT_FALSE(efiReadPin(GPIOA_6));
|
||||
EXPECT_FALSE(dut.getLogicValue());
|
||||
}
|
||||
|
||||
TEST(gpio, pinSetInverted) {
|
||||
OutputPin dut;
|
||||
|
||||
pin_output_mode_e mode = OM_INVERTED;
|
||||
dut.initPin("test", GPIOA_6, &mode);
|
||||
|
||||
// Initial state should be logic 0
|
||||
EXPECT_TRUE(efiReadPin(GPIOA_6));
|
||||
|
||||
dut.setValue(true);
|
||||
EXPECT_FALSE(efiReadPin(GPIOA_6));
|
||||
EXPECT_TRUE(dut.getLogicValue());
|
||||
|
||||
dut.setValue(false);
|
||||
EXPECT_TRUE(efiReadPin(GPIOA_6));
|
||||
EXPECT_FALSE(dut.getLogicValue());
|
||||
}
|
|
@ -63,4 +63,5 @@ TESTS_SRC_CPP = \
|
|||
tests/test_fuel_math.cpp \
|
||||
tests/test_binary_log.cpp \
|
||||
tests/test_dynoview.cpp \
|
||||
tests/test_gpio.cpp \
|
||||
|
||||
|
|
Loading…
Reference in New Issue