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

sca: Add cppcheck (FOSS and premium) #80961

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

rettichschnidi
Copy link
Contributor

@rettichschnidi rettichschnidi commented Nov 6, 2024

This allows to use cppcheck directly, without going trough CodeChecker.

TODO:

  • Get cppcheck premium to not (always) exit with code 1
    • Make the current workaround work with FOSS edition too
  • Test with newer (post 2.10) cppcheck (non premium) to see if zephyr.cfg is supported
  • Support all platforms, not just ARM 32-bit
  • Support variables set by Twister (similar to CodeChecker)
  • Export cppcheck command line to CMake (similar to CodeChecker)
  • Use parallelization properly (set -j <n>)
  • Fix asserts in include/zephyr/kernel/internal/mm.h
  • Fix true positive Zephyr issues found by Cppcheck

Background: I am doing this because I am currently evaluating Cppcheck Premium.

@rettichschnidi rettichschnidi force-pushed the gardena/rs/upstream/sca-cppcheck branch 2 times, most recently from a1554b5 to e8355ad Compare November 27, 2024 13:28
@zephyrbot
Copy link
Collaborator

zephyrbot commented Nov 27, 2024

The following west manifest projects have changed revision in this Pull Request:

Name Old Revision New Revision Diff
cmsis 4b96cbb174678dcd3ca86e11e1f24bc5f8726da0 gardena/rs/upstream/sca-cppcheck N/A

Additional metadata changed:

Name URL Submodules West cmds module.yml
cmsis

DNM label due to: 1 project with metadata changes and 1 unreachable repo

Note: This message is automatically posted and updated by the Manifest GitHub Action.

@zephyrbot zephyrbot added manifest manifest-cmsis DNM This PR should not be merged (Do Not Merge) labels Nov 27, 2024
find_program(CPPCHECK_EXE NAMES cppcheck REQUIRED)
message(STATUS "Found SCA: cppcheck (${CPPCHECK_EXE})")

# CodeChecker uses the compile_commands.json as input
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy paste error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed. Thanks!

COMMAND
${CPPCHECK_HTMLREPORT_EXE} --title=Zephyr
--file=${output_dir}/cppcheck.xml # Read in file created by cppcheck
--report-dir=${output_dir} # Set output director # Set output directory
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
--report-dir=${output_dir} # Set output director # Set output directory
--report-dir=${output_dir} # Set output directory

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed. Thanks!

@rettichschnidi rettichschnidi force-pushed the gardena/rs/upstream/sca-cppcheck branch 2 times, most recently from 9db0694 to b917536 Compare December 3, 2024 22:11
@rettichschnidi rettichschnidi force-pushed the gardena/rs/upstream/sca-cppcheck branch 2 times, most recently from d703fb8 to c4e5050 Compare December 25, 2024 13:57
This commit adds cppcheck as a Static Analyser using Zephyr's SCA
framework.

By specifing -DZEPHYR_SCA_VARIANT=cppcheck to west build, the file
sca/cppcheck/index.html will be generated.

Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>
This change allows cppcheck to go past the compiler check macros.

Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>
This is a proper finding by cppcheck. Remove the code for now because it
blocks finding of other issues.
Putting #ifdef inside a macro invocation is undefined behavior.

Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>
This is needed to allow Cppcheck to work.
Putting #ifdef inside a macro invocation is undefined behavior.

Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>
@rettichschnidi rettichschnidi force-pushed the gardena/rs/upstream/sca-cppcheck branch from c4e5050 to 8b98c73 Compare December 26, 2024 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DNM This PR should not be merged (Do Not Merge) manifest manifest-cmsis
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants