Skip to content

Commit

Permalink
cppcheck with --project
Browse files Browse the repository at this point in the history
CI: test misra with RELEASE=1
Generates compile db without ALLOW_DEBUG
  • Loading branch information
dzid26 committed Sep 19, 2024
1 parent fd6fe90 commit b892a9c
Show file tree
Hide file tree
Showing 8 changed files with 704 additions and 8 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ examples/output.csv
nosetests.xml
.mypy_cache/
.sconsign.dblite
compile_commands*.json

# CTU info files generated by Cppcheck
*.*.ctu-info
Expand Down
4 changes: 2 additions & 2 deletions SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -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')
667 changes: 667 additions & 0 deletions tests/misra/checkers.txt

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions tests/misra/panda_macro_config.h
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -12,5 +12,4 @@
#ifdef ENABLE_SPI
#endif
#endif
#else
#endif
22 changes: 21 additions & 1 deletion tests/misra/test_misra.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fi

cd $PANDA_DIR
if [ -z "${SKIP_BUILD}" ]; then
scons -j8
scons -j8 --compile_db
fi

CHECKLIST=$DIR/checkers.txt
Expand Down Expand Up @@ -61,6 +61,7 @@ cppcheck() {
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"
Expand All @@ -72,6 +73,25 @@ cppcheck $PANDA_DIR/board/main.c -I$PANDA_DIR/board/ \
--include=$DIR/panda_macro_config.h -i$DIR \
--enable=all --addon=misra \
--force --suppress=unknownMacro
# TODO remove this test when cppcheck supports system level misra reporting with --project

if [ -z "$PANDA_SYSTEM_LEVEL_ONLY" ]; then
# Test standalone Panda program. (Unused functions 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
# TODO add --addon=misra when cppcheck supports system level misra reporting with --project

# Test whole Panda project for unused functions
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 --disable=unusedFunction \
-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.14.1 with --project argument
fi
printf "\n${GREEN}Success!${NC} took $SECONDS seconds\n"


Expand Down
2 changes: 1 addition & 1 deletion tests/misra/test_mutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b892a9c

Please sign in to comment.