diff --git a/firmware/hw_layer/HIP9011.cpp b/firmware/hw_layer/HIP9011.cpp index 95f96b5a50..feacfc1d9a 100644 --- a/firmware/hw_layer/HIP9011.cpp +++ b/firmware/hw_layer/HIP9011.cpp @@ -185,7 +185,7 @@ void setHip9011FrankensoPinout(void) { // boardConfiguration->hip9011CsPin = GPIOD_0; // rev 0.1 boardConfiguration->isHip9011Enabled = true; - engineConfiguration->hip9011PrescalerAndSDO = 6; // 8MHz chip + engineConfiguration->hip9011PrescalerAndSDO = _8MHZ_PRESCALER; // 8MHz chip boardConfiguration->is_enabled_spi_2 = true; // todo: convert this to rusEfi, hardware-independent enum #if EFI_PROD_CODE diff --git a/firmware/hw_layer/HIP9011_logic.h b/firmware/hw_layer/HIP9011_logic.h index 2dd44b9c01..9db880d4b1 100644 --- a/firmware/hw_layer/HIP9011_logic.h +++ b/firmware/hw_layer/HIP9011_logic.h @@ -103,4 +103,6 @@ int getHip9011GainIndex(DEFINE_HIP_PARAMS); // 0b10000000 #define SET_GAIN_CMD 0x80 +#define _8MHZ_PRESCALER 6 + #endif /* HW_LAYER_HIP9011_LOGIC_H_ */ diff --git a/unit_tests/Makefile b/unit_tests/Makefile index 82584f358d..e23e213892 100644 --- a/unit_tests/Makefile +++ b/unit_tests/Makefile @@ -111,6 +111,7 @@ CSRC = $(UTILSRC) \ # setting. CPPSRC = $(UTILSRC_CPP) \ gtest-all.cpp \ + gmock-all.cpp \ $(CONTROLLERS_ALGO_SRC_CPP) \ $(TRIGGER_DECODERS_SRC_CPP) \ $(ENGINES_SRC_CPP) \ @@ -170,6 +171,7 @@ INCDIR = . \ $(PROJECT_DIR)/hw_layer/algo \ $(PROJECT_DIR)/hw_layer/sensors/ \ test_data_structures \ + googletest/googlemock/include \ googletest/googletest \ googletest/googletest/include \ tests \ diff --git a/unit_tests/gmock-all.cpp b/unit_tests/gmock-all.cpp new file mode 100644 index 0000000000..52dba99c88 --- /dev/null +++ b/unit_tests/gmock-all.cpp @@ -0,0 +1,8 @@ +// this is a work-around since our Makefile does not recognice .cc format +// todo: adjust the makefile so that we can remove this + +#include "googletest/googlemock/src/gmock-cardinalities.cc" +#include "googletest/googlemock/src/gmock-internal-utils.cc" +#include "googletest/googlemock/src/gmock-matchers.cc" +#include "googletest/googlemock/src/gmock-spec-builders.cc" +#include "googletest/googlemock/src/gmock.cc" diff --git a/unit_tests/tests/test_hip9011.cpp b/unit_tests/tests/test_hip9011.cpp index 5898fafd7b..4a18a07a96 100644 --- a/unit_tests/tests/test_hip9011.cpp +++ b/unit_tests/tests/test_hip9011.cpp @@ -9,6 +9,7 @@ #include "HIP9011_logic.h" #include "gtest/gtest.h" #include "gmock/gmock.h" +using ::testing::_; TEST(hip9011, lookup) { assertEqualsM2("", 3183.1013, getRpmByAngleWindowAndTimeUs(600, 360), 0.1); @@ -54,7 +55,36 @@ public: MOCK_METHOD1(sendCommand, void(unsigned char)); }; -TEST(hip9011, takeValue) { +TEST(hip9011, configurationCommands) { - HIP9011 instace(NULL); + MockHip9011Hardware mock; + + HIP9011 instance(&mock); + + instance.prepareHip9011RpmLookup(50); + +// want to invoke method with same parameters a few times +#define PARAMETERS 600, _8MHZ_PRESCALER, /* knockBandCustom*/0, /*cylinderBore*/76, /*hip9011Gain*/1 + + // Not making assumptions on the message send ... + EXPECT_CALL(mock, sendSyncCommand(_)).Times(0); + EXPECT_CALL(mock, sendCommand(SET_GAIN_CMD + 0xE)).Times(1); + instance.handleValue(PARAMETERS); + + EXPECT_CALL(mock, sendSyncCommand(_)).Times(0); + EXPECT_CALL(mock, sendCommand(SET_INTEGRATOR_CMD + 0x1C)).Times(1); + instance.handleValue(PARAMETERS); + + EXPECT_CALL(mock, sendSyncCommand(_)).Times(0); + EXPECT_CALL(mock, sendCommand(SET_BAND_PASS_CMD + 0x2A)).Times(1); + instance.handleValue(PARAMETERS); + + EXPECT_CALL(mock, sendSyncCommand(_)).Times(0); + EXPECT_CALL(mock, sendCommand(SET_PRESCALER_CMD + 6)).Times(1); + instance.handleValue(PARAMETERS); + + // initialization is over, no commands should be sent + EXPECT_CALL(mock, sendSyncCommand(_)).Times(0); + EXPECT_CALL(mock, sendCommand(_)).Times(0); + instance.handleValue(PARAMETERS); }