From 34935963bc113a297d8a01c50694dacac63dd310 Mon Sep 17 00:00:00 2001 From: dzid26 Date: Sun, 22 Sep 2024 19:43:13 -0700 Subject: [PATCH] cppcheck with --project CI: test misra with RELEASE=1 Generates compile db without ALLOW_DEBUG --- .github/workflows/test.yaml | 5 +- .gitignore | 1 + SConscript | 4 +- SConstruct | 6 + tests/misra/checkers.txt | 461 +------------------------------ tests/misra/panda_macro_config.h | 5 +- tests/misra/suppressions.txt | 2 +- tests/misra/test_misra.sh | 26 +- tests/misra/test_mutation.py | 2 +- 9 files changed, 42 insertions(+), 470 deletions(-) mode change 100755 => 100644 tests/misra/test_mutation.py diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index d1d9f7605aa..9dfae7ce86e 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -96,9 +96,12 @@ jobs: run: eval "$BUILD" - name: Build FW run: ${{ env.RUN }} "scons -j$(nproc)" - - name: Run MISRA C:2012 analysis + - name: Run MISRA C:2012 analysis - ALLOW_DEBUG timeout-minutes: 1 run: ${{ env.RUN }} "cd tests/misra && ./test_misra.sh" + - name: Run MISRA C:2012 analysis - RELEASE + timeout-minutes: 2 + run: ${{ env.RUN }} "cd tests/misra && CERT=./certs/debug RELEASE=1 ./test_misra.sh" - name: MISRA mutation tests timeout-minutes: 7 run: ${{ env.RUN }} "cd tests/misra && pytest -n8 test_mutation.py" diff --git a/.gitignore b/.gitignore index 640f25f8e0a..173a0b41ebc 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ examples/output.csv nosetests.xml .mypy_cache/ .sconsign.dblite +compile_commands*.json # CTU info files generated by Cppcheck *.*.ctu-info diff --git a/SConscript b/SConscript index 4c86d0cfabc..9054f32b592 100644 --- a/SConscript +++ b/SConscript @@ -107,8 +107,8 @@ def build_project(project_name, project, extra_flags): # Bootstub crypto_obj = [ - env.Object(f"rsa-{project_name}", f"{panda_root}/crypto/rsa.c"), - env.Object(f"sha-{project_name}", f"{panda_root}/crypto/sha.c") + env.Object(f"bootstub-rsa-{project_name}", f"{panda_root}/crypto/rsa.c"), + env.Object(f"bootstub-sha-{project_name}", f"{panda_root}/crypto/sha.c") ] bootstub_obj = env.Object(f"bootstub-{project_name}", File(project.get("BOOTSTUB", f"{panda_root}/board/bootstub.c"))) bootstub_elf = env.Program(f"obj/bootstub.{project_name}.elf", diff --git a/SConstruct b/SConstruct index aa13f592299..9ff8c36733f 100644 --- a/SConstruct +++ b/SConstruct @@ -22,7 +22,13 @@ env = Environment( ) if GetOption('compile_db'): + # whole project compilation database env.CompilationDatabase("compile_commands.json") + # Panda compilation database + env_p = env.Clone() + env_p["COMPILATIONDB_PATH_FILTER"] = '*board/[!jungle/][!bootstub]*' + env_p.CompilationDatabase("compile_commands_panda.json") + # panda fw & test files SConscript('SConscript') diff --git a/tests/misra/checkers.txt b/tests/misra/checkers.txt index 16489ca7203..8fb3ab35d80 100644 --- a/tests/misra/checkers.txt +++ b/tests/misra/checkers.txt @@ -5,7 +5,7 @@ Cppcheck checkers list from test_misra.sh: TEST variant options: -/board/main.c -I/board/ -DPANDA -DALLOW_DEBUG -UPANDA_JUNGLE -UFINAL_PROVISIONING -UBOOTSTUB -UDEBUG -UDEBUG_COMMS -UDEBUG_FAULTS -UDEBUG_FAN -UDEBUG_SPI -UDEBUG_UART -UDEBUG_USB --config-exclude=/board/stm32f4/inc --config-exclude=/board/stm32h7/inc --include=/tests/misra/panda_macro_config.h -i/tests/misra --enable=all --addon=misra --force --suppress=unknownMacro +--project=/compile_commands.json --enable=all --addon=misra -i/board/bootstub.c -i/board/jungle/ -i/crypto/ Critical errors @@ -194,466 +194,7 @@ Yes CheckType::checkSignConversion Yes CheckType::checkTooBigBitwiseShift Yes CheckUninitVar::check Yes CheckUninitVar::valueFlowUninit -<<<<<<< HEAD Yes CheckUnusedFunctions::check -======= -No CheckUnusedFunctions::check require:unusedFunction -Yes CheckUnusedVar::checkFunctionVariableUsage -Yes CheckUnusedVar::checkStructMemberUsage -Yes CheckVaarg::va_list_usage -Yes CheckVaarg::va_start_argument - - -Premium checkers ----------------- -Not available, Cppcheck Premium is not used - - -Autosar -------- -Not available, Cppcheck Premium is not used - - -Cert C ------- -Not available, Cppcheck Premium is not used - - -Cert C++ --------- -Not available, Cppcheck Premium is not used - - -Misra C 2012 ------------- -No Misra C 2012: Dir 1.1 -No Misra C 2012: Dir 2.1 -No Misra C 2012: Dir 3.1 -No Misra C 2012: Dir 4.1 -No Misra C 2012: Dir 4.2 -No Misra C 2012: Dir 4.3 -No Misra C 2012: Dir 4.4 -No Misra C 2012: Dir 4.5 -No Misra C 2012: Dir 4.6 amendment:3 -No Misra C 2012: Dir 4.7 -No Misra C 2012: Dir 4.8 -No Misra C 2012: Dir 4.9 amendment:3 -No Misra C 2012: Dir 4.10 -No Misra C 2012: Dir 4.11 amendment:3 -No Misra C 2012: Dir 4.12 -No Misra C 2012: Dir 4.13 -No Misra C 2012: Dir 4.14 amendment:2 -No Misra C 2012: Dir 4.15 amendment:3 -No Misra C 2012: Dir 5.1 amendment:4 -No Misra C 2012: Dir 5.2 amendment:4 -No Misra C 2012: Dir 5.3 amendment:4 -Yes Misra C 2012: 1.1 -Yes Misra C 2012: 1.2 -Yes Misra C 2012: 1.3 -Yes Misra C 2012: 1.4 amendment:2 -No Misra C 2012: 1.5 amendment:3 require:premium -Yes Misra C 2012: 2.1 -Yes Misra C 2012: 2.2 -Yes Misra C 2012: 2.3 -Yes Misra C 2012: 2.4 -Yes Misra C 2012: 2.5 -Yes Misra C 2012: 2.6 -Yes Misra C 2012: 2.7 -Yes Misra C 2012: 2.8 -Yes Misra C 2012: 3.1 -Yes Misra C 2012: 3.2 -Yes Misra C 2012: 4.1 -Yes Misra C 2012: 4.2 -Yes Misra C 2012: 5.1 -Yes Misra C 2012: 5.2 -Yes Misra C 2012: 5.3 -Yes Misra C 2012: 5.4 -Yes Misra C 2012: 5.5 -Yes Misra C 2012: 5.6 -Yes Misra C 2012: 5.7 -Yes Misra C 2012: 5.8 -Yes Misra C 2012: 5.9 -Yes Misra C 2012: 6.1 -Yes Misra C 2012: 6.2 -No Misra C 2012: 6.3 -Yes Misra C 2012: 7.1 -Yes Misra C 2012: 7.2 -Yes Misra C 2012: 7.3 -Yes Misra C 2012: 7.4 -No Misra C 2012: 7.5 -No Misra C 2012: 7.6 -Yes Misra C 2012: 8.1 -Yes Misra C 2012: 8.2 -No Misra C 2012: 8.3 -Yes Misra C 2012: 8.4 -Yes Misra C 2012: 8.5 -Yes Misra C 2012: 8.6 -Yes Misra C 2012: 8.7 -Yes Misra C 2012: 8.8 -Yes Misra C 2012: 8.9 -Yes Misra C 2012: 8.10 -Yes Misra C 2012: 8.11 -Yes Misra C 2012: 8.12 -Yes Misra C 2012: 8.13 -Yes Misra C 2012: 8.14 -No Misra C 2012: 8.15 -No Misra C 2012: 8.16 -No Misra C 2012: 8.17 -Yes Misra C 2012: 9.1 -Yes Misra C 2012: 9.2 -Yes Misra C 2012: 9.3 -Yes Misra C 2012: 9.4 -Yes Misra C 2012: 9.5 -No Misra C 2012: 9.6 -No Misra C 2012: 9.7 -Yes Misra C 2012: 10.1 -Yes Misra C 2012: 10.2 -Yes Misra C 2012: 10.3 -Yes Misra C 2012: 10.4 -Yes Misra C 2012: 10.5 -Yes Misra C 2012: 10.6 -Yes Misra C 2012: 10.7 -Yes Misra C 2012: 10.8 -Yes Misra C 2012: 11.1 -Yes Misra C 2012: 11.2 -Yes Misra C 2012: 11.3 -Yes Misra C 2012: 11.4 -Yes Misra C 2012: 11.5 -Yes Misra C 2012: 11.6 -Yes Misra C 2012: 11.7 -Yes Misra C 2012: 11.8 -Yes Misra C 2012: 11.9 -No Misra C 2012: 11.10 -Yes Misra C 2012: 12.1 -Yes Misra C 2012: 12.2 -Yes Misra C 2012: 12.3 -Yes Misra C 2012: 12.4 -Yes Misra C 2012: 12.5 amendment:1 -No Misra C 2012: 12.6 amendment:4 require:premium -Yes Misra C 2012: 13.1 -No Misra C 2012: 13.2 -Yes Misra C 2012: 13.3 -Yes Misra C 2012: 13.4 -Yes Misra C 2012: 13.5 -Yes Misra C 2012: 13.6 -Yes Misra C 2012: 14.1 -Yes Misra C 2012: 14.2 -Yes Misra C 2012: 14.3 -Yes Misra C 2012: 14.4 -Yes Misra C 2012: 15.1 -Yes Misra C 2012: 15.2 -Yes Misra C 2012: 15.3 -Yes Misra C 2012: 15.4 -Yes Misra C 2012: 15.5 -Yes Misra C 2012: 15.6 -Yes Misra C 2012: 15.7 -Yes Misra C 2012: 16.1 -Yes Misra C 2012: 16.2 -Yes Misra C 2012: 16.3 -Yes Misra C 2012: 16.4 -Yes Misra C 2012: 16.5 -Yes Misra C 2012: 16.6 -Yes Misra C 2012: 16.7 -Yes Misra C 2012: 17.1 -Yes Misra C 2012: 17.2 -Yes Misra C 2012: 17.3 -No Misra C 2012: 17.4 -Yes Misra C 2012: 17.5 -Yes Misra C 2012: 17.6 -Yes Misra C 2012: 17.7 -Yes Misra C 2012: 17.8 -No Misra C 2012: 17.9 -No Misra C 2012: 17.10 -No Misra C 2012: 17.11 -No Misra C 2012: 17.12 -No Misra C 2012: 17.13 -Yes Misra C 2012: 18.1 -Yes Misra C 2012: 18.2 -Yes Misra C 2012: 18.3 -Yes Misra C 2012: 18.4 -Yes Misra C 2012: 18.5 -Yes Misra C 2012: 18.6 -Yes Misra C 2012: 18.7 -Yes Misra C 2012: 18.8 -No Misra C 2012: 18.9 -No Misra C 2012: 18.10 -Yes Misra C 2012: 19.1 -Yes Misra C 2012: 19.2 -Yes Misra C 2012: 20.1 -Yes Misra C 2012: 20.2 -Yes Misra C 2012: 20.3 -Yes Misra C 2012: 20.4 -Yes Misra C 2012: 20.5 -Yes Misra C 2012: 20.6 -Yes Misra C 2012: 20.7 -Yes Misra C 2012: 20.8 -Yes Misra C 2012: 20.9 -Yes Misra C 2012: 20.10 -Yes Misra C 2012: 20.11 -Yes Misra C 2012: 20.12 -Yes Misra C 2012: 20.13 -Yes Misra C 2012: 20.14 -Yes Misra C 2012: 21.1 -Yes Misra C 2012: 21.2 -Yes Misra C 2012: 21.3 -Yes Misra C 2012: 21.4 -Yes Misra C 2012: 21.5 -Yes Misra C 2012: 21.6 -Yes Misra C 2012: 21.7 -Yes Misra C 2012: 21.8 -Yes Misra C 2012: 21.9 -Yes Misra C 2012: 21.10 -Yes Misra C 2012: 21.11 -Yes Misra C 2012: 21.12 -Yes Misra C 2012: 21.13 amendment:1 -Yes Misra C 2012: 21.14 amendment:1 -Yes Misra C 2012: 21.15 amendment:1 -Yes Misra C 2012: 21.16 amendment:1 -Yes Misra C 2012: 21.17 amendment:1 -Yes Misra C 2012: 21.18 amendment:1 -Yes Misra C 2012: 21.19 amendment:1 -Yes Misra C 2012: 21.20 amendment:1 -Yes Misra C 2012: 21.21 amendment:3 -No Misra C 2012: 21.22 amendment:3 require:premium -No Misra C 2012: 21.23 amendment:3 require:premium -No Misra C 2012: 21.24 amendment:3 require:premium -No Misra C 2012: 21.25 amendment:4 require:premium -No Misra C 2012: 21.26 amendment:4 require:premium -Yes Misra C 2012: 22.1 -Yes Misra C 2012: 22.2 -Yes Misra C 2012: 22.3 -Yes Misra C 2012: 22.4 -Yes Misra C 2012: 22.5 -Yes Misra C 2012: 22.6 -Yes Misra C 2012: 22.7 amendment:1 -Yes Misra C 2012: 22.8 amendment:1 -Yes Misra C 2012: 22.9 amendment:1 -Yes Misra C 2012: 22.10 amendment:1 -No Misra C 2012: 22.11 amendment:4 require:premium -No Misra C 2012: 22.12 amendment:4 require:premium -No Misra C 2012: 22.13 amendment:4 require:premium -No Misra C 2012: 22.14 amendment:4 require:premium -No Misra C 2012: 22.15 amendment:4 require:premium -No Misra C 2012: 22.16 amendment:4 require:premium -No Misra C 2012: 22.17 amendment:4 require:premium -No Misra C 2012: 22.18 amendment:4 require:premium -No Misra C 2012: 22.19 amendment:4 require:premium -No Misra C 2012: 22.20 amendment:4 require:premium -No Misra C 2012: 23.1 amendment:3 require:premium -No Misra C 2012: 23.2 amendment:3 require:premium -No Misra C 2012: 23.3 amendment:3 require:premium -No Misra C 2012: 23.4 amendment:3 require:premium -No Misra C 2012: 23.5 amendment:3 require:premium -No Misra C 2012: 23.6 amendment:3 require:premium -No Misra C 2012: 23.7 amendment:3 require:premium -No Misra C 2012: 23.8 amendment:3 require:premium - - -Misra C++ 2008 --------------- -Not available, Cppcheck Premium is not used - - -Misra C++ 2023 --------------- -Not available, Cppcheck Premium is not used - - - - - -TEST variant options: ---enable=all --disable=unusedFunction -DPANDA --addon=misra -DSTM32H7 -DSTM32H725xx /board/main.c - - -Critical errors ---------------- -No critical errors, all files were checked. -Important: Analysis is still not guaranteed to be 'complete' it is possible there are false negatives. - - -Open source checkers --------------------- -Yes Check64BitPortability::pointerassignment -Yes CheckAssert::assertWithSideEffects -Yes CheckAutoVariables::assignFunctionArg -Yes CheckAutoVariables::autoVariables -Yes CheckAutoVariables::checkVarLifetime -No CheckBool::checkAssignBoolToFloat require:style,c++ -Yes CheckBool::checkAssignBoolToPointer -No CheckBool::checkBitwiseOnBoolean require:style,inconclusive -Yes CheckBool::checkComparisonOfBoolExpressionWithInt -No CheckBool::checkComparisonOfBoolWithBool require:style,c++ -No CheckBool::checkComparisonOfBoolWithInt require:warning,c++ -No CheckBool::checkComparisonOfFuncReturningBool require:style,c++ -Yes CheckBool::checkIncrementBoolean -Yes CheckBool::pointerArithBool -Yes CheckBool::returnValueOfFunctionReturningBool -No CheckBoost::checkBoostForeachModification -Yes CheckBufferOverrun::analyseWholeProgram -Yes CheckBufferOverrun::argumentSize -Yes CheckBufferOverrun::arrayIndex -Yes CheckBufferOverrun::arrayIndexThenCheck -Yes CheckBufferOverrun::bufferOverflow -Yes CheckBufferOverrun::negativeArraySize -Yes CheckBufferOverrun::objectIndex -Yes CheckBufferOverrun::pointerArithmetic -No CheckBufferOverrun::stringNotZeroTerminated require:warning,inconclusive -Yes CheckClass::analyseWholeProgram -No CheckClass::checkConst require:style,inconclusive -No CheckClass::checkConstructors require:style,warning -No CheckClass::checkCopyConstructors require:warning -No CheckClass::checkDuplInheritedMembers require:warning -No CheckClass::checkExplicitConstructors require:style -No CheckClass::checkMemset -No CheckClass::checkMissingOverride require:style,c++03 -No CheckClass::checkReturnByReference require:performance -No CheckClass::checkSelfInitialization -No CheckClass::checkThisUseAfterFree require:warning -No CheckClass::checkUnsafeClassRefMember require:warning,safeChecks -No CheckClass::checkUselessOverride require:style -No CheckClass::checkVirtualFunctionCallInConstructor require:warning -No CheckClass::initializationListUsage require:performance -No CheckClass::initializerListOrder require:style,inconclusive -No CheckClass::operatorEqRetRefThis require:style -No CheckClass::operatorEqToSelf require:warning -No CheckClass::privateFunctions require:style -No CheckClass::thisSubtraction require:warning -No CheckClass::virtualDestructor -Yes CheckCondition::alwaysTrueFalse -Yes CheckCondition::assignIf -Yes CheckCondition::checkAssignmentInCondition -Yes CheckCondition::checkBadBitmaskCheck -Yes CheckCondition::checkCompareValueOutOfTypeRange -Yes CheckCondition::checkDuplicateConditionalAssign -Yes CheckCondition::checkIncorrectLogicOperator -Yes CheckCondition::checkInvalidTestForOverflow -Yes CheckCondition::checkModuloAlwaysTrueFalse -Yes CheckCondition::checkPointerAdditionResultNotNull -Yes CheckCondition::clarifyCondition -Yes CheckCondition::comparison -Yes CheckCondition::duplicateCondition -Yes CheckCondition::multiCondition -Yes CheckCondition::multiCondition2 -No CheckExceptionSafety::checkCatchExceptionByValue require:style -No CheckExceptionSafety::checkRethrowCopy require:style -No CheckExceptionSafety::deallocThrow require:warning -No CheckExceptionSafety::destructors require:warning -No CheckExceptionSafety::nothrowThrows -No CheckExceptionSafety::rethrowNoCurrentException -No CheckExceptionSafety::unhandledExceptionSpecification require:style,inconclusive -Yes CheckFunctions::checkIgnoredReturnValue -Yes CheckFunctions::checkMathFunctions -Yes CheckFunctions::checkMissingReturn -Yes CheckFunctions::checkProhibitedFunctions -Yes CheckFunctions::invalidFunctionUsage -Yes CheckFunctions::memsetInvalid2ndParam -Yes CheckFunctions::memsetZeroBytes -No CheckFunctions::returnLocalStdMove require:performance,c++11 -Yes CheckFunctions::useStandardLibrary -No CheckIO::checkCoutCerrMisusage require:c -Yes CheckIO::checkFileUsage -Yes CheckIO::checkWrongPrintfScanfArguments -Yes CheckIO::invalidScanf -Yes CheckLeakAutoVar::check -No CheckMemoryLeakInClass::check -Yes CheckMemoryLeakInFunction::checkReallocUsage -Yes CheckMemoryLeakNoVar::check -No CheckMemoryLeakNoVar::checkForUnsafeArgAlloc -Yes CheckMemoryLeakStructMember::check -Yes CheckNullPointer::analyseWholeProgram -Yes CheckNullPointer::arithmetic -Yes CheckNullPointer::nullConstantDereference -Yes CheckNullPointer::nullPointer -No CheckOther::checkAccessOfMovedVariable require:c++11,warning -Yes CheckOther::checkCastIntToCharAndBack -Yes CheckOther::checkCharVariable -Yes CheckOther::checkComparePointers -Yes CheckOther::checkComparisonFunctionIsAlwaysTrueOrFalse -Yes CheckOther::checkConstPointer -No CheckOther::checkConstVariable require:style,c++ -No CheckOther::checkDuplicateBranch require:style,inconclusive -Yes CheckOther::checkDuplicateExpression -Yes CheckOther::checkEvaluationOrder -Yes CheckOther::checkFuncArgNamesDifferent -No CheckOther::checkIncompleteArrayFill require:warning,portability,inconclusive -Yes CheckOther::checkIncompleteStatement -No CheckOther::checkInterlockedDecrement require:windows-platform -Yes CheckOther::checkInvalidFree -Yes CheckOther::checkKnownArgument -Yes CheckOther::checkKnownPointerToBool -No CheckOther::checkMisusedScopedObject require:style,c++ -Yes CheckOther::checkModuloOfOne -Yes CheckOther::checkNanInArithmeticExpression -Yes CheckOther::checkNegativeBitwiseShift -Yes CheckOther::checkOverlappingWrite -No CheckOther::checkPassByReference require:performance,c++ -Yes CheckOther::checkRedundantAssignment -No CheckOther::checkRedundantCopy require:c++,performance,inconclusive -Yes CheckOther::checkRedundantPointerOp -Yes CheckOther::checkShadowVariables -Yes CheckOther::checkSignOfUnsignedVariable -No CheckOther::checkSuspiciousCaseInSwitch require:warning,inconclusive -No CheckOther::checkSuspiciousSemicolon require:warning,inconclusive -Yes CheckOther::checkUnreachableCode -Yes CheckOther::checkUnusedLabel -Yes CheckOther::checkVarFuncNullUB -Yes CheckOther::checkVariableScope -Yes CheckOther::checkZeroDivision -Yes CheckOther::clarifyCalculation -Yes CheckOther::clarifyStatement -Yes CheckOther::invalidPointerCast -Yes CheckOther::redundantBitwiseOperationInSwitch -Yes CheckOther::suspiciousFloatingPointCast -No CheckOther::warningOldStylePointerCast require:style,c++ -No CheckPostfixOperator::postfixOperator require:performance -Yes CheckSizeof::checkSizeofForArrayParameter -Yes CheckSizeof::checkSizeofForNumericParameter -Yes CheckSizeof::checkSizeofForPointerSize -Yes CheckSizeof::sizeofCalculation -Yes CheckSizeof::sizeofFunction -Yes CheckSizeof::sizeofVoid -Yes CheckSizeof::sizeofsizeof -No CheckSizeof::suspiciousSizeofCalculation require:warning,inconclusive -No CheckStl::checkDereferenceInvalidIterator require:warning -No CheckStl::checkDereferenceInvalidIterator2 -No CheckStl::checkFindInsert require:performance -No CheckStl::checkMutexes require:warning -No CheckStl::erase -No CheckStl::eraseIteratorOutOfBounds -No CheckStl::if_find require:warning,performance -No CheckStl::invalidContainer -No CheckStl::iterators -No CheckStl::knownEmptyContainer require:style -No CheckStl::misMatchingContainerIterator -No CheckStl::misMatchingContainers -No CheckStl::missingComparison require:warning -No CheckStl::negativeIndex -No CheckStl::outOfBounds -No CheckStl::outOfBoundsIndexExpression -No CheckStl::redundantCondition require:style -No CheckStl::size require:performance,c++03 -No CheckStl::stlBoundaries -No CheckStl::stlOutOfBounds -No CheckStl::string_c_str -No CheckStl::useStlAlgorithm require:style -No CheckStl::uselessCalls require:performance,warning -Yes CheckString::checkAlwaysTrueOrFalseStringCompare -Yes CheckString::checkIncorrectStringCompare -Yes CheckString::checkSuspiciousStringCompare -Yes CheckString::overlappingStrcmp -Yes CheckString::sprintfOverlappingData -Yes CheckString::strPlusChar -Yes CheckString::stringLiteralWrite -Yes CheckType::checkFloatToIntegerOverflow -Yes CheckType::checkIntegerOverflow -Yes CheckType::checkLongCast -Yes CheckType::checkSignConversion -Yes CheckType::checkTooBigBitwiseShift -Yes CheckUninitVar::check -Yes CheckUninitVar::valueFlowUninit -No CheckUnusedFunctions::check require:unusedFunction ->>>>>>> 8545c68e4d51eab55803c9c28cdf8bb7bfaa261e Yes CheckUnusedVar::checkFunctionVariableUsage Yes CheckUnusedVar::checkStructMemberUsage Yes CheckVaarg::va_list_usage diff --git a/tests/misra/panda_macro_config.h b/tests/misra/panda_macro_config.h index 30ba1cfc8f0..766517c311b 100644 --- a/tests/misra/panda_macro_config.h +++ b/tests/misra/panda_macro_config.h @@ -1,5 +1,5 @@ -// This is a dummy structure to allow cppcheck to test certain macro combinations -// together and in one seesion (needed for things like unused macros) +// This is a dummy structure to allow cppcheck to test certain macro combinations +// together and in one seesion (needed for things like unused macros) // The structure should represents macro configurations used in scons #ifdef STM32H7 @@ -12,5 +12,4 @@ #ifdef ENABLE_SPI #endif #endif -#else #endif diff --git a/tests/misra/suppressions.txt b/tests/misra/suppressions.txt index 4b79e109f5d..04fc81158f9 100644 --- a/tests/misra/suppressions.txt +++ b/tests/misra/suppressions.txt @@ -18,7 +18,7 @@ unusedFunction:*/interrupt_handlers.h # all of the below suppressions are from new checks introduced after updating # cppcheck from 2.5 -> 2.13. they are listed here to separate the update from # fixing the violations and all are intended to be removed soon after -misra-c2012-2.5 # unused macros. a few legit, rest aren't common between F4/H7 builds. should we do this in the unusedFunction pass? +misra-c2012-5.9 # false positives ? misra-c2012-8.7 misra-c2012-8.4 misra-c2012-21.15 diff --git a/tests/misra/test_misra.sh b/tests/misra/test_misra.sh index 5f713bfa6f1..a723546014f 100755 --- a/tests/misra/test_misra.sh +++ b/tests/misra/test_misra.sh @@ -28,7 +28,7 @@ fi cd $PANDA_DIR if [ -z "${SKIP_BUILD}" ]; then - scons -j8 + scons -j8 --compile_db fi CHECKLIST=$DIR/checkers.txt @@ -61,6 +61,27 @@ cppcheck() { fi } +if [ -z "$PANDA_SYSTEM_LEVEL_ONLY" ]; then +# Test whole Panda project for unused functions / constants +printf "\n${GREEN}** Panda project - tests: Cppcheck whole program + MISRA per translation unit **${NC}\n" +cppcheck --project=$PANDA_DIR/compile_commands.json \ + --enable=all --addon=misra \ + -i$PANDA_DIR/board/bootstub.c \ + -i$PANDA_DIR/board/jungle/ \ + -i$PANDA_DIR/crypto/ +# TODO enable bootstub and jungle for the whole build +# Note: MISRA system level tests (e.g. rule 2.5) not supported by cppcheck 2.15 with --project argument + + +# Test standalone Panda program. (Unused functions / constants is more strict than whole project check) + printf "\n${GREEN}** Panda standalone - tests: Cppcheck whole program **${NC}\n" + cppcheck --project=$PANDA_DIR/compile_commands_panda.json \ + --enable=all --addon=misra + + +fi + +# *** Legacy cppcheck test type by providing c files list *** # --force checks different macro combinations to avoid reporting macros and functions used by only one panda configuration # panda_macro_config.h lets cppcheck know macro combinations used for the build printf "\n${GREEN}** Panda tests: cppcheck whole program anlysis + Misra addon system level analysis **${NC}\n" @@ -71,7 +92,8 @@ cppcheck $PANDA_DIR/board/main.c -I$PANDA_DIR/board/ \ --config-exclude=$PANDA_DIR/board/stm32f4/inc --config-exclude=$PANDA_DIR/board/stm32h7/inc \ --include=$DIR/panda_macro_config.h -i$DIR \ --enable=all --addon=misra \ - --force --suppress=unknownMacro + --force +# TODO remove this test when cppcheck fully supports system level misra reporting with --project printf "\n${GREEN}Success!${NC} took $SECONDS seconds\n" diff --git a/tests/misra/test_mutation.py b/tests/misra/test_mutation.py old mode 100755 new mode 100644 index da6aa85bdec..85047a4173e --- a/tests/misra/test_mutation.py +++ b/tests/misra/test_mutation.py @@ -81,6 +81,6 @@ def test_misra_mutation(fn, patch, should_fail, tmp_path): assert r == 0 # run test - r = subprocess.run("SKIP_TABLES_DIFF=1 tests/misra/test_misra.sh", cwd=tmp_path, shell=True) + r = subprocess.run("SKIP_TABLES_DIFF=1 PANDA_SYSTEM_LEVEL_ONLY=1 tests/misra/test_misra.sh", cwd=tmp_path, shell=True) failed = r.returncode != 0 assert failed == should_fail