diff --git a/.github/workflows/build-unit-tests.yaml b/.github/workflows/build-unit-tests.yaml index d15630b4cf..3f42ae0e96 100644 --- a/.github/workflows/build-unit-tests.yaml +++ b/.github/workflows/build-unit-tests.yaml @@ -24,9 +24,7 @@ jobs: if: ${{ matrix.os != 'macos-latest' }} run: | sudo apt-get update - sudo apt-get install mtools - sudo apt-get install zip - sudo apt-get install dosfstools + sudo apt-get install mtools zip dosfstools sshpass lcov valgrind - name: Install required software (macos) if: ${{ matrix.os == 'macos-latest' }} @@ -53,15 +51,11 @@ jobs: - name: Build Tests working-directory: ./unit_tests/ run: make -j4 COVERAGE=yes - + - name: Run Tests working-directory: ./unit_tests/ run: ASAN_OPTIONS=detect_stack_use_after_return=1 build/rusefi_test - - name: Install Coverage Tools - if: ${{ matrix.os != 'macos-latest' }} - run: sudo apt-get install sshpass lcov - - name: Generate Code Coverage if: ${{ matrix.os != 'macos-latest' && github.event_name == 'push' && github.ref == 'refs/heads/master' }} working-directory: ./unit_tests/ @@ -70,3 +64,16 @@ jobs: - name: Run Tests (sharded) working-directory: ./unit_tests/ run: bash ./run_sharded_tests.sh + + - name: Rebuild Tests For Valgrind + # Valgrind isn't compatible with address sanitizer, so we have to rebuild the code + if: ${{ matrix.os != 'macos-latest' }} + working-directory: ./unit_tests/ + run: | + make clean + make -j4 SANITIZE=no + + - name: Run Tests (Valgrind) + if: ${{ matrix.os != 'macos-latest' }} + working-directory: ./unit_tests/ + run: valgrind --error-exitcode=1 --leak-check=no build/rusefi_test diff --git a/firmware/controllers/actuators/idle_thread.cpp b/firmware/controllers/actuators/idle_thread.cpp index c9529b3fe3..337aa37058 100644 --- a/firmware/controllers/actuators/idle_thread.cpp +++ b/firmware/controllers/actuators/idle_thread.cpp @@ -130,6 +130,9 @@ void setManualIdleValvePosition(int positionPercent) { #endif /* EFI_UNIT_TEST */ void IdleController::init(pid_s* idlePidConfig) { + engine->idle.shouldResetPid = false; + engine->idle.mightResetPid = false; + engine->idle.wasResetPid = false; m_timingPid.initPidClass(idlePidConfig); } diff --git a/firmware/controllers/system/efi_gpio.cpp b/firmware/controllers/system/efi_gpio.cpp index 0eb92d2dc7..579728ee4b 100644 --- a/firmware/controllers/system/efi_gpio.cpp +++ b/firmware/controllers/system/efi_gpio.cpp @@ -339,6 +339,7 @@ void NamedOutputPin::setLow() { } InjectorOutputPin::InjectorOutputPin() : NamedOutputPin() { + overlappingCounter = 1; // Force update in reset reset(); injectorIndex = -1; } diff --git a/unit_tests/logicdata_csv_reader.h b/unit_tests/logicdata_csv_reader.h index 041a70ee68..8e2e913229 100644 --- a/unit_tests/logicdata_csv_reader.h +++ b/unit_tests/logicdata_csv_reader.h @@ -31,8 +31,8 @@ private: FILE *fp; char buffer[255]; - bool currentState[2]; - bool currentVvtState[CAM_INPUTS_COUNT]; + bool currentState[2] = {0, 0}; + bool currentVvtState[CAM_INPUTS_COUNT] = {0, 0}; int m_lineIndex = -1; diff --git a/unit_tests/tests/ignition_injection/test_fuel_map.cpp b/unit_tests/tests/ignition_injection/test_fuel_map.cpp index bf6607967c..f4cd0621d5 100644 --- a/unit_tests/tests/ignition_injection/test_fuel_map.cpp +++ b/unit_tests/tests/ignition_injection/test_fuel_map.cpp @@ -87,8 +87,9 @@ TEST(misc, testFuelMap) { } -static void confgiureFordAspireTriggerWaveform(TriggerWaveform * s) { +static void configureFordAspireTriggerWaveform(TriggerWaveform * s) { s->initialize(FOUR_STROKE_CAM_SENSOR); + s->useOnlyRisingEdgeForTriggerTemp = false; s->addEvent720(53.747, T_SECONDARY, TV_RISE); s->addEvent720(121.90, T_SECONDARY, TV_FALL); @@ -182,7 +183,7 @@ TEST(misc, testAngleResolver) { ASSERT_FLOAT_EQ(178.24, injectionStart.angleOffsetFromTriggerEvent); TriggerWaveform t; - confgiureFordAspireTriggerWaveform(&t); + configureFordAspireTriggerWaveform(&t); } TEST(misc, testPinHelper) { diff --git a/unit_tests/tests/trigger/test_trigger_decoder.cpp b/unit_tests/tests/trigger/test_trigger_decoder.cpp index d0ba852b95..601a060931 100644 --- a/unit_tests/tests/trigger/test_trigger_decoder.cpp +++ b/unit_tests/tests/trigger/test_trigger_decoder.cpp @@ -465,6 +465,7 @@ TEST(misc, testTriggerDecoder) { EXPAND_Engine; TriggerWaveform * s = &e.triggerCentral.triggerShape; + s->useOnlyRisingEdgeForTriggerTemp = false; initializeSkippedToothTriggerWaveformExt(s, 2, 0, FOUR_STROKE_CAM_SENSOR); assertEqualsM("shape size", s->getSize(), 4); ASSERT_EQ(s->wave->getSwitchTime(0), 0.25); diff --git a/unit_tests/tests/trigger/test_trigger_multi_sync.cpp b/unit_tests/tests/trigger/test_trigger_multi_sync.cpp index 92b163daa1..ee156dacb1 100644 --- a/unit_tests/tests/trigger/test_trigger_multi_sync.cpp +++ b/unit_tests/tests/trigger/test_trigger_multi_sync.cpp @@ -10,6 +10,7 @@ TEST(trigger, miataNA) { TriggerWaveform naShape; + naShape.useOnlyRisingEdgeForTriggerTemp = false; initializeMazdaMiataNaShape(&naShape); WITH_ENGINE_TEST_HELPER(FRANKENSO_MIATA_NA6_MAP); diff --git a/unit_tests/unit_test_rules.mk b/unit_tests/unit_test_rules.mk index 73a4cb48c5..aa6ba9d064 100644 --- a/unit_tests/unit_test_rules.mk +++ b/unit_tests/unit_test_rules.mk @@ -1,12 +1,12 @@ UNIT_TESTS_DIR=$(PROJECT_DIR)/../unit_tests CPPSRC += gtest-all.cpp \ - gmock-all.cpp \ + gmock-all.cpp \ INCDIR += $(UNIT_TESTS_DIR)/googletest/googlemock/include \ - $(UNIT_TESTS_DIR)/googletest/googletest \ - $(UNIT_TESTS_DIR)/googletest/googletest/include \ + $(UNIT_TESTS_DIR)/googletest/googletest \ + $(UNIT_TESTS_DIR)/googletest/googletest/include \ PCH_DIR = ../firmware/pch PCHSRC = $(PCH_DIR)/pch.h @@ -14,6 +14,13 @@ PCHSUB = unit_tests include $(PROJECT_DIR)/rusefi_rules.mk +ifneq ($(OS),Windows_NT) + SANITIZE = yes +else + SANITIZE = no +endif + + # Compiler options here. ifeq ($(USE_OPT),) # -O2 is needed for mingw, without it there is a linking issue to isnanf?!?! @@ -35,7 +42,7 @@ endif USE_OPT += -DEFI_UNIT_TEST=1 -DEFI_PROD_CODE=0 -DEFI_SIMULATOR=0 # Enable address sanitizer, but not on Windows since x86_64-w64-mingw32-g++ doesn't support it. -ifneq ($(OS),Windows_NT) +ifeq ($(SANITIZE),yes) USE_OPT += -fsanitize=address endif @@ -189,7 +196,7 @@ ifeq ($(COVERAGE),yes) ULIBS += --coverage endif -ifneq ($(OS),Windows_NT) +ifeq ($(SANITIZE),yes) ULIBS += -fsanitize=address endif