Skip to content

Commit ab24501

Browse files
committed
add GH action for scan build
add scan target to Makefile
1 parent 33ec360 commit ab24501

File tree

12 files changed

+377
-40
lines changed

12 files changed

+377
-40
lines changed

.github/workflows/static-analysis.yml

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,37 @@ jobs:
6363
echo "❌ Static analysis failed - errors or warnings were found"
6464
exit 1
6565
66+
scan-build:
67+
runs-on: ubuntu-latest
68+
69+
steps:
70+
- name: Checkout wolfHSM
71+
uses: actions/checkout@v4
72+
with:
73+
path: wolfHSM
74+
75+
- name: Checkout wolfssl
76+
uses: actions/checkout@v4
77+
with:
78+
repository: wolfssl/wolfssl
79+
path: wolfssl
80+
81+
- name: Install dependencies
82+
run: |
83+
sudo apt-get update
84+
sudo apt-get install -y clang build-essential clang-tools
85+
86+
- name: Run scan-build
87+
id: scan-build
88+
run:
89+
cd wolfHSM && make scan
90+
91+
- name: Fail if scan-build issues found
92+
if: steps.scan-build.outcome == 'failure'
93+
run: |
94+
echo "❌ scan-build analysis failed - errors or warnings were found"
95+
exit 1
96+
6697
clang-tidy:
6798
runs-on: ubuntu-latest
6899

@@ -106,7 +137,6 @@ jobs:
106137
echo ""
107138
# Show first 50 issues to avoid overwhelming output
108139
head -50 tools/static-analysis/reports/clang_tidy_summary.txt
109-
110140
TOTAL_ISSUES=$((ERROR_COUNT + WARNING_COUNT))
111141
if [ "$TOTAL_ISSUES" -gt 50 ]; then
112142
echo ""

Makefile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,36 @@ tools:
1515
examples:
1616
make -C examples
1717

18+
SCAN_DIR = ./scan_out
19+
20+
scan_result_check:
21+
@num=$$(grep -h -o '^[0-9]\+ warnings\? generated' ./$(SCAN_DIR)/*.log | grep -o '^[0-9]\+' | awk '{s+=$$1} END {print s}');\
22+
if [ -z "$$num" ]; then \
23+
echo "no warnings found";\
24+
exit 0; \
25+
fi; \
26+
if [ $$num -ne 0 ]; then \
27+
echo "scan-build found $$num warnings";\
28+
for f in $(SCAN_DIR)/*.log; do \
29+
echo "---- $$f ----"; \
30+
cat $$f; \
31+
echo ""; \
32+
done; \
33+
exit 1; \
34+
fi;
35+
36+
37+
scan:
38+
@echo "Running scan-build static analysis"
39+
@rm -rf $(SCAN_DIR)
40+
@mkdir -p $(SCAN_DIR)
41+
@make clean
42+
-@make SCAN=1 -C test scan
43+
-@make SCAN=1 -C benchmark scan
44+
-@make NOCRYPTO=1 SCAN=1 -C tools/whnvmtool scan
45+
-@make NOCRYPTO=1 SCAN=1 -C examples
46+
@$(MAKE) scan_result_check
47+
1848
clean:
1949
make -C test clean
2050
make -C benchmark clean

benchmark/Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ ifeq ($(NOCRYPTO),1)
103103
DEF += -DWOLFHSM_CFG_NO_CRYPTO
104104
endif
105105

106+
ifeq ($(SCAN),1)
107+
SCAN_LOG = scan_benchmark.log
108+
# Default target
109+
.DEFAULT_GOAL := scan
110+
endif
111+
106112
# Support a DMA-capable build
107113
ifeq ($(DMA),1)
108114
DEF += -DWOLFHSM_CFG_DMA
@@ -161,6 +167,13 @@ build_static: $(BUILD_DIR) $(BUILD_DIR)/$(BIN).a
161167
@echo ""
162168
$(CMD_ECHO) $(SIZE) $(BUILD_DIR)/$(BIN).a
163169

170+
analyze: $(OBJS_ASM) $(OBJS_C)
171+
172+
scan:$(BUILD_DIR)
173+
@echo "Running scan-build static analysis"
174+
@mkdir -p $(WOLFHSM_DIR)/scan_out/
175+
@scan-build --status-bugs $(MAKE) analyze 2> $(WOLFHSM_DIR)/scan_out/$(SCAN_LOG)
176+
164177
$(BUILD_DIR):
165178
$(CMD_ECHO) mkdir -p $(BUILD_DIR)
166179

examples/demo/client/wh_demo_client_crypto.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040

4141
#include "wh_demo_client_crypto.h"
4242

43+
#ifndef WOLFHSM_CFG_NO_CRYPTO
44+
4345
#if !defined(NO_RSA)
4446

4547
/*
@@ -1359,3 +1361,4 @@ int wh_DemoClient_CryptoCmacOneshotImport(whClientContext* clientContext)
13591361
return ret;
13601362
}
13611363
#endif /* WOLFSSL_CMAC && !NO_AES */
1364+
#endif /* WOLFHSM_CFG_NO_CRYPTO */

examples/demo/client/wh_demo_client_keystore.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ int wh_DemoClient_KeystoreCommitKey(whClientContext* clientContext)
121121
return WH_ERROR_OK;
122122
}
123123

124-
#ifndef NO_AES
124+
#if !defined(NO_AES) && !defined(WOLFHSM_CFG_NO_CRYPTO)
125125
int wh_DemoClient_KeystoreAes(whClientContext* clientContext)
126126
{
127127
int ret;

0 commit comments

Comments
 (0)