Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable unusedFunction checks #1970

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
Draft

Conversation

dzid26
Copy link
Contributor

@dzid26 dzid26 commented Jun 4, 2024

Find unusedFunctions for Panda program. Allows to:

  • treat F4 and H7 variants as a part of same program
  • differentiate between functions used in Panda and e.g. PandaJungle

Links: #1954 #1794 #1878

@dzid26 dzid26 force-pushed the unusedFunction branch 3 times, most recently from 31ff4a0 to b9e64f8 Compare June 5, 2024 16:53
@dzid26
Copy link
Contributor Author

dzid26 commented Jun 5, 2024

  • I enabled --project compile_commands.json for Misra and unusedFunctions now.
    • it uses scons, so it can check macros we are interested in.
    • for CI I think we may run twice. With and without RELEASE env
    • it checks all main() files, so it found 104 violations (to be fixed)
  • I still kept per build checks for unusedFunctions but only for Panda and bootstubs builds - I think this best practise and I think this similar will be need to be achieved for misra 8.x rules.

@dzid26 dzid26 force-pushed the unusedFunction branch 6 times, most recently from ee1eeb3 to f8d5b49 Compare June 7, 2024 14:03
@dzid26
Copy link
Contributor Author

dzid26 commented Jun 7, 2024

@adeebshihadeh is SPI ever used for Panda F4 besides the CI test?
I removed the stm32f4/llspi.h header since normal scons job doesn't use it and mutation test was failing sometimes.

I can:

  • remove building with ENABLE_SPI from CI test
  • or add ENABLE_SPI in misra tests

@adeebshihadeh
Copy link
Contributor

@adeebshihadeh is SPI ever used for Panda F4 besides the CI test? I removed the stm32f4/llspi.h header since normal scons job doesn't use it and so mutation test was failing sometimes.

I can:

  • remove building with ENABLE_SPI from CI test
  • or add ENABLE_SPI in misra tests

Let's add it to the tests. We don't use it yet, but might want to in the future.

@dzid26 dzid26 force-pushed the unusedFunction branch 6 times, most recently from df66b33 to 60c3a42 Compare June 9, 2024 08:41
@dzid26
Copy link
Contributor Author

dzid26 commented Jun 9, 2024

I noticed that cppcheck doesn't report system level misra violation when used with --project= compile_commands.json argument.
I will see if I can fix it, because otherwise, it is the most robust way to call whole program analysis.

@dzid26 dzid26 force-pushed the unusedFunction branch 2 times, most recently from ebf561a to dac2b4d Compare June 10, 2024 21:15
- gnu.cfg replaces __typeof__ with typeof() and triggered some misra-c2012-10.4 - fixed by making both function args the same essential type
- combines panda build configurations

Increase mutation test timeout
remove Panda specific functions
STMF4 doesn't use uart interrupt
DAC and watchdog are not used
memset is needed by the linker
@dzid26
Copy link
Contributor Author

dzid26 commented Jun 11, 2024

--project=compile_commands.json is definitely the way to go in the future, but I needed to give up on it until cppcheck bugs (resulting in false negatives on system level misra checks) get fixed.

In the meantime, I figured out a way to check different macro configurations together using --force and force-included dummy/helper header which specifies possible combinations for F4 & H7. This should make checking for unused macros (rule 2.5) fairly straightforward as well.

@dzid26 dzid26 marked this pull request as ready for review June 12, 2024 02:00
tests/misra/test_mutation.py Outdated Show resolved Hide resolved
@@ -193,440 +193,7 @@ Yes CheckType::checkSignConversion
Yes CheckType::checkTooBigBitwiseShift
Yes CheckUninitVar::check
Yes CheckUninitVar::valueFlowUninit
No CheckUnusedFunctions::check require:unusedFunction
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did all of this get removed?

Copy link
Contributor Author

@dzid26 dzid26 Jun 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diff is a bit weird - the second variant used to start at line 440 and now is removed.
Basically now, instead of checking F4 and H7 separately, they are checked together using cppcheck configuration combination capability (which is enforced with... --force argument ).

tests/misra/test_mutation.py Outdated Show resolved Hide resolved
@dzid26
Copy link
Contributor Author

dzid26 commented Jul 26, 2024

Converting to draft.
It seems that Cppcheck bails out if it encounters [unknownMacro] violation. But since I had --suppress=unknownMacro it wouldn't report any remaining violations. https://sourceforge.net/p/cppcheck/discussion/general/thread/769381a303/#f0dc

We need to add --safety flag to avoid quiet bail-outs like this. danmar/cppcheck#5777 (comment)

Underlying issue is related to how --force option works:
https://sourceforge.net/p/cppcheck/discussion/general/thread/5c740643e6/?limit=25#7278

@dzid26 dzid26 marked this pull request as draft July 26, 2024 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants