test_timer
This commit is contained in:
parent
16b8fb64ca
commit
490d3a6957
|
@ -2,6 +2,10 @@
|
|||
|
||||
#include "efitime.h"
|
||||
|
||||
/**
|
||||
* Helper class with "has X amount of time elapsed since most recent reset" methods
|
||||
* Brand new instances have most recent reset time far in the past, i.e. "hasElapse" is true for any reasonable range
|
||||
*/
|
||||
class Timer {
|
||||
public:
|
||||
void reset();
|
||||
|
|
|
@ -127,7 +127,7 @@ void EngineTestHelper::fireRise(float delayMs) {
|
|||
}
|
||||
|
||||
void EngineTestHelper::smartFireRise(float delayMs) {
|
||||
smartMoveTimeForwardUs(MS2US(delayMs));
|
||||
moveTimeForwardAndInvokeEventsUs(MS2US(delayMs));
|
||||
firePrimaryTriggerRise();
|
||||
}
|
||||
|
||||
|
@ -137,7 +137,7 @@ void EngineTestHelper::fireFall(float delayMs) {
|
|||
}
|
||||
|
||||
void EngineTestHelper::smartFireFall(float delayMs) {
|
||||
smartMoveTimeForwardUs(MS2US(delayMs));
|
||||
moveTimeForwardAndInvokeEventsUs(MS2US(delayMs));
|
||||
firePrimaryTriggerFall();
|
||||
}
|
||||
|
||||
|
@ -196,6 +196,10 @@ void EngineTestHelper::moveTimeForwardMs(float deltaTimeMs) {
|
|||
moveTimeForwardUs(MS2US(deltaTimeMs));
|
||||
}
|
||||
|
||||
void EngineTestHelper::moveTimeForwardSec(float deltaTimeSec) {
|
||||
moveTimeForwardUs(MS2US(1000 * deltaTimeSec));
|
||||
}
|
||||
|
||||
void EngineTestHelper::moveTimeForwardUs(int deltaTimeUs) {
|
||||
if (printTriggerDebug || printFuelDebug) {
|
||||
printf("moveTimeForwardUs %.1fms\r\n", deltaTimeUs / 1000.0);
|
||||
|
@ -203,16 +207,16 @@ void EngineTestHelper::moveTimeForwardUs(int deltaTimeUs) {
|
|||
timeNowUs += deltaTimeUs;
|
||||
}
|
||||
|
||||
void EngineTestHelper::smartMoveTimeForwardSeconds(int deltaTimeSeconds) {
|
||||
smartMoveTimeForwardUs(MS2US(1000 * deltaTimeSeconds));
|
||||
void EngineTestHelper::moveTimeForwardAndInvokeEventsSec(int deltaTimeSeconds) {
|
||||
moveTimeForwardAndInvokeEventsUs(MS2US(1000 * deltaTimeSeconds));
|
||||
}
|
||||
|
||||
/**
|
||||
* this method executed all pending events wile
|
||||
* this method executes all pending events while moving time forward
|
||||
*/
|
||||
void EngineTestHelper::smartMoveTimeForwardUs(int deltaTimeUs) {
|
||||
void EngineTestHelper::moveTimeForwardAndInvokeEventsUs(int deltaTimeUs) {
|
||||
if (printTriggerDebug || printFuelDebug) {
|
||||
printf("smartMoveTimeForwardUs %.1fms\r\n", deltaTimeUs / 1000.0);
|
||||
printf("moveTimeForwardAndInvokeEventsUs %.1fms\r\n", deltaTimeUs / 1000.0);
|
||||
}
|
||||
int targetTime = timeNowUs + deltaTimeUs;
|
||||
|
||||
|
|
|
@ -53,8 +53,8 @@ public:
|
|||
*/
|
||||
void smartFireRise(float delayMs);
|
||||
void smartFireFall(float delayMs);
|
||||
void smartMoveTimeForwardUs(int deltaTimeUs);
|
||||
void smartMoveTimeForwardSeconds(int deltaTimeSeconds);
|
||||
void moveTimeForwardAndInvokeEventsUs(int deltaTimeUs);
|
||||
void moveTimeForwardAndInvokeEventsSec(int deltaTimeSeconds);
|
||||
void smartFireTriggerEvents2(int count, float delayMs);
|
||||
|
||||
/**
|
||||
|
@ -82,6 +82,7 @@ public:
|
|||
|
||||
int executeActions();
|
||||
void moveTimeForwardMs(float deltaTimeMs);
|
||||
void moveTimeForwardSec(float deltaTimeSec);
|
||||
efitimeus_t getTimeNowUs(void);
|
||||
|
||||
Engine engine;
|
||||
|
|
|
@ -33,7 +33,7 @@ TEST(DynoView, VSS_T1) {
|
|||
setMockVehicleSpeed(18.0);
|
||||
dut.update(ICU);
|
||||
|
||||
eth.smartMoveTimeForwardSeconds(20);
|
||||
eth.moveTimeForwardAndInvokeEventsSec(20);
|
||||
setMockVehicleSpeed(126.0);
|
||||
dut.update(ICU);
|
||||
|
||||
|
|
|
@ -165,7 +165,7 @@ TEST(LaunchControl, CompleteRun) {
|
|||
|
||||
|
||||
//we have a 3 seconds delay to actually enable it!
|
||||
eth.smartMoveTimeForwardSeconds(1);
|
||||
eth.moveTimeForwardAndInvokeEventsSec(1);
|
||||
updateLaunchConditions(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
spark = false;
|
||||
fuel = false;
|
||||
|
@ -174,7 +174,7 @@ TEST(LaunchControl, CompleteRun) {
|
|||
EXPECT_FALSE(spark);
|
||||
EXPECT_FALSE(fuel);
|
||||
|
||||
eth.smartMoveTimeForwardSeconds(3);
|
||||
eth.moveTimeForwardAndInvokeEventsSec(3);
|
||||
updateLaunchConditions(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
spark = false;
|
||||
fuel = false;
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
TEST(start, startStop) {
|
||||
std::unordered_map<SensorType, float> sensorVals = {{ SensorType::AcceleratorPedal, 0 }};
|
||||
WITH_ENGINE_TEST_HELPER_SENS(BMW_M73_PROTEUS, sensorVals);
|
||||
eth.smartMoveTimeForwardSeconds(1); // '0' time has special meaning for implementation so let's move forward
|
||||
eth.moveTimeForwardAndInvokeEventsSec(1); // '0' time has special meaning for implementation so let's move forward
|
||||
|
||||
// this is a pull-up, so 'true' on start-up
|
||||
setMockState(engineConfiguration->startStopButtonPin, true);
|
||||
|
@ -22,25 +22,25 @@ TEST(start, startStop) {
|
|||
ASSERT_FALSE(efiReadPin(engineConfiguration->starterControlPin));
|
||||
|
||||
// startup 'timeout' duration of time is a special case so let's sleep a bit
|
||||
eth.smartMoveTimeForwardSeconds(10);
|
||||
eth.moveTimeForwardAndInvokeEventsSec(10);
|
||||
slowStartStopButtonCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
ASSERT_FALSE(efiReadPin(engineConfiguration->starterControlPin));
|
||||
|
||||
|
||||
|
||||
eth.smartMoveTimeForwardSeconds(10);
|
||||
eth.moveTimeForwardAndInvokeEventsSec(10);
|
||||
// hit 'start' button! inverted since pull-up
|
||||
setMockState(engineConfiguration->startStopButtonPin, false);
|
||||
slowStartStopButtonCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
ASSERT_TRUE(efiReadPin(engineConfiguration->starterControlPin));
|
||||
|
||||
eth.smartMoveTimeForwardSeconds(5);
|
||||
eth.moveTimeForwardAndInvokeEventsSec(5);
|
||||
slowStartStopButtonCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
|
||||
eth.smartMoveTimeForwardSeconds(5);
|
||||
eth.moveTimeForwardAndInvokeEventsSec(5);
|
||||
slowStartStopButtonCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
|
||||
eth.smartMoveTimeForwardSeconds(5);
|
||||
eth.moveTimeForwardAndInvokeEventsSec(5);
|
||||
slowStartStopButtonCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
// starter is now OFF due to timeout
|
||||
ASSERT_FALSE(efiReadPin(engineConfiguration->starterControlPin));
|
||||
|
|
|
@ -18,6 +18,7 @@ TESTS_SRC_CPP = \
|
|||
tests/sensor/test_cj125.cpp \
|
||||
tests/util/test_buffered_writer.cpp \
|
||||
tests/util/test_error_accumulator.cpp \
|
||||
tests/util/test_timer.cpp \
|
||||
tests/test_util.cpp \
|
||||
tests/test_start_stop.cpp \
|
||||
tests/test_hardware_reinit.cpp \
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
#include "engine_test_helper.h"
|
||||
#include "timer.h"
|
||||
|
||||
|
||||
TEST(util, timer) {
|
||||
WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
|
||||
Timer timer;
|
||||
ASSERT_TRUE(timer.hasElapsedSec(3));
|
||||
timer.reset();
|
||||
ASSERT_FALSE(timer.hasElapsedSec(3));
|
||||
|
||||
eth.moveTimeForwardSec(4);
|
||||
ASSERT_TRUE(timer.hasElapsedSec(3));
|
||||
}
|
Loading…
Reference in New Issue