From 8c17dbefbd63b143b8a0674b865ca943a9ff9855 Mon Sep 17 00:00:00 2001 From: Chun-Hung Tseng Date: Fri, 1 Mar 2024 21:48:59 +0100 Subject: [PATCH] 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 --- .github/workflows/main.yml | 12 +++++++++++- Makefile | 8 ++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9f85c5fc..2537e3ea 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -85,7 +85,7 @@ jobs: - name: install-dependencies run: | sudo apt-get update -q -y - sudo apt-get install -q -y libsdl2-dev libsdl2-mixer-dev + sudo apt-get install -q -y libsdl2-dev libsdl2-mixer-dev valgrind .ci/riscv-toolchain-install.sh wget https://apt.llvm.org/llvm.sh sudo chmod +x ./llvm.sh @@ -119,6 +119,16 @@ jobs: run: | make clean && make ENABLE_UBSAN=1 check -j$(nproc) make ENABLE_JIT=1 clean && make ENABLE_JIT=1 ENABLE_UBSAN=1 check -j$(nproc) + - name: valgrind check (without JIT) + run: | + make clean && make ENABLE_SDL=0 ENABLE_JIT=0 ENABLE_VALGRIND=1 + valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1 ./build/rv32emu ./build/hello.elf + valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1 ./build/rv32emu ./build/aes.elf + - name: valgrind check (with JIT) + run: | + make clean && make ENABLE_SDL=0 ENABLE_JIT=1 ENABLE_VALGRIND=1 + valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1 ./build/rv32emu ./build/hello.elf + valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1 ./build/rv32emu ./build/aes.elf host-arm64: needs: [detect-code-related-file-changes] diff --git a/Makefile b/Makefile index d8359110..a6d51fa6 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,14 @@ CFLAGS = -std=gnu99 -O2 -Wall -Wextra CFLAGS += -Wno-unused-label CFLAGS += -include src/common.h +ENABLE_VALGRIND ?= 0 +ifeq ("$(ENABLE_UBSAN)", "1") +# 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." +# In order to use Valgrind, we need to compile with -g +CFLAGS += -g +LDFLAGS += -g +endif + # Enable link-time optimization (LTO) ENABLE_LTO ?= 1 ifeq ($(call has, LTO), 1)