TEST(sensors, testCamInput) { // setting some weird engine WITH_ENGINE_TEST_HELPER(FORD_ESCORT_GT); // and now changing to ONE trigger on CRANK with CAM/VVT setOperationMode(engineConfiguration, FOUR_STROKE_CRANK_SENSOR); engineConfiguration->useOnlyRisingEdgeForTrigger = true; eth.setTriggerType(TT_ONE PASS_ENGINE_PARAMETER_SUFFIX); engineConfiguration->camInput = GPIOA_10; // we just need to indicate that we have CAM ASSERT_EQ( 0, GET_RPM()) << "testCamInput RPM"; for (int i = 0; i < 5;i++) { eth.fireRise(50); } ASSERT_EQ(1200, GET_RPM()) << "testCamInput RPM"; ASSERT_EQ(0, unitTestWarningCodeState.recentWarnings.getCount()) << "warningCounter#testCamInput"; for (int i = 0; i < 600;i++) { eth.fireRise(50); } ASSERT_EQ(1, unitTestWarningCodeState.recentWarnings.getCount()) << "warningCounter#testCamInput #2"; ASSERT_EQ(OBD_Camshaft_Position_Sensor_Circuit_Range_Performance, unitTestWarningCodeState.recentWarnings.get(0)) << "@0"; unitTestWarningCodeState.recentWarnings.clear(); for (int i = 0; i < 600;i++) { eth.fireRise(50); hwHandleVvtCamSignal(TV_FALL PASS_ENGINE_PARAMETER_SUFFIX); } ASSERT_EQ(0, unitTestWarningCodeState.recentWarnings.getCount()) << "warningCounter#testCamInput #3"; }
TEST(big, testNoiselessDecoder) { printf("====================================================================================== testNoiselessDecoder\r\n"); WITH_ENGINE_TEST_HELPER(TEST_ENGINE); engineConfiguration->ignitionMode = IM_WASTED_SPARK; engineConfiguration->useOnlyRisingEdgeForTrigger = true; setupSimpleTestEngineWithMafAndTT_ONE_trigger(ð); // we'll test on 60-2 wheel eth.setTriggerType(TT_TOOTHED_WHEEL_60_2 PASS_ENGINE_PARAMETER_SUFFIX); ASSERT_EQ(0, engine->triggerCentral.triggerState.totalTriggerErrorCounter); ASSERT_EQ( 0, GET_RPM()) << "testNoiselessDecoder RPM"; //printTriggerDebug = true; #if 0 // try normal trigger mode, no noise filtering CONFIGB(useNoiselessTriggerDecoder) = false; // for test validation, it should be 1 trigger error testNoiselessDecoderProcedure(eth, 1 PASS_ENGINE_PARAMETER_SUFFIX); #endif // now enable our noise filtering algo CONFIGB(useNoiselessTriggerDecoder) = true; // should be 0 errors! testNoiselessDecoderProcedure(eth, 0 PASS_ENGINE_PARAMETER_SUFFIX); //printTriggerDebug = false; }
TEST(sensors, testNoStartUpWarnings) { WITH_ENGINE_TEST_HELPER(TEST_ENGINE); // for this test we need a trigger with isSynchronizationNeeded=true engineConfiguration->trigger.customTotalToothCount = 3; engineConfiguration->trigger.customSkippedToothCount = 1; eth.setTriggerType(TT_TOOTHED_WHEEL PASS_ENGINE_PARAMETER_SUFFIX); ASSERT_EQ( 0, GET_RPM()) << "testNoStartUpWarnings RPM"; for (int i = 0;i < 10;i++) { eth.fireRise(50); eth.fireFall(50); eth.fireRise(50); eth.fireFall(150); } ASSERT_EQ(400, GET_RPM()) << "testNoStartUpWarnings RPM"; ASSERT_EQ( 0, unitTestWarningCodeState.recentWarnings.getCount()) << "warningCounter#testNoStartUpWarnings"; // now let's post something unneeded eth.fireRise(50); eth.fireFall(50); eth.fireRise(50); // this is noise eth.fireFall(50); // this is noise eth.fireRise(50); eth.fireFall(150); for (int i = 0;i < 1;i++) { eth.fireRise(50); eth.fireFall(50); eth.fireRise(50); eth.fireFall(150); } ASSERT_EQ( 2, unitTestWarningCodeState.recentWarnings.getCount()) << "warningCounter#testNoStartUpWarnings CUSTOM_SYNC_COUNT_MISMATCH expected"; ASSERT_EQ(CUSTOM_SYNC_ERROR, unitTestWarningCodeState.recentWarnings.get(0)); ASSERT_EQ(CUSTOM_SYNC_COUNT_MISMATCH, unitTestWarningCodeState.recentWarnings.get(1)); }
TEST(sensors, testNoStartUpWarningsNoSyncronizationTrigger) { WITH_ENGINE_TEST_HELPER(TEST_ENGINE); // one tooth does not need synchronization it just counts tooth eth.setTriggerType(TT_ONE PASS_ENGINE_PARAMETER_SUFFIX); ASSERT_EQ( 0, GET_RPM()) << "testNoStartUpWarnings RPM"; eth.fireTriggerEvents2(/*count*/10, /*duration*/50); ASSERT_EQ(1200, GET_RPM()) << "testNoStartUpWarnings RPM"; ASSERT_EQ( 0, unitTestWarningCodeState.recentWarnings.getCount()) << "warningCounter#testNoStartUpWarningsNoSyncronizationTrigger"; }
TEST(maf2map, util) { WITH_ENGINE_TEST_HELPER(FORD_ASPIRE_1996); engineConfiguration->fuelAlgorithm = LM_REAL_MAF; ASSERT_FLOAT_EQ(61.1, estimateMapByRpmAndMaf(8000, 0.6)); ASSERT_FLOAT_EQ(1.4, estimateMapByRpmAndMaf(2000, 5.6)); }
static void doTestFasterEngineSpinningUp60_2(int startUpDelayMs, int rpm1, int expectedRpm) { WITH_ENGINE_TEST_HELPER(TEST_ENGINE); // turn on FasterEngineSpinUp mode engineConfiguration->bc.isFasterEngineSpinUpEnabled = true; setupSimpleTestEngineWithMaf(ð, IM_SEQUENTIAL, TT_TOOTHED_WHEEL_60_2); eth.moveTimeForwardMs(startUpDelayMs); // fire 30 tooth rise/fall signals eth.fireTriggerEvents2(30 /* count */, 1 /*ms*/); // now fire missed tooth rise/fall eth.fireRise(4 /*ms*/); EXPECT_EQ(rpm1, GET_RPM()) << "test RPM: After rise " + std::to_string(startUpDelayMs); eth.fireFall(4 /*ms*/); EXPECT_EQ(expectedRpm, GET_RPM()) << "test RPM: with " + std::to_string(startUpDelayMs) + " startUpDelayMs"; }
TEST(sensors, testNoisyInput) { WITH_ENGINE_TEST_HELPER(TEST_ENGINE); ASSERT_EQ( 0, GET_RPM()) << "testNoisyInput RPM"; eth.firePrimaryTriggerRise(); eth.firePrimaryTriggerFall(); eth.firePrimaryTriggerRise(); eth.firePrimaryTriggerFall(); eth.firePrimaryTriggerRise(); eth.firePrimaryTriggerFall(); eth.firePrimaryTriggerRise(); eth.firePrimaryTriggerFall(); // error condition since events happened too quick while time does not move ASSERT_EQ(NOISY_RPM, GET_RPM()) << "testNoisyInput RPM should be noisy"; ASSERT_EQ( 2, unitTestWarningCodeState.recentWarnings.getCount()) << "warningCounter#testNoisyInput"; ASSERT_EQ(CUSTOM_SYNC_COUNT_MISMATCH, unitTestWarningCodeState.recentWarnings.get(0)) << "@0"; ASSERT_EQ(OBD_Crankshaft_Position_Sensor_A_Circuit_Malfunction, unitTestWarningCodeState.recentWarnings.get(1)) << "@0"; }
TEST(cranking, testFasterEngineSpinningUp) { printf("*************************************************** testFasterEngineSpinningUp\r\n"); WITH_ENGINE_TEST_HELPER(TEST_ENGINE); // turn on FasterEngineSpinUp mode engineConfiguration->bc.isFasterEngineSpinUpEnabled = true; // set ignition mode engineConfiguration->ignitionMode = IM_INDIVIDUAL_COILS; // set cranking threshold (used below) engineConfiguration->cranking.rpm = 999; // set sequential injection mode to test auto-change to simultaneous when spinning-up setupSimpleTestEngineWithMafAndTT_ONE_trigger(ð, IM_SEQUENTIAL); ASSERT_EQ(IM_INDIVIDUAL_COILS, getCurrentIgnitionMode(PASS_ENGINE_PARAMETER_SIGNATURE)); eth.moveTimeForwardMs(1000 /*ms*/); eth.firePrimaryTriggerRise(); // check if it's true ASSERT_EQ(IM_SEQUENTIAL, engine->getCurrentInjectionMode(PASS_ENGINE_PARAMETER_SIGNATURE)); ASSERT_EQ(IM_WASTED_SPARK, getCurrentIgnitionMode(PASS_ENGINE_PARAMETER_SIGNATURE)); // check if the engine has the right state ASSERT_EQ(SPINNING_UP, engine->rpmCalculator.getState()); // check RPM ASSERT_EQ( 0, GET_RPM()) << "RPM=0"; // the queue should be empty, no trigger events yet ASSERT_EQ(0, engine->executor.size()) << "plain#1"; // check all events starting from now int timeStartUs = eth.getTimeNowUs(); // advance 1 revolution // because we have trivial TT_ONE trigger here synchronization would happen with just one rise front eth.fireRise(200); // check if the mode is changed ASSERT_EQ(SPINNING_UP, engine->rpmCalculator.getState()); // due to isFasterEngineSpinUp=true, we should have already detected RPM! ASSERT_EQ( 300, GET_RPM()) << "spinning-RPM#1"; // two simultaneous injections ASSERT_EQ(4, engine->executor.size()) << "plain#2"; // test if they are simultaneous ASSERT_EQ(IM_SIMULTANEOUS, engine->getCurrentInjectionMode(PASS_ENGINE_PARAMETER_SIGNATURE)); // test if ignition mode is temporary changed to wasted spark, if set to individual coils ASSERT_EQ(IM_WASTED_SPARK, getCurrentIgnitionMode(PASS_ENGINE_PARAMETER_SIGNATURE)); // check real events eth.assertEvent5(&engine->executor, "inj start#1", 0, (void*)startSimultaniousInjection, timeStartUs, MS2US(200) + 81250); eth.assertEvent5(&engine->executor, "inj end#1", 1, (void*)endSimultaniousInjection, timeStartUs, MS2US(200) + 100000); // skip the rest of the cycle eth.fireFall(200); // now clear and advance more eth.clearQueue(); eth.fireRise(200); // check if the mode is changed when fully synched ASSERT_EQ(CRANKING, engine->rpmCalculator.getState()); // check RPM ASSERT_EQ( 200, GET_RPM()) << "RPM#2"; // test if they are simultaneous in cranking mode too ASSERT_EQ(IM_SIMULTANEOUS, engine->getCurrentInjectionMode(PASS_ENGINE_PARAMETER_SIGNATURE)); // test if ignition mode is restored to ind.coils ASSERT_EQ(IM_INDIVIDUAL_COILS, getCurrentIgnitionMode(PASS_ENGINE_PARAMETER_SIGNATURE)); // two simultaneous injections ASSERT_EQ( 4, engine->executor.size()) << "plain#2"; // check real events eth.assertEvent5(&engine->executor, "inj start#2", 0, (void*)startSimultaniousInjection, eth.getTimeNowUs(), 131250); eth.assertEvent5(&engine->executor, "inj end#2", 1, (void*)endSimultaniousInjection, eth.getTimeNowUs(), 150000); // skip, clear & advance 1 more revolution at higher RPM eth.fireFall(60); eth.clearQueue(); timeStartUs = eth.getTimeNowUs(); eth.fireTriggerEventsWithDuration(60); // check if the mode is now changed to 'running' at higher RPM ASSERT_EQ(RUNNING, engine->rpmCalculator.getState()); // check RPM ASSERT_EQ( 1000, GET_RPM()) << "RPM#3"; // check if the injection mode is back to sequential now ASSERT_EQ(IM_SEQUENTIAL, engine->getCurrentInjectionMode(PASS_ENGINE_PARAMETER_SIGNATURE)); // 4 sequential injections for the full cycle ASSERT_EQ( 8, engine->executor.size()) << "plain#3"; // check real events for sequential injection // Note: See addFuelEvents() fix inside setRpmValue()! eth.assertEvent5(&engine->executor, "inj start#3", 0, (void*)seTurnPinHigh, timeStartUs, MS2US(60) + 11250); eth.assertEvent5(&engine->executor, "inj end#3", 1, (void*)seTurnPinLow, timeStartUs, MS2US(60) + 11250 + 3000); }
TEST(maf2map, integrated) { WITH_ENGINE_TEST_HELPER(MIATA_NA6_VAF); }