rusefi/java_console/autotest/src/main/java/com/rusefi/f4discovery/CommonFunctionalTest.java

490 lines
17 KiB
Java
Raw Normal View History

package com.rusefi.f4discovery;
2015-07-10 06:01:56 -07:00
2023-05-24 05:23:50 -07:00
import com.rusefi.config.generated.Fields;
import com.rusefi.RusefiTestBase;
2015-07-10 06:01:56 -07:00
import com.rusefi.core.Sensor;
import com.rusefi.core.SensorCentral;
import com.rusefi.enums.SensorType;
import com.rusefi.enums.engine_type_e;
2020-12-12 15:58:30 -08:00
import com.rusefi.functional_tests.EcuTestHelper;
2015-07-10 06:01:56 -07:00
import com.rusefi.waves.EngineChart;
import org.junit.Test;
2015-07-10 06:01:56 -07:00
import java.util.Arrays;
import static com.rusefi.IoUtil.getEnableCommand;
import static com.rusefi.TestingUtils.assertNull;
import static com.rusefi.config.generated.Fields.CMD_SET_SENSOR_MOCK;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
2015-07-10 06:01:56 -07:00
/**
* rusEFI firmware simulator functional test suite
2015-07-10 06:01:56 -07:00
* <p/>
* java -cp rusefi_console.jar com.rusefi.AutoTest
*
* @author Andrey Belomutskiy
* 3/5/14
2015-07-10 06:01:56 -07:00
*/
public class CommonFunctionalTest extends RusefiTestBase {
@Test
public void testChangingIgnitionMode() {
ecu.setEngineType(engine_type_e.FORD_ASPIRE_1996);
ecu.changeRpm(2000);
2020-12-22 06:23:17 -08:00
// First is wasted spark
ecu.sendCommand("set ignition_mode 2");
2020-12-22 06:23:17 -08:00
{
// Check that we're in wasted spark mode
EngineChart chart = nextChart();
2020-12-22 06:23:17 -08:00
// Wasted spark should fire cylinders 1/3...
assertWaveNotNull(chart,
EngineChart.SPARK_1,
EngineChart.SPARK_3
);
2020-12-22 06:23:17 -08:00
// ...but not cylinders 2/4
assertWaveNull(chart,
EngineChart.SPARK_2,
EngineChart.SPARK_4
);
}
2020-12-22 06:23:17 -08:00
// Now switch to sequential mode
ecu.sendCommand("set ignition_mode 1");
2020-12-22 06:23:17 -08:00
{
// Check that we're in sequential spark mode
EngineChart chart = nextChart();
2020-12-22 06:23:17 -08:00
// All 4 cylinders should be firing
assertWaveNotNull(chart,
EngineChart.SPARK_1,
EngineChart.SPARK_2,
EngineChart.SPARK_3,
EngineChart.SPARK_4
);
}
2020-12-22 06:23:17 -08:00
// Now switch to "one coil" mode
2020-12-22 06:23:17 -08:00
ecu.sendCommand("set ignition_mode 0");
{
// Check that we're in sequential spark mode
EngineChart chart = nextChart();
// Only coil 1 should be active
assertWaveNotNull(chart, EngineChart.SPARK_1);
// And no others
assertWaveNull(chart,
EngineChart.SPARK_2,
EngineChart.SPARK_3,
EngineChart.SPARK_4
);
2020-12-22 06:23:17 -08:00
}
// Now switch BACK to wasted mode
ecu.sendCommand("set ignition_mode 2");
2020-12-22 06:23:17 -08:00
{
// Check that we're in wasted spark mode
EngineChart chart = nextChart();
2020-12-22 06:23:17 -08:00
// Wasted spark should fire cylinders 1/3...
assertWaveNotNull(chart,
EngineChart.SPARK_1,
EngineChart.SPARK_3
);
2020-12-22 06:23:17 -08:00
// ...but not cylinders 2/4
assertWaveNull(chart,
EngineChart.SPARK_2,
EngineChart.SPARK_4
);
}
}
2020-12-22 06:23:17 -08:00
@Test
public void testRevLimiter() {
ecu.setEngineType(engine_type_e.FORD_ASPIRE_1996);
ecu.changeRpm(2000);
// Alpha-N mode so that we actually inject some fuel (without mocking tons of sensors)
ecu.sendCommand("set algorithm 2");
// Set tps to 25% - make alpha-n happy
ecu.sendCommand(CMD_SET_SENSOR_MOCK + " " + SensorType.Tps1.ordinal() + " 25");
ecu.sendCommand("set rpm_hard_limit 2500");
{
// Check that neither ignition nor injection is cut
EngineChart chart = nextChart();
assertWaveNotNull(chart,
EngineChart.SPARK_1,
EngineChart.INJECTOR_1
);
}
// Now go above the hard limiter
ecu.changeRpm(3000);
{
// Check that both ignition and injection are cut
EngineChart chart = nextChart();
// These channels are allowed to have falling edges - aka closing injectors and firing coils
// but not allowed to have rising edges - aka opening injectors and charging coils
assertWaveNoRises(chart,
EngineChart.SPARK_1,
EngineChart.INJECTOR_1
);
}
// Check that it recovers when we go back under the limit
ecu.changeRpm(2000);
{
// Check that neither ignition nor injection is cut
EngineChart chart = nextChart();
assertWaveNotNull(chart,
EngineChart.SPARK_1,
EngineChart.INJECTOR_1
);
}
}
@Test
public void testCustomEngine() {
ecu.setEngineType(engine_type_e.DEFAULT_FRANKENSO);
2020-12-12 15:58:30 -08:00
ecu.sendCommand("set_toothed_wheel 4 0");
2017-02-24 07:06:31 -08:00
// sendCommand("enable trigger_only_front");
// changeRpm(100);
// changeRpm(1500);
2017-02-24 08:55:38 -08:00
// sendCommand("disable trigger_only_front");
// changeRpm(100);
// changeRpm(1500);
2017-02-23 05:12:03 -08:00
}
2021-02-17 21:11:26 -08:00
@Test
public void testAuxValveNissan() {
ecu.setEngineType(engine_type_e.NISSAN_PRIMERA);
2021-02-17 21:11:26 -08:00
ecu.changeRpm(1200);
}
@Test
2024-01-16 07:31:03 -08:00
public void testTwoStrokeSachs() {
ecu.setEngineType(engine_type_e.SACHS);
2020-12-12 15:58:30 -08:00
ecu.changeRpm(1200);
2015-07-10 06:01:56 -07:00
}
2024-03-05 17:28:16 -08:00
@Test
public void test2003DodgeNeon() {
ecu.setEngineType(engine_type_e.DODGE_NEON_2003_CRANK);
2020-12-12 15:58:30 -08:00
ecu.sendCommand("set wwaeTau 0");
ecu.sendCommand("set wwaeBeta 0");
ecu.sendCommand(CMD_SET_SENSOR_MOCK + " " + SensorType.Map.ordinal() + " 69.12");
ecu.sendCommand(CMD_SET_SENSOR_MOCK + " " + SensorType.BatteryVoltage.ordinal() + " 12");
2020-12-12 15:58:30 -08:00
ecu.sendCommand("disable cylinder_cleanup");
2015-07-10 06:01:56 -07:00
EngineChart chart;
String msg = "2003 Neon cranking ";
2020-12-12 15:58:30 -08:00
ecu.changeRpm(200);
ecu.changeRpm(250); // another approach to artificial delay
ecu.changeRpm(200);
2021-06-20 23:46:11 -07:00
EcuTestHelper.assertSomewhatClose("VBatt", 12, SensorCentral.getInstance().getValue(Sensor.VBATT));
2015-07-10 06:01:56 -07:00
chart = nextChart();
double x = 100;
assertWaveNotNull(msg, chart, EngineChart.SPARK_1);
assertWaveNull(msg, chart, EngineChart.SPARK_2);
assertWaveNotNull(msg, chart, EngineChart.SPARK_3);
assertWaveNull(msg, chart, EngineChart.SPARK_4);
x = 176.856;
// todo: why is width precision so low here? is that because of loaded Windows with 1ms precision?
double widthRatio = 0.25;
// WAT? this was just 0.009733333333333387?
assertWaveNotNull(msg, chart, EngineChart.INJECTOR_1);
assertWaveNotNull(msg, chart, EngineChart.INJECTOR_2);
assertWaveNotNull(msg, chart, EngineChart.INJECTOR_3);
assertWaveNotNull(msg, chart, EngineChart.INJECTOR_4);
2015-07-10 06:01:56 -07:00
msg = "2003 Neon running";
2020-12-12 15:58:30 -08:00
ecu.changeRpm(2000);
ecu.changeRpm(2700);
ecu.changeRpm(2000);
2015-07-10 06:01:56 -07:00
chart = nextChart();
x = 104.0;
assertWaveNotNull(msg, chart, EngineChart.SPARK_1);
assertWaveNull(msg, chart, EngineChart.SPARK_2);
assertWaveNotNull(msg, chart, EngineChart.SPARK_3);
assertWaveNull(msg, chart, EngineChart.SPARK_4);
2015-07-10 06:01:56 -07:00
2016-01-21 22:01:42 -08:00
chart = nextChart();
x = 74;
assertWaveNotNull(msg, chart, EngineChart.INJECTOR_1);
assertWaveNotNull(msg, chart, EngineChart.INJECTOR_2);
assertWaveNotNull(msg, chart, EngineChart.INJECTOR_3);
assertWaveNotNull(msg, chart, EngineChart.INJECTOR_4);
2016-08-17 19:03:05 -07:00
2020-12-12 15:58:30 -08:00
ecu.sendCommand(getEnableCommand("trigger_only_front"));
2015-09-24 19:02:47 -07:00
chart = nextChart();
assertWaveNotNull(msg, chart, EngineChart.INJECTOR_1);
assertWaveNotNull(msg, chart, EngineChart.INJECTOR_2);
assertWaveNotNull(msg, chart, EngineChart.INJECTOR_3);
assertWaveNotNull(msg, chart, EngineChart.INJECTOR_4);
2016-11-28 17:03:43 -08:00
2020-12-12 15:58:30 -08:00
ecu.sendCommand("set_whole_timing_map 520");
2020-06-25 19:27:39 -07:00
chart = nextChart();
x = 328;
assertWaveNotNull(msg, chart, EngineChart.SPARK_1);
2016-11-28 17:03:43 -08:00
2020-12-12 15:58:30 -08:00
ecu.sendCommand("set_whole_timing_map 0");
2020-06-25 19:27:39 -07:00
chart = nextChart();
x = 128;
assertWaveNotNull(msg, chart, EngineChart.SPARK_1);
2015-07-10 06:01:56 -07:00
}
@Test
public void testMazdaProtege() {
ecu.setEngineType(engine_type_e.FORD_ESCORT_GT);
2015-07-10 06:01:56 -07:00
EngineChart chart;
ecu.sendCommand(CMD_SET_SENSOR_MOCK + " " + SensorType.BatteryVoltage.ordinal() + " 12");
// Alpha-N mode so that we actually inject some fuel (without mocking tons of sensors)
ecu.sendCommand("set algorithm 2");
// Set tps to 25% - make alpha-n happy
ecu.sendCommand(CMD_SET_SENSOR_MOCK + " " + SensorType.Tps1.ordinal() + " 25");
2020-12-12 15:58:30 -08:00
ecu.changeRpm(200);
ecu.changeRpm(260);
ecu.changeRpm(200);
2015-07-10 06:01:56 -07:00
String msg = "ProtegeLX cranking";
2020-06-25 19:27:39 -07:00
chart = nextChart();
2021-06-20 23:46:11 -07:00
EcuTestHelper.assertSomewhatClose("", 12, SensorCentral.getInstance().getValue(Sensor.VBATT), 0.1);
assertWaveNotNull(msg, chart, EngineChart.SPARK_3);
assertWaveNotNull(msg, chart, EngineChart.SPARK_1);
assertWaveNotNull(msg, chart, EngineChart.INJECTOR_1);
assertWaveNotNull(msg, chart, EngineChart.INJECTOR_2);
2015-07-10 06:01:56 -07:00
msg = "ProtegeLX running";
2020-12-12 15:58:30 -08:00
ecu.changeRpm(2000);
2020-06-25 19:27:39 -07:00
chart = nextChart();
assertWaveNotNull(msg, chart, EngineChart.SPARK_1);
assertWaveNotNull(msg, chart, EngineChart.INJECTOR_1);
assertWaveNotNull(msg, chart, EngineChart.INJECTOR_2);
2015-07-10 06:01:56 -07:00
}
@Test
public void test1995DodgeNeon() {
ecu.setEngineType(engine_type_e.DODGE_NEON_1995);
2015-07-10 06:01:56 -07:00
EngineChart chart;
2023-05-24 05:23:50 -07:00
sendComplexCommand(Fields.CMD_INDIVIDUAL_INJECTION);
2015-07-10 06:01:56 -07:00
/**
* note that command order matters - RPM change resets wave chart
*/
2020-12-12 15:58:30 -08:00
ecu.changeRpm(2000);
2020-06-25 19:27:39 -07:00
chart = nextChart();
2015-07-10 06:01:56 -07:00
String msg = "1995 Neon";
//assertWaveNotNull(msg, chart, EngineChart.INJECTOR_4);
//assertWaveNotNull(msg, chart, EngineChart.INJECTOR_2);
//assertWaveNotNull(msg, chart, EngineChart.INJECTOR_1);
//assertWaveNotNull(msg, chart, EngineChart.INJECTOR_3);
assertWaveNotNull(msg, chart, EngineChart.SPARK_4);
assertWaveNotNull(msg, chart, EngineChart.SPARK_2);
assertWaveNotNull(msg, chart, EngineChart.SPARK_1);
assertWaveNotNull(msg, chart, EngineChart.SPARK_3);
2015-07-10 06:01:56 -07:00
// switching to Speed Density
ecu.sendCommand(CMD_SET_SENSOR_MOCK + " " + SensorType.Map.ordinal() + " 69.12");
sendComplexCommand("set algorithm 0");
2020-12-12 15:58:30 -08:00
ecu.changeRpm(2600);
ecu.changeRpm(2000);
2020-06-25 19:27:39 -07:00
chart = nextChart();
assertWaveNotNull(msg, chart, EngineChart.INJECTOR_4);
2015-07-10 06:01:56 -07:00
}
@Test
public void testFord6() {
ecu.setEngineType(engine_type_e.FORD_INLINE_6_1995);
2015-07-10 06:01:56 -07:00
EngineChart chart;
2020-12-12 15:58:30 -08:00
ecu.changeRpm(2000);
2020-06-25 19:27:39 -07:00
chart = nextChart();
2015-07-10 06:01:56 -07:00
String msg = "ford 6";
assertWaveNotNull(msg, chart, EngineChart.SPARK_1);
2015-07-10 06:01:56 -07:00
assertWaveNull(msg, chart, EngineChart.TRIGGER_2);
sendComplexCommand("set " + "trigger_type" + " " + com.rusefi.enums.trigger_type_e.TT_FORD_ASPIRE.ordinal());
2020-06-25 19:27:39 -07:00
chart = nextChart();
assertTrue(chart.get(EngineChart.TRIGGER_2) != null);
2015-07-10 06:01:56 -07:00
}
@Test
public void testFordAspire() {
ecu.setEngineType(engine_type_e.FORD_ASPIRE_1996);
2020-12-12 15:58:30 -08:00
ecu.sendCommand("disable cylinder_cleanup");
ecu.sendCommand(CMD_SET_SENSOR_MOCK + " " + SensorType.Map.ordinal() + " 69.12");
ecu.sendCommand(CMD_SET_SENSOR_MOCK + " " + SensorType.BatteryVoltage.ordinal() + " 12");
2015-07-10 06:01:56 -07:00
String msg;
EngineChart chart;
// todo: interesting changeRpm(100);
2017-01-06 06:03:33 -08:00
sendComplexCommand("set cranking_rpm 500");
2020-12-12 15:58:30 -08:00
ecu.changeRpm(200);
2015-07-10 06:01:56 -07:00
2020-06-25 19:27:39 -07:00
chart = nextChart();
2021-06-20 23:46:11 -07:00
EcuTestHelper.assertSomewhatClose(12, SensorCentral.getInstance().getValue(Sensor.VBATT));
assertWaveNotNull("aspire default cranking ", chart, EngineChart.SPARK_1);
2015-07-10 06:01:56 -07:00
2020-12-12 15:58:30 -08:00
ecu.changeRpm(600);
2020-06-25 19:27:39 -07:00
chart = nextChart();
assertWaveNotNull("aspire default running ", chart, EngineChart.SPARK_1);
2015-07-10 06:01:56 -07:00
2020-12-12 15:58:30 -08:00
ecu.changeRpm(200);
2015-07-10 06:01:56 -07:00
2020-12-12 15:58:30 -08:00
ecu.sendCommand("set cranking_charge_angle 65");
ecu.sendCommand("set cranking_timing_angle -31");
2015-07-10 06:01:56 -07:00
chart = nextChart();
assertWaveNotNull("aspire cranking", chart, EngineChart.SPARK_1);
2015-07-10 06:01:56 -07:00
2020-12-12 15:58:30 -08:00
ecu.sendCommand("set cranking_timing_angle -40");
2015-07-10 06:01:56 -07:00
chart = nextChart();
assertWaveNotNull("aspire", chart, EngineChart.SPARK_1);
2020-12-12 15:58:30 -08:00
ecu.sendCommand("set cranking_timing_angle 149");
2015-07-10 06:01:56 -07:00
2020-12-12 15:58:30 -08:00
ecu.sendCommand("set cranking_charge_angle 40");
2015-07-10 06:01:56 -07:00
chart = nextChart();
assertWaveNotNull("aspire", chart, EngineChart.SPARK_1);
2020-12-12 15:58:30 -08:00
ecu.sendCommand("set cranking_charge_angle 65");
2015-07-10 06:01:56 -07:00
2020-12-12 15:58:30 -08:00
ecu.changeRpm(600);
2017-01-06 06:03:33 -08:00
sendComplexCommand("set cranking_rpm 700");
2015-07-10 06:01:56 -07:00
chart = nextChart();
assertWaveNotNull("cranking@600", chart, EngineChart.SPARK_1);
2015-07-10 06:01:56 -07:00
2020-12-12 15:58:30 -08:00
ecu.changeRpm(2000);
2015-07-10 06:01:56 -07:00
2020-12-12 15:58:30 -08:00
ecu.changeRpm(2600);
ecu.changeRpm(2000);
2015-07-10 06:01:56 -07:00
chart = nextChart();
msg = "aspire running";
assertWaveNotNull(msg, chart, EngineChart.INJECTOR_1);
assertWaveNotNull(msg, chart, EngineChart.INJECTOR_2);
assertWaveNotNull(msg, chart, EngineChart.INJECTOR_3);
assertWaveNotNull(msg, chart, EngineChart.INJECTOR_4);
2015-07-10 06:01:56 -07:00
assertWaveNotNull(chart, EngineChart.SPARK_1);
2015-07-10 06:01:56 -07:00
2020-12-12 15:58:30 -08:00
ecu.sendCommand("set_fuel_map 2200 4 15.66");
ecu.sendCommand("set_fuel_map 2000 4 15.66");
ecu.sendCommand("set_fuel_map 2200 4.2 15.66");
ecu.sendCommand("set_fuel_map 2000 4.2 15.66");
2017-01-06 07:04:41 -08:00
sendComplexCommand("set global_trigger_offset_angle 175");
2015-07-10 06:01:56 -07:00
chart = nextChart();
assertWaveNotNull(msg + " fuel", chart, EngineChart.INJECTOR_1);
assertWaveNotNull(msg + " fuel", chart, EngineChart.INJECTOR_2);
assertWaveNotNull(msg + " fuel", chart, EngineChart.INJECTOR_3);
assertWaveNotNull(msg + " fuel", chart, EngineChart.INJECTOR_4);
2015-07-10 06:01:56 -07:00
assertWaveNotNull(chart, EngineChart.SPARK_1);
2015-07-10 06:01:56 -07:00
assertWaveNull(chart, EngineChart.SPARK_2);
2017-01-06 07:04:41 -08:00
sendComplexCommand("set global_trigger_offset_angle 130");
sendComplexCommand("set injection_offset 369");
2015-07-10 06:01:56 -07:00
chart = nextChart();
assertWaveNotNull(chart, EngineChart.SPARK_1);
2015-07-10 06:01:56 -07:00
// let's enable more channels dynamically
2023-05-24 05:23:50 -07:00
sendComplexCommand(Fields.CMD_INDIVIDUAL_INJECTION);
2015-07-10 06:01:56 -07:00
chart = nextChart();
assertWaveNotNull("Switching Aspire into INDIVIDUAL_COILS mode", chart, EngineChart.SPARK_2);
assertWaveNotNull(chart, EngineChart.SPARK_3);
2015-07-10 06:01:56 -07:00
2020-12-12 15:58:30 -08:00
ecu.sendCommand("set_whole_timing_map 520");
2015-07-10 06:01:56 -07:00
chart = nextChart();
assertWaveNotNull(chart, EngineChart.SPARK_2);
2015-07-10 06:01:56 -07:00
// switching to Speed Density
sendComplexCommand("set algorithm 0");
2020-12-12 15:58:30 -08:00
ecu.changeRpm(2400);
ecu.changeRpm(2000);
2015-07-10 06:01:56 -07:00
chart = nextChart();
2021-06-20 23:46:11 -07:00
EcuTestHelper.assertSomewhatClose("MAP", 69.12, SensorCentral.getInstance().getValue(Sensor.MAP));
2015-07-10 06:01:56 -07:00
//assertEquals(1, SensorCentral.getInstance().getValue(Sensor.));
assertWaveNotNull(msg + " fuel SD #1", chart, EngineChart.INJECTOR_1);
assertWaveNotNull(msg + " fuel SD #2", chart, EngineChart.INJECTOR_2);
assertWaveNotNull(msg + " fuel SD #3", chart, EngineChart.INJECTOR_3);
assertWaveNotNull(msg + " fuel SD #4", chart, EngineChart.INJECTOR_4);
2015-07-10 06:01:56 -07:00
// above hard limit
2020-12-12 15:58:30 -08:00
ecu.changeRpm(10000);
2015-07-10 06:01:56 -07:00
chart = nextChart();
assertWaveNull("hard limit check", chart, EngineChart.INJECTOR_1);
}
2021-10-04 05:19:58 -07:00
@Test
public void testStackOverflow() {
// This ECU command has a built in check to make sure no threads are near overflow
ecu.sendCommand("threadsinfo");
}
2016-01-26 14:01:57 -08:00
/**
* This method waits for longer then usual.
2021-06-20 20:58:32 -07:00
* todo: inline this method? complex and less complex seem to have same timeout these days?
2016-01-26 14:01:57 -08:00
*/
2020-06-25 18:14:08 -07:00
private void sendComplexCommand(String command) {
2021-06-20 20:58:32 -07:00
ecu.sendCommand(command);
2015-07-10 06:01:56 -07:00
}
private static void assertWaveNull(EngineChart chart, String key) {
assertWaveNull("", chart, key);
}
private static void assertWaveNull(EngineChart chart, String... keys) {
Arrays.stream(keys).peek(k -> assertWaveNull(chart, k));
}
2015-07-10 06:01:56 -07:00
private static void assertWaveNull(String msg, EngineChart chart, String key) {
assertNull(msg + "chart for " + key, chart.get(key));
}
2020-12-22 06:23:17 -08:00
private static void assertWaveNotNull(EngineChart chart, String key) {
assertWaveNotNull("", chart, key);
}
private static void assertWaveNotNull(String msg, EngineChart chart, String key) {
assertTrue(msg, chart.get(key) != null);
2020-12-22 06:23:17 -08:00
}
private static void assertWaveNotNull(EngineChart chart, String... keys) {
Arrays.stream(keys).peek(k -> assertWaveNotNull(chart, k));
}
private static void assertWaveNoRises(EngineChart chart, String key) {
StringBuilder events = chart.get(key);
// if no events of this type at all, return since this passes the test
if (events == null) {
return;
}
// Assert that there are no up (rise) events in the channel's sequence
assertFalse(events.toString().contains("u"));
}
private static void assertWaveNoRises(EngineChart chart, String... keys) {
Arrays.stream(keys).peek(k -> assertWaveNoRises(chart, k));
}
2015-07-10 06:01:56 -07:00
}