forked from RedisJSON/RedisJSON
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemcheck-summary
executable file
·97 lines (81 loc) · 2.37 KB
/
memcheck-summary
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/bash
PROGNAME="${BASH_SOURCE[0]}"
HERE="$(cd "$(dirname "$PROGNAME")" &>/dev/null && pwd)"
ROOT=$(cd $HERE/.. && pwd)
export READIES=$ROOT/deps/readies
. $READIES/shibumi/defs
cd $HERE
#----------------------------------------------------------------------------------------------
valgrind_check() {
echo -n "${NOCOLOR}"
if grep -l "$1" $logdir/*.valgrind.log &> /dev/null; then
echo
echo "${LIGHTRED}### Valgrind: ${TYPE} detected:${RED}"
grep -l "$1" $logdir/*.valgrind.log
echo -n "${NOCOLOR}"
E=1
fi
}
valgrind_summary() {
local logdir="$ROOT/tests/$DIR/logs"
local leaks_head=0
for file in $(ls $logdir/*.valgrind.log 2>/dev/null); do
# If the last "definitely lost: " line of a logfile has a nonzero value, print the file name
if tac "$file" | grep -a -m 1 "definitely lost: " | grep "definitely lost: [1-9][0-9,]* bytes" &> /dev/null; then
if [[ $leaks_head == 0 ]]; then
echo
echo "${LIGHTRED}### Valgrind: leaks detected:${RED}"
leaks_head=1
fi
echo "$file"
E=1
fi
done
TYPE="invalid reads" valgrind_check "Invalid read"
TYPE="invalid writes" valgrind_check "Invalid write"
}
#----------------------------------------------------------------------------------------------
sanitizer_check() {
if grep -l "$1" $logdir/*.asan.log* &> /dev/null; then
echo
echo "${LIGHTRED}### Sanitizer: ${TYPE} detected:${RED}"
grep -l "$1" $logdir/*.asan.log*
echo "${NOCOLOR}"
if [[ -z $WARN || $WARN != 1 ]]; then
E=1
fi
fi
}
sanitizer_summary() {
local logdir="$ROOT/tests/$DIR/logs"
if ! TYPE="leaks" sanitizer_check "Direct leak"; then
TYPE="leaks" sanitizer_check "detected memory leaks"
fi
TYPE="buffer overflow" sanitizer_check "dynamic-stack-buffer-overflow"
TYPE="memory errors" sanitizer_check "memcpy-param-overlap"
TYPE="stack use after scope" sanitizer_check "stack-use-after-scope"
TYPE="use after free" sanitizer_check "heap-use-after-free"
TYPE="signal 11" WARN=1 sanitizer_check "signal 11"
}
#----------------------------------------------------------------------------------------------
E=0
DIRS=
if [[ $UNIT == 1 ]]; then
DIRS+=" ."
fi
if [[ $FLOW == 1 ]]; then
DIRS+=" pytests"
fi
if [[ $VG == 1 ]]; then
for dir in $DIRS; do
DIR="$dir" valgrind_summary
done
elif [[ -n $SAN ]]; then
for dir in $DIRS; do
DIR="$dir" sanitizer_summary
done
fi
if [[ $E == 0 ]]; then
echo "# No leaks detected"
fi
exit $E