mock TPS refactoring

This commit is contained in:
rusefi 2017-11-16 10:29:40 -05:00
parent 5d18216133
commit 9bd52debc0
3 changed files with 18 additions and 9 deletions

View File

@ -9,11 +9,20 @@
#include "allsensors.h" #include "allsensors.h"
#if !EFI_PROD_CODE #if !EFI_PROD_CODE
int mockTps; static int mockTps;
#endif #endif
EXTERN_ENGINE; EXTERN_ENGINE;
/**
* this allows unit tests to simulate TPS position
*/
void setMockTpsPosition(percent_t tpsPosition) {
#if !EFI_PROD_CODE
mockTps = TPS_TS_CONVERSION * tpsPosition;
#endif
}
/** /**
* We are using one instance for read and another for modification, this is how we get lock-free thread-safety * We are using one instance for read and another for modification, this is how we get lock-free thread-safety
* *
@ -94,8 +103,9 @@ float getTPSVoltage(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
*/ */
int getTPS12bitAdc(DECLARE_ENGINE_PARAMETER_SIGNATURE) { int getTPS12bitAdc(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
#if !EFI_PROD_CODE #if !EFI_PROD_CODE
if (mockTps != MOCK_UNDEFINED) if (mockTps != MOCK_UNDEFINED) {
return mockTps; return mockTps;
}
#endif #endif
if (engineConfiguration->tpsAdcChannel == EFI_ADC_NONE) if (engineConfiguration->tpsAdcChannel == EFI_ADC_NONE)
return -1; return -1;

View File

@ -30,6 +30,7 @@ int getTPS12bitAdc(DECLARE_ENGINE_PARAMETER_SIGNATURE);
float getTPSVoltage(DECLARE_ENGINE_PARAMETER_SIGNATURE); float getTPSVoltage(DECLARE_ENGINE_PARAMETER_SIGNATURE);
percent_t getTpsValue(int adc DECLARE_ENGINE_PARAMETER_SUFFIX); percent_t getTpsValue(int adc DECLARE_ENGINE_PARAMETER_SUFFIX);
void setBosch0280750009(DECLARE_ENGINE_PARAMETER_SIGNATURE); void setBosch0280750009(DECLARE_ENGINE_PARAMETER_SIGNATURE);
void setMockTpsPosition(percent_t tpsPosition);
typedef struct { typedef struct {
efitimeus_t prevTime; efitimeus_t prevTime;

View File

@ -240,8 +240,6 @@ static void testTriggerDecoder3(const char *msg, engine_type_e type, int synchPo
extern EventQueue schedulingQueue; extern EventQueue schedulingQueue;
extern int mockTps;
void testStartupFuelPumping(void) { void testStartupFuelPumping(void) {
printf("*************************************************** testStartupFuelPumping\r\n"); printf("*************************************************** testStartupFuelPumping\r\n");
EngineTestHelper eth(FORD_INLINE_6_1995); EngineTestHelper eth(FORD_INLINE_6_1995);
@ -254,11 +252,11 @@ void testStartupFuelPumping(void) {
engine->engineConfiguration->tpsMin = 0; engine->engineConfiguration->tpsMin = 0;
engine->engineConfiguration->tpsMax = 10; engine->engineConfiguration->tpsMax = 10;
mockTps = TPS_TS_CONVERSION * 6; setMockTpsPosition(6);
sf.update(PASS_ENGINE_PARAMETER_SIGNATURE); sf.update(PASS_ENGINE_PARAMETER_SIGNATURE);
assertEqualsM("pc#1", 1, sf.pumpsCounter); assertEqualsM("pc#1", 1, sf.pumpsCounter);
mockTps = TPS_TS_CONVERSION * 3; setMockTpsPosition(3);
sf.update(PASS_ENGINE_PARAMETER_SIGNATURE); sf.update(PASS_ENGINE_PARAMETER_SIGNATURE);
assertEqualsM("pumpsCounter#2", 1, sf.pumpsCounter); assertEqualsM("pumpsCounter#2", 1, sf.pumpsCounter);
@ -269,16 +267,16 @@ void testStartupFuelPumping(void) {
sf.update(PASS_ENGINE_PARAMETER_SIGNATURE); sf.update(PASS_ENGINE_PARAMETER_SIGNATURE);
assertEqualsM("pc#4", 0, sf.pumpsCounter); assertEqualsM("pc#4", 0, sf.pumpsCounter);
mockTps = TPS_TS_CONVERSION * 7; setMockTpsPosition(7);
engine->rpmCalculator.mockRpm = 0; engine->rpmCalculator.mockRpm = 0;
sf.update(PASS_ENGINE_PARAMETER_SIGNATURE); sf.update(PASS_ENGINE_PARAMETER_SIGNATURE);
assertEqualsM("pc#5", 1, sf.pumpsCounter); assertEqualsM("pc#5", 1, sf.pumpsCounter);
mockTps = TPS_TS_CONVERSION * 3; setMockTpsPosition(3);
sf.update(PASS_ENGINE_PARAMETER_SIGNATURE); sf.update(PASS_ENGINE_PARAMETER_SIGNATURE);
assertEqualsM("pc#6", 1, sf.pumpsCounter); assertEqualsM("pc#6", 1, sf.pumpsCounter);
mockTps = TPS_TS_CONVERSION * 7; setMockTpsPosition(7);
sf.update(PASS_ENGINE_PARAMETER_SIGNATURE); sf.update(PASS_ENGINE_PARAMETER_SIGNATURE);
assertEqualsM("pc#7", 2, sf.pumpsCounter); assertEqualsM("pc#7", 2, sf.pumpsCounter);
} }