Add more unit tests for TAE

This commit is contained in:
Josh Stewart 2022-05-25 15:28:11 +10:00
parent e16108d806
commit ec2fcd906f
2 changed files with 78 additions and 6 deletions

View File

@ -15,7 +15,7 @@ framework=arduino
build_unflags = -Os
build_flags = -O3 -ffast-math -fshort-enums -funroll-loops -Wall -Wextra -std=c99
lib_deps = EEPROM, Time
;test_build_project_src = true
test_build_project_src = true
test_build_src = yes
debug_tool = simavr
test_ignore = test_table3d_native

View File

@ -208,11 +208,16 @@ void test_corrections_TAE_setup()
//Divided by 100
configPage2.aeTaperMin = 10; //1000
configPage2.aeTaperMax = 50; //5000
//Set the coolant to be above the warmup AE taper
configPage2.aeColdTaperMax = 60;
configPage2.aeColdTaperMin = 0;
currentStatus.coolant = (int)(configPage2.aeColdTaperMax - CALIBRATION_TEMPERATURE_OFFSET) + 1;
BIT_CLEAR(currentStatus.engine, BIT_ENGINE_ACC); //Make sure AE is turned off
}
void test_corrections_TAE_no_taper()
void test_corrections_TAE_no_rpm_taper()
{
//Disable the taper
currentStatus.RPM = 2000;
@ -226,10 +231,10 @@ void test_corrections_TAE_no_taper()
TEST_ASSERT_EQUAL(75, currentStatus.tpsDOT); //DOT is 750%/s (25 * 30), value divided by 10;
TEST_ASSERT_EQUAL((100+132), accelValue);
TEST_ASSERT_TRUE(BIT_CHECK(currentStatus.engine, BIT_ENGINE_ACC)); //Confirm AE is flagged on
}
void test_corrections_TAE_50pc_taper()
void test_corrections_TAE_50pc_rpm_taper()
{
//RPM is 50% of the way through the taper range
currentStatus.RPM = 3000;
@ -243,7 +248,66 @@ void test_corrections_TAE_50pc_taper()
TEST_ASSERT_EQUAL(75, currentStatus.tpsDOT); //DOT is 750%/s (25 * 30), value divided by 10;
TEST_ASSERT_EQUAL((100+66), accelValue);
TEST_ASSERT_TRUE(BIT_CHECK(currentStatus.engine, BIT_ENGINE_ACC)); //Confirm AE is flagged on
}
void test_corrections_TAE_110pc_rpm_taper()
{
//RPM is 110% of the way through the taper range, which should result in no additional AE
currentStatus.RPM = 5400;
configPage2.aeTaperMin = 10; //1000
configPage2.aeTaperMax = 50; //5000
currentStatus.TPSlast = 0;
currentStatus.TPS = 50; //25% actual value
uint16_t accelValue = correctionAccel(); //Run the AE calcs
TEST_ASSERT_EQUAL(75, currentStatus.tpsDOT); //DOT is 750%/s (25 * 30), value divided by 10;
TEST_ASSERT_EQUAL(100, accelValue); //Should be no AE as we're above the RPM taper end point
TEST_ASSERT_TRUE(BIT_CHECK(currentStatus.engine, BIT_ENGINE_ACC)); //Confirm AE is flagged on
}
void test_corrections_TAE_under_threshold()
{
//RPM is 50% of the way through the taper range, but TPS value will be below threshold
currentStatus.RPM = 3000;
configPage2.aeTaperMin = 10; //1000
configPage2.aeTaperMax = 50; //5000
currentStatus.TPSlast = 0;
currentStatus.TPS = 6; //3% actual value. TPSDot should be 90%/s
configPage2.taeThresh = 100; //Above the reading of 90%/s
uint16_t accelValue = correctionAccel(); //Run the AE calcs
TEST_ASSERT_EQUAL(9, currentStatus.tpsDOT); //DOT is 90%/s (3% * 30), value divided by 10;
TEST_ASSERT_EQUAL(100, accelValue); //Should be no AE as we're above the RPM taper end point
TEST_ASSERT_FALSE(BIT_CHECK(currentStatus.engine, BIT_ENGINE_ACC)); //Confirm AE is flagged off
}
void test_corrections_TAE_50pc_warmup_taper()
{
//Disable the RPM taper
currentStatus.RPM = 2000;
configPage2.aeTaperMin = 50; //5000
configPage2.aeTaperMax = 60; //6000
currentStatus.TPSlast = 0;
currentStatus.TPS = 50; //25% actual value
//Set a cold % of 50% increase
configPage2.aeColdPct = 200;
configPage2.aeColdTaperMax = 60 + CALIBRATION_TEMPERATURE_OFFSET;
configPage2.aeColdTaperMin = 0 + CALIBRATION_TEMPERATURE_OFFSET;
//Set the coolant to be 50% of the way through the warmup range
currentStatus.coolant = 30;
uint16_t accelValue = correctionAccel(); //Run the AE calcs
TEST_ASSERT_EQUAL(75, currentStatus.tpsDOT); //DOT is 750%/s (25 * 30), value divided by 10;
TEST_ASSERT_EQUAL((100+165), accelValue); //Total AE should be 132 + (50% * 50%) = 132 * 1.25 = 165
TEST_ASSERT_TRUE(BIT_CHECK(currentStatus.engine, BIT_ENGINE_ACC)); //Confirm AE is flagged on
}
void test_corrections_TAE()
@ -251,7 +315,15 @@ void test_corrections_TAE()
test_corrections_TAE_setup();
RUN_TEST(test_corrections_TAE_no_taper);
RUN_TEST(test_corrections_TAE_no_rpm_taper);
BIT_CLEAR(currentStatus.engine, BIT_ENGINE_ACC); //Flag must be cleared between tests
RUN_TEST(test_corrections_TAE_50pc_taper);
RUN_TEST(test_corrections_TAE_50pc_rpm_taper);
BIT_CLEAR(currentStatus.engine, BIT_ENGINE_ACC); //Flag must be cleared between tests
RUN_TEST(test_corrections_TAE_110pc_rpm_taper);
BIT_CLEAR(currentStatus.engine, BIT_ENGINE_ACC); //Flag must be cleared between tests
RUN_TEST(test_corrections_TAE_under_threshold);
BIT_CLEAR(currentStatus.engine, BIT_ENGINE_ACC); //Flag must be cleared between tests
RUN_TEST(test_corrections_TAE_50pc_warmup_taper);
}