Skip to content

Commit 6a2a933

Browse files
mandeseroBuristan
authored andcommitted
ci: add Valgrind testing workflow
This patch adds CI testing with Valgrind in three scenarios: - Full leak checks enabled. - No leak checks, with memory fill set to `--malloc-fill=0x00` and `--free-fill=0x00`. - No leak checks, with memory fill set to `--malloc-fill=0xff` and `--free-fill=0xff`. The use of `0x00` and `0xff` for memory fill helps to detect dirty reads. `0x00` mimics zero-initialized memory, which can mask some uninitialized memory usage. `0xff` fills memory with non-zero values to make such errors easier to spot. Closes tarantool/tarantool#3705 Reviewed-by: Sergey Bronnikov <[email protected]> Reviewed-by: Sergey Kaplun <[email protected]> Signed-off-by: Sergey Kaplun <[email protected]> (cherry picked from commit 508171c)
1 parent dda99c5 commit 6a2a933

File tree

3 files changed

+126
-0
lines changed

3 files changed

+126
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Setup environment for Valgrind on Linux
2+
3+
Action setups the environment on Linux runners (install requirements, setup the
4+
workflow environment, etc) for testing with Valgrind.
5+
6+
## How to use Github Action from Github workflow
7+
8+
Add the following code to the running steps before LuaJIT configuration:
9+
```
10+
- uses: ./.github/actions/setup-valgrind
11+
if: ${{ matrix.OS == 'Linux' }}
12+
```
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: Setup CI environment with Valgrind on Linux
2+
description: Extend setup-linux with Valgrind installation
3+
4+
runs:
5+
using: composite
6+
steps:
7+
- name: Setup CI environment (Linux)
8+
uses: ./.github/actions/setup-linux
9+
- name: Install Valgrind
10+
run: |
11+
apt -y install valgrind
12+
shell: bash
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
name: Valgrind testing
2+
3+
on:
4+
push:
5+
branches-ignore:
6+
- '**-notest'
7+
- 'upstream-**'
8+
tags-ignore:
9+
- '**'
10+
11+
concurrency:
12+
# An update of a developer branch cancels the previously
13+
# scheduled workflow run for this branch. However, the default
14+
# branch, and long-term branch (tarantool/release/2.11,
15+
# tarantool/release/2.10, etc) workflow runs are never canceled.
16+
#
17+
# We use a trick here: define the concurrency group as 'workflow
18+
# run ID' + # 'workflow run attempt' because it is a unique
19+
# combination for any run. So it effectively discards grouping.
20+
#
21+
# XXX: we cannot use `github.sha` as a unique identifier because
22+
# pushing a tag may cancel a run that works on a branch push
23+
# event.
24+
group: ${{ startsWith(github.ref, 'refs/heads/tarantool/')
25+
&& format('{0}-{1}', github.run_id, github.run_attempt)
26+
|| format('{0}-{1}', github.workflow, github.ref) }}
27+
cancel-in-progress: true
28+
29+
jobs:
30+
test-valgrind:
31+
strategy:
32+
fail-fast: false
33+
matrix:
34+
# XXX: Let's start with only Linux/x86_64.
35+
# We don't test on arm64 because the address returned by
36+
# the system allocator may exceed 47 bits. As a result, we
37+
# are unable to allocate memory for `lua_State`.
38+
# Therefore, testing on this platform is currently
39+
# disabled.
40+
BUILDTYPE: [Debug, Release]
41+
VALGRIND_SCENARIO: [full, malloc-free-fill-0x00, malloc-free-fill-0xff]
42+
include:
43+
- BUILDTYPE: Debug
44+
CMAKEFLAGS: -DCMAKE_BUILD_TYPE=Debug -DLUA_USE_ASSERT=ON -DLUA_USE_APICHECK=ON
45+
- BUILDTYPE: Release
46+
CMAKEFLAGS: -DCMAKE_BUILD_TYPE=RelWithDebInfo
47+
- VALGRIND_SCENARIO: full
48+
VALGRIND_OPTS: --leak-check=full --show-leak-kinds=all --track-origins=yes
49+
JOB_POSTFIX: "leak-check: full"
50+
# The use of `0x00` and `0xFF` for memory fill helps
51+
# to detect dirty reads. `0x00` mimics
52+
# zero-initialized memory, which can mask some
53+
# uninitialized memory usage. `0xFF` fills memory with
54+
# a non-zero values to make such errors easier to
55+
# spot.
56+
- VALGRIND_SCENARIO: malloc-free-fill-0x00
57+
VALGRIND_OPTS: --leak-check=no --malloc-fill=0x00 --free-fill=0x00
58+
JOB_POSTFIX: "malloc/free-fill: 0x00"
59+
- VALGRIND_SCENARIO: malloc-free-fill-0xff
60+
VALGRIND_OPTS: --leak-check=no --malloc-fill=0xff --free-fill=0xff
61+
JOB_POSTFIX: "malloc/free-fill: 0xff"
62+
runs-on: [self-hosted, regular, Linux, x86_64]
63+
name: >
64+
LuaJIT with Valgrind (Linux/x86_64)
65+
${{ matrix.BUILDTYPE }}
66+
CC: gcc
67+
GC64:ON SYSMALLOC:ON
68+
${{ matrix.JOB_POSTFIX }}
69+
steps:
70+
- uses: actions/checkout@v4
71+
with:
72+
fetch-depth: 0
73+
submodules: recursive
74+
- name: setup Linux for Valgrind
75+
uses: ./.github/actions/setup-valgrind
76+
- name: configure
77+
# XXX: LuaJIT configuration requires a couple of tweaks:
78+
# LUAJIT_USE_SYSMALLOC=ON: Unfortunately, the internal
79+
# LuaJIT memory allocator is not instrumented yet, so to
80+
# find any memory errors, it's better to build LuaJIT with
81+
# the system-provided memory allocator (i.e. run CMake
82+
# configuration phase with -DLUAJIT_USE_SYSMALLOC=ON).
83+
# For more info, see root CMakeLists.txt.
84+
# LUAJIT_ENABLE_GC64=ON: LUAJIT_USE_SYSMALLOC cannot be
85+
# enabled on x64 without GC64, since realloc usually
86+
# doesn't return addresses in the right address range.
87+
# For more info, see root CMakeLists.txt.
88+
run: >
89+
cmake -S . -B ${{ env.BUILDDIR }}
90+
-G Ninja
91+
${{ matrix.CMAKEFLAGS }}
92+
-DLUAJIT_USE_VALGRIND=ON
93+
-DLUAJIT_ENABLE_GC64=ON
94+
-DLUAJIT_USE_SYSMALLOC=ON
95+
- name: build
96+
run: cmake --build . --parallel
97+
working-directory: ${{ env.BUILDDIR }}
98+
- name: test
99+
env:
100+
VALGRIND_OPTS: ${{ matrix.VALGRIND_OPTS }}
101+
run: cmake --build . --parallel --target LuaJIT-test
102+
working-directory: ${{ env.BUILDDIR }}

0 commit comments

Comments
 (0)