Skip to content

Commit 1988b18

Browse files
committed
Add GitHub Actions CI: host tests, sanitizers, cppcheck, firmware build
Four jobs run on push to main and on every pull request: 1. host-tests — gcc compiles and runs the 66 host-side unit tests in tests/. 2. host-tests-sanitizers — same suite rebuilt with -fsanitize= address,undefined and run with halt_on_error/abort_on_error so any memory or undefined-behavior issue fails the build. 3. cppcheck — static analysis on bcm_master/Core/Src and lighting_node/Core/Src at warning, performance, and portability levels; non-zero exit on any finding. 4. firmware-build — installs gcc-arm-none-eabi and builds both firmware images with their Makefiles, then uploads the .elf, .hex, and .bin artifacts.
1 parent 2416153 commit 1988b18

1 file changed

Lines changed: 103 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
host-tests:
11+
name: Host unit tests
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
- name: Build and run tests
16+
working-directory: tests
17+
run: |
18+
gcc -Wall -Wextra -I./stubs \
19+
-I../bcm_master/Core/Inc \
20+
-I../lighting_node/Core/Inc \
21+
test_runner.c \
22+
test_heartbeat_timeout.c \
23+
test_checksum_validation.c \
24+
test_lamp_arbitration.c \
25+
../bcm_master/Core/Src/com_lighting_if.c \
26+
../bcm_master/Core/Src/io_bcm_inputs.c \
27+
../lighting_node/Core/Src/io_lighting_outputs.c \
28+
-o run_tests
29+
./run_tests
30+
31+
host-tests-sanitizers:
32+
name: Host tests (ASan + UBSan)
33+
runs-on: ubuntu-latest
34+
env:
35+
ASAN_OPTIONS: detect_leaks=1:halt_on_error=1:abort_on_error=1
36+
UBSAN_OPTIONS: halt_on_error=1:abort_on_error=1:print_stacktrace=1
37+
steps:
38+
- uses: actions/checkout@v4
39+
- name: Build with sanitizers and run
40+
working-directory: tests
41+
run: |
42+
gcc -Wall -Wextra -g -O1 \
43+
-fsanitize=address,undefined -fno-omit-frame-pointer \
44+
-I./stubs \
45+
-I../bcm_master/Core/Inc \
46+
-I../lighting_node/Core/Inc \
47+
test_runner.c \
48+
test_heartbeat_timeout.c \
49+
test_checksum_validation.c \
50+
test_lamp_arbitration.c \
51+
../bcm_master/Core/Src/com_lighting_if.c \
52+
../bcm_master/Core/Src/io_bcm_inputs.c \
53+
../lighting_node/Core/Src/io_lighting_outputs.c \
54+
-o run_tests_san
55+
./run_tests_san
56+
57+
cppcheck:
58+
name: Static analysis (cppcheck)
59+
runs-on: ubuntu-latest
60+
steps:
61+
- uses: actions/checkout@v4
62+
- name: Install cppcheck
63+
run: sudo apt-get update && sudo apt-get install -y cppcheck
64+
- name: Run cppcheck on application sources
65+
run: |
66+
cppcheck \
67+
--enable=warning,performance,portability \
68+
--inline-suppr \
69+
--suppress=missingInclude \
70+
--error-exitcode=2 \
71+
--quiet \
72+
bcm_master/Core/Src \
73+
lighting_node/Core/Src
74+
75+
firmware-build:
76+
name: Firmware cross-compile (arm-none-eabi-gcc)
77+
runs-on: ubuntu-latest
78+
steps:
79+
- uses: actions/checkout@v4
80+
- name: Install ARM GCC toolchain
81+
run: sudo apt-get update && sudo apt-get install -y gcc-arm-none-eabi
82+
- name: Build bcm_master
83+
working-directory: bcm_master
84+
run: make -j$(nproc)
85+
- name: Build lighting_node
86+
working-directory: lighting_node
87+
run: make -j$(nproc)
88+
- name: Show firmware sizes
89+
run: |
90+
arm-none-eabi-size bcm_master/build/bcm_master.elf
91+
arm-none-eabi-size lighting_node/build/lighting_node.elf
92+
- name: Upload firmware artifacts
93+
uses: actions/upload-artifact@v4
94+
with:
95+
name: firmware-images
96+
path: |
97+
bcm_master/build/bcm_master.elf
98+
bcm_master/build/bcm_master.hex
99+
bcm_master/build/bcm_master.bin
100+
lighting_node/build/lighting_node.elf
101+
lighting_node/build/lighting_node.hex
102+
lighting_node/build/lighting_node.bin
103+
if-no-files-found: error

0 commit comments

Comments
 (0)