ETB JNI test progress

Coffee is important!
This commit is contained in:
Andrey 2022-11-29 10:25:15 -05:00
parent 2a0756c95d
commit 6eed99a646
4 changed files with 22 additions and 19 deletions

View File

@ -7,10 +7,10 @@ package com.rusefi.native_;
* See native_impl.cpp * See native_impl.cpp
*/ */
public class EngineLogic { public class EngineLogic {
public native String getVersion(); public static native String getVersion();
// huh? I am having trouble making this method static? // huh? I am having trouble making this method static?
public native void resetTest(); public static native void resetTest();
public native void setSensor(String sensorTypeName, double value); public native void setSensor(String sensorTypeName, double value);

View File

@ -18,17 +18,16 @@ import static junit.framework.Assert.*;
public class JniUnitTest { public class JniUnitTest {
@Before @Before
public void reset() { public void reset() {
// new EngineLogic().resetTest(); JniSandbox.loadLibrary();
EngineLogic.resetTest();
} }
@Test @Test
public void run() { public void run() {
JniSandbox.loadLibrary(); String version = EngineLogic.getVersion();
EngineLogic engineLogic = new EngineLogic();
String version = engineLogic.getVersion();
assertTrue("Got " + version, version.contains("Hello")); assertTrue("Got " + version, version.contains("Hello"));
EngineLogic engineLogic = new EngineLogic();
engineLogic.invokePeriodicCallback(); engineLogic.invokePeriodicCallback();
assertEquals(TS_FILE_VERSION, (int) getValue(engineLogic.getOutputs(), Sensor.FIRMWARE_VERSION)); assertEquals(TS_FILE_VERSION, (int) getValue(engineLogic.getOutputs(), Sensor.FIRMWARE_VERSION));
@ -54,8 +53,6 @@ public class JniUnitTest {
@Test @Test
public void testEtbStuff() { public void testEtbStuff() {
JniSandbox.loadLibrary();
EngineLogic engineLogic = new EngineLogic(); EngineLogic engineLogic = new EngineLogic();
engineLogic.setSensor(SensorType.Tps1Primary.name(), 30); engineLogic.setSensor(SensorType.Tps1Primary.name(), 30);
@ -71,12 +68,12 @@ public class JniUnitTest {
engineLogic.setConfiguration(new byte[]{3}, Fields.THROTTLEPEDALPOSITIONADCCHANNEL.getTotalOffset(), 1); engineLogic.setConfiguration(new byte[]{3}, Fields.THROTTLEPEDALPOSITIONADCCHANNEL.getTotalOffset(), 1);
engineLogic.setConfiguration(new byte[]{3}, Fields.THROTTLEPEDALPOSITIONSECONDADCCHANNEL.getTotalOffset(), 1); engineLogic.setConfiguration(new byte[]{3}, Fields.THROTTLEPEDALPOSITIONSECONDADCCHANNEL.getTotalOffset(), 1);
// engineLogic.initTps(); engineLogic.initTps();
// engineLogic.burnRequest(); engineLogic.burnRequest();
// System.out.println("engineLogic.invokeEtbCycle"); System.out.println("engineLogic.invokeEtbCycle");
// engineLogic.invokeEtbCycle(); engineLogic.invokeEtbCycle();
//
// assertEquals(120.36, getValue(engineLogic.getOutputs(), Sensor.etb1DutyCycle)); assertEquals(120.36, getValue(engineLogic.getOutputs(), Sensor.etb1DutyCycle));
} }
private double getField(EngineLogic engineLogic, Field field) { private double getField(EngineLogic engineLogic, Field field) {

View File

@ -13,7 +13,7 @@ extern "C" {
* Signature: ()Ljava/lang/String; * Signature: ()Ljava/lang/String;
*/ */
JNIEXPORT jstring JNICALL Java_com_rusefi_native_1_EngineLogic_getVersion JNIEXPORT jstring JNICALL Java_com_rusefi_native_1_EngineLogic_getVersion
(JNIEnv *, jobject); (JNIEnv *, jclass);
/* /*
* Class: com_rusefi_native__EngineLogic * Class: com_rusefi_native__EngineLogic
@ -21,7 +21,7 @@ JNIEXPORT jstring JNICALL Java_com_rusefi_native_1_EngineLogic_getVersion
* Signature: ()V * Signature: ()V
*/ */
JNIEXPORT void JNICALL Java_com_rusefi_native_1_EngineLogic_resetTest JNIEXPORT void JNICALL Java_com_rusefi_native_1_EngineLogic_resetTest
(JNIEnv *, jobject); (JNIEnv *, jclass);
/* /*
* Class: com_rusefi_native__EngineLogic * Class: com_rusefi_native__EngineLogic

View File

@ -25,12 +25,12 @@ static EngineTestHelper* getEth() {
} }
JNIEXPORT void JNICALL Java_com_rusefi_native_1_EngineLogic_resetTest JNIEXPORT void JNICALL Java_com_rusefi_native_1_EngineLogic_resetTest
(JNIEnv *, jobject) { (JNIEnv *, jclass) {
printf("[native] resetTest\n"); printf("[native] resetTest\n");
ethPtr = nullptr; ethPtr = nullptr;
} }
JNIEXPORT jstring JNICALL Java_com_rusefi_native_1_EngineLogic_getVersion(JNIEnv * env, jobject) { JNIEXPORT jstring JNICALL Java_com_rusefi_native_1_EngineLogic_getVersion(JNIEnv * env, jclass) {
const char msg[60] = "Hello from unit tests"; const char msg[60] = "Hello from unit tests";
const char* fileName = msg; const char* fileName = msg;
jstring result = env->NewStringUTF(msg); jstring result = env->NewStringUTF(msg);
@ -116,6 +116,12 @@ JNIEXPORT void JNICALL Java_com_rusefi_native_1_EngineLogic_initTps
initTps(); initTps();
} }
JNIEXPORT void JNICALL Java_com_rusefi_native_1_EngineLogic_initTps2
(JNIEnv *, jobject) {
printf("[native] initTps2\n");
}
JNIEXPORT jbyteArray JNICALL Java_com_rusefi_native_1_EngineLogic_getOutputs(JNIEnv * env, jobject instance) { JNIEXPORT jbyteArray JNICALL Java_com_rusefi_native_1_EngineLogic_getOutputs(JNIEnv * env, jobject instance) {
jbyteArray retVal = env->NewByteArray(TS_TOTAL_OUTPUT_SIZE); jbyteArray retVal = env->NewByteArray(TS_TOTAL_OUTPUT_SIZE);
jbyte *buf = env->GetByteArrayElements(retVal, NULL); jbyte *buf = env->GetByteArrayElements(retVal, NULL);