#include #include #include #include "tests_corrections.h" void testCorrections() { test_corrections_WUE(); test_corrections_dfco(); /* RUN_TEST(test_corrections_cranking); //Not written yet RUN_TEST(test_corrections_ASE); //Not written yet RUN_TEST(test_corrections_floodclear); //Not written yet RUN_TEST(test_corrections_closedloop); //Not written yet RUN_TEST(test_corrections_flex); //Not written yet RUN_TEST(test_corrections_bat); //Not written yet RUN_TEST(test_corrections_iatdensity); //Not written yet RUN_TEST(test_corrections_baro); //Not written yet RUN_TEST(test_corrections_launch); //Not written yet RUN_TEST(test_corrections_dfco); //Not written yet */ } void test_corrections_WUE_active(void) { //Check for WUE being active currentStatus.coolant = 0; ((uint8_t*)WUETable.axisX)[9] = 120 + CALIBRATION_TEMPERATURE_OFFSET; //Set a WUE end value of 120 correctionWUE(); TEST_ASSERT_BIT_HIGH(BIT_ENGINE_WARMUP, currentStatus.engine); } void test_corrections_WUE_inactive(void) { //Check for WUE being inactive due to the temp being too high currentStatus.coolant = 200; ((uint8_t*)WUETable.axisX)[9] = 120 + CALIBRATION_TEMPERATURE_OFFSET; //Set a WUE end value of 120 correctionWUE(); TEST_ASSERT_BIT_LOW(BIT_ENGINE_WARMUP, currentStatus.engine); } void test_corrections_WUE_inactive_value(void) { //Check for WUE being set to the final row of the WUE curve if the coolant is above the max WUE temp currentStatus.coolant = 200; ((uint8_t*)WUETable.axisX)[9] = 100; ((uint8_t*)WUETable.values)[9] = 123; //Use a value other than 100 here to ensure we are using the non-default value //Force invalidate the cache WUETable.cacheTime = currentStatus.secl - 1; TEST_ASSERT_EQUAL(123, correctionWUE() ); } void test_corrections_WUE_active_value(void) { //Check for WUE being made active and returning a correct interpolated value currentStatus.coolant = 80; //Set some fake values in the table axis. Target value will fall between points 6 and 7 ((uint8_t*)WUETable.axisX)[0] = 0; ((uint8_t*)WUETable.axisX)[1] = 0; ((uint8_t*)WUETable.axisX)[2] = 0; ((uint8_t*)WUETable.axisX)[3] = 0; ((uint8_t*)WUETable.axisX)[4] = 0; ((uint8_t*)WUETable.axisX)[5] = 0; ((uint8_t*)WUETable.axisX)[6] = 70 + CALIBRATION_TEMPERATURE_OFFSET; ((uint8_t*)WUETable.axisX)[7] = 90 + CALIBRATION_TEMPERATURE_OFFSET; ((uint8_t*)WUETable.axisX)[8] = 100 + CALIBRATION_TEMPERATURE_OFFSET; ((uint8_t*)WUETable.axisX)[9] = 120 + CALIBRATION_TEMPERATURE_OFFSET; ((uint8_t*)WUETable.values)[6] = 120; ((uint8_t*)WUETable.values)[7] = 130; //Force invalidate the cache WUETable.cacheTime = currentStatus.secl - 1; //Value should be midway between 120 and 130 = 125 TEST_ASSERT_EQUAL(125, correctionWUE() ); } void test_corrections_WUE(void) { RUN_TEST(test_corrections_WUE_active); RUN_TEST(test_corrections_WUE_inactive); RUN_TEST(test_corrections_WUE_active_value); RUN_TEST(test_corrections_WUE_inactive_value); } void test_corrections_cranking(void) { } void test_corrections_ASE(void) { } void test_corrections_floodclear(void) { } void test_corrections_closedloop(void) { } void test_corrections_flex(void) { } void test_corrections_bat(void) { } void test_corrections_iatdensity(void) { } void test_corrections_baro(void) { } void test_corrections_launch(void) { } void setup_DFCO_on() { //Sets all the required conditions to have the DFCO be active configPage2.dfcoEnabled = 1; //Ensure DFCO option is turned on currentStatus.RPM = 4000; //Set the current simulated RPM to a level above the DFCO rpm threshold currentStatus.TPS = 0; //Set the simulated TPS to 0 currentStatus.coolant = 80; configPage4.dfcoRPM = 150; //DFCO enable RPM = 1500 configPage4.dfcoTPSThresh = 1; configPage4.dfcoHyster = 50; configPage2.dfcoMinCLT = 40; //Actually 0 with offset configPage2.dfcoDelay = 10; runSecsX10 = 1; correctionDFCO(); runSecsX10 = 20; } void test_corrections_dfco_on(void) { //Test under ideal conditions that DFCO goes active setup_DFCO_on(); TEST_ASSERT_TRUE(correctionDFCO()); } void test_corrections_dfco_off_RPM() { //Test that DFCO comes on and then goes off when the RPM drops below threshold setup_DFCO_on(); TEST_ASSERT_TRUE(correctionDFCO()); //Make sure DFCO is on initially currentStatus.RPM = 1000; //Set the current simulated RPM below the threshold + hyster TEST_ASSERT_FALSE(correctionDFCO()); //Test DFCO is now off } void test_corrections_dfco_off_TPS() { //Test that DFCO comes on and then goes off when the TPS goes above the required threshold (ie not off throttle) setup_DFCO_on(); TEST_ASSERT_TRUE(correctionDFCO()); //Make sure DFCO is on initially currentStatus.TPS = 10; //Set the current simulated TPS to be above the threshold TEST_ASSERT_FALSE(correctionDFCO()); //Test DFCO is now off } void test_corrections_dfco_off_delay() { //Test that DFCO comes will not activate if there has not been a long enough delay //The steup function below simulates a 2 second delay setup_DFCO_on(); //Set the threshold to be 2.5 seconds, above the simulated delay of 2s configPage2.dfcoDelay = 250; TEST_ASSERT_FALSE(correctionDFCO()); //Make sure DFCO does not come on } void test_corrections_dfco() { RUN_TEST(test_corrections_dfco_on); RUN_TEST(test_corrections_dfco_off_RPM); RUN_TEST(test_corrections_dfco_off_TPS); RUN_TEST(test_corrections_dfco_off_delay); }