Skip to content

Commit 8c17dbe

Browse files
committed
Introduce valgrind to the CI pipeline
The static analyzer alone can't catch all the runtime issues. In this commit, the dynamic analysis tool Valgrind is added to the CI pipeline. ENABLE_SDL is set to 0, in order to reduce noise caused by the external libraries. Reference: - https://valgrind.org/docs/manual/quick-start.html - https://linux.die.net/man/1/gcc
1 parent a2e3aaa commit 8c17dbe

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

.github/workflows/main.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ jobs:
8585
- name: install-dependencies
8686
run: |
8787
sudo apt-get update -q -y
88-
sudo apt-get install -q -y libsdl2-dev libsdl2-mixer-dev
88+
sudo apt-get install -q -y libsdl2-dev libsdl2-mixer-dev valgrind
8989
.ci/riscv-toolchain-install.sh
9090
wget https://apt.llvm.org/llvm.sh
9191
sudo chmod +x ./llvm.sh
@@ -119,6 +119,16 @@ jobs:
119119
run: |
120120
make clean && make ENABLE_UBSAN=1 check -j$(nproc)
121121
make ENABLE_JIT=1 clean && make ENABLE_JIT=1 ENABLE_UBSAN=1 check -j$(nproc)
122+
- name: valgrind check (without JIT)
123+
run: |
124+
make clean && make ENABLE_SDL=0 ENABLE_JIT=0 ENABLE_VALGRIND=1
125+
valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1 ./build/rv32emu ./build/hello.elf
126+
valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1 ./build/rv32emu ./build/aes.elf
127+
- name: valgrind check (with JIT)
128+
run: |
129+
make clean && make ENABLE_SDL=0 ENABLE_JIT=1 ENABLE_VALGRIND=1
130+
valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1 ./build/rv32emu ./build/hello.elf
131+
valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1 ./build/rv32emu ./build/aes.elf
122132
123133
host-arm64:
124134
needs: [detect-code-related-file-changes]

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ CFLAGS = -std=gnu99 -O2 -Wall -Wextra
1111
CFLAGS += -Wno-unused-label
1212
CFLAGS += -include src/common.h
1313

14+
ENABLE_VALGRIND ?= 0
15+
ifeq ("$(ENABLE_UBSAN)", "1")
16+
# according to gcc's man page: "If you use multiple -O options, with or without level numbers, the last such option is the one that is effective."
17+
# In order to use Valgrind, we need to compile with -g
18+
CFLAGS += -g
19+
LDFLAGS += -g
20+
endif
21+
1422
# Enable link-time optimization (LTO)
1523
ENABLE_LTO ?= 1
1624
ifeq ($(call has, LTO), 1)

0 commit comments

Comments
 (0)