Skip to content

Commit be0d1bb

Browse files
committed
codechecker
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
1 parent f070786 commit be0d1bb

File tree

5 files changed

+145
-0
lines changed

5 files changed

+145
-0
lines changed

.codechecker.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,16 @@ analyzer:
1717
- --disable=clang-diagnostic-reserved-identifier
1818
- --disable=clang-diagnostic-reserved-macro-identifier
1919

20+
# userspace includes c files
21+
- --disable=bugprone-suspicious-include
22+
23+
- --disable=clang-diagnostic-unused-parameter
24+
- --disable=bugprone-narrowing-conversions
25+
26+
# LOG_ macros
27+
- --disable=alpha.core.SizeofPtr
28+
- --disable=bugprone-sizeof-expression
29+
- --disable=performance-no-int-to-ptr
30+
2031
# Cleanup
2132
- --clean

.github/codechecker/skipfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-lib/libc/picolibc/*

.github/workflows/codechecker.yml

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
name: Codechecker
2+
on:
3+
pull_request:
4+
branches:
5+
- main
6+
push:
7+
branches:
8+
- main
9+
- v*-branch
10+
- collab-*
11+
permissions:
12+
contents: read
13+
14+
concurrency:
15+
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.head_ref || github.ref }}
16+
cancel-in-progress: true
17+
18+
jobs:
19+
Codechecker:
20+
if: github.repository_owner == 'zephyrproject-rtos'
21+
permissions:
22+
pull-requests: write # to create/update pull request comments
23+
security-events: write
24+
runs-on:
25+
group: zephyr-runner-v2-linux-x64-4xlarge
26+
container:
27+
image: ghcr.io/zephyrproject-rtos/ci-repo-cache:v0.27.4.20241026
28+
options: '--entrypoint /bin/bash'
29+
env:
30+
CCACHE_DIR: /node-cache/ccache-zephyr
31+
CCACHE_REMOTE_STORAGE: "redis://cache-*.keydb-cache.svc.cluster.local|shards=1,2,3"
32+
CCACHE_REMOTE_ONLY: "true"
33+
CCACHE_IGNOREOPTIONS: '-specs=* --specs=*'
34+
LLVM_TOOLCHAIN_PATH: /usr/lib/llvm-16
35+
BASE_REF: ${{ github.base_ref }}
36+
steps:
37+
- name: Apply container owner mismatch workaround
38+
run: |
39+
# FIXME: The owner UID of the GITHUB_WORKSPACE directory may not
40+
# match the container user UID because of the way GitHub
41+
# Actions runner is implemented. Remove this workaround when
42+
# GitHub comes up with a fundamental fix for this problem.
43+
git config --global --add safe.directory ${GITHUB_WORKSPACE}
44+
45+
- name: Print cloud service information
46+
run: |
47+
echo "ZEPHYR_RUNNER_CLOUD_PROVIDER = ${ZEPHYR_RUNNER_CLOUD_PROVIDER}"
48+
echo "ZEPHYR_RUNNER_CLOUD_NODE = ${ZEPHYR_RUNNER_CLOUD_NODE}"
49+
echo "ZEPHYR_RUNNER_CLOUD_POD = ${ZEPHYR_RUNNER_CLOUD_POD}"
50+
51+
- name: Clone cached Zephyr repository
52+
continue-on-error: true
53+
run: |
54+
git clone --shared /repo-cache/zephyrproject/zephyr .
55+
git remote set-url origin ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}
56+
57+
- name: Checkout
58+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
59+
with:
60+
fetch-depth: 0
61+
persist-credentials: false
62+
63+
- name: Environment Setup
64+
run: |
65+
echo "$HOME/.local/bin" >> $GITHUB_PATH
66+
git config --global user.email "bot@zephyrproject.org"
67+
git config --global user.name "Zephyr Bot"
68+
rm -fr ".git/rebase-apply"
69+
rm -fr ".git/rebase-merge"
70+
git clean -f -d
71+
git log --pretty=oneline | head -n 10
72+
west init -l . || true
73+
west config --global update.narrow true
74+
west config manifest.group-filter -- +ci,-optional
75+
# In some cases modules are left in a state where they can't be
76+
# updated (i.e. when we cancel a job and the builder is killed),
77+
# So first retry to update, if that does not work, remove all modules
78+
# and start over. (Workaround until we implement more robust module
79+
# west caching).
80+
west update --path-cache /repo-cache/zephyrproject 2>&1 1> west.log || west update --path-cache /repo-cache/zephyrproject 2>&1 1> west2.log || ( rm -rf ../modules ../bootloader ../tools && west update --path-cache /repo-cache/zephyrproject)
81+
82+
echo "ZEPHYR_SDK_INSTALL_DIR=/opt/toolchains/zephyr-sdk-$( cat SDK_VERSION )" >> $GITHUB_ENV
83+
84+
- name: Check Environment
85+
run: |
86+
cmake --version
87+
${LLVM_TOOLCHAIN_PATH}/bin/clang --version
88+
gcc --version
89+
ls -la
90+
91+
- name: Run Tests with Twister
92+
id: twister
93+
run: |
94+
export ZEPHYR_BASE=${PWD}
95+
export ZEPHYR_TOOLCHAIN_VARIANT=zephyr
96+
export ZEPHYR_SCA_VARIANT=codechecker
97+
export CODECHECKER_CONFIG_FILE=$ZEPHYR_BASE/.codechecker.yml
98+
export CODECHECKER_CLEANUP=y
99+
export CODECHECKER_EXPORT=sarif
100+
export CODECHECKER_SKIP_FILE=$ZEPHYR_BASE/.github/codechecker/skipfile
101+
102+
pip install codechecker==v6.25.1 cppcheck sarif-tools jq
103+
sudo apt-get update
104+
sudo apt-get install -y jq
105+
export PATH=/usr/lib/llvm-16/bin/:$PATH
106+
107+
./scripts/twister --jobs 16 -i --force-color -N -v --build-only --timeout-multiplier 2 -p qemu_x86 -T tests/kernel/threads/thread_apis/
108+
109+
#sarif copy --output results.sarif $(find twister-out -name "codechecker.sarif")
110+
jq -s '{ "$schema": "https://json.schemastore.org/sarif-2.1.0", "version": "2.1.0", "runs": map(.runs) | add }' $(find twister-out -name "codechecker.sarif") > results.sarif
111+
112+
- name: Upload SARIF as artifact
113+
if: always() && github.event_name == 'push'
114+
uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4.6.1
115+
with:
116+
name: sarif
117+
if-no-files-found: ignore
118+
path: |
119+
build/sca/codechecker/codechecker.sarif
120+
results.sarif
121+
122+
- name: Upload Analysis Results
123+
if: always()
124+
uses: github/codeql-action/upload-sarif@v3
125+
with:
126+
sarif_file: results.sarif

cmake/sca/codechecker/sca.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ zephyr_get(CODECHECKER_ANALYZE_JOBS)
1515
zephyr_get(CODECHECKER_ANALYZE_OPTS)
1616
zephyr_get(CODECHECKER_CLEANUP)
1717
zephyr_get(CODECHECKER_CONFIG_FILE)
18+
zephyr_get(CODECHECKER_SKIP_FILE)
1819
zephyr_get(CODECHECKER_EXPORT)
1920
zephyr_get(CODECHECKER_NAME)
2021
zephyr_get(CODECHECKER_PARSE_EXIT_STATUS)
@@ -47,6 +48,10 @@ if(CODECHECKER_CONFIG_FILE)
4748
set(CODECHECKER_CONFIG_FILE "--config;${CODECHECKER_CONFIG_FILE}")
4849
endif()
4950

51+
if(CODECHECKER_SKIP_FILE)
52+
set(CODECHECKER_SKIP_FILE "--skip;${CODECHECKER_SKIP_FILE}")
53+
endif()
54+
5055
if(CODECHECKER_STORE_TAG)
5156
set(CODECHECKER_STORE_TAG "--tag;${CODECHECKER_STORE_TAG}")
5257
else()

west.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,8 @@ manifest:
325325
- name: nrf_hw_models
326326
revision: d5b95fdd0260e8189e788d40d2863d1e2d4be159
327327
path: modules/bsim_hw_models/nrf_hw_models
328+
groups:
329+
- hal
328330
- name: nrf_wifi
329331
revision: d89b42a5a301d20f0083b3450789bab294e3f2c4
330332
path: modules/lib/nrf_wifi

0 commit comments

Comments
 (0)