From 1defa2551e3d0a2739af6f3bde21e73f4edab82e Mon Sep 17 00:00:00 2001 From: rusefi Date: Thu, 10 Jan 2019 23:15:24 -0500 Subject: [PATCH] reducing global variables in tests --- unit_tests/tests/test_fuelCut.cpp | 2 +- unit_tests/tests/test_trigger_decoder.cpp | 32 ++++++++++----------- unit_tests/tests/test_trigger_noiseless.cpp | 8 +++--- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/unit_tests/tests/test_fuelCut.cpp b/unit_tests/tests/test_fuelCut.cpp index 51b794669a..12275036a8 100644 --- a/unit_tests/tests/test_fuelCut.cpp +++ b/unit_tests/tests/test_fuelCut.cpp @@ -42,7 +42,7 @@ TEST(fuelCut, coasting) { // set 'running' RPM - just above RpmHigh threshold engine->rpmCalculator.mockRpm = engineConfiguration->coastingFuelCutRpmHigh + 1; // 'advance' time (amount doesn't matter) - timeNowUs += 1000; + eth.moveTimeForwardUs(1000); const float normalInjDuration = 1.5f; /* diff --git a/unit_tests/tests/test_trigger_decoder.cpp b/unit_tests/tests/test_trigger_decoder.cpp index 12a79df774..7bc5378691 100644 --- a/unit_tests/tests/test_trigger_decoder.cpp +++ b/unit_tests/tests/test_trigger_decoder.cpp @@ -339,7 +339,7 @@ void testRpmCalculator(void) { assertEquals(engine->triggerCentral.triggerState.shaft_is_synchronized, 1); - timeNowUs += MS2US(5); // 5ms + eth.moveTimeForwardUs(MS2US(5)); // 5ms int start = eth.getTimeNowUs(); assertEqualsM("start value", 485000, start); @@ -433,7 +433,7 @@ void testRpmCalculator(void) { assertEqualsM("queue size 7", 0, engine->executor.size()); engine->executor.clear(); - timeNowUs += 5000; // 5ms + eth.moveTimeForwardUs(5000); // 5ms eth.firePrimaryTriggerRise(); assertEqualsM("queue size 8", 4, engine->executor.size()); // todo: assert queue elements completely @@ -698,7 +698,7 @@ static void setTestBug299(EngineTestHelper *eth) { /** * Trigger up again */ - timeNowUs += MS2US(20); + eth->moveTimeForwardUs(MS2US(20)); eth->assertInjectorUpEvent("22@0", 0, MS2US(-11.5), 0); eth->assertInjectorDownEvent("22@1", 1, MS2US(-10), 0); eth->assertInjectorUpEvent("22@2", 2, MS2US(-1.5), 1); @@ -718,7 +718,7 @@ static void setTestBug299(EngineTestHelper *eth) { assertEqualsM("exec#2", 0, eth->executeActions()); - timeNowUs += MS2US(20); + eth->moveTimeForwardUs(MS2US(20)); eth->executeActions(); eth->firePrimaryTriggerFall(); // fuel schedule - short pulses. and more realistic schedule this time @@ -777,7 +777,7 @@ void testFuelSchedulerBug299smallAndMedium(void) { assertEqualsM("duty for maf=3", 62.5, getInjectorDutyCycle(eth.engine.rpmCalculator.getRpm(PASS_ENGINE_PARAMETER_SIGNATURE) PASS_ENGINE_PARAMETER_SUFFIX)); assertEqualsM("qs#1", 4, engine->executor.size()); - timeNowUs += MS2US(20); + eth.moveTimeForwardUs(MS2US(20)); assertEqualsM("exec#2#0", 4, eth.executeActions()); assertEqualsM("qs#1#2", 0, engine->executor.size()); @@ -842,7 +842,7 @@ void testFuelSchedulerBug299smallAndMedium(void) { assertInjectionEvent("inj#2", &t->elements[2], 0, 0, 153, false); assertInjectionEvent("inj#3", &t->elements[3], 1, 0, 333, false); - timeNowUs += MS2US(20); + eth.moveTimeForwardUs(MS2US(20)); assertEqualsM("qs#02", 5, engine->executor.size()); // assertInjectorUpEvent("6@0", 0, MS2US(-12.5), 1); // assertInjectorDownEvent("6@1", 1, MS2US(-10.0), 0); @@ -869,7 +869,7 @@ void testFuelSchedulerBug299smallAndMedium(void) { assertInjectors("#1_ij_", 0, 0); - timeNowUs += MS2US(20); + eth.moveTimeForwardUs(MS2US(20)); // time...|-20.....|-10.....|0.......|10......|20......|30......|40......| // inj #0 |########|.......#|........|........|........|........|........| @@ -901,7 +901,7 @@ void testFuelSchedulerBug299smallAndMedium(void) { assertEqualsM("executed #6", 0, eth.executeActions()); - timeNowUs += MS2US(20); + eth.moveTimeForwardUs(MS2US(20)); assertEqualsM("executed #06", 4, eth.executeActions()); assertEqualsM("qs#06", 1, engine->executor.size()); assertInjectors("inj#2", 1, 0); @@ -920,7 +920,7 @@ void testFuelSchedulerBug299smallAndMedium(void) { // assertInjectorDownEvent("07@8", 8, MS2US(50), 0); assertEqualsM("executeAll#3", 0, eth.executeActions()); - timeNowUs += MS2US(20); + eth.moveTimeForwardUs(MS2US(20)); assertEqualsM("executeAll#4", 4, eth.executeActions()); t = &ENGINE(injectionEvents); @@ -967,7 +967,7 @@ void testFuelSchedulerBug299smallAndMedium(void) { eth.fireFall(20); eth.executeActions(); - timeNowUs += MS2US(20); + eth.moveTimeForwardUs(MS2US(20)); eth.executeActions(); eth.firePrimaryTriggerRise(); @@ -1056,7 +1056,7 @@ void testFuelSchedulerBug299smallAndLarge(void) { assertEqualsM("Lqs#1", 4, engine->executor.size()); - timeNowUs += MS2US(20); + eth.moveTimeForwardUs(MS2US(20)); eth.executeActions(); // injector #1 is low before the test @@ -1107,7 +1107,7 @@ void testFuelSchedulerBug299smallAndLarge(void) { assertFalseM("injector@3", enginePins.injectors[0].currentLogicValue); - timeNowUs += MS2US(20); + eth.moveTimeForwardUs(MS2US(20)); eth.executeActions(); assertEqualsM("Lqs#04", 0, engine->executor.size()); @@ -1127,12 +1127,12 @@ void testFuelSchedulerBug299smallAndLarge(void) { //todo assertInjectorDownEvent("L016@2", 2, MS2US(10), 0); - timeNowUs += MS2US(20); + eth.moveTimeForwardUs(MS2US(20)); eth.executeActions(); // issue here eth.firePrimaryTriggerFall(); - timeNowUs += MS2US(20); + eth.moveTimeForwardUs(MS2US(20)); eth.executeActions(); eth.firePrimaryTriggerRise(); @@ -1195,14 +1195,14 @@ void testSparkReverseOrderBug319(void) { eth.executeActions(); - timeNowUs += 100; // executing new signal too early + eth.moveTimeForwardUs(100); // executing new signal too early eth.firePrimaryTriggerFall(); eth.executeActions(); assertEqualsM("out-of-order #1", 1, enginePins.coils[3].outOfOrder); - timeNowUs += MS2US(200); // moving time forward to execute all pending actions + eth.moveTimeForwardUs(MS2US(200)); // moving time forward to execute all pending actions eth.executeActions(); assertEqualsM("out-of-order #2", 0, enginePins.coils[3].outOfOrder); diff --git a/unit_tests/tests/test_trigger_noiseless.cpp b/unit_tests/tests/test_trigger_noiseless.cpp index 74c2e1cf8d..52d6651dab 100644 --- a/unit_tests/tests/test_trigger_noiseless.cpp +++ b/unit_tests/tests/test_trigger_noiseless.cpp @@ -43,7 +43,7 @@ static void fireEvent(EngineTestHelper *eth, bool isRise) { */ static void noisyPulse(EngineTestHelper *eth, int idx, int durationUs, bool isRise, int noiseIdx, int durationNoiseUs, int offsetNoiseUs, int numSpikes) { // skip some time at the beginning - timeNowUs += offsetNoiseUs; + eth->moveTimeForwardUs(offsetNoiseUs); durationUs -= offsetNoiseUs; // add noise spikes if (idx == noiseIdx) { @@ -53,19 +53,19 @@ static void noisyPulse(EngineTestHelper *eth, int idx, int durationUs, bool isRi for (int i = 0; i < numSpikes; i++) { // start spike fireEvent(eth, isRise); - timeNowUs += durationNoiseUs; + eth->moveTimeForwardUs(durationNoiseUs); durationUs -= durationNoiseUs; // end spike fireEvent(eth, !isRise); // add space between spikes - timeNowUs += noiseIntervalUs; + eth->moveTimeForwardUs(noiseIntervalUs); durationUs -= noiseIntervalUs; } } // add the rest of pulse period - timeNowUs += durationUs; + eth->moveTimeForwardUs(durationUs); fireEvent(eth, isRise); }