Skip to content

Commit 485d987

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 9e4e13e commit 485d987

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

.github/workflows/main.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
- name: install-dependencies
4343
run: |
4444
sudo apt-get update -q -y
45-
sudo apt-get install -q -y libsdl2-dev libsdl2-mixer-dev
45+
sudo apt-get install -q -y libsdl2-dev libsdl2-mixer-dev valgrind
4646
.ci/riscv-toolchain-install.sh
4747
shell: bash
4848
- name: default build
@@ -73,6 +73,18 @@ jobs:
7373
run: |
7474
make ENABLE_UBSAN=1 clean check
7575
make ENABLE_JIT=1 ENABLE_UBSAN=1 clean check
76+
- name: valgrind check (without JIT)
77+
run: |
78+
make clean
79+
make ENABLE_SDL=0 ENABLE_JIT=0 ENABLE_VALGRIND=1
80+
valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1 ./build/rv32emu ./build/hello.elf
81+
valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1 ./build/rv32emu ./build/aes.elf
82+
- name: valgrind check (with JIT)
83+
run: |
84+
make clean
85+
make ENABLE_SDL=0 ENABLE_JIT=1 ENABLE_VALGRIND=1
86+
valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1 ./build/rv32emu ./build/hello.elf
87+
valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1 ./build/rv32emu ./build/aes.elf
7688
7789
host-arm64:
7890
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)