mock TPS refactoring
This commit is contained in:
parent
6b69ac333c
commit
935622a4e2
|
@ -9,11 +9,20 @@
|
|||
#include "allsensors.h"
|
||||
|
||||
#if !EFI_PROD_CODE
|
||||
int mockTps;
|
||||
static int mockTps;
|
||||
#endif
|
||||
|
||||
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
|
||||
*
|
||||
|
@ -94,8 +103,9 @@ float getTPSVoltage(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
*/
|
||||
int getTPS12bitAdc(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||
#if !EFI_PROD_CODE
|
||||
if (mockTps != MOCK_UNDEFINED)
|
||||
if (mockTps != MOCK_UNDEFINED) {
|
||||
return mockTps;
|
||||
}
|
||||
#endif
|
||||
if (engineConfiguration->tpsAdcChannel == EFI_ADC_NONE)
|
||||
return -1;
|
||||
|
|
|
@ -30,6 +30,7 @@ int getTPS12bitAdc(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
|||
float getTPSVoltage(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
||||
percent_t getTpsValue(int adc DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||
void setBosch0280750009(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
||||
void setMockTpsPosition(percent_t tpsPosition);
|
||||
|
||||
typedef struct {
|
||||
efitimeus_t prevTime;
|
||||
|
|
|
@ -240,8 +240,6 @@ static void testTriggerDecoder3(const char *msg, engine_type_e type, int synchPo
|
|||
|
||||
extern EventQueue schedulingQueue;
|
||||
|
||||
extern int mockTps;
|
||||
|
||||
void testStartupFuelPumping(void) {
|
||||
printf("*************************************************** testStartupFuelPumping\r\n");
|
||||
EngineTestHelper eth(FORD_INLINE_6_1995);
|
||||
|
@ -254,11 +252,11 @@ void testStartupFuelPumping(void) {
|
|||
engine->engineConfiguration->tpsMin = 0;
|
||||
engine->engineConfiguration->tpsMax = 10;
|
||||
|
||||
mockTps = TPS_TS_CONVERSION * 6;
|
||||
setMockTpsPosition(6);
|
||||
sf.update(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
assertEqualsM("pc#1", 1, sf.pumpsCounter);
|
||||
|
||||
mockTps = TPS_TS_CONVERSION * 3;
|
||||
setMockTpsPosition(3);
|
||||
sf.update(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
assertEqualsM("pumpsCounter#2", 1, sf.pumpsCounter);
|
||||
|
||||
|
@ -269,16 +267,16 @@ void testStartupFuelPumping(void) {
|
|||
sf.update(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
assertEqualsM("pc#4", 0, sf.pumpsCounter);
|
||||
|
||||
mockTps = TPS_TS_CONVERSION * 7;
|
||||
setMockTpsPosition(7);
|
||||
engine->rpmCalculator.mockRpm = 0;
|
||||
sf.update(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
assertEqualsM("pc#5", 1, sf.pumpsCounter);
|
||||
|
||||
mockTps = TPS_TS_CONVERSION * 3;
|
||||
setMockTpsPosition(3);
|
||||
sf.update(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
assertEqualsM("pc#6", 1, sf.pumpsCounter);
|
||||
|
||||
mockTps = TPS_TS_CONVERSION * 7;
|
||||
setMockTpsPosition(7);
|
||||
sf.update(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
assertEqualsM("pc#7", 2, sf.pumpsCounter);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue