-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdogfood
More file actions
executable file
·437 lines (412 loc) · 10.3 KB
/
dogfood
File metadata and controls
executable file
·437 lines (412 loc) · 10.3 KB
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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
#!/bin/bash
nproc=$(nproc)
unset windows
terminal=
if [[ "${OS}" =~ "Windows" ]]
then
windows=1
configs=( Release Debug )
buildopt="-m"
launch=( start )
launchdir="Release"
if [[ -x $( type -p dos2unix ) ]]
then
dos2unix="dos2unix -O"
else
dos2unix="cat -v"
fi
else
configs=( "" )
buildopt="-j${nproc}"
launch=()
launchdir=""
dos2unix="cat -v"
fi
builddir="$(dirname $(pwd))/build/$(basename $(pwd))"
logfile="${builddir}/dogfood.out"
tmpfile="${builddir}/dogfood.tmp"
rm -fv "${logfile}"
_run()
{
# Usage: _run: command
echo -en "\nRun: ${@} " 2>&1 | tee -a "${logfile}"
date 2>&1 | tee -a "${logfile}"
if [[ "$1" == "--direct" ]]
then
shift
"${@}"
else
( time ${@} ) 2>&1 | tee "${tmpfile}"
set -x
${dos2unix} "${tmpfile}" >> "${logfile}"
set +x
rm "${tmpfile}"
fi
}
tmuxopts="-d"
if [[ -n "${DISPLAY}" ]] && type -t gnome-terminal >& /dev/null
then
terminal="gnome-terminal --"
tmuxopts=""
fi
if [[ -z "${TMUX}" ]] && type -t tmux >& /dev/null
then
# set -x
cmd=( ${terminal} tmux new-session ${tmuxopts} -s rippled -x 80 -y 30 \
sleep 600 )
_run "${cmd[@]}" || true
cmd=( tmux new-window -d -a -t rippled:$ -n dogfood \
"${0}" "${@}" wait )
_run "${cmd[@]}" || true
cmd=( tmux select-window -t rippled:dogfood )
_run "${cmd[@]}" || true
cmd=( tmux kill-window -t rippled:sleep )
_run "${cmd[@]}" || true
# tmux set-option -w -t rippled:dogfood remain-on-exit on
echo 'Running in tmux session. Use "tmux attach -t rippled" to join it'
exit
fi
# Exit if anything fails
set -e
# Output commands before executing them
# set -x
cmake_prefix="${builddir}/cmake/"
cmake_dirs=$(\ls -r ${cmake_prefix})
echo Dirs: ${cmake_dirs}
cmake_targets="rippled"
echo Targets: ${cmake_targets}
echo "Configs: ${configs[@]}"
rundir=$(\ls -r ${cmake_prefix} | head -1)
echo rundir: ${rundir}
gdb=()
gdbextra=()
clean=0
fast=0
build=yes
test=0
while [[ ${#@} > 0 ]]
do
if [[ "$1" == "fast" || "$1" == "notest" ]]
then
shift
fast=1
elif [[ "$1" == "nobuild" ]]
then
shift
build=no
elif [[ "$1" == "onlyrun" || "$1" == "runonly" || "$1" == "one" ]]
then
shift
build=run
elif [[ "$1" == "debug" && -n "${launchdir}" ]]
then
shift
launchdir="Debug"
elif [[ "$1" == "debug" ]] && type -t gdb >& /dev/null
then
shift
gdb=( gdb -q )
gdbextra=( --fg )
elif [[ "$1" == "debug" ]] && type -t lldb >& /dev/null
then
shift
gdb=( lldb )
gdbextra=( )
elif [[ "$1" == "test" ]]
then
shift
test=1
elif [[ "$1" == "clean" ]]
then
shift
clean=1
elif [[ "$1" == "wait" ]]
then
shift
wait=1
elif [[ "$1" == "--config" ]]
then
shift
configs=( $1 )
shift
elif [[ "$1" == "--exe" ]]
then
shift
cmake_targets="$1"
shift
elif [[ ${#gdb[@]} > 0 && "$1" == "--" ]]
then
shift
if [[ "${#@}" ]]
then
gdb+=( "${@}" )
shift "${#@}"
fi
elif [[ -d "${cmake_prefix}$1" ]]
then
rundir="$1"
echo rundir changed to: ${rundir}
shift
else
echo "Unknown option: $1" 2>&1
exit 127
fi
done
if [[ "$build" == "run" ]]
then
cmake_dirs="${rundir}"
fi
datestamp=$( date +%s )
time (
set -o pipefail
if [[ ${clean} != 0 ]]
then
for dir in ${cmake_dirs}
do
dir=${cmake_prefix}${dir}
cmd=( cmake --build $dir --target clean )
_run "${cmd[@]}" || exit 1
done
fi
# set -x
if [[ "${build}" != "no" ]]
then
# Parallel unit tests have been enabled since 2017
if type -t SimpleTestLoop >& /dev/null
then
for target in ${cmake_targets}
do
if [[ "$target" == "rippled" ]] && \
type -t SimpleRippledTestLoop >& /dev/null
then
cmd=( SimpleRippledTestLoop ${cmake_dirs} )
if [[ -n "${configs[@]}" ]]
then
cmd+=( "${configs[@]}" )
fi
if [[ ${fast} != 0 ]]
then
cmd+=( "--version" )
fi
elif [[ "$target" == "xrpld" ]] && \
type -t SimpleXrpldTestLoop >& /dev/null
then
cmd=( SimpleXrpldTestLoop ${cmake_dirs} )
if [[ -n "${configs[@]}" ]]
then
cmd+=( "${configs[@]}" )
fi
if [[ ${fast} != 0 ]]
then
cmd+=( "--version" )
fi
else
cmd=( SimpleTestLoop "${target}" ${cmake_dirs} )
if [[ -n "${configs[@]}" ]]
then
cmd+=( "${configs[@]}" )
fi
if [[ ${fast} != 0 ]]
then
cmd+=( "--version" )
else
cmd+=( "--unittest --unittest-jobs=$( nproc )" )
fi
fi
_run --direct "${cmd[@]}" || exit 1
cmd=( echo "No failures found in SimpleTestLoop output" )
_run "${cmd[@]}"
done || exit 1
else
for dir in ${cmake_dirs}
do
dir=${cmake_prefix}${dir}
src=$(pwd)
if pushd $dir
then
cmd=( cmake "${src}" )
echo "Run: (from $(basename $(pwd)))" 2>&1 | tee -a "${logfile}"
_run "${cmd[@]}" || exit 1
popd
fi
for target in ${cmake_targets}
do
for config in "${configs[@]}"
do
echo Building $target in $dir 2>&1 | tee -a "${logfile}"
if [[ -n "$config" ]]
then
echo "With configuration $config" 2>&1 | tee -a "${logfile}"
testdir="$config"
config="--config $config"
fi
cmd=( cmake --build $dir --target $target $config -- ${buildopt} )
_run "${cmd[@]}" || exit 1
if [[ ${fast} == 0 ]]
then
if [[ -n "$testdir" ]]
then
rd="${dir}/${testdir}/${target}"
else
rd="${dir}/${target}"
fi
cmd=( "${rd}" "--unittest" "--unittest-jobs=$( nproc )" )
_run "${cmd[@]}" || exit 1
fi
done
done
done || exit 1
fi
fi
) || exit 1
if [[ ${test} != 0 ]]
then
exit 0
fi
# set -x
ulimit -c unlimited
if type -t tmux >& /dev/null
then
launch=( tmux new-window -a -t rippled:$ -n rippled )
switch=( tmux last-window )
cmd=( ${terminal} tmux new-session ${tmuxopts} -s rippled -x 80 -y 30
sleep 600 )
_run "${cmd[@]}" || true
# Give the terminal a few seconds to create
sleep 2
fi
for network in rippled # rippled-altnet
do
cfgfile="${HOME}/.config/ripple/${network}.cfg"
if [ -e "${cfgfile}" ]
then
runpath="${cmake_prefix}${rundir}/${launchdir}"
for target in ${cmake_targets}
do
for runfile in ${target}{.exe,}
do
if [[ -f "${runpath}/${runfile}" ]]
then
exe="${runpath}/${runfile}"
break
fi
done
if [[ ! -f "${exe}" ]]
then
echo "Error: Expected executable not found: ${target}"
break
fi
# Clean up old files
for file in "${builddir}/${target}".* "${builddir}/gdb".*
do
if [[ ! -e "${file}" ]]
then
continue
fi
echo $file
parts=( $( echo "${file}" | sed 's/\./ /g' ) )
echo "${parts[@]}"
ls -ltr "${builddir}"/*.${parts[1]}*
if [[ -e "${builddir}/core.${parts[1]}" ]]
then
continue
fi
rm -fv "${builddir}"/*.${parts[1]}*
done
if [[ ${#gdb[@]} > 0 ]] && type -t gdb >& /dev/null
then
temp=(
'set pagination off'
"set logging file ${builddir}/gdb.${datestamp}.txt"
"run"
'tui enable'
'winheight src -8'
"generate-core-file ${builddir}/core.${datestamp}"
# "set logging overwrite on"
"set logging enabled on"
"thread apply all bt full"
# "set logging enabled off"
"quit"
# "info break"
# "delete 2"
# "fg"
# "thread apply all bt full"
# "set logging enabled off"
)
gdbcommands=()
for c in "${temp[@]}"
do
gdbcommands+=( -ex "${c}" )
done
gdbcommands+=( "--args" )
elif [[ ${#gdb[@]} > 0 ]] && type -t lldb >& /dev/null
then
: "TODO: Figure out how to do fancy startup stuff in lldb"
temp=(
# 'set pagination off'
# "set logging file ${builddir}/gdb.${datestamp}.txt"
"run"
# 'tui enable'
# 'winheight src -8'
# "generate-core-file ${builddir}/core.${datestamp}"
# "set logging enabled on"
# "thread apply all bt full"
"quit"
)
gdbcommands=()
for c in "${temp[@]}"
do
gdbcommands+=( -o "${c}" )
done
gdbcommands+=( "--" )
fi
# Stop the currently running rippled, if any
cmd=( "${exe}" --conf "${cfgfile}" stop )
_run "${cmd[@]}" || true
# Save the executable
cmd=( cp -v "${exe}" "${builddir}/${runfile}.${datestamp}" )
_run "${cmd[@]}" || true
# Start the new rippled
cmd=( "${launch[@]}" "${gdb[@]}" "${gdbcommands[@]}"
"${exe}" --conf ${cfgfile} --net "${gdbextra[@]}" )
_run --direct "${cmd[@]}" || true
: 'https://sourceware.org/gdb/onlinedocs/gdb/TUI-Commands.html'
: 'C-x a'
if [[ "${#switch}" -gt 0 ]]
then
_run --direct "${switch[@]}"
fi
# Rotate the logfile(s)
if [[ -f $HOME/.logrotate.conf ]] && \
grep -q rippled $HOME/.logrotate.conf && \
crontab -l | grep -q logrotate
then
cmd=(
eval "$(
crontab -l | grep logrotate | \
awk '(index($6, "logrotate") != 0) \
{l=$6; $1=$2=$3=$4=$5=$6=""; print l " --force --verbose " $0 }'
)"
)
_run "${cmd[@]}" || true
else
for file in debug.log logs/debug.log log/debug.log \
perf.log logs/perf.log log/perf.log
do
if [ -e "${HOME}/${network}/${file}" ]
then
mv -vi "${HOME}/${network}/${file}"{,.${datestamp}} || true
fi
done
fi
done
else
echo "Error: config file not found: ${cfgfile}"
fi
done
cmd=( grep failures "${logfile}" )
_run "${cmd[@]}"
if [[ -n "${wait}" ]]
then
read -n 1 -p "Press any key to continue..." -s
fi