6 # This file and its contents are supplied under the terms of the
7 # Common Development and Distribution License ("CDDL"), version 1.0.
8 # You may only use this file in accordance with the terms of version
11 # A full copy of the text of the CDDL should have accompanied this
12 # source. A copy of the CDDL is also available via the Internet at
13 # http://www.illumos.org/license/CDDL.
19 # Copyright (c) 2015 by Delphix. All rights reserved.
20 # Copyright (C) 2016 Lawrence Livermore National Security, LLC.
21 # Copyright (c) 2017, Intel Corporation.
24 BASE_DIR
=$
(dirname "$0")
25 SCRIPT_COMMON
=common.sh
26 if [ -f "${BASE_DIR}/${SCRIPT_COMMON}" ]; then
27 .
"${BASE_DIR}/${SCRIPT_COMMON}"
29 echo "Missing helper script ${SCRIPT_COMMON}" && exit 1
32 # shellcheck disable=SC2034
36 DEFAULTWORKDIR
=/var
/tmp
37 DEFAULTCOREDIR
=/var
/tmp
/zloop
43 $0 [-hl] [-c <dump directory>] [-f <vdev directory>]
44 [-m <max core dumps>] [-s <vdev size>] [-t <timeout>]
45 [-I <max iterations>] [-- [extra ztest parameters]]
47 This script runs ztest repeatedly with randomized arguments.
48 If a crash is encountered, the ztest logs, any associated
49 vdev files, and core file (if one exists) are moved to the
50 output directory ($DEFAULTCOREDIR by default). Any options
51 after the -- end-of-options marker will be passed to ztest.
54 -c Specify a core dump directory to use.
55 -f Specify working directory for ztest vdev files.
56 -h Print this help message.
57 -l Create 'ztest.core.N' symlink to core directory.
58 -m Max number of core dumps to allow before exiting.
59 -s Size of vdev devices.
60 -t Total time to loop for, in seconds. If not provided,
62 -I Max number of iterations to loop before exiting.
69 # shellcheck disable=SC2068
71 echo "Command failed: $*"
82 origcorepattern
="$(cat /proc/sys/kernel/core_pattern)"
83 coreglob
="$(grep -E -o '^([^|%[:space:]]*)' /proc/sys/kernel/core_pattern)*"
85 if [[ $coreglob = "*" ]]; then
86 echo "Setting core file pattern..."
87 echo "core" > /proc
/sys
/kernel
/core_pattern
88 coreglob
="$(grep -E -o '^([^|%[:space:]]*)' \
89 /proc/sys/kernel/core_pattern)*"
99 # shellcheck disable=SC2012,SC2086
100 ls -tr1 $coreglob 2>/dev
/null |
head -1
106 core_id
=$
($GDB --batch -c "$1" |
grep "Core was generated by" | \
108 if [[ "$core_id" == *"zdb "* ]]; then
117 if [[ $ztrc -ne 0 ]] ||
[[ -f "$core" ]]; then
118 df
-h "$workdir" >>ztest.out
119 coreid
=$
(date "+zloop-%y%m%d-%H%M%S")
120 foundcrashes
=$
((foundcrashes
+ 1))
123 zdbcmd
="$ZDB -U "$workdir/zpool.cache
" -dddMmDDG ztest"
124 zdbdebug
=$
($zdbcmd 2>&1)
125 echo -e "$zdbcmd\n" >>ztest.zdb
126 echo "$zdbdebug" >>ztest.zdb
128 dest
=$coredir/$coreid
129 or_die mkdir
-p "$dest"
130 or_die mkdir
-p "$dest/vdev"
132 if [[ $symlink -ne 0 ]]; then
133 or_die
ln -sf "$dest" ztest.core.
$foundcrashes
136 echo "*** ztest crash found - moving logs to $dest"
138 or_die
mv ztest.
history "$dest/"
139 or_die
mv ztest.zdb
"$dest/"
140 or_die
mv ztest.out
"$dest/"
141 or_die
mv "$workdir/ztest*" "$dest/vdev/"
143 if [[ -e "$workdir/zpool.cache" ]]; then
144 or_die
mv "$workdir/zpool.cache" "$dest/vdev/"
148 if [[ -f "$core" ]]; then
149 coreprog
=$
(core_prog
"$core")
150 coredebug
=$
($GDB --batch --quiet \
151 -ex "set print thread-events off" \
152 -ex "printf \"*\n* Backtrace \n*\n\"" \
154 -ex "printf \"*\n* Libraries \n*\n\"" \
155 -ex "info sharedlib" \
156 -ex "printf \"*\n* Threads (full) \n*\n\"" \
158 -ex "printf \"*\n* Backtraces \n*\n\"" \
159 -ex "thread apply all bt" \
160 -ex "printf \"*\n* Backtraces (full) \n*\n\"" \
161 -ex "thread apply all bt full" \
162 -ex "quit" "$coreprog" "$core" 2>&1 | \
165 # Dump core + logs to stored directory
166 echo "$coredebug" >>"$dest/ztest.gdb"
167 or_die
mv "$core" "$dest/"
169 # Record info in cores logfile
170 echo "*** core @ $coredir/$coreid/$core:" | \
174 if [[ $coremax -gt 0 ]] &&
175 [[ $foundcrashes -ge $coremax ]]; then
176 echo "exiting... max $coremax allowed cores"
185 # expected format: zloop [-t timeout] [-c coredir] [-- extra ztest args]
186 coredir
=$DEFAULTCOREDIR
187 basedir
=$DEFAULTWORKDIR
194 while getopts ":ht:m:I:s:c:f:l" opt
; do
196 t
) [[ $OPTARG -gt 0 ]] && timeout
=$OPTARG ;;
197 m
) [[ $OPTARG -gt 0 ]] && coremax
=$OPTARG ;;
198 I
) [[ $OPTARG ]] && iterations
=$OPTARG ;;
199 s
) [[ $OPTARG ]] && size
=$OPTARG ;;
200 c
) [[ $OPTARG ]] && coredir
=$OPTARG ;;
201 f
) [[ $OPTARG ]] && basedir
=$
(readlink
-f "$OPTARG") ;;
206 * ) echo "Invalid argument: -$OPTARG";
211 # pass remaining arguments on to ztest
212 shift $
((OPTIND
- 1))
216 export ASAN_OPTIONS
=abort_on_error
=1:disable_coredump
=0
218 if [[ -f "$(core_file)" ]]; then
219 echo -n "There's a core dump here you might want to look at first... "
225 if [[ ! -d $coredir ]]; then
226 echo "core dump directory ($coredir) does not exist, creating it."
227 or_die mkdir
-p "$coredir"
230 if [[ ! -w $coredir ]]; then
231 echo "core dump directory ($coredir) is not writable."
235 or_die
rm -f ztest.
history
236 or_die
rm -f ztest.zdb
237 or_die
rm -f ztest.cores
239 ztrc
=0 # ztest return value
240 foundcrashes
=0 # number of crashes found so far
241 starttime
=$
(date +%s
)
245 # if no timeout was specified, loop forever.
246 while (( timeout
== 0 )) ||
(( curtime
<= (starttime
+ timeout
) )); do
247 if (( iterations
> 0 )) && (( iteration
++ == iterations
)); then
253 # start each run with an empty directory
254 workdir
="$basedir/$rundir"
255 or_die
rm -rf "$workdir"
256 or_die mkdir
"$workdir"
258 # switch between three types of configs
259 # 1/3 basic, 1/3 raidz mix, and 1/3 draid mix
260 choice
=$
((RANDOM
% 3))
262 # ashift range 9 - 15
263 align
=$
(((RANDOM
% 2) * 3 + 9))
265 # randomly use special classes
266 class
="special=random"
268 if [[ $choice -eq 0 ]]; then
277 elif [[ $choice -eq 1 ]]; then
278 # fully randomized mirror/raidz (sans dRAID)
279 parity
=$
(((RANDOM
% 3) + 1))
280 mirrors
=$
(((RANDOM
% 3) * 1))
283 raid_children
=$
((((RANDOM
% 9) + parity
+ 1) * (RANDOM
% 2)))
284 vdevs
=$
(((RANDOM
% 3) + 3))
287 # fully randomized dRAID (sans mirror/raidz)
288 parity
=$
(((RANDOM
% 3) + 1))
290 draid_data
=$
(((RANDOM
% 8) + 3))
291 draid_spares
=$
(((RANDOM
% 2) + parity
))
292 stripe
=$
((draid_data
+ parity
))
293 extra
=$
((draid_spares
+ (RANDOM
% 4)))
294 raid_children
=$
(((((RANDOM
% 4) + 1) * stripe
) + extra
))
295 vdevs
=$
((RANDOM
% 3))
299 zopt
="$zopt -K $raid_type"
300 zopt
="$zopt -m $mirrors"
301 zopt
="$zopt -r $raid_children"
302 zopt
="$zopt -D $draid_data"
303 zopt
="$zopt -S $draid_spares"
304 zopt
="$zopt -R $parity"
305 zopt
="$zopt -v $vdevs"
306 zopt
="$zopt -a $align"
307 zopt
="$zopt -C $class"
308 zopt
="$zopt -s $size"
309 zopt
="$zopt -f $workdir"
311 cmd
="$ZTEST $zopt $*"
312 desc
="$(date '+%m/%d %T') $cmd"
313 echo "$desc" |
tee -a ztest.
history
314 echo "$desc" >>ztest.out
315 $cmd >>ztest.out
2>&1
317 grep -E '===|WARNING' ztest.out
>>ztest.
history
324 echo "zloop finished, $foundcrashes crashes found"
326 # restore core pattern.
329 echo "$origcorepattern" > /proc
/sys
/kernel
/core_pattern
337 if [[ $foundcrashes -gt 0 ]]; then