3 # Copyright (C) 2012 Dreamhost, LLC
5 # This is free software; see the source for copying conditions.
6 # There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR
7 # A PARTICULAR PURPOSE.
9 # This is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as
11 # published by the Free Software Foundation version 2.
14 # run_xfstests -t /dev/<testdev> -s /dev/<scratchdev> [-f <fstype>] -- <tests>
15 # - test device and scratch device will both get trashed
16 # - fstypes can be xfs, ext4, or btrfs (xfs default)
17 # - tests can be listed individually: generic/001 xfs/008 xfs/009
18 # tests can also be specified by group: -g quick
23 # 2: other runtime error
24 # 99: argument count error (programming error)
25 # 100: getopt error (internal error)
27 # Alex Elder <elder@dreamhost.com>
32 PROGNAME=$(basename $0)
34 # Default command line option values
37 DO_RANDOMIZE="" # false
39 SCRATCH_DEV="" # MUST BE SPECIFIED
40 TEST_DEV="" # MUST BE SPECIFIED
41 TESTS="-g auto" # The "auto" group is supposed to be "known good"
43 # print an error message and quit with non-zero status
47 echo "${PROGNAME}: ${FUNCNAME[1]}: $@" >&2
52 # routine used to validate argument counts to all shell functions
53 function arg_count() {
59 func="${FUNCNAME[1]}" # calling function
63 func="${FUNCNAME[0]}" # i.e., arg_count
67 [ "${want}" -eq "${got}" ] && return 0
68 echo "${PROGNAME}: ${func}: arg count bad (want ${want} got ${got})" >&2
72 # validation function for repeat count argument
73 function count_valid() {
76 test "$1" -gt 0 # 0 is pointless; negative is wrong
79 # validation function for filesystem type argument
80 function fs_type_valid() {
84 xfs|ext4|btrfs) return 0 ;;
89 # validation function for device arguments
90 function device_valid() {
93 # Very simple testing--really should try to be more careful...
97 # validation function for expunge file argument
98 function expunge_file_valid() {
104 # print a usage message and quit
106 # if a message is supplied, print that first, and then exit
107 # with non-zero status
109 if [ $# -gt 0 ]; then
115 echo "Usage: ${PROGNAME} <options> -- <tests>" >&2
118 echo " -h or --help" >&2
119 echo " show this message" >&2
120 echo " -c or --count" >&2
121 echo " iteration count (1 or more)" >&2
122 echo " -f or --fs-type" >&2
123 echo " one of: xfs, ext4, btrfs" >&2
124 echo " (default fs-type: xfs)" >&2
125 echo " -r or --randomize" >&2
126 echo " randomize test order" >&2
127 echo " -s or --scratch-dev (REQUIRED)" >&2
128 echo " name of device used for scratch filesystem" >&2
129 echo " -t or --test-dev (REQUIRED)" >&2
130 echo " name of device used for test filesystem" >&2
131 echo " -x or --expunge-file" >&2
132 echo " name of file with list of tests to skip" >&2
134 echo " list of test numbers, e.g.:" >&2
135 echo " generic/001 xfs/008 shared/032 btrfs/009" >&2
136 echo " or possibly an xfstests test group, e.g.:" >&2
138 echo " (default tests: -g auto)" >&2
141 [ $# -gt 0 ] && exit 1
143 exit 0 # This is used for a --help
146 # parse command line arguments
147 function parseargs() {
150 SHORT_OPTS="${SHORT_OPTS},h"
151 SHORT_OPTS="${SHORT_OPTS},c:"
152 SHORT_OPTS="${SHORT_OPTS},f:"
153 SHORT_OPTS="${SHORT_OPTS},r"
154 SHORT_OPTS="${SHORT_OPTS},s:"
155 SHORT_OPTS="${SHORT_OPTS},t:"
156 SHORT_OPTS="${SHORT_OPTS},x:"
160 LONG_OPTS="${LONG_OPTS},help"
161 LONG_OPTS="${LONG_OPTS},count:"
162 LONG_OPTS="${LONG_OPTS},fs-type:"
163 LONG_OPTS="${LONG_OPTS},randomize"
164 LONG_OPTS="${LONG_OPTS},scratch-dev:"
165 LONG_OPTS="${LONG_OPTS},test-dev:"
166 LONG_OPTS="${LONG_OPTS},expunge-file:"
168 TEMP=$(getopt --name "${PROGNAME}" \
169 --options "${SHORT_OPTS}" \
170 --longoptions "${LONG_OPTS}" \
174 while [ "$1" != "--" ]; do
181 usage "invalid count '$2'"
186 fs_type_valid "$2" ||
187 usage "invalid fs_type '$2'"
196 usage "invalid scratch-dev '$2'"
202 usage "invalid test-dev '$2'"
207 expunge_file_valid "$2" ||
208 usage "invalid expunge-file '$2'"
213 exit 100 # Internal error
220 [ -n "${TEST_DEV}" ] || usage "test-dev must be supplied"
221 [ -n "${SCRATCH_DEV}" ] || usage "scratch-dev must be supplied"
223 [ $# -eq 0 ] || TESTS="$@"
226 ################################################################
228 # run mkfs on the given device using the specified filesystem type
237 ext4) options="-F" ;;
238 btrfs) options="-f" ;;
241 "mkfs.${FSTYP}" ${options} "${dev}" ||
242 err "unable to make ${FSTYP} file system on device \"${dev}\""
245 # top-level setup routine
249 wget -P "${TESTDIR}" http://download.ceph.com/qa/xfstests.tar.gz
250 tar zxf "${TESTDIR}/xfstests.tar.gz" -C "$(dirname "${XFSTESTS_DIR}")"
252 mkdir "${SCRATCH_MNT}"
253 do_mkfs "${TEST_DEV}"
256 # top-level (final) cleanup routine
260 # ensure teuthology can clean up the logs
261 chmod -R a+rw "${TESTDIR}/archive"
263 findmnt "${TEST_DEV}" && umount "${TEST_DEV}"
264 [ -d "${SCRATCH_MNT}" ] && rmdir "${SCRATCH_MNT}"
265 [ -d "${TEST_DIR}" ] && rmdir "${TEST_DIR}"
266 rm -rf "${XFSTESTS_DIR}"
267 rm -f "${TESTDIR}/xfstests.tar.gz"
270 # ################################################################
274 [ -n "${TESTDIR}" ] || usage "TESTDIR env variable must be set"
275 [ -d "${TESTDIR}/archive" ] || usage "\$TESTDIR/archive directory must exist"
276 TESTDIR="$(readlink -e "${TESTDIR}")"
277 [ -n "${EXPUNGE_FILE}" ] && EXPUNGE_FILE="$(readlink -e "${EXPUNGE_FILE}")"
279 XFSTESTS_DIR="/var/lib/xfstests" # hardcoded into dbench binary
280 TEST_DIR="/mnt/test_dir"
281 SCRATCH_MNT="/mnt/scratch_mnt"
283 EXT_MOUNT_OPTIONS="-o block_validity"
285 trap cleanup EXIT ERR HUP INT QUIT
294 export EXT_MOUNT_OPTIONS
296 pushd "${XFSTESTS_DIR}"
297 for (( i = 1 ; i <= "${COUNT}" ; i++ )); do
298 [ "${COUNT}" -gt 1 ] && echo "=== Iteration "$i" starting at: $(date)"
300 RESULT_BASE="${TESTDIR}/archive/results-${i}"
301 mkdir "${RESULT_BASE}"
305 [ -n "${EXPUNGE_FILE}" ] && EXPUNGE="-E ${EXPUNGE_FILE}"
308 [ -n "${DO_RANDOMIZE}" ] && RANDOMIZE="-r"
310 # -T output timestamps
311 PATH="${PWD}/bin:${PATH}" ./check -T ${RANDOMIZE} ${EXPUNGE} ${TESTS}
312 findmnt "${TEST_DEV}" && umount "${TEST_DEV}"
314 [ "${COUNT}" -gt 1 ] && echo "=== Iteration "$i" complete at: $(date)"
318 # cleanup is called via the trap call, above
320 echo "This xfstests run started at: ${start_date}"
321 echo "xfstests run completed at: $(date)"
322 [ "${COUNT}" -gt 1 ] && echo "xfstests run consisted of ${COUNT} iterations"