Use Valgrind to detect unitialized variable references. (#3555)

* Use Valgrind to detect unitialized variable references.

Fix the edge cases that pop up

* Comment and disable Mac run
This commit is contained in:
Scott Smith 2021-11-15 20:42:23 -08:00 committed by GitHub
parent 5d65c70a62
commit c354d30a71
8 changed files with 38 additions and 17 deletions

View File

@ -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' }}
@ -58,10 +56,6 @@ jobs:
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

View File

@ -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);
}

View File

@ -339,6 +339,7 @@ void NamedOutputPin::setLow() {
}
InjectorOutputPin::InjectorOutputPin() : NamedOutputPin() {
overlappingCounter = 1; // Force update in reset
reset();
injectorIndex = -1;
}

View File

@ -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;

View File

@ -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) {

View File

@ -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);

View File

@ -10,6 +10,7 @@
TEST(trigger, miataNA) {
TriggerWaveform naShape;
naShape.useOnlyRisingEdgeForTriggerTemp = false;
initializeMazdaMiataNaShape(&naShape);
WITH_ENGINE_TEST_HELPER(FRANKENSO_MIATA_NA6_MAP);

View File

@ -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