better pch usage and gmock constructors (#3426)
* break out mock constructors * comment and spacing * unnecessary compiler options * happy stepper Co-authored-by: Matthew Kennedy <makenne@microsoft.com>
This commit is contained in:
parent
1a979805ce
commit
29ec0a5859
|
@ -188,7 +188,7 @@ bool StepDirectionStepper::pulse() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StepperHw::sleep(void) {
|
void StepperHw::sleep() {
|
||||||
pause();
|
pause();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,3 +236,7 @@ void StepDirectionStepper::initialize(brain_pin_e stepPin, brain_pin_e direction
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if EFI_UNIT_TEST
|
||||||
|
void StepperHw::sleep() { }
|
||||||
|
#endif // EFI_UNIT_TEST
|
||||||
|
|
|
@ -18,7 +18,7 @@ public:
|
||||||
// pause between steps
|
// pause between steps
|
||||||
void pause(int divisor = 1) const;
|
void pause(int divisor = 1) const;
|
||||||
// pause and enter the idle mode (less current consumption)
|
// pause and enter the idle mode (less current consumption)
|
||||||
virtual void sleep(void);
|
virtual void sleep();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void setReactionTime(float ms);
|
void setReactionTime(float ms);
|
||||||
|
@ -51,7 +51,7 @@ public:
|
||||||
|
|
||||||
bool step(bool positive) override;
|
bool step(bool positive) override;
|
||||||
|
|
||||||
void sleep(void) override;
|
void sleep() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool update(float dutyMult);
|
bool update(float dutyMult);
|
||||||
|
|
|
@ -101,7 +101,7 @@ bool DualHBridgeStepper::update(float dutyMult) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DualHBridgeStepper::sleep(void) {
|
void DualHBridgeStepper::sleep() {
|
||||||
float sleepingCoef = minI(CONFIG(stepperMinDutyCycle), CONFIG(stepperMaxDutyCycle)) * phaseDutyCycleDivisor;
|
float sleepingCoef = minI(CONFIG(stepperMinDutyCycle), CONFIG(stepperMaxDutyCycle)) * phaseDutyCycleDivisor;
|
||||||
update(sleepingCoef);
|
update(sleepingCoef);
|
||||||
pause();
|
pause();
|
||||||
|
|
|
@ -35,4 +35,5 @@
|
||||||
#include <gmock/gmock.h>
|
#include <gmock/gmock.h>
|
||||||
#include "mocks.h"
|
#include "mocks.h"
|
||||||
#include "engine_test_helper.h"
|
#include "engine_test_helper.h"
|
||||||
|
#include "mock/mock_sensor.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -61,6 +61,7 @@ CPPSRC += $(ALLCPPSRC) \
|
||||||
$(PROJECT_DIR)/../unit_tests/global_mocks.cpp \
|
$(PROJECT_DIR)/../unit_tests/global_mocks.cpp \
|
||||||
$(PROJECT_DIR)/console/binary/tooth_logger.cpp \
|
$(PROJECT_DIR)/console/binary/tooth_logger.cpp \
|
||||||
$(PROJECT_DIR)/console/binary_log/log_field.cpp \
|
$(PROJECT_DIR)/console/binary_log/log_field.cpp \
|
||||||
|
$(PROJECT_DIR)/../unit_tests/mocks.cpp \
|
||||||
|
|
||||||
INCDIR += \
|
INCDIR += \
|
||||||
$(PCH_DIR) \
|
$(PCH_DIR) \
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
#include "pch.h"
|
||||||
|
|
||||||
|
// Constructors/destructors for all mocks live here. If they only exist
|
||||||
|
// in the header (ie, implicitely defined), then that code has to be generated
|
||||||
|
// in every cpp file, instead of generating them only once, which we do here.
|
||||||
|
|
||||||
|
// See https://github.com/google/googletest/blob/master/docs/gmock_cook_book.md#making-the-compilation-faster
|
||||||
|
|
||||||
|
MockEtb::MockEtb() { }
|
||||||
|
MockEtb::~MockEtb() { }
|
||||||
|
|
||||||
|
MockMotor::MockMotor() { }
|
||||||
|
MockMotor::~MockMotor() { }
|
||||||
|
|
||||||
|
MockVp3d::MockVp3d() { }
|
||||||
|
MockVp3d::~MockVp3d() { }
|
||||||
|
|
||||||
|
MockPwm::MockPwm() { }
|
||||||
|
MockPwm::~MockPwm() { }
|
||||||
|
|
||||||
|
MockOutputPin::MockOutputPin() { }
|
||||||
|
MockOutputPin::~MockOutputPin() { }
|
||||||
|
|
||||||
|
MockExecutor::MockExecutor() { }
|
||||||
|
MockExecutor::~MockExecutor() { }
|
||||||
|
|
||||||
|
MockAirmass::MockAirmass() : AirmassVeModelBase(veTable) { }
|
||||||
|
MockAirmass::~MockAirmass() { }
|
||||||
|
|
||||||
|
MockInjectorModel2::MockInjectorModel2() { }
|
||||||
|
MockInjectorModel2::~MockInjectorModel2() { }
|
||||||
|
|
||||||
|
MockStepperHardware::MockStepperHardware() { }
|
||||||
|
MockStepperHardware::~MockStepperHardware() { }
|
|
@ -12,6 +12,9 @@
|
||||||
|
|
||||||
class MockEtb : public IEtbController {
|
class MockEtb : public IEtbController {
|
||||||
public:
|
public:
|
||||||
|
MockEtb();
|
||||||
|
virtual ~MockEtb();
|
||||||
|
|
||||||
// IEtbController mocks
|
// IEtbController mocks
|
||||||
MOCK_METHOD(void, reset, (), (override));
|
MOCK_METHOD(void, reset, (), (override));
|
||||||
MOCK_METHOD(void, update, (), (override));
|
MOCK_METHOD(void, update, (), (override));
|
||||||
|
@ -31,6 +34,9 @@ public:
|
||||||
|
|
||||||
class MockMotor : public DcMotor {
|
class MockMotor : public DcMotor {
|
||||||
public:
|
public:
|
||||||
|
MockMotor();
|
||||||
|
virtual ~MockMotor();
|
||||||
|
|
||||||
MOCK_METHOD(bool, set, (float duty), (override));
|
MOCK_METHOD(bool, set, (float duty), (override));
|
||||||
MOCK_METHOD(float, get, (), (const, override));
|
MOCK_METHOD(float, get, (), (const, override));
|
||||||
MOCK_METHOD(void, enable, (), (override));
|
MOCK_METHOD(void, enable, (), (override));
|
||||||
|
@ -40,21 +46,33 @@ public:
|
||||||
|
|
||||||
class MockVp3d : public ValueProvider3D {
|
class MockVp3d : public ValueProvider3D {
|
||||||
public:
|
public:
|
||||||
|
MockVp3d();
|
||||||
|
virtual ~MockVp3d();
|
||||||
|
|
||||||
MOCK_METHOD(float, getValue, (float xColumn, float yRow), (const, override));
|
MOCK_METHOD(float, getValue, (float xColumn, float yRow), (const, override));
|
||||||
};
|
};
|
||||||
|
|
||||||
class MockPwm : public IPwm {
|
class MockPwm : public IPwm {
|
||||||
public:
|
public:
|
||||||
|
MockPwm();
|
||||||
|
virtual ~MockPwm();
|
||||||
|
|
||||||
MOCK_METHOD(void, setSimplePwmDutyCycle, (float dutyCycle), (override));
|
MOCK_METHOD(void, setSimplePwmDutyCycle, (float dutyCycle), (override));
|
||||||
};
|
};
|
||||||
|
|
||||||
class MockOutputPin : public OutputPin {
|
class MockOutputPin : public OutputPin {
|
||||||
public:
|
public:
|
||||||
|
MockOutputPin();
|
||||||
|
virtual ~MockOutputPin();
|
||||||
|
|
||||||
MOCK_METHOD(void, setValue, (int value), (override));
|
MOCK_METHOD(void, setValue, (int value), (override));
|
||||||
};
|
};
|
||||||
|
|
||||||
class MockExecutor : public TestExecutor {
|
class MockExecutor : public TestExecutor {
|
||||||
public:
|
public:
|
||||||
|
MockExecutor();
|
||||||
|
virtual ~MockExecutor();
|
||||||
|
|
||||||
MOCK_METHOD(void, scheduleByTimestamp, (const char *msg, scheduling_s *scheduling, efitimeus_t timeUs, action_s action), (override));
|
MOCK_METHOD(void, scheduleByTimestamp, (const char *msg, scheduling_s *scheduling, efitimeus_t timeUs, action_s action), (override));
|
||||||
MOCK_METHOD(void, scheduleByTimestampNt, (const char *msg, scheduling_s *scheduling, efitime_t timeUs, action_s action), (override));
|
MOCK_METHOD(void, scheduleByTimestampNt, (const char *msg, scheduling_s *scheduling, efitime_t timeUs, action_s action), (override));
|
||||||
MOCK_METHOD(void, scheduleForLater, (scheduling_s *scheduling, int delayUs, action_s action), (override));
|
MOCK_METHOD(void, scheduleForLater, (scheduling_s *scheduling, int delayUs, action_s action), (override));
|
||||||
|
@ -63,7 +81,8 @@ public:
|
||||||
|
|
||||||
class MockAirmass : public AirmassVeModelBase {
|
class MockAirmass : public AirmassVeModelBase {
|
||||||
public:
|
public:
|
||||||
MockAirmass() : AirmassVeModelBase(veTable) {}
|
MockAirmass();
|
||||||
|
virtual ~MockAirmass();
|
||||||
|
|
||||||
MockVp3d veTable;
|
MockVp3d veTable;
|
||||||
|
|
||||||
|
@ -72,6 +91,9 @@ public:
|
||||||
|
|
||||||
class MockInjectorModel2 : public IInjectorModel {
|
class MockInjectorModel2 : public IInjectorModel {
|
||||||
public:
|
public:
|
||||||
|
MockInjectorModel2();
|
||||||
|
virtual ~MockInjectorModel2();
|
||||||
|
|
||||||
MOCK_METHOD(void, prepare, (), (override));
|
MOCK_METHOD(void, prepare, (), (override));
|
||||||
MOCK_METHOD(floatms_t, getInjectionDuration, (float fuelMassGram), (const, override));
|
MOCK_METHOD(floatms_t, getInjectionDuration, (float fuelMassGram), (const, override));
|
||||||
MOCK_METHOD(float, getFuelMassForDuration, (floatms_t duration), (const, override));
|
MOCK_METHOD(float, getFuelMassForDuration, (floatms_t duration), (const, override));
|
||||||
|
@ -79,5 +101,8 @@ public:
|
||||||
|
|
||||||
class MockStepperHardware : public StepperHw {
|
class MockStepperHardware : public StepperHw {
|
||||||
public:
|
public:
|
||||||
|
MockStepperHardware();
|
||||||
|
virtual ~MockStepperHardware();
|
||||||
|
|
||||||
MOCK_METHOD(bool, step, (bool positive), (override));
|
MOCK_METHOD(bool, step, (bool positive), (override));
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#include "pch.h"
|
#include "pch.h"
|
||||||
#include "injector_model.h"
|
#include "injector_model.h"
|
||||||
#include "mock/mock_sensor.h"
|
|
||||||
|
|
||||||
using ::testing::_;
|
using ::testing::_;
|
||||||
using ::testing::StrictMock;
|
using ::testing::StrictMock;
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#include "pch.h"
|
#include "pch.h"
|
||||||
#include "rusefi_lua.h"
|
#include "rusefi_lua.h"
|
||||||
#include <gtest/gtest.h>
|
|
||||||
|
|
||||||
TEST(LuaBasic, ReturnsNumber) {
|
TEST(LuaBasic, ReturnsNumber) {
|
||||||
auto script = R"(
|
auto script = R"(
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#include "pch.h"
|
#include "pch.h"
|
||||||
|
|
||||||
#include "mock/mock_sensor.h"
|
|
||||||
#include "stored_value_sensor.h"
|
#include "stored_value_sensor.h"
|
||||||
|
|
||||||
class SensorBasic : public ::testing::Test {
|
class SensorBasic : public ::testing::Test {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include "func_chain.h"
|
#include "pch.h"
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include "func_chain.h"
|
||||||
|
|
||||||
struct AddOne final : public SensorConverter {
|
struct AddOne final : public SensorConverter {
|
||||||
SensorResult convert(float input) const {
|
SensorResult convert(float input) const {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include "function_pointer_sensor.h"
|
#include "pch.h"
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include "function_pointer_sensor.h"
|
||||||
|
|
||||||
class SensorFunctionPointer : public ::testing::Test {
|
class SensorFunctionPointer : public ::testing::Test {
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "stored_value_sensor.h"
|
#include "stored_value_sensor.h"
|
||||||
#include "global.h"
|
|
||||||
|
|
||||||
struct MockSensor final : public StoredValueSensor
|
struct MockSensor final : public StoredValueSensor
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
#include "pch.h"
|
#include "pch.h"
|
||||||
|
|
||||||
#include "mock/mock_sensor.h"
|
|
||||||
|
|
||||||
class SensorMocking : public ::testing::Test {
|
class SensorMocking : public ::testing::Test {
|
||||||
protected:
|
protected:
|
||||||
MockSensor realSensor;
|
MockSensor realSensor;
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
|
#include "pch.h"
|
||||||
|
|
||||||
#include "redundant_sensor.h"
|
#include "redundant_sensor.h"
|
||||||
#include "redundant_ford_tps.h"
|
#include "redundant_ford_tps.h"
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
|
||||||
|
|
||||||
#include "mock/mock_sensor.h"
|
|
||||||
|
|
||||||
class SensorRedundant : public ::testing::Test
|
class SensorRedundant : public ::testing::Test
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
|
#include "pch.h"
|
||||||
|
|
||||||
#include "sensor_reader.h"
|
#include "sensor_reader.h"
|
||||||
|
|
||||||
#include "mock/mock_sensor.h"
|
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
|
||||||
|
|
||||||
class SensorBasicReader : public ::testing::Test {
|
class SensorBasicReader : public ::testing::Test {
|
||||||
protected:
|
protected:
|
||||||
void SetUp() override {
|
void SetUp() override {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
#include "pch.h"
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
|
||||||
#include "deadband.h"
|
#include "deadband.h"
|
||||||
|
|
||||||
TEST(Deadband, OutsideDeadband) {
|
TEST(Deadband, OutsideDeadband) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
|
#include "pch.h"
|
||||||
|
|
||||||
#include "buffered_writer.h"
|
#include "buffered_writer.h"
|
||||||
#include <gtest/gtest.h>
|
|
||||||
#include <gmock/gmock.h>
|
|
||||||
|
|
||||||
using ::testing::_;
|
using ::testing::_;
|
||||||
using ::testing::Return;
|
using ::testing::Return;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include <gtest/gtest.h>
|
#include "pch.h"
|
||||||
|
|
||||||
#include "error_accumulator.h"
|
#include "error_accumulator.h"
|
||||||
|
|
||||||
TEST(errorAccumulator, ignoreSmallError) {
|
TEST(errorAccumulator, ignoreSmallError) {
|
||||||
|
|
|
@ -52,7 +52,7 @@ endif
|
||||||
|
|
||||||
# C++ specific options here (added to USE_OPT).
|
# C++ specific options here (added to USE_OPT).
|
||||||
ifeq ($(USE_CPPOPT),)
|
ifeq ($(USE_CPPOPT),)
|
||||||
USE_CPPOPT = -std=gnu++17 -fno-rtti -fpermissive -fexceptions -fno-use-cxa-atexit -Winvalid-pch
|
USE_CPPOPT = -std=gnu++17 -fno-rtti -fno-use-cxa-atexit -Winvalid-pch
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Enable this if you want the linker to remove unused code and data
|
# Enable this if you want the linker to remove unused code and data
|
||||||
|
|
Loading…
Reference in New Issue