forked from rusefi/rusefi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_sd_log_trigger.cpp
More file actions
88 lines (72 loc) · 2.62 KB
/
Copy pathtest_sd_log_trigger.cpp
File metadata and controls
88 lines (72 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
* @file test_sd_log_trigger.cpp
*
* Conditional SD logging trigger (phase 1) state machine tests.
*/
#include "pch.h"
#include "sd_log_trigger.h"
TEST(sdLog, unconditionalWhenDisabled) {
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
engineConfiguration->sdCardConditionalLogging = false;
auto m = engine->module<SdLogTrigger>();
m->onSlowCallback();
EXPECT_TRUE(m->shouldLog());
EXPECT_EQ(SD_LOG_UNCONDITIONAL, m->getState());
}
TEST(sdLog, rpmHysteresisAndStopDelay) {
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
engineConfiguration->sdCardConditionalLogging = true;
engineConfiguration->sdLogStartRpm = 4000;
engineConfiguration->sdLogStopRpm = 3000;
engineConfiguration->sdLogStopDelay = 2;
auto m = engine->module<SdLogTrigger>();
// below start -> not logging
Sensor::setMockValue(SensorType::Rpm, 1000);
m->onSlowCallback();
EXPECT_FALSE(m->shouldLog());
EXPECT_EQ(SD_LOG_WAIT_RPM, m->getState());
// at/above start -> logging
Sensor::setMockValue(SensorType::Rpm, 5000);
m->onSlowCallback();
EXPECT_TRUE(m->shouldLog());
EXPECT_EQ(SD_LOG_ACTIVE, m->getState());
// dead zone (stop <= rpm < start) -> keep logging (hysteresis)
Sensor::setMockValue(SensorType::Rpm, 3500);
m->onSlowCallback();
EXPECT_TRUE(m->shouldLog());
EXPECT_EQ(SD_LOG_ACTIVE, m->getState());
// below stop but within the delay -> still logging
Sensor::setMockValue(SensorType::Rpm, 1000);
m->onSlowCallback();
EXPECT_TRUE(m->shouldLog());
EXPECT_EQ(SD_LOG_STOP_DELAY, m->getState());
// still below stop after the delay -> stop logging
eth.moveTimeForwardSec(3);
m->onSlowCallback();
EXPECT_FALSE(m->shouldLog());
EXPECT_EQ(SD_LOG_WAIT_RPM, m->getState());
}
TEST(sdLog, secondaryConditionGatesEntry) {
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
engineConfiguration->sdCardConditionalLogging = true;
engineConfiguration->sdLogStartRpm = 4000;
engineConfiguration->sdLogStopRpm = 3000;
engineConfiguration->sdLogMinTps = 50;
auto m = engine->module<SdLogTrigger>();
// RPM ok but TPS below the minimum -> does not start
Sensor::setMockValue(SensorType::Rpm, 5000);
Sensor::setMockValue(SensorType::Tps1, 10);
m->onSlowCallback();
EXPECT_FALSE(m->shouldLog());
EXPECT_EQ(SD_LOG_WAIT_COND, m->getState());
// TPS now above the minimum -> starts
Sensor::setMockValue(SensorType::Tps1, 80);
m->onSlowCallback();
EXPECT_TRUE(m->shouldLog());
EXPECT_EQ(SD_LOG_ACTIVE, m->getState());
// secondary conditions gate ENTRY only: TPS dropping does not stop logging while RPM stays up
Sensor::setMockValue(SensorType::Tps1, 0);
m->onSlowCallback();
EXPECT_TRUE(m->shouldLog());
EXPECT_EQ(SD_LOG_ACTIVE, m->getState());
}