forked from RedisJSON/RedisJSON
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.sh
executable file
·283 lines (220 loc) · 6.9 KB
/
tests.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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
#!/bin/bash
# [[ $VERBOSE == 1 ]] && set -x
# [[ $IGNERR == 1 ]] || set -e
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
export ROOT=$(cd $HERE/../.. && pwd)
READIES=$ROOT/deps/readies
. $READIES/shibumi/defs
cd $HERE
#----------------------------------------------------------------------------------------------
help() {
cat <<-END
Run Python tests
[ARGVARS...] tests.sh [--help|help] [<module-so-path>]
Argument variables:
MODULE=path Path to redisai.so
TEST=test Run specific test (e.g. test.py:test_name)
REDIS=addr Use redis-server at addr
GEN=1 General tests
AOF=1 Tests with --test-aof
SLAVES=1 Tests with --test-slaves
CLUSTER=1 Test with OSS cluster, one shard
QUICK=1 Run general tests only
VALGRIND|VG=1 Run with Valgrind
SAN=type Use LLVM sanitizer (type=address|memory|leak|thread)
MEMINFO=1 Show memory information
VERBOSE=1 Print commands
IGNERR=1 Do not abort on error
NOP=1 Dry run
LOG=1 Write to log
QUIET=1 Be less verbose
END
}
#----------------------------------------------------------------------------------------------
install_git_lfs() {
[[ $NO_LFS == 1 ]] && return
[[ $(git lfs env > /dev/null 2>&1 ; echo $?) != 0 ]] && git lfs install
git lfs pull
}
#----------------------------------------------------------------------------------------------
setup_redis_server() {
if [[ -n $SAN ]]; then
if [[ $SAN == address ]]; then
REDIS_SERVER=${REDIS_SERVER:-redis-server-asan-6.2}
if ! command -v $REDIS_SERVER > /dev/null; then
echo Building Redis for clang-asan ...
$READIES/bin/getredis --force -v 6.2 --own-openssl --no-run --suffix asan --clang-asan --clang-san-blacklist /build/redis.blacklist
fi
export ASAN_OPTIONS=detect_odr_violation=0
# :detect_leaks=0
elif [[ $SAN == memory ]]; then
REDIS_SERVER=${REDIS_SERVER:-redis-server-msan-6.2}
if ! command -v $REDIS_SERVER > /dev/null; then
echo Building Redis for clang-msan ...
$READIES/bin/getredis --force -v 6.2 --no-run --own-openssl --suffix msan --clang-msan --llvm-dir /opt/llvm-project/build-msan --clang-san-blacklist /build/redis.blacklist
fi
fi
elif [[ $VALGRIND == 1 ]]; then
REDIS_SERVER=${REDIS_SERVER:-redis-server-vg}
if ! is_command $REDIS_SERVER; then
echo Building Redis for Valgrind ...
$READIES/bin/getredis -v 6 --valgrind --suffix vg
fi
else
REDIS_SERVER=${REDIS_SERVER:-redis-server}
fi
if ! is_command $REDIS_SERVER; then
echo "Cannot find $REDIS_SERVER. Aborting."
exit 1
fi
}
#----------------------------------------------------------------------------------------------
valgrind_config() {
export VALGRIND=1 # for RLTest
export VG_OPTIONS="
-q \
--leak-check=full \
--show-reachable=no \
--show-possibly-lost=no"
VALGRIND_SUPRESSIONS=$ROOT/tests/redis_valgrind.sup
RLTEST_ARGS+="\
--use-valgrind \
--vg-suppressions $VALGRIND_SUPRESSIONS"
}
valgrind_summary() {
# Collect name of each flow log that contains leaks
FILES_WITH_LEAKS=$(grep -l "definitely lost" logs/*.valgrind.log)
if [[ ! -z $FILES_WITH_LEAKS ]]; then
echo "Memory leaks introduced in flow tests."
echo $FILES_WITH_LEAKS
# Print the full Valgrind output for each leaking file
echo $FILES_WITH_LEAKS | xargs cat
exit 1
else
echo Valgrind test ok
fi
}
#----------------------------------------------------------------------------------------------
run_tests() {
local title="$1"
shift
if [[ -n $title ]]; then
$READIES/bin/sep
printf "Testing $title:\n\n"
fi
cd $ROOT/tests/pytest
[[ $SERDE_JSON == 1 ]] && MODARGS+=" JSON_BACKEND SERDE_JSON"
if [[ $EXISTING_ENV != 1 ]]; then
rltest_config=$(mktemp "${TMPDIR:-/tmp}/rltest.XXXXXXX")
cat <<-EOF > $rltest_config
--oss-redis-path=$REDIS_SERVER
--module $MODULE
--module-args '$MODARGS'
$RLTEST_ARGS
$VALGRIND_ARGS
$SAN_ARGS
$COV_ARGS
EOF
else # existing env
xredis_conf=$(mktemp "${TMPDIR:-/tmp}/xredis_conf.XXXXXXX")
cat <<-EOF > $xredis_conf
loadmodule $MODULE $MODARGS
EOF
rltest_config=$(mktemp "${TMPDIR:-/tmp}/xredis_rltest.XXXXXXX")
cat <<-EOF > $rltest_config
--env existing-env
$RLTEST_ARGS
EOF
if [[ $VERBOSE == 1 ]]; then
echo "External redis-server configuration:"
cat $xredis_conf
fi
$REDIS_SERVER $xredis_conf &
XREDIS_PID=$!
echo "External redis-server pid: " $XREDIS_PID
fi
# Use configuration file in the current directory if it exists
if [[ -n $CONFIG_FILE && -e $CONFIG_FILE ]]; then
cat $CONFIG_FILE >> $rltest_config
fi
if [[ $VERBOSE == 1 ]]; then
echo "RLTest configuration:"
cat $rltest_config
fi
local E=0
if [[ $NOP != 1 ]]; then
{ $OP python3 -m RLTest @$rltest_config; (( E |= $? )); } || true
else
$OP python3 -m RLTest @$rltest_config
fi
rm -f $rltest_config
if [[ -n $XREDIS_PID ]]; then
echo "killing external redis-server: $XREDIS_PID"
kill -9 $XREDIS_PID
rm -f $xredis_conf
fi
if [[ $QUICK != 1 && $FINAL != 1 ]]; then
{ (SERDE_JSON=1 FINAL=1 run_tests "$title (with serde_json)"); (( E |= $? )); } || true
fi
return $E
}
#----------------------------------------------------------------------------------------------
[[ $1 == --help || $1 == help || $HELP == 1 ]] && { help; exit 0; }
GDB=${GDB:-0}
OP=""
[[ $NOP == 1 ]] && OP="echo"
[[ $VG == 1 ]] && VALGRIND=1
[[ $SAN == addr ]] && SAN=address
[[ $SAN == mem ]] && SAN=memory
[[ -n $SAN ]] && QUICK=1
if [[ $QUICK == 1 ]]; then
GEN=${GEN:-1}
SLAVES=${SLAVES:-0}
AOF=${AOF:-0}
CLUSTER=${CLUSTER:-0}
else
GEN=${GEN:-1}
SLAVES=${SLAVES:-1}
AOF=${AOF:-1}
CLUSTER=${CLUSTER:-1}
fi
MODULE=${MODULE:-$1}
[[ -z $MODULE || ! -f $MODULE ]] && { echo "Module not found at ${MODULE}. Aborting."; exit 1; }
[[ $VALGRIND == 1 ]] && valgrind_config
if [[ -n $TEST ]]; then
RLTEST_ARGS+=" --test $TEST"
if [[ $LOG != 1 && $QUIET != 1 ]]; then
RLTEST_ARGS+=" -s"
export BB=${BB:-1}
fi
export RUST_BACKTRACE=1
fi
[[ $VERBOSE == 1 ]] && RLTEST_ARGS+=" -v -s"
[[ $GDB == 1 ]] && RLTEST_ARGS+=" -i --verbose"
export OS=$($READIES/bin/platform --os)
if [[ -n $SAN ]]; then
# for RLTest
export SANITIZER="$SAN"
fi
#----------------------------------------------------------------------------------------------
cd $ROOT/tests/pytest
# install_git_lfs
setup_redis_server
if [[ ! -z $REDIS ]]; then
RLTEST_ARGS+=" --env existing-env --existing-env-addr $REDIS"
fi
E=0
if [[ $GEN == 1 ]]; then
{ (run_tests "general"); (( E |= $? )); } || true
fi
if [[ $VALGRIND != 1 && $SLAVES == 1 ]]; then
{ (RLTEST_ARGS+=" --use-slaves" run_tests "--use-slaves"); (( E |= $? )); } || true
fi
if [[ $AOF == 1 ]]; then
{ (RLTEST_ARGS+=" --use-aof" run_tests "--use-aof"); (( E |= $? )); } || true
fi
if [[ $CLUSTER == 1 ]]; then
{ (RLTEST_ARGS+=" --env oss-cluster --shards-count 1" run_tests "--env oss-cluster"); (( E |= $? )); } || true
fi
[[ $VALGRIND == 1 ]] && valgrind_summary
exit $E