mirror of https://github.com/rusefi/rusefi.git
only: setTimeNowUs(): replace global fiddling with a function call
This commit is contained in:
parent
b5e3694647
commit
302b11abee
|
@ -48,3 +48,8 @@ efitimems_t getTimeNowMs();
|
|||
* @brief Current system time in seconds (32 bits)
|
||||
*/
|
||||
efitimesec_t getTimeNowS();
|
||||
|
||||
#if EFI_UNIT_TEST
|
||||
void setTimeNowUs(int us);
|
||||
void advanceTimeUs(int us);
|
||||
#endif
|
||||
|
|
|
@ -73,7 +73,7 @@ namespace chibios_rt {
|
|||
}
|
||||
#endif
|
||||
|
||||
#define UNIT_TEST_BUSY_WAIT_CALLBACK() { timeNowUs++; }
|
||||
#define UNIT_TEST_BUSY_WAIT_CALLBACK() { advanceTimeUs(1); }
|
||||
|
||||
#define chsnprintf snprintf
|
||||
#define chvsnprintf vsnprintf
|
||||
|
|
|
@ -12,6 +12,16 @@ efitimems_t getTimeNowMs() {
|
|||
return US2MS(getTimeNowUs());
|
||||
}
|
||||
|
||||
extern int timeNowUs;
|
||||
|
||||
void setTimeNowUs(int us) {
|
||||
timeNowUs = us;
|
||||
}
|
||||
|
||||
void advanceTimeUs(int us) {
|
||||
timeNowUs += us;
|
||||
}
|
||||
|
||||
void initLogging(LoggingWithStorage *logging, const char *name) {
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ extern int minCrankingRpm;
|
|||
|
||||
EngineTestHelperBase::EngineTestHelperBase(Engine * eng, engine_configuration_s * econfig, persistent_config_s * pers) {
|
||||
// todo: make this not a global variable, we need currentTimeProvider interface on engine
|
||||
timeNowUs = 0;
|
||||
setTimeNowUs(0);
|
||||
minCrankingRpm = 0;
|
||||
EnableToothLogger();
|
||||
if (engine || engineConfiguration || config) {
|
||||
|
@ -227,7 +227,7 @@ void EngineTestHelper::clearQueue() {
|
|||
}
|
||||
|
||||
int EngineTestHelper::executeActions() {
|
||||
return engine.executor.executeAll(timeNowUs);
|
||||
return engine.executor.executeAll(getTimeNowUs());
|
||||
}
|
||||
|
||||
void EngineTestHelper::moveTimeForwardMs(float deltaTimeMs) {
|
||||
|
@ -242,7 +242,7 @@ void EngineTestHelper::moveTimeForwardUs(int deltaTimeUs) {
|
|||
if (printTriggerDebug || printFuelDebug) {
|
||||
printf("moveTimeForwardUs %.1fms\r\n", deltaTimeUs / 1000.0);
|
||||
}
|
||||
timeNowUs += deltaTimeUs;
|
||||
advanceTimeUs(deltaTimeUs);
|
||||
}
|
||||
|
||||
void EngineTestHelper::moveTimeForwardAndInvokeEventsSec(int deltaTimeSeconds) {
|
||||
|
|
|
@ -165,8 +165,7 @@ TEST(fuelCut, delay) {
|
|||
|
||||
const float normalInjDuration = 1.5f;
|
||||
|
||||
extern int timeNowUs;
|
||||
timeNowUs = 1e6;
|
||||
setTimeNowUs(1e6);
|
||||
|
||||
// process
|
||||
eth.engine.periodicFastCallback();
|
||||
|
@ -182,14 +181,14 @@ TEST(fuelCut, delay) {
|
|||
EXPECT_NORMAL();
|
||||
|
||||
// Change nothing else, but advance time and update again
|
||||
timeNowUs += 0.9e6;
|
||||
advanceTimeUs(0.9e6);
|
||||
eth.engine.periodicFastCallback();
|
||||
|
||||
// too soon, still no cut
|
||||
EXPECT_NORMAL();
|
||||
|
||||
// Change nothing else, but advance time and update again
|
||||
timeNowUs += 0.2e6;
|
||||
advanceTimeUs(0.2e6);
|
||||
eth.engine.periodicFastCallback();
|
||||
|
||||
// Should now be cut!
|
||||
|
|
Loading…
Reference in New Issue