remove jni weirdness

This commit is contained in:
Matthew Kennedy 2023-02-20 21:18:13 -08:00
parent e01879761f
commit 9d101331a3
9 changed files with 0 additions and 421 deletions

View File

@ -39,11 +39,6 @@ jobs:
working-directory: .
run: gcc -v
- name: Build Native Unit Tests as shared library
working-directory: ./unit_tests/
# we have a unit test of JNI thus we need to build shared library
run: make -j4 SANITIZE=no build/lib_rusefi_test
- name: Build Android
env:
RUSEFI_ANDROID_KEYPASS: ${{ secrets.RUSEFI_ANDROID_KEYPASS }}

View File

@ -44,11 +44,6 @@ jobs:
working-directory: .
run: gcc -v
- name: Build Native Unit Tests as shared library
working-directory: ./unit_tests/
# we have a unit test of JNI thus we need to build shared library
run: make -j4 SANITIZE=no build/lib_rusefi_test
- name: Test console
# at the moment 'jar' task does not depend on tests?! maybe because tests take some time?
working-directory: ./java_tools

View File

@ -1,32 +0,0 @@
package com.rusefi.native_;
/**
* Native interface allowing java to invoke rusEFI unit_tests library
*
* See com_rusefi_native__EngineLogic.h
* See native_impl.cpp
*/
public class EngineLogic {
public static native String getVersion();
// huh? I am having trouble making this method static?
public static native void resetTest();
public native void setSensor(String sensorTypeName, double value);
public native byte[] getConfiguration();
public native void setConfiguration(byte[] content, int offset, int size);
public native void setEngineType(int engineType);
public native void initTps();
public native void invokePeriodicCallback();
public native void invokeEtbCycle();
public native void burnRequest();
public native byte[] getOutputs();
}

View File

@ -1,40 +0,0 @@
package com.rusefi.native_;
import com.rusefi.FileLog;
import javax.xml.bind.SchemaOutputResolver;
import java.io.File;
import java.util.Arrays;
/**
* Following VM option is needed to launch:
* -Djava.library.path=../unit_tests/build
*/
public class JniSandbox {
private static final String LIBNAME = "_rusefi_test";
public static void main(String[] args) {
loadLibrary();
EngineLogic engineLogic = new EngineLogic();
System.out.println(engineLogic.getVersion());
engineLogic.setSensor("clt", 90);
engineLogic.setConfiguration(new byte[4], 24, 14);
}
public static void loadLibrary() {
String libPath = System.getProperty("java.library.path");
System.out.println("Looking for libraries at " + libPath);
String[] list = new File(libPath).list((dir, name) -> name.contains(LIBNAME));
System.out.println("Matching files: " + Arrays.toString(list));
if (list.length == 0) {
if (FileLog.isWindows()) {
System.out.println("Have you invoked `make -j4 SANITIZE=no build/_rusefi_test'?");
} else {
System.out.println("Have you invoked `make -j4 SANITIZE=no build/lib_rusefi_test`?");
}
}
System.loadLibrary(LIBNAME);
}
}

View File

@ -1,89 +0,0 @@
package com.rusefi.native_;
import com.opensr5.ConfigurationImage;
import com.rusefi.config.Field;
import com.rusefi.config.generated.Fields;
import com.rusefi.core.Sensor;
import com.rusefi.enums.SensorType;
import org.junit.Before;
import org.junit.Test;
import java.nio.ByteBuffer;
import static com.rusefi.config.generated.Fields.TS_FILE_VERSION;
import static com.rusefi.config.generated.Fields.engine_type_e_MRE_MIATA_NB2_MAP;
import static com.rusefi.core.FileUtil.littleEndianWrap;
import static junit.framework.Assert.*;
public class JniUnitTest {
@Before
public void reset() {
JniSandbox.loadLibrary();
EngineLogic.resetTest();
}
@Test
public void run() {
String version = EngineLogic.getVersion();
assertTrue("Got " + version, version.contains("Hello"));
EngineLogic engineLogic = new EngineLogic();
engineLogic.invokePeriodicCallback();
assertEquals(TS_FILE_VERSION, (int) getValue(engineLogic.getOutputs(), Sensor.FIRMWARE_VERSION));
assertEquals(14.0, getValue(engineLogic.getOutputs(), Sensor.afrTarget));
double veValue = getValue(engineLogic.getOutputs(), Sensor.veValue);
assertTrue("veValue", veValue > 40 && veValue < 90);
assertEquals(18.11, getValue(engineLogic.getOutputs(), Sensor.runningFuel));
engineLogic.setSensor(SensorType.Rpm.name(), 4000);
engineLogic.invokePeriodicCallback();
assertEquals(4000.0, getValue(engineLogic.getOutputs(), Sensor.RPMValue));
assertEquals(18.11, getValue(engineLogic.getOutputs(), Sensor.runningFuel));
assertEquals(0.25096, getValue(engineLogic.getOutputs(), Sensor.sdAirMassInOneCylinder), 0.0001);
engineLogic.setEngineType(engine_type_e_MRE_MIATA_NB2_MAP);
assertEquals(2.45, getField(engineLogic, Fields.GEARRATIO1));
}
@Test
public void testEtbStuff() {
EngineLogic engineLogic = new EngineLogic();
engineLogic.setSensor(SensorType.Tps1Primary.name(), 30);
engineLogic.setSensor(SensorType.Tps1Secondary.name(), 30);
engineLogic.burnRequest(); // hack: this is here to initialize engine helper prior to mocking sensors
engineLogic.setSensor(SensorType.AcceleratorPedalPrimary.name(), 40);
engineLogic.setSensor(SensorType.AcceleratorPedalSecondary.name(), 40);
engineLogic.setConfiguration(new byte[]{3}, Fields.TPS1_1ADCCHANNEL.getTotalOffset(), 1);
engineLogic.setConfiguration(new byte[]{3}, Fields.TPS1_2ADCCHANNEL.getTotalOffset(), 1);
engineLogic.setConfiguration(new byte[]{3}, Fields.THROTTLEPEDALPOSITIONADCCHANNEL.getTotalOffset(), 1);
engineLogic.setConfiguration(new byte[]{3}, Fields.THROTTLEPEDALPOSITIONSECONDADCCHANNEL.getTotalOffset(), 1);
engineLogic.initTps();
engineLogic.burnRequest();
System.out.println("engineLogic.invokeEtbCycle");
engineLogic.invokeEtbCycle();
assertEquals(120.38, getValue(engineLogic.getOutputs(), Sensor.etb1DutyCycle));
}
private double getField(EngineLogic engineLogic, Field field) {
byte[] configuration = engineLogic.getConfiguration();
assertNotNull("configuration", configuration);
return field.getValue(new ConfigurationImage(configuration), field.getScale());
}
private double getValue(byte[] outputs, Sensor sensor) {
ByteBuffer bb = littleEndianWrap(outputs, sensor.getOffset(), 4);
return sensor.getValueForChannel(bb) * sensor.getScale();
}
}

View File

@ -37,7 +37,6 @@ CPPSRC += $(ALLCPPSRC) \
$(PROJECT_DIR)/config/boards/hellen/hellen_board_id.cpp \
$(PROJECT_DIR)/hw_layer/drivers/can/can_hw.cpp \
$(PROJECT_DIR)/../unit_tests/logicdata.cpp \
$(PROJECT_DIR)/../unit_tests/native/native_impl.cpp \
$(PROJECT_DIR)/../unit_tests/main.cpp \
$(PROJECT_DIR)/../unit_tests/global_mocks.cpp \
$(PROJECT_DIR)/../unit_tests/mocks.cpp \

View File

@ -1,101 +0,0 @@
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_rusefi_native__EngineLogic */
#ifndef _Included_com_rusefi_native__EngineLogic
#define _Included_com_rusefi_native__EngineLogic
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: com_rusefi_native__EngineLogic
* Method: getVersion
* Signature: ()Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_com_rusefi_native_1_EngineLogic_getVersion
(JNIEnv *, jclass);
/*
* Class: com_rusefi_native__EngineLogic
* Method: resetTest
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_com_rusefi_native_1_EngineLogic_resetTest
(JNIEnv *, jclass);
/*
* Class: com_rusefi_native__EngineLogic
* Method: setSensor
* Signature: (Ljava/lang/String;D)V
*/
JNIEXPORT void JNICALL Java_com_rusefi_native_1_EngineLogic_setSensor
(JNIEnv *, jobject, jstring, jdouble);
/*
* Class: com_rusefi_native__EngineLogic
* Method: getConfiguration
* Signature: ()[B
*/
JNIEXPORT jbyteArray JNICALL Java_com_rusefi_native_1_EngineLogic_getConfiguration
(JNIEnv *, jobject);
/*
* Class: com_rusefi_native__EngineLogic
* Method: setConfiguration
* Signature: ([BII)V
*/
JNIEXPORT void JNICALL Java_com_rusefi_native_1_EngineLogic_setConfiguration
(JNIEnv *, jobject, jbyteArray, jint, jint);
/*
* Class: com_rusefi_native__EngineLogic
* Method: setEngineType
* Signature: (I)V
*/
JNIEXPORT void JNICALL Java_com_rusefi_native_1_EngineLogic_setEngineType
(JNIEnv *, jobject, jint);
/*
* Class: com_rusefi_native__EngineLogic
* Method: initTps
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_com_rusefi_native_1_EngineLogic_initTps
(JNIEnv *, jobject);
/*
* Class: com_rusefi_native__EngineLogic
* Method: invokePeriodicCallback
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_com_rusefi_native_1_EngineLogic_invokePeriodicCallback
(JNIEnv *, jobject);
/*
* Class: com_rusefi_native__EngineLogic
* Method: invokeEtbCycle
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_com_rusefi_native_1_EngineLogic_invokeEtbCycle
(JNIEnv *, jobject);
/*
* Class: com_rusefi_native__EngineLogic
* Method: burnRequest
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_com_rusefi_native_1_EngineLogic_burnRequest
(JNIEnv *, jobject);
/*
* Class: com_rusefi_native__EngineLogic
* Method: getOutputs
* Signature: ()[B
*/
JNIEXPORT jbyteArray JNICALL Java_com_rusefi_native_1_EngineLogic_getOutputs
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,134 +0,0 @@
/*
* native_impl.cpp
*
* @date Feb 26, 2022
* @author Andrey Belomutskiy, (c) 2012-2022
*/
#include "pch.h"
#include "com_rusefi_native__EngineLogic.h"
#include "auto_generated_sensor.h"
#include "tunerstudio.h"
#include "live_data.h"
#include "init.h"
#include <memory>
static std::unique_ptr<EngineTestHelper> ethPtr;
static EngineTestHelper* getEth() {
if (!ethPtr) {
printf("make_unique<EngineTestHelper>(TEST_ENGINE)\n");
ethPtr = std::make_unique<EngineTestHelper>(TEST_ENGINE);
}
return ethPtr.get();
}
JNIEXPORT void JNICALL Java_com_rusefi_native_1_EngineLogic_resetTest
(JNIEnv *, jclass) {
printf("[native] resetTest\n");
ethPtr = nullptr;
}
JNIEXPORT jstring JNICALL Java_com_rusefi_native_1_EngineLogic_getVersion(JNIEnv * env, jclass) {
const char msg[60] = "Hello from unit tests";
const char* fileName = msg;
jstring result = env->NewStringUTF(msg);
printf("[native] hello\n");
return result;
}
JNIEXPORT jbyteArray JNICALL Java_com_rusefi_native_1_EngineLogic_getConfiguration(JNIEnv *env, jobject instance) {
jbyteArray retVal = env->NewByteArray(sizeof(engine_configuration_s));
jbyte *buf = env->GetByteArrayElements(retVal, NULL);
EngineTestHelper* eth = getEth();
memcpy(buf, (const void*)&eth->persistentConfig.engineConfiguration, sizeof(engine_configuration_s));
env->ReleaseByteArrayElements(retVal, buf, 0);
return retVal;
}
JNIEXPORT void JNICALL Java_com_rusefi_native_1_EngineLogic_setConfiguration(JNIEnv *env, jobject instance,
jbyteArray data, jint offset, jint size) {
EngineTestHelper* eth = getEth();
printf("[native] setConfiguration offset=%d size=%d\n", offset, size);
jbyte *buf = env->GetByteArrayElements(data, NULL);
int printSize = size > 4 ? 4 : size;
for (int i = 0;i < printSize;i++) {
printf("[native] buf[%d] %x\n", i, buf[i]);
}
memcpy(((uint8_t*)&eth->persistentConfig.engineConfiguration) + offset, buf, size);
}
JNIEXPORT void JNICALL Java_com_rusefi_native_1_EngineLogic_setSensor
(JNIEnv *env, jobject instance, jstring sensorName, jdouble sensorValue) {
const char *sensorNameNative = env->GetStringUTFChars(sensorName, 0);
SensorType type = findSensorTypeByName(sensorNameNative);
printf("[native] Setting [%s] to %f\n", getSensorType(type), sensorValue);
Sensor::setMockValue(type, sensorValue);
env->ReleaseStringUTFChars(sensorName, sensorNameNative);
}
JNIEXPORT void JNICALL Java_com_rusefi_native_1_EngineLogic_setEngineType
(JNIEnv *, jobject, jint engineType) {
EngineTestHelper* eth = getEth();
resetConfigurationExt((engine_type_e)engineType);
}
JNIEXPORT void JNICALL Java_com_rusefi_native_1_EngineLogic_invokePeriodicCallback
(JNIEnv *, jobject) {
EngineTestHelper* eth = getEth();
eth->engine.periodicSlowCallback();
eth->engine.periodicFastCallback();
}
JNIEXPORT void JNICALL Java_com_rusefi_native_1_EngineLogic_invokeEtbCycle
(JNIEnv *, jobject) {
EngineTestHelper* eth = getEth();
Engine *engine = &eth->engine;
printf("[native] invokeEtbCycle\n");
for (int i = 0; i < ETB_COUNT; i++) {
if (auto etb = engine->etbControllers[i]) {
etb->update();
}
}
}
JNIEXPORT void JNICALL Java_com_rusefi_native_1_EngineLogic_burnRequest
(JNIEnv *, jobject) {
printf("[native] onBurnRequest\n");
getEth();// just to make sure we have initialized
onBurnRequest();
}
JNIEXPORT void JNICALL Java_com_rusefi_native_1_EngineLogic_initTps
(JNIEnv *, jobject) {
printf("[native] initTps\n");
getEth();// just to make sure we have initialized
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) {
jbyteArray retVal = env->NewByteArray(TS_TOTAL_OUTPUT_SIZE);
jbyte *buf = env->GetByteArrayElements(retVal, NULL);
EngineTestHelper* eth = getEth();
updateTunerStudioState();
copyRange((uint8_t*)buf, getLiveDataFragments(), 0, TS_TOTAL_OUTPUT_SIZE);
env->ReleaseByteArrayElements(retVal, buf, 0);
return retVal;
}

View File

@ -10,16 +10,6 @@ ifeq ($(BUILDDIR),.)
endif
BINARY_OUTPUT = $(BUILDDIR)/$(PROJECT)
ifeq ($(OS),Windows_NT)
# todo: something is not right here how can we avoid explicit suffix?
# should not gcc figure it out based on 'shared' option?
SHARED_OUTPUT = $(BUILDDIR)/_$(PROJECT)
SHARED_OUTPUT_OPT = $(SHARED_OUTPUT).dll
else
SHARED_OUTPUT = $(BUILDDIR)/lib_$(PROJECT)
SHARED_OUTPUT_OPT = $(SHARED_OUTPUT).so
endif
# Automatic compiler options
OPT = $(USE_OPT)
COPT = $(USE_COPT)
@ -150,10 +140,6 @@ else
@$(LD) $(OBJS) $(LDFLAGS) $(LIBS) -o $@
endif
$(SHARED_OUTPUT): $(OBJS)
@echo Linking shared library $@ output $(SHARED_OUTPUT_OPT)
@$(LD) $(OBJS) $(LDFLAGS) $(LIBS) -o $(SHARED_OUTPUT_OPT) -shared
clean: CLEAN_RULE_HOOK
@echo Cleaning
-rm -fR .dep $(BUILDDIR)