From bc15e0826dcc2ec6f91f3830c9ffb794f217fedd Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Wed, 15 Apr 2020 13:20:45 -0700 Subject: [PATCH] CLT consumer: fsio (#1302) * idle * CLT test prep * idle target * header * air interpolate * ancient comment * fuel cut * fuel cut, idle tests * cleanup * fsio test help --- firmware/controllers/core/fsio_impl.cpp | 4 +- unit_tests/engine_test_helper.cpp | 5 +- unit_tests/engine_test_helper.h | 2 +- unit_tests/global.h | 9 ++- unit_tests/tests/test_logic_expression.cpp | 69 ++++++++++------------ 5 files changed, 44 insertions(+), 45 deletions(-) diff --git a/firmware/controllers/core/fsio_impl.cpp b/firmware/controllers/core/fsio_impl.cpp index 49df9af255..06652b7c11 100644 --- a/firmware/controllers/core/fsio_impl.cpp +++ b/firmware/controllers/core/fsio_impl.cpp @@ -121,9 +121,9 @@ float getEngineValue(le_action_e action DECLARE_ENGINE_PARAMETER_SUFFIX) { case LE_METHOD_AC_TOGGLE: return getAcToggle(PASS_ENGINE_PARAMETER_SIGNATURE); case LE_METHOD_COOLANT: - return getCoolantTemperature(); + return Sensor::get(SensorType::Clt).value_or(0); case LE_METHOD_IS_COOLANT_BROKEN: - return engine->isCltBroken; + return !Sensor::get(SensorType::Clt).Valid; case LE_METHOD_INTAKE_AIR: return getIntakeAirTemperature(); case LE_METHOD_RPM: diff --git a/unit_tests/engine_test_helper.cpp b/unit_tests/engine_test_helper.cpp index dcd8f09539..17edd9567d 100644 --- a/unit_tests/engine_test_helper.cpp +++ b/unit_tests/engine_test_helper.cpp @@ -76,7 +76,10 @@ EngineTestHelper::EngineTestHelper(engine_type_e engineType, configuration_callb } -EngineTestHelper::EngineTestHelper(engine_type_e engineType) : EngineTestHelper(engineType, &emptyCallbackWithConfiguration) { +EngineTestHelper::EngineTestHelper(engine_type_e engineType, const std::unordered_map& sensorValues) : EngineTestHelper(engineType, &emptyCallbackWithConfiguration) { + for (const auto [s, v] : sensorValues) { + Sensor::setMockValue(s, v); + } } EngineTestHelper::~EngineTestHelper() { diff --git a/unit_tests/engine_test_helper.h b/unit_tests/engine_test_helper.h index a6dc70a7a7..47e75f8dba 100644 --- a/unit_tests/engine_test_helper.h +++ b/unit_tests/engine_test_helper.h @@ -29,7 +29,7 @@ public: */ class EngineTestHelper : public EngineTestHelperBase { public: - explicit EngineTestHelper(engine_type_e engineType); + EngineTestHelper(engine_type_e engineType, const std::unordered_map& sensorValues); EngineTestHelper(engine_type_e engineType, configuration_callback_t boardCallback); ~EngineTestHelper(); diff --git a/unit_tests/global.h b/unit_tests/global.h index 63ab479659..656b214d5a 100644 --- a/unit_tests/global.h +++ b/unit_tests/global.h @@ -87,8 +87,13 @@ void print(const char *fmt, ...); Engine *engine = ð.engine; \ EXPAND_Engine -#define WITH_ENGINE_TEST_HELPER(x) EngineTestHelper eth(x); \ - EXPAND_EngineTestHelper; +#define WITH_ENGINE_TEST_HELPER_SENS(x, sensorvals) \ + EngineTestHelper eth(x, sensorvals); \ + EXPAND_EngineTestHelper; + +#define WITH_ENGINE_TEST_HELPER(x) \ + EngineTestHelper eth(x, std::unordered_map{}); \ + EXPAND_EngineTestHelper; #define CONFIG_PARAM(x) (x) diff --git a/unit_tests/tests/test_logic_expression.cpp b/unit_tests/tests/test_logic_expression.cpp index 63dd61c90d..806d535c0c 100644 --- a/unit_tests/tests/test_logic_expression.cpp +++ b/unit_tests/tests/test_logic_expression.cpp @@ -19,7 +19,7 @@ float getEngineValue(le_action_e action DECLARE_ENGINE_PARAMETER_SUFFIX) { case LE_METHOD_FAN: return engine->fsioState.mockFan; case LE_METHOD_COOLANT: - return getCoolantTemperature(); + return Sensor::get(SensorType::Clt).value_or(0); case LE_METHOD_RPM: return engine->fsioState.mockRpm; case LE_METHOD_CRANKING_RPM: @@ -101,13 +101,13 @@ static void testExpression2(float selfValue, const char *line, float expected, E ASSERT_EQ(expected, c.getValue2(selfValue, element PASS_ENGINE_PARAMETER_SUFFIX)) << line; } -static void testExpression2(float selfValue, const char *line, float expected) { - WITH_ENGINE_TEST_HELPER(FORD_INLINE_6_1995); +static void testExpression2(float selfValue, const char *line, float expected, const std::unordered_map& sensorVals = {}) { + WITH_ENGINE_TEST_HELPER_SENS(FORD_INLINE_6_1995, sensorVals); testExpression2(selfValue, line, expected, engine); } -static void testExpression(const char *line, float expectedValue) { - testExpression2(0, line, expectedValue); +static void testExpression(const char *line, float expectedValue, const std::unordered_map& sensorVals = {}) { + testExpression2(0, line, expectedValue, sensorVals); } TEST(fsio, testIfFunction) { @@ -115,8 +115,6 @@ TEST(fsio, testIfFunction) { } TEST(fsio, testLogicExpressions) { - printf("*************************************************** testLogicExpressions\r\n"); - testParsing(); { @@ -181,36 +179,32 @@ TEST(fsio, testLogicExpressions) { * fan = fan NOT coolant 90 AND more fan coolant 85 more AND OR */ - { - WITH_ENGINE_TEST_HELPER(FORD_INLINE_6_1995); - engine->sensors.mockClt = 100; - engine->periodicSlowCallback(PASS_ENGINE_PARAMETER_SIGNATURE); - testExpression2(0, "coolant 1 +", 101, engine); - } - testExpression("fan", 0); - testExpression("fan not", 1); - testExpression("coolant 90 >", 1); - testExpression("fan not coolant 90 > and", 1); + std::unordered_map sensorVals = {{SensorType::Clt, 100}}; + testExpression("coolant 1 +", 101, sensorVals); + + testExpression("fan", 0, sensorVals); + testExpression("fan not", 1, sensorVals); + testExpression("coolant 90 >", 1, sensorVals); + testExpression("fan not coolant 90 > and", 1, sensorVals); testExpression("100 200 1 if", 200); testExpression("10 99 max", 99); testExpression2(123, "10 self max", 123); - testExpression("fan NOT coolant 90 > AND fan coolant 85 > AND OR", 1); - { - WITH_ENGINE_TEST_HELPER(FORD_INLINE_6_1995); - LEElement thepool[TEST_POOL_SIZE]; - LEElementPool pool(thepool, TEST_POOL_SIZE); - LEElement * element = pool.parseExpression("fan NOT coolant 90 > AND fan coolant 85 > AND OR"); - ASSERT_TRUE(element != NULL) << "Not NULL expected"; - LECalculator c; - ASSERT_EQ( 1, c.getValue2(0, element PASS_ENGINE_PARAMETER_SUFFIX)) << "that expression"; + testExpression("fan NOT coolant 90 > AND fan coolant 85 > AND OR", 1, sensorVals); - ASSERT_EQ(12, c.currentCalculationLogPosition); - ASSERT_EQ(102, c.calcLogAction[0]); - ASSERT_EQ(0, c.calcLogValue[0]); - } + WITH_ENGINE_TEST_HELPER_SENS(FORD_INLINE_6_1995, sensorVals); + LEElement thepool[TEST_POOL_SIZE]; + LEElementPool pool(thepool, TEST_POOL_SIZE); + LEElement * element = pool.parseExpression("fan NOT coolant 90 > AND fan coolant 85 > AND OR"); + ASSERT_TRUE(element != NULL) << "Not NULL expected"; + LECalculator c; + ASSERT_EQ( 1, c.getValue2(0, element PASS_ENGINE_PARAMETER_SUFFIX)) << "that expression"; + + ASSERT_EQ(12, c.currentCalculationLogPosition); + ASSERT_EQ(102, c.calcLogAction[0]); + ASSERT_EQ(0, c.calcLogValue[0]); testExpression("cfg_fanOffTemperature", 0); testExpression("coolant cfg_fanOffTemperature >", 1); @@ -222,13 +216,10 @@ TEST(fsio, testLogicExpressions) { testExpression(FAN_CONTROL_LOGIC, 1); - { - WITH_ENGINE_TEST_HELPER(FORD_INLINE_6_1995); - engine->fsioState.mockRpm = 900; - engine->fsioState.mockCrankingRpm = 200; - testExpression2(0, "rpm", 900, engine); - testExpression2(0, "cranking_rpm", 200, engine); - testExpression2(0, STARTER_RELAY_LOGIC, 0, engine); - testExpression2(0, "rpm cranking_rpm > ", 1, engine); - } + engine->fsioState.mockRpm = 900; + engine->fsioState.mockCrankingRpm = 200; + testExpression2(0, "rpm", 900, engine); + testExpression2(0, "cranking_rpm", 200, engine); + testExpression2(0, STARTER_RELAY_LOGIC, 0, engine); + testExpression2(0, "rpm cranking_rpm > ", 1, engine); }