mirror of
https://github.com/sysprog21/lkmpg.git
synced 2024-11-22 15:05:54 +08:00
CI: Run static analysis with Cppcheck (#105)
Cppcheck[1] is integrated into CI pipeline for running static analysis. However, Cppcheck is known to report false-positive, and we have to suppress some warnings in advance. [1] https://cppcheck.sourceforge.io/
This commit is contained in:
parent
55b77fac8d
commit
5070fcd9d0
32
.ci/static-analysis.sh
Executable file
32
.ci/static-analysis.sh
Executable file
|
@ -0,0 +1,32 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
SOURCES=$(find $(git rev-parse --show-toplevel) | egrep "\.(cpp|cc|c|h)\$")
|
||||
|
||||
CPPCHECK=$(which cppcheck)
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "[!] cppcheck not installed. Failed to run static analysis the source code." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
## Suppression list ##
|
||||
# This list will explain the detail of suppressed warnings.
|
||||
# The prototype of the item should be like:
|
||||
# "- [{file}] {spec}: {reason}"
|
||||
#
|
||||
# - [hello-1.c] unusedFunction: False positive of init_module and cleanup_module.
|
||||
# - [*.c] missingIncludeSystem: Focus on the example code, not the kernel headers.
|
||||
|
||||
OPTS=" --enable=warning,style,performance,information
|
||||
--suppress=unusedFunction:hello-1.c
|
||||
--suppress=missingIncludeSystem
|
||||
--std=c89 "
|
||||
|
||||
$CPPCHECK $OPTS --xml ${SOURCES} 2> cppcheck.xml
|
||||
ERROR_COUNT=$(cat cppcheck.xml | egrep -c "</error>" )
|
||||
|
||||
if [ $ERROR_COUNT -gt 0 ]; then
|
||||
echo "Cppcheck failed: error count is $ERROR_COUNT"
|
||||
cat cppcheck.xml
|
||||
exit 1
|
||||
fi
|
||||
exit 0
|
2
.github/workflows/generate_doc.yaml
vendored
2
.github/workflows/generate_doc.yaml
vendored
|
@ -44,6 +44,8 @@ jobs:
|
|||
- name: validate coding style and functionality
|
||||
run: |
|
||||
sudo apt-get install -q -y clang-format-11
|
||||
sudo apt-get install -q -y cppcheck
|
||||
.ci/check-format.sh
|
||||
.ci/static-analysis.sh
|
||||
.ci/build-n-run.sh
|
||||
shell: bash
|
||||
|
|
|
@ -7,10 +7,10 @@
|
|||
|
||||
#define BYTE_TO_BINARY_PATTERN "%c%c%c%c%c%c%c%c"
|
||||
#define BYTE_TO_BINARY(byte) \
|
||||
(byte & 0x80 ? '1' : '0'), (byte & 0x40 ? '1' : '0'), \
|
||||
(byte & 0x20 ? '1' : '0'), (byte & 0x10 ? '1' : '0'), \
|
||||
(byte & 0x08 ? '1' : '0'), (byte & 0x04 ? '1' : '0'), \
|
||||
(byte & 0x02 ? '1' : '0'), (byte & 0x01 ? '1' : '0')
|
||||
((byte & 0x80) ? '1' : '0'), ((byte & 0x40) ? '1' : '0'), \
|
||||
((byte & 0x20) ? '1' : '0'), ((byte & 0x10) ? '1' : '0'), \
|
||||
((byte & 0x08) ? '1' : '0'), ((byte & 0x04) ? '1' : '0'), \
|
||||
((byte & 0x02) ? '1' : '0'), ((byte & 0x01) ? '1' : '0')
|
||||
|
||||
static void atomic_add_subtract(void)
|
||||
{
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
#include <linux/uaccess.h>
|
||||
|
||||
struct ioctl_arg {
|
||||
unsigned int reg;
|
||||
unsigned int val;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user