Skip to content

Commit ae3f762

Browse files
committed
CI: memcheck.sh improvements; github workflow for nightly memleak tests and other minor changes
Enhanced memory checking script with automatic leak detection and reporting. The script now: - Scans memory checker log files - Identifies memory leaks using predefined patterns - Provides detailed output for detected leaks - Exits with an error code if leaks are found Configured a scheduled GitHub Actions workflow to run memory leak detection tests using Valgrind. The workflow: - Runs nightly - Uses a specialized Valgrind-enabled Docker container - Executes memcheck.sh for comprehensive memory leak testing - Uploads test artifacts for further analysis
1 parent ecc1b5d commit ae3f762

File tree

6 files changed

+104
-8
lines changed

6 files changed

+104
-8
lines changed

.github/workflows/clt_nightly.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: Nightly tests
2-
run-name: Nightly tests ${{ github.sha }}
2+
run-name: 🌙 Nightly tests ${{ github.sha }}
33

44
on:
55
schedule:

.github/workflows/nightly_dumps.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: CLT testing of supported versions of mysqldump
2-
run-name: CLT testing of supported versions of mysqldump ${{ github.sha }}
2+
run-name: 🌙 CLT testing of supported versions of mysqldump ${{ github.sha }}
33

44
on:
55
schedule:
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Nightly memleaks tests
2+
run-name: 🌙 Nightly memleaks tests ${{ github.sha }}
3+
4+
on:
5+
schedule:
6+
- cron: '00 20 * * *'
7+
push:
8+
paths:
9+
- '.github/workflows/nightly_memleaks.yml'
10+
11+
# cancels the previous workflow run when a new one appears in the same branch (e.g. master or a PR's branch)
12+
concurrency:
13+
group: nightly_memleaks_${{ github.ref }}
14+
cancel-in-progress: true
15+
16+
jobs:
17+
memleaks:
18+
name: Memleak tests
19+
runs-on: ubuntu-22.04
20+
defaults:
21+
run:
22+
shell: bash
23+
timeout-minutes: 300
24+
container:
25+
image: manticoresearch/manticore_valgrind:jammy
26+
env:
27+
DIAGNOSTIC: 1
28+
VERBOSE: 1
29+
CTEST_CONFIGURATION_TYPE: "RelWithDebInfo"
30+
UNITY_BUILD: 1
31+
CACHEB: "../cache"
32+
steps:
33+
- name: Checkout repository
34+
uses: actions/checkout@v3
35+
with:
36+
token: ${{ secrets.GITHUB_TOKEN }}
37+
set-safe-directory: true
38+
- name: Check out cache before building
39+
uses: actions/cache/[email protected]
40+
with:
41+
path: cache
42+
key: build_linux_debug_x86_64
43+
- name: memcheck.sh
44+
run: |
45+
mysqld &
46+
bash memcheck.sh
47+
- name: Upload build artifacts
48+
if: always()
49+
continue-on-error: true
50+
uses: manticoresoftware/upload_artifact_with_retries@v4
51+
with:
52+
name: memleaks_${{ github.sha }}
53+
path: build/Testing
54+

memcheck.sh

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
# This script can be run on the host, or in the docker
44

55
chmod +x valgrind
6+
mkdir -p build
67
cd build
78

8-
[[ ! -z "${CACHEB}" ]] && export CACHEB=../cache
9-
[[ ! -z "${uid}" ]] && export uid=`id -u`
10-
[[ ! -z "${gid}" ]] && export gid=`id -g`
9+
[[ -z "${CACHEB}" ]] && export CACHEB=../cache
10+
[[ ! -e "${CACHEB}" ]] && mkdir -p ${CACHEB}
11+
[[ -z "${uid}" ]] && export uid=`id -u`
12+
[[ -z "${gid}" ]] && export gid=`id -g`
13+
trap "chown -R $uid:$gid ." EXIT
1114

1215
export CTEST_CONFIGURATION_TYPE=RelWithDebInfo
1316
export CTEST_CMAKE_GENERATOR=Ninja
@@ -24,4 +27,42 @@ export NO_TESTS=0
2427
rm -f Testing/Temporary/MemoryChecker.*.log
2528
time ctest -V -S ../misc/ctest/memcheck.cmake
2629
find Testing/Temporary/MemoryChecker.*.log -size 0 -delete
27-
chown -R $uid:$gid .
30+
31+
# Analysis of memory leak reports
32+
echo "Analyzing memory leak reports..."
33+
LEAK_FOUND=0
34+
LEAK_PATTERNS=("definitely lost")
35+
36+
# Function to check for memory leaks in a file
37+
check_leaks() {
38+
local file=$1
39+
local test_num=$(basename "$file" | sed -E 's/MemoryChecker\.([0-9]+)\.log/\1/')
40+
41+
for pattern in "${LEAK_PATTERNS[@]}"; do
42+
if grep -i "$pattern" "$file" > /dev/null; then
43+
echo "===================================================================="
44+
echo "MEMORY LEAK DETECTED in test_$test_num"
45+
echo "Pattern found: $pattern"
46+
echo "===================================================================="
47+
echo "Full log content:"
48+
cat "$file"
49+
echo "===================================================================="
50+
LEAK_FOUND=1
51+
fi
52+
done
53+
}
54+
55+
# Process all memory checker log files
56+
for log_file in Testing/Temporary/MemoryChecker.*.log; do
57+
if [ -f "$log_file" ]; then
58+
check_leaks "$log_file"
59+
fi
60+
done
61+
62+
if [ $LEAK_FOUND -eq 1 ]; then
63+
echo "Memory leaks were detected. Check the logs above for details."
64+
exit 1
65+
else
66+
echo "No memory leaks detected."
67+
exit 0
68+
fi

memdocker.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/bin/bash
22
#Run shell in valgrind docker
33

4-
BUILD_DOCKER=manticore_valgrind:jammy
4+
# Use environment variable BUILD_DOCKER if set, otherwise use default value
5+
BUILD_DOCKER=${BUILD_DOCKER:-manticoresearch/manticore_valgrind:jammy}
56
CONFIG=RelWithDebInfo
67
WORKDIR=/work
78

misc/ctest/memcheck.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ It is recommended to clean the `/manticore/source/dir/build` folder. This may no
2020

2121
After running, you may notice the text near the end of the output:
2222
```
23-
MemCheck log files can be found here: (<#> corresponds to the test number)
23+
MemCheck log files can be found here: (<#> corresponds to test number)
2424
/manticore/source/dir/build/Testing/Temporary/MemoryChecker.<#>.log
2525
```
2626

0 commit comments

Comments
 (0)