-
Notifications
You must be signed in to change notification settings - Fork 56
/
helper.sh
executable file
·69 lines (64 loc) · 1.62 KB
/
helper.sh
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
#!/usr/bin/env bash
set -eu
LOG_FILE=""
function setup()
{
mkdir -p build
cd build
cmake ..
make
cd -
rm dump.rdb 2>/dev/null || true
rm appendonly.aof 2>/dev/null || true
}
function start_redis()
{
local USE_VALGRIND="no"
local USE_AOF="no"
while [[ $# -gt 0 ]]; do
local PARAM="$1"
case $PARAM in
--valgrind)
USE_VALGRIND="yes"
LOG_FILE=$(mktemp)
;;
--aof)
USE_AOF="yes"
;;
esac
shift
done
local REDIS_COMMAND="./deps/redis/src/redis-server --loadmodule ./build/libredis-roaring.so"
local VALGRIND_COMMAND="valgrind --leak-check=yes --show-leak-kinds=definite,indirect --suppressions=./deps/redis/src/valgrind.sup --error-exitcode=1 --log-file=$LOG_FILE"
local AOF_OPTION="--appendonly $USE_AOF"
if [ "$USE_VALGRIND" == "no" ]; then
VALGRIND_COMMAND=""
fi
eval "$VALGRIND_COMMAND" "$REDIS_COMMAND" "$AOF_OPTION" &
while [ "$(./deps/redis/src/redis-cli PING 2>/dev/null)" != "PONG" ]; do
sleep 0.1
done
}
function stop_redis()
{
pkill -f redis || true
while [ $(ps aux | grep redis | grep -v grep | wc -l) -ne 0 ]; do
sleep 0.1
done
sleep 2
if [ "$LOG_FILE" != "" ]; then
cat "$LOG_FILE"
local VALGRIND_ERRORS=$(cat "$LOG_FILE" | grep --color=no "indirectly lost\|definitely lost\|Invalid write\|Invalid read\|uninitialised\|Invalid free\|a block of size" | grep --color=no -v ": 0 bytes in 0 blocks")
[ "$VALGRIND_ERRORS" == "" ]
rm "$LOG_FILE"
LOG_FILE=""
fi
}
function end()
{
echo ""
echo "************************"
echo "*** ALL TESTS PASSED ***"
echo "************************"
echo ""
}