Skip to content

Commit 1cb35ac

Browse files
authored
Merge pull request #120 from linD026/master
CI: Introduce GCC static analysis
2 parents b0bbe01 + d6e1044 commit 1cb35ac

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

.ci/static-analysis.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,28 @@ function do_sparse()
6060
make -C examples clean
6161
}
6262

63+
function do_gcc()
64+
{
65+
local GCC=$(which gcc-10)
66+
if [ $? -ne 0 ]; then
67+
echo "[!] gcc-10 is not installed. Failed to run static analysis with GCC." >&2
68+
exit 1
69+
fi
70+
71+
make -C examples CONFIG_STATUS_CHECK_GCC=y STATUS_CHECK_GCC=$GCC 2> gcc.log
72+
73+
local WARNING_COUNT=$(cat gcc.log | egrep -c " warning:" )
74+
local ERROR_COUNT=$(cat gcc.log | egrep -c " error:" )
75+
local COUNT=`expr $WARNING_COUNT + $ERROR_COUNT`
76+
if [ $COUNT -gt 0 ]; then
77+
echo "gcc failed: $WARNING_COUNT warning(s), $ERROR_COUNT error(s)"
78+
cat gcc.log
79+
exit 1
80+
fi
81+
make -C examples CONFIG_STATUS_CHECK_GCC=y STATUS_CHECK_GCC=$GCC clean
82+
}
83+
6384
do_cppcheck
6485
do_sparse
86+
do_gcc
6587
exit 0

.github/workflows/status-check.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ jobs:
1818
run: |
1919
sudo apt-get install -q -y clang-format-11
2020
sudo apt-get install -q -y cppcheck
21+
sudo apt-get install -q -y gcc-10
2122
.ci/check-format.sh
2223
.ci/static-analysis.sh
2324
.ci/build-n-run.sh

examples/Makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,16 @@ obj-m += ioctl.o
3232

3333
PWD := $(CURDIR)
3434

35+
ifeq ($(CONFIG_STATUS_CHECK_GCC),y)
36+
CC=$(STATUS_CHECK_GCC)
37+
ccflags-y += -fanalyzer
38+
endif
39+
3540
all:
36-
$(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
41+
$(MAKE) -C /lib/modules/$(shell uname -r)/build CC=$(CC) M=$(PWD) modules
3742

3843
clean:
39-
$(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
44+
$(MAKE) -C /lib/modules/$(shell uname -r)/build CC=$(CC) M=$(PWD) clean
4045
$(RM) other/cat_noblock *.plist
4146

4247
indent:

0 commit comments

Comments
 (0)