Skip to content

Commit af835ac

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 d23e0f1 commit af835ac

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

.github/workflows/main.yml

Lines changed: 12 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
wget https://apt.llvm.org/llvm.sh
4848
sudo chmod +x ./llvm.sh
@@ -76,6 +76,16 @@ jobs:
7676
run: |
7777
make clean && make ENABLE_UBSAN=1 check -j$(nproc)
7878
make ENABLE_JIT=1 clean clean && make ENABLE_JIT=1 ENABLE_UBSAN=1 check -j$(nproc)
79+
- name: valgrind check (without JIT)
80+
run: |
81+
make clean && make ENABLE_SDL=0 ENABLE_JIT=0 ENABLE_VALGRIND=1
82+
valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1 ./build/rv32emu ./build/hello.elf
83+
valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1 ./build/rv32emu ./build/aes.elf
84+
- name: valgrind check (with JIT)
85+
run: |
86+
make clean && make ENABLE_SDL=0 ENABLE_JIT=1 ENABLE_VALGRIND=1
87+
valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1 ./build/rv32emu ./build/hello.elf
88+
valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1 ./build/rv32emu ./build/aes.elf
7989
8090
host-arm64:
8191
needs: [detect-code-related-file-changes]
@@ -187,3 +197,4 @@ jobs:
187197
context: .
188198
platforms: linux/amd64,linux/arm64/v8
189199
tags: sysprog21/rv32emu:latest, sysprog21/rv32emu:${{ env.short_hash }}
200+

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)