1*7a7741afSMartin Matuska#!/usr/bin/env bash 2e92ffd9bSMartin Matuska# shellcheck disable=SC2154 3*7a7741afSMartin Matuska# shellcheck disable=SC2292 4eda14cbcSMatt Macy# 5eda14cbcSMatt Macy# CDDL HEADER START 6eda14cbcSMatt Macy# 7eda14cbcSMatt Macy# The contents of this file are subject to the terms of the 8eda14cbcSMatt Macy# Common Development and Distribution License, Version 1.0 only 9eda14cbcSMatt Macy# (the "License"). You may not use this file except in compliance 10eda14cbcSMatt Macy# with the License. 11eda14cbcSMatt Macy# 12eda14cbcSMatt Macy# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 13271171e0SMartin Matuska# or https://opensource.org/licenses/CDDL-1.0. 14eda14cbcSMatt Macy# See the License for the specific language governing permissions 15eda14cbcSMatt Macy# and limitations under the License. 16eda14cbcSMatt Macy# 17eda14cbcSMatt Macy# When distributing Covered Code, include this CDDL HEADER in each 18eda14cbcSMatt Macy# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 19eda14cbcSMatt Macy# If applicable, add the following below this CDDL HEADER, with the 20eda14cbcSMatt Macy# fields enclosed by brackets "[]" replaced with your own identifying 21eda14cbcSMatt Macy# information: Portions Copyright [yyyy] [name of copyright owner] 22eda14cbcSMatt Macy# 23eda14cbcSMatt Macy# CDDL HEADER END 24eda14cbcSMatt Macy# 25eda14cbcSMatt Macy 26681ce946SMartin Matuska# 27681ce946SMartin Matuska# Copyright 2020 OmniOS Community Edition (OmniOSce) Association. 28681ce946SMartin Matuska# 29681ce946SMartin Matuska 30716fd348SMartin MatuskaSCRIPT_COMMON=${SCRIPT_COMMON:-${0%/*}/common.sh} 31716fd348SMartin Matuska. "${SCRIPT_COMMON}" || exit 32eda14cbcSMatt Macy 33eda14cbcSMatt MacyPROG=zfs-tests.sh 34eda14cbcSMatt MacyVERBOSE="no" 35eda14cbcSMatt MacyQUIET="" 360d4ad640SMartin MatuskaDEBUG="" 37eda14cbcSMatt MacyCLEANUP="yes" 38eda14cbcSMatt MacyCLEANUPALL="no" 39da5137abSMartin MatuskaKMSG="" 40eda14cbcSMatt MacyLOOPBACK="yes" 41eda14cbcSMatt MacySTACK_TRACER="no" 42eda14cbcSMatt MacyFILESIZE="4G" 43eda14cbcSMatt MacyDEFAULT_RUNFILES="common.run,$(uname | tr '[:upper:]' '[:lower:]').run" 44eda14cbcSMatt MacyRUNFILES=${RUNFILES:-$DEFAULT_RUNFILES} 45eda14cbcSMatt MacyFILEDIR=${FILEDIR:-/var/tmp} 46eda14cbcSMatt MacyDISKS=${DISKS:-""} 47eda14cbcSMatt MacySINGLETEST="" 48eda14cbcSMatt MacySINGLETESTUSER="root" 49eda14cbcSMatt MacyTAGS="" 50eda14cbcSMatt MacyITERATIONS=1 51eda14cbcSMatt MacyZFS_DBGMSG="$STF_SUITE/callbacks/zfs_dbgmsg.ksh" 52eda14cbcSMatt MacyZFS_DMESG="$STF_SUITE/callbacks/zfs_dmesg.ksh" 53716fd348SMartin MatuskaUNAME=$(uname) 54681ce946SMartin MatuskaRERUN="" 55c03c5b1cSMartin MatuskaKMEMLEAK="" 56eda14cbcSMatt Macy 57eda14cbcSMatt Macy# Override some defaults if on FreeBSD 58eda14cbcSMatt Macyif [ "$UNAME" = "FreeBSD" ] ; then 59eda14cbcSMatt Macy TESTFAIL_CALLBACKS=${TESTFAIL_CALLBACKS:-"$ZFS_DMESG"} 60eda14cbcSMatt Macy LOSETUP=/sbin/mdconfig 61eda14cbcSMatt Macy DMSETUP=/sbin/gpart 62eda14cbcSMatt Macyelse 63eda14cbcSMatt Macy ZFS_MMP="$STF_SUITE/callbacks/zfs_mmp.ksh" 64eda14cbcSMatt Macy TESTFAIL_CALLBACKS=${TESTFAIL_CALLBACKS:-"$ZFS_DBGMSG:$ZFS_DMESG:$ZFS_MMP"} 65eda14cbcSMatt Macy LOSETUP=${LOSETUP:-/sbin/losetup} 66eda14cbcSMatt Macy DMSETUP=${DMSETUP:-/sbin/dmsetup} 67eda14cbcSMatt Macyfi 68eda14cbcSMatt Macy 69eda14cbcSMatt Macy# 70eda14cbcSMatt Macy# Log an informational message when additional verbosity is enabled. 71eda14cbcSMatt Macy# 72eda14cbcSMatt Macymsg() { 73eda14cbcSMatt Macy if [ "$VERBOSE" = "yes" ]; then 74eda14cbcSMatt Macy echo "$@" 75eda14cbcSMatt Macy fi 76eda14cbcSMatt Macy} 77eda14cbcSMatt Macy 78eda14cbcSMatt Macy# 79eda14cbcSMatt Macy# Log a failure message, cleanup, and return an error. 80eda14cbcSMatt Macy# 81eda14cbcSMatt Macyfail() { 82eda14cbcSMatt Macy echo "$PROG: $1" >&2 83eda14cbcSMatt Macy cleanup 84eda14cbcSMatt Macy exit 1 85eda14cbcSMatt Macy} 86eda14cbcSMatt Macy 87eda14cbcSMatt Macycleanup_freebsd_loopback() { 88eda14cbcSMatt Macy for TEST_LOOPBACK in ${LOOPBACKS}; do 89eda14cbcSMatt Macy if [ -c "/dev/${TEST_LOOPBACK}" ]; then 90eda14cbcSMatt Macy sudo "${LOSETUP}" -d -u "${TEST_LOOPBACK}" || 91eda14cbcSMatt Macy echo "Failed to destroy: ${TEST_LOOPBACK}" 92eda14cbcSMatt Macy fi 93eda14cbcSMatt Macy done 94eda14cbcSMatt Macy} 95eda14cbcSMatt Macy 96eda14cbcSMatt Macycleanup_linux_loopback() { 97eda14cbcSMatt Macy for TEST_LOOPBACK in ${LOOPBACKS}; do 98dae17134SMartin Matuska LOOP_DEV="${TEST_LOOPBACK##*/}" 99eda14cbcSMatt Macy DM_DEV=$(sudo "${DMSETUP}" ls 2>/dev/null | \ 100716fd348SMartin Matuska awk -v l="${LOOP_DEV}" '$0 ~ l {print $1}') 101eda14cbcSMatt Macy 102eda14cbcSMatt Macy if [ -n "$DM_DEV" ]; then 103eda14cbcSMatt Macy sudo "${DMSETUP}" remove "${DM_DEV}" || 104eda14cbcSMatt Macy echo "Failed to remove: ${DM_DEV}" 105eda14cbcSMatt Macy fi 106eda14cbcSMatt Macy 107eda14cbcSMatt Macy if [ -n "${TEST_LOOPBACK}" ]; then 108eda14cbcSMatt Macy sudo "${LOSETUP}" -d "${TEST_LOOPBACK}" || 109eda14cbcSMatt Macy echo "Failed to remove: ${TEST_LOOPBACK}" 110eda14cbcSMatt Macy fi 111eda14cbcSMatt Macy done 112eda14cbcSMatt Macy} 113eda14cbcSMatt Macy 114eda14cbcSMatt Macy# 115eda14cbcSMatt Macy# Attempt to remove loopback devices and files which where created earlier 116eda14cbcSMatt Macy# by this script to run the test framework. The '-k' option may be passed 117eda14cbcSMatt Macy# to the script to suppress cleanup for debugging purposes. 118eda14cbcSMatt Macy# 119eda14cbcSMatt Macycleanup() { 120eda14cbcSMatt Macy if [ "$CLEANUP" = "no" ]; then 121eda14cbcSMatt Macy return 0 122eda14cbcSMatt Macy fi 123eda14cbcSMatt Macy 124eda14cbcSMatt Macy 125eda14cbcSMatt Macy if [ "$LOOPBACK" = "yes" ]; then 126eda14cbcSMatt Macy if [ "$UNAME" = "FreeBSD" ] ; then 127eda14cbcSMatt Macy cleanup_freebsd_loopback 128eda14cbcSMatt Macy else 129eda14cbcSMatt Macy cleanup_linux_loopback 130eda14cbcSMatt Macy fi 131eda14cbcSMatt Macy fi 132eda14cbcSMatt Macy 133716fd348SMartin Matuska # shellcheck disable=SC2086 134716fd348SMartin Matuska rm -f ${FILES} >/dev/null 2>&1 135eda14cbcSMatt Macy 136eda14cbcSMatt Macy if [ "$STF_PATH_REMOVE" = "yes" ] && [ -d "$STF_PATH" ]; then 137eda14cbcSMatt Macy rm -Rf "$STF_PATH" 138eda14cbcSMatt Macy fi 139eda14cbcSMatt Macy} 140eda14cbcSMatt Macytrap cleanup EXIT 141eda14cbcSMatt Macy 142eda14cbcSMatt Macy# 143eda14cbcSMatt Macy# Attempt to remove all testpools (testpool.XXX), unopened dm devices, 144eda14cbcSMatt Macy# loopback devices, and files. This is a useful way to cleanup a previous 145eda14cbcSMatt Macy# test run failure which has left the system in an unknown state. This can 146eda14cbcSMatt Macy# be dangerous and should only be used in a dedicated test environment. 147eda14cbcSMatt Macy# 148eda14cbcSMatt Macycleanup_all() { 149716fd348SMartin Matuska TEST_POOLS=$(ASAN_OPTIONS=detect_leaks=false "$ZPOOL" list -Ho name | grep testpool) 150eda14cbcSMatt Macy if [ "$UNAME" = "FreeBSD" ] ; then 151eda14cbcSMatt Macy TEST_LOOPBACKS=$(sudo "${LOSETUP}" -l) 152eda14cbcSMatt Macy else 153716fd348SMartin Matuska TEST_LOOPBACKS=$("${LOSETUP}" -a | awk -F: '/file-vdev/ {print $1}') 154eda14cbcSMatt Macy fi 155716fd348SMartin Matuska TEST_FILES=$(ls "${FILEDIR}"/file-vdev* /var/tmp/file-vdev* 2>/dev/null) 156eda14cbcSMatt Macy 157eda14cbcSMatt Macy msg 158eda14cbcSMatt Macy msg "--- Cleanup ---" 159716fd348SMartin Matuska # shellcheck disable=2116,2086 160716fd348SMartin Matuska msg "Removing pool(s): $(echo ${TEST_POOLS})" 161eda14cbcSMatt Macy for TEST_POOL in $TEST_POOLS; do 162c03c5b1cSMartin Matuska sudo env ASAN_OPTIONS=detect_leaks=false "$ZPOOL" destroy "${TEST_POOL}" 163eda14cbcSMatt Macy done 164eda14cbcSMatt Macy 165eda14cbcSMatt Macy if [ "$UNAME" != "FreeBSD" ] ; then 166716fd348SMartin Matuska msg "Removing all dm(s): $(sudo "${DMSETUP}" ls | 167eda14cbcSMatt Macy grep loop | tr '\n' ' ')" 168eda14cbcSMatt Macy sudo "${DMSETUP}" remove_all 169eda14cbcSMatt Macy fi 170eda14cbcSMatt Macy 171716fd348SMartin Matuska # shellcheck disable=2116,2086 172716fd348SMartin Matuska msg "Removing loopback(s): $(echo ${TEST_LOOPBACKS})" 173eda14cbcSMatt Macy for TEST_LOOPBACK in $TEST_LOOPBACKS; do 174eda14cbcSMatt Macy if [ "$UNAME" = "FreeBSD" ] ; then 175eda14cbcSMatt Macy sudo "${LOSETUP}" -d -u "${TEST_LOOPBACK}" 176eda14cbcSMatt Macy else 177eda14cbcSMatt Macy sudo "${LOSETUP}" -d "${TEST_LOOPBACK}" 178eda14cbcSMatt Macy fi 179eda14cbcSMatt Macy done 180eda14cbcSMatt Macy 181716fd348SMartin Matuska # shellcheck disable=2116,2086 182716fd348SMartin Matuska msg "Removing files(s): $(echo ${TEST_FILES})" 183716fd348SMartin Matuska # shellcheck disable=2086 184716fd348SMartin Matuska sudo rm -f ${TEST_FILES} 185eda14cbcSMatt Macy} 186eda14cbcSMatt Macy 187eda14cbcSMatt Macy# 188eda14cbcSMatt Macy# Takes a name as the only arguments and looks for the following variations 189eda14cbcSMatt Macy# on that name. If one is found it is returned. 190eda14cbcSMatt Macy# 191eda14cbcSMatt Macy# $RUNFILE_DIR/<name> 192eda14cbcSMatt Macy# $RUNFILE_DIR/<name>.run 193eda14cbcSMatt Macy# <name> 194eda14cbcSMatt Macy# <name>.run 195eda14cbcSMatt Macy# 196eda14cbcSMatt Macyfind_runfile() { 197eda14cbcSMatt Macy NAME=$1 198eda14cbcSMatt Macy 199eda14cbcSMatt Macy if [ -f "$RUNFILE_DIR/$NAME" ]; then 200716fd348SMartin Matuska echo "$RUNFILE_DIR/$NAME" 201eda14cbcSMatt Macy elif [ -f "$RUNFILE_DIR/$NAME.run" ]; then 202716fd348SMartin Matuska echo "$RUNFILE_DIR/$NAME.run" 203eda14cbcSMatt Macy elif [ -f "$NAME" ]; then 204716fd348SMartin Matuska echo "$NAME" 205eda14cbcSMatt Macy elif [ -f "$NAME.run" ]; then 206716fd348SMartin Matuska echo "$NAME.run" 207716fd348SMartin Matuska else 208716fd348SMartin Matuska return 1 209eda14cbcSMatt Macy fi 210eda14cbcSMatt Macy} 211eda14cbcSMatt Macy 212*7a7741afSMartin Matuska# Given a TAGS with a format like "1/3" or "2/3" then divide up the test list 213*7a7741afSMartin Matuska# into portions and print that portion. So "1/3" for "the first third of the 214*7a7741afSMartin Matuska# test tags". 215*7a7741afSMartin Matuska# 216*7a7741afSMartin Matuska# 217*7a7741afSMartin Matuskasplit_tags() { 218*7a7741afSMartin Matuska # Get numerator and denominator 219*7a7741afSMartin Matuska NUM=$(echo "$TAGS" | cut -d/ -f1) 220*7a7741afSMartin Matuska DEN=$(echo "$TAGS" | cut -d/ -f2) 221*7a7741afSMartin Matuska # At the point this is called, RUNFILES will contain a comma separated 222*7a7741afSMartin Matuska # list of full paths to the runfiles, like: 223*7a7741afSMartin Matuska # 224*7a7741afSMartin Matuska # "/home/hutter/qemu/tests/runfiles/common.run,/home/hutter/qemu/tests/runfiles/linux.run" 225*7a7741afSMartin Matuska # 226*7a7741afSMartin Matuska # So to get tags for our selected tests we do: 227*7a7741afSMartin Matuska # 228*7a7741afSMartin Matuska # 1. Remove unneeded chars: [],\ 229*7a7741afSMartin Matuska # 2. Print out the last field of each tag line. This will be the tag 230*7a7741afSMartin Matuska # for the test (like 'zpool_add'). 231*7a7741afSMartin Matuska # 3. Remove duplicates between the runfiles. If the same tag is defined 232*7a7741afSMartin Matuska # in multiple runfiles, then when you do '-T <tag>' ZTS is smart 233*7a7741afSMartin Matuska # enough to know to run the tag in each runfile. So '-T zpool_add' 234*7a7741afSMartin Matuska # will run the zpool_add from common.run and linux.run. 235*7a7741afSMartin Matuska # 4. Ignore the 'functional' tag since we only want individual tests 236*7a7741afSMartin Matuska # 5. Print out the tests in our faction of all tests. This uses modulus 237*7a7741afSMartin Matuska # so "1/3" will run tests 1,3,6,9 etc. That way the tests are 238*7a7741afSMartin Matuska # interleaved so, say, "3/4" isn't running all the zpool_* tests that 239*7a7741afSMartin Matuska # appear alphabetically at the end. 240*7a7741afSMartin Matuska # 6. Remove trailing comma from list 241*7a7741afSMartin Matuska # 242*7a7741afSMartin Matuska # TAGS will then look like: 243*7a7741afSMartin Matuska # 244*7a7741afSMartin Matuska # "append,atime,bootfs,cachefile,checksum,cp_files,deadman,dos_attributes, ..." 245*7a7741afSMartin Matuska 246*7a7741afSMartin Matuska # Change the comma to a space for easy processing 247*7a7741afSMartin Matuska _RUNFILES=${RUNFILES//","/" "} 248*7a7741afSMartin Matuska # shellcheck disable=SC2002,SC2086 249*7a7741afSMartin Matuska cat $_RUNFILES | tr -d "[],\'" | awk '/tags = /{print $NF}' | sort | \ 250*7a7741afSMartin Matuska uniq | grep -v functional | \ 251*7a7741afSMartin Matuska awk -v num="$NUM" -v den="$DEN" '{ if(NR % den == (num - 1)) {printf "%s,",$0}}' | \ 252*7a7741afSMartin Matuska sed -E 's/,$//' 253*7a7741afSMartin Matuska} 254*7a7741afSMartin Matuska 255eda14cbcSMatt Macy# 256eda14cbcSMatt Macy# Symlink file if it appears under any of the given paths. 257eda14cbcSMatt Macy# 258eda14cbcSMatt Macycreate_links() { 259eda14cbcSMatt Macy dir_list="$1" 260eda14cbcSMatt Macy file_list="$2" 261eda14cbcSMatt Macy 262eda14cbcSMatt Macy [ -n "$STF_PATH" ] || fail "STF_PATH wasn't correctly set" 263eda14cbcSMatt Macy 264eda14cbcSMatt Macy for i in $file_list; do 265eda14cbcSMatt Macy for j in $dir_list; do 266eda14cbcSMatt Macy [ ! -e "$STF_PATH/$i" ] || continue 267eda14cbcSMatt Macy 268eda14cbcSMatt Macy if [ ! -d "$j/$i" ] && [ -e "$j/$i" ]; then 269eda14cbcSMatt Macy ln -sf "$j/$i" "$STF_PATH/$i" || \ 270eda14cbcSMatt Macy fail "Couldn't link $i" 271eda14cbcSMatt Macy break 272eda14cbcSMatt Macy fi 273eda14cbcSMatt Macy done 274eda14cbcSMatt Macy 275eda14cbcSMatt Macy [ ! -e "$STF_PATH/$i" ] && \ 276eda14cbcSMatt Macy STF_MISSING_BIN="$STF_MISSING_BIN $i" 277eda14cbcSMatt Macy done 278eda14cbcSMatt Macy STF_MISSING_BIN=${STF_MISSING_BIN# } 279eda14cbcSMatt Macy} 280eda14cbcSMatt Macy 281eda14cbcSMatt Macy# 282eda14cbcSMatt Macy# Constrain the path to limit the available binaries to a known set. 283eda14cbcSMatt Macy# When running in-tree a top level ./bin/ directory is created for 284eda14cbcSMatt Macy# convenience, otherwise a temporary directory is used. 285eda14cbcSMatt Macy# 286eda14cbcSMatt Macyconstrain_path() { 287eda14cbcSMatt Macy . "$STF_SUITE/include/commands.cfg" 288eda14cbcSMatt Macy 289eda14cbcSMatt Macy # On FreeBSD, base system zfs utils are in /sbin and OpenZFS utils 290eda14cbcSMatt Macy # install to /usr/local/sbin. To avoid testing the wrong utils we 291eda14cbcSMatt Macy # need /usr/local to come before / in the path search order. 292eda14cbcSMatt Macy SYSTEM_DIRS="/usr/local/bin /usr/local/sbin" 2937877fdebSMatt Macy SYSTEM_DIRS="$SYSTEM_DIRS /usr/bin /usr/sbin /bin /sbin $LIBEXEC_DIR" 294eda14cbcSMatt Macy 295eda14cbcSMatt Macy if [ "$INTREE" = "yes" ]; then 296716fd348SMartin Matuska # Constrained path set to $(top_builddir)/tests/zfs-tests/bin 297eda14cbcSMatt Macy STF_PATH="$BIN_DIR" 298eda14cbcSMatt Macy STF_PATH_REMOVE="no" 299eda14cbcSMatt Macy STF_MISSING_BIN="" 300eda14cbcSMatt Macy if [ ! -d "$STF_PATH" ]; then 301eda14cbcSMatt Macy mkdir "$STF_PATH" 302eda14cbcSMatt Macy chmod 755 "$STF_PATH" || fail "Couldn't chmod $STF_PATH" 303eda14cbcSMatt Macy fi 304eda14cbcSMatt Macy 305eda14cbcSMatt Macy # Special case links for standard zfs utilities 306716fd348SMartin Matuska create_links "$CMD_DIR" "$ZFS_FILES" 307eda14cbcSMatt Macy 308eda14cbcSMatt Macy # Special case links for zfs test suite utilities 309716fd348SMartin Matuska create_links "$CMD_DIR/tests/zfs-tests/cmd" "$ZFSTEST_FILES" 310eda14cbcSMatt Macy else 311eda14cbcSMatt Macy # Constrained path set to /var/tmp/constrained_path.* 3127877fdebSMatt Macy SYSTEMDIR=${SYSTEMDIR:-/var/tmp/constrained_path.XXXXXX} 313eda14cbcSMatt Macy STF_PATH=$(mktemp -d "$SYSTEMDIR") 314eda14cbcSMatt Macy STF_PATH_REMOVE="yes" 315eda14cbcSMatt Macy STF_MISSING_BIN="" 316eda14cbcSMatt Macy 317eda14cbcSMatt Macy chmod 755 "$STF_PATH" || fail "Couldn't chmod $STF_PATH" 318eda14cbcSMatt Macy 319eda14cbcSMatt Macy # Special case links for standard zfs utilities 320eda14cbcSMatt Macy create_links "$SYSTEM_DIRS" "$ZFS_FILES" 321eda14cbcSMatt Macy 322eda14cbcSMatt Macy # Special case links for zfs test suite utilities 323eda14cbcSMatt Macy create_links "$STF_SUITE/bin" "$ZFSTEST_FILES" 324eda14cbcSMatt Macy fi 325eda14cbcSMatt Macy 326eda14cbcSMatt Macy # Standard system utilities 327eda14cbcSMatt Macy SYSTEM_FILES="$SYSTEM_FILES_COMMON" 328eda14cbcSMatt Macy if [ "$UNAME" = "FreeBSD" ] ; then 329eda14cbcSMatt Macy SYSTEM_FILES="$SYSTEM_FILES $SYSTEM_FILES_FREEBSD" 330eda14cbcSMatt Macy else 331eda14cbcSMatt Macy SYSTEM_FILES="$SYSTEM_FILES $SYSTEM_FILES_LINUX" 332eda14cbcSMatt Macy fi 333eda14cbcSMatt Macy create_links "$SYSTEM_DIRS" "$SYSTEM_FILES" 334eda14cbcSMatt Macy 335eda14cbcSMatt Macy # Exceptions 336eda14cbcSMatt Macy if [ "$UNAME" = "Linux" ] ; then 337eda14cbcSMatt Macy ln -fs /sbin/fsck.ext4 "$STF_PATH/fsck" 338eda14cbcSMatt Macy ln -fs /sbin/mkfs.ext4 "$STF_PATH/newfs" 339eda14cbcSMatt Macy ln -fs "$STF_PATH/gzip" "$STF_PATH/compress" 340eda14cbcSMatt Macy ln -fs "$STF_PATH/gunzip" "$STF_PATH/uncompress" 341eda14cbcSMatt Macy elif [ "$UNAME" = "FreeBSD" ] ; then 342eda14cbcSMatt Macy ln -fs /usr/local/bin/ksh93 "$STF_PATH/ksh" 343eda14cbcSMatt Macy fi 344eda14cbcSMatt Macy} 345eda14cbcSMatt Macy 346eda14cbcSMatt Macy# 347eda14cbcSMatt Macy# Output a useful usage message. 348eda14cbcSMatt Macy# 349eda14cbcSMatt Macyusage() { 350eda14cbcSMatt Macycat << EOF 351eda14cbcSMatt MacyUSAGE: 3522c48331dSMatt Macy$0 [-hvqxkfS] [-s SIZE] [-r RUNFILES] [-t PATH] [-u USER] 353eda14cbcSMatt Macy 354eda14cbcSMatt MacyDESCRIPTION: 355eda14cbcSMatt Macy ZFS Test Suite launch script 356eda14cbcSMatt Macy 357eda14cbcSMatt MacyOPTIONS: 358eda14cbcSMatt Macy -h Show this message 359eda14cbcSMatt Macy -v Verbose zfs-tests.sh output 360eda14cbcSMatt Macy -q Quiet test-runner output 3610d4ad640SMartin Matuska -D Debug; show all test output immediately (noisy) 362eda14cbcSMatt Macy -x Remove all testpools, dm, lo, and files (unsafe) 363eda14cbcSMatt Macy -k Disable cleanup after test failure 364da5137abSMartin Matuska -K Log test names to /dev/kmsg 365eda14cbcSMatt Macy -f Use files only, disables block device tests 366eda14cbcSMatt Macy -S Enable stack tracer (negative performance impact) 367eda14cbcSMatt Macy -c Only create and populate constrained path 368681ce946SMartin Matuska -R Automatically rerun failing tests 369c03c5b1cSMartin Matuska -m Enable kmemleak reporting (Linux only) 370eda14cbcSMatt Macy -n NFSFILE Use the nfsfile to determine the NFS configuration 371eda14cbcSMatt Macy -I NUM Number of iterations 372716fd348SMartin Matuska -d DIR Use world-writable DIR for files and loopback devices 373eda14cbcSMatt Macy -s SIZE Use vdevs of SIZE (default: 4G) 374eda14cbcSMatt Macy -r RUNFILES Run tests in RUNFILES (default: ${DEFAULT_RUNFILES}) 3751719886fSMartin Matuska -t PATH|NAME Run single test at PATH relative to test suite, 3761719886fSMartin Matuska or search for test by NAME 377eda14cbcSMatt Macy -T TAGS Comma separated list of tags (default: 'functional') 378*7a7741afSMartin Matuska Alternately, specify a fraction like "1/3" or "2/3" to 379*7a7741afSMartin Matuska run the first third of tests or 2nd third of the tests. This 380*7a7741afSMartin Matuska is useful for splitting up the test amongst different 381*7a7741afSMartin Matuska runners. 382eda14cbcSMatt Macy -u USER Run single test as USER (default: root) 383eda14cbcSMatt Macy 384eda14cbcSMatt MacyEXAMPLES: 385*7a7741afSMartin Matuska# Run the default ${DEFAULT_RUNFILES//\.run/} suite of tests and output the configuration used. 386eda14cbcSMatt Macy$0 -v 387eda14cbcSMatt Macy 388eda14cbcSMatt Macy# Run a smaller suite of tests designed to run more quickly. 389eda14cbcSMatt Macy$0 -r linux-fast 390eda14cbcSMatt Macy 391eda14cbcSMatt Macy# Run a single test 392eda14cbcSMatt Macy$0 -t tests/functional/cli_root/zfs_bookmark/zfs_bookmark_cliargs.ksh 393eda14cbcSMatt Macy 3941719886fSMartin Matuska# Run a single test by name 3951719886fSMartin Matuska$0 -t zfs_bookmark_cliargs 3961719886fSMartin Matuska 397eda14cbcSMatt Macy# Cleanup a previous run of the test suite prior to testing, run the 398*7a7741afSMartin Matuska# default ${DEFAULT_RUNFILES//\.run//} suite of tests and perform no cleanup on exit. 399eda14cbcSMatt Macy$0 -x 400eda14cbcSMatt Macy 401eda14cbcSMatt MacyEOF 402eda14cbcSMatt Macy} 403eda14cbcSMatt Macy 4040d4ad640SMartin Matuskawhile getopts 'hvqxkKfScRmn:d:Ds:r:?t:T:u:I:' OPTION; do 405eda14cbcSMatt Macy case $OPTION in 406eda14cbcSMatt Macy h) 407eda14cbcSMatt Macy usage 408eda14cbcSMatt Macy exit 1 409eda14cbcSMatt Macy ;; 410eda14cbcSMatt Macy v) 411eda14cbcSMatt Macy VERBOSE="yes" 412eda14cbcSMatt Macy ;; 413eda14cbcSMatt Macy q) 414eda14cbcSMatt Macy QUIET="yes" 415eda14cbcSMatt Macy ;; 416eda14cbcSMatt Macy x) 417eda14cbcSMatt Macy CLEANUPALL="yes" 418eda14cbcSMatt Macy ;; 419eda14cbcSMatt Macy k) 420eda14cbcSMatt Macy CLEANUP="no" 421eda14cbcSMatt Macy ;; 422da5137abSMartin Matuska K) 423da5137abSMartin Matuska KMSG="yes" 424da5137abSMartin Matuska ;; 425eda14cbcSMatt Macy f) 426eda14cbcSMatt Macy LOOPBACK="no" 427eda14cbcSMatt Macy ;; 428eda14cbcSMatt Macy S) 429eda14cbcSMatt Macy STACK_TRACER="yes" 430eda14cbcSMatt Macy ;; 431eda14cbcSMatt Macy c) 432eda14cbcSMatt Macy constrain_path 433eda14cbcSMatt Macy exit 434eda14cbcSMatt Macy ;; 435681ce946SMartin Matuska R) 436681ce946SMartin Matuska RERUN="yes" 437681ce946SMartin Matuska ;; 438c03c5b1cSMartin Matuska m) 439c03c5b1cSMartin Matuska KMEMLEAK="yes" 440c03c5b1cSMartin Matuska ;; 441eda14cbcSMatt Macy n) 442eda14cbcSMatt Macy nfsfile=$OPTARG 443eda14cbcSMatt Macy [ -f "$nfsfile" ] || fail "Cannot read file: $nfsfile" 444eda14cbcSMatt Macy export NFS=1 445eda14cbcSMatt Macy . "$nfsfile" 446eda14cbcSMatt Macy ;; 447eda14cbcSMatt Macy d) 448eda14cbcSMatt Macy FILEDIR="$OPTARG" 449eda14cbcSMatt Macy ;; 4500d4ad640SMartin Matuska D) 4510d4ad640SMartin Matuska DEBUG="yes" 4520d4ad640SMartin Matuska ;; 453eda14cbcSMatt Macy I) 454eda14cbcSMatt Macy ITERATIONS="$OPTARG" 455eda14cbcSMatt Macy if [ "$ITERATIONS" -le 0 ]; then 456eda14cbcSMatt Macy fail "Iterations must be greater than 0." 457eda14cbcSMatt Macy fi 458eda14cbcSMatt Macy ;; 459eda14cbcSMatt Macy s) 460eda14cbcSMatt Macy FILESIZE="$OPTARG" 461eda14cbcSMatt Macy ;; 462eda14cbcSMatt Macy r) 463eda14cbcSMatt Macy RUNFILES="$OPTARG" 464eda14cbcSMatt Macy ;; 465eda14cbcSMatt Macy t) 466eda14cbcSMatt Macy if [ -n "$SINGLETEST" ]; then 467eda14cbcSMatt Macy fail "-t can only be provided once." 468eda14cbcSMatt Macy fi 469eda14cbcSMatt Macy SINGLETEST="$OPTARG" 470eda14cbcSMatt Macy ;; 471eda14cbcSMatt Macy T) 472eda14cbcSMatt Macy TAGS="$OPTARG" 473eda14cbcSMatt Macy ;; 474eda14cbcSMatt Macy u) 475eda14cbcSMatt Macy SINGLETESTUSER="$OPTARG" 476eda14cbcSMatt Macy ;; 477eda14cbcSMatt Macy ?) 478eda14cbcSMatt Macy usage 479eda14cbcSMatt Macy exit 480eda14cbcSMatt Macy ;; 481e92ffd9bSMartin Matuska *) 482e92ffd9bSMartin Matuska ;; 483eda14cbcSMatt Macy esac 484eda14cbcSMatt Macydone 485eda14cbcSMatt Macy 486eda14cbcSMatt Macyshift $((OPTIND-1)) 487eda14cbcSMatt Macy 488eda14cbcSMatt MacyFILES=${FILES:-"$FILEDIR/file-vdev0 $FILEDIR/file-vdev1 $FILEDIR/file-vdev2"} 489eda14cbcSMatt MacyLOOPBACKS=${LOOPBACKS:-""} 490eda14cbcSMatt Macy 491eda14cbcSMatt Macyif [ -n "$SINGLETEST" ]; then 492eda14cbcSMatt Macy if [ -n "$TAGS" ]; then 493eda14cbcSMatt Macy fail "-t and -T are mutually exclusive." 494eda14cbcSMatt Macy fi 495eda14cbcSMatt Macy RUNFILE_DIR="/var/tmp" 496eda14cbcSMatt Macy RUNFILES="zfs-tests.$$.run" 497716fd348SMartin Matuska [ -n "$QUIET" ] && SINGLEQUIET="True" || SINGLEQUIET="False" 498eda14cbcSMatt Macy 499e92ffd9bSMartin Matuska cat >"${RUNFILE_DIR}/${RUNFILES}" << EOF 500eda14cbcSMatt Macy[DEFAULT] 501eda14cbcSMatt Macypre = 502eda14cbcSMatt Macyquiet = $SINGLEQUIET 503eda14cbcSMatt Macypre_user = root 504eda14cbcSMatt Macyuser = $SINGLETESTUSER 505eda14cbcSMatt Macytimeout = 600 506eda14cbcSMatt Macypost_user = root 507eda14cbcSMatt Macypost = 508eda14cbcSMatt Macyoutputdir = /var/tmp/test_results 509eda14cbcSMatt MacyEOF 5101719886fSMartin Matuska if [ "$SINGLETEST" = "${SINGLETEST%/*}" ] ; then 5111719886fSMartin Matuska NEWSINGLETEST=$(find "$STF_SUITE" -name "$SINGLETEST*" -print -quit) 5121719886fSMartin Matuska if [ -z "$NEWSINGLETEST" ] ; then 5131719886fSMartin Matuska fail "couldn't find test matching '$SINGLETEST'" 5141719886fSMartin Matuska fi 5151719886fSMartin Matuska SINGLETEST=$NEWSINGLETEST 5161719886fSMartin Matuska fi 517eda14cbcSMatt Macy 5181719886fSMartin Matuska SINGLETESTDIR="${SINGLETEST%/*}" 519716fd348SMartin Matuska SETUPDIR="$SINGLETESTDIR" 520716fd348SMartin Matuska [ "${SETUPDIR#/}" = "$SETUPDIR" ] && SETUPDIR="$STF_SUITE/$SINGLETESTDIR" 521716fd348SMartin Matuska [ -x "$SETUPDIR/setup.ksh" ] && SETUPSCRIPT="setup" || SETUPSCRIPT= 522716fd348SMartin Matuska [ -x "$SETUPDIR/cleanup.ksh" ] && CLEANUPSCRIPT="cleanup" || CLEANUPSCRIPT= 523eda14cbcSMatt Macy 524716fd348SMartin Matuska SINGLETESTFILE="${SINGLETEST##*/}" 525e92ffd9bSMartin Matuska cat >>"${RUNFILE_DIR}/${RUNFILES}" << EOF 526eda14cbcSMatt Macy 527eda14cbcSMatt Macy[$SINGLETESTDIR] 528eda14cbcSMatt Macytests = ['$SINGLETESTFILE'] 529eda14cbcSMatt Macypre = $SETUPSCRIPT 530eda14cbcSMatt Macypost = $CLEANUPSCRIPT 531eda14cbcSMatt Macytags = ['functional'] 532eda14cbcSMatt MacyEOF 533eda14cbcSMatt Macyfi 534eda14cbcSMatt Macy 535eda14cbcSMatt Macy# 536eda14cbcSMatt Macy# Use default tag if none was specified 537eda14cbcSMatt Macy# 538eda14cbcSMatt MacyTAGS=${TAGS:='functional'} 539eda14cbcSMatt Macy 540*7a7741afSMartin Matuska 541*7a7741afSMartin Matuska 542eda14cbcSMatt Macy# 543eda14cbcSMatt Macy# Attempt to locate the runfiles describing the test workload. 544eda14cbcSMatt Macy# 545eda14cbcSMatt MacyR="" 546eda14cbcSMatt MacyIFS=, 547eda14cbcSMatt Macyfor RUNFILE in $RUNFILES; do 548eda14cbcSMatt Macy if [ -n "$RUNFILE" ]; then 549eda14cbcSMatt Macy SAVED_RUNFILE="$RUNFILE" 550716fd348SMartin Matuska RUNFILE=$(find_runfile "$RUNFILE") || 551716fd348SMartin Matuska fail "Cannot find runfile: $SAVED_RUNFILE" 552eda14cbcSMatt Macy R="$R,$RUNFILE" 553eda14cbcSMatt Macy fi 554eda14cbcSMatt Macy 555eda14cbcSMatt Macy if [ ! -r "$RUNFILE" ]; then 556eda14cbcSMatt Macy fail "Cannot read runfile: $RUNFILE" 557eda14cbcSMatt Macy fi 558eda14cbcSMatt Macydone 559eda14cbcSMatt Macyunset IFS 560eda14cbcSMatt MacyRUNFILES=${R#,} 561eda14cbcSMatt Macy 562*7a7741afSMartin Matuska# The tag can be a fraction to indicate which portion of ZTS to run, Like 563*7a7741afSMartin Matuska# 564*7a7741afSMartin Matuska# "1/3": Run first one third of all tests in runfiles 565*7a7741afSMartin Matuska# "2/3": Run second one third of all test in runfiles 566*7a7741afSMartin Matuska# "6/10": Run 6th tenth of all tests in runfiles 567*7a7741afSMartin Matuska# 568*7a7741afSMartin Matuska# This is useful for splitting up the test across multiple runners. 569*7a7741afSMartin Matuska# 570*7a7741afSMartin Matuska# After this code block, TAGS will be transformed from something like 571*7a7741afSMartin Matuska# "1/3" to a comma separate taglist, like: 572*7a7741afSMartin Matuska# 573*7a7741afSMartin Matuska# "append,atime,bootfs,cachefile,checksum,cp_files,deadman,dos_attributes, ..." 574*7a7741afSMartin Matuska# 575*7a7741afSMartin Matuskaif echo "$TAGS" | grep -Eq '^[0-9]+/[0-9]+$' ; then 576*7a7741afSMartin Matuska TAGS=$(split_tags) 577*7a7741afSMartin Matuskafi 578*7a7741afSMartin Matuska 579eda14cbcSMatt Macy# 580eda14cbcSMatt Macy# This script should not be run as root. Instead the test user, which may 581eda14cbcSMatt Macy# be a normal user account, needs to be configured such that it can 582eda14cbcSMatt Macy# run commands via sudo passwordlessly. 583eda14cbcSMatt Macy# 584eda14cbcSMatt Macyif [ "$(id -u)" = "0" ]; then 585eda14cbcSMatt Macy fail "This script must not be run as root." 586eda14cbcSMatt Macyfi 587eda14cbcSMatt Macy 588716fd348SMartin Matuskaif [ "$(sudo id -un)" != "root" ]; then 589eda14cbcSMatt Macy fail "Passwordless sudo access required." 590eda14cbcSMatt Macyfi 591eda14cbcSMatt Macy 592eda14cbcSMatt Macy# 593eda14cbcSMatt Macy# Constrain the available binaries to a known set. 594eda14cbcSMatt Macy# 595eda14cbcSMatt Macyconstrain_path 596eda14cbcSMatt Macy 597eda14cbcSMatt Macy# 598eda14cbcSMatt Macy# Check if ksh exists 599eda14cbcSMatt Macy# 600eda14cbcSMatt Macyif [ "$UNAME" = "FreeBSD" ]; then 601eda14cbcSMatt Macy sudo ln -fs /usr/local/bin/ksh93 /bin/ksh 602eda14cbcSMatt Macyfi 603eda14cbcSMatt Macy[ -e "$STF_PATH/ksh" ] || fail "This test suite requires ksh." 604eda14cbcSMatt Macy[ -e "$STF_SUITE/include/default.cfg" ] || fail \ 605eda14cbcSMatt Macy "Missing $STF_SUITE/include/default.cfg file." 606eda14cbcSMatt Macy 607eda14cbcSMatt Macy# 608eda14cbcSMatt Macy# Verify the ZFS module stack is loaded. 609eda14cbcSMatt Macy# 610eda14cbcSMatt Macyif [ "$STACK_TRACER" = "yes" ]; then 611eda14cbcSMatt Macy sudo "${ZFS_SH}" -S >/dev/null 2>&1 612eda14cbcSMatt Macyelse 613eda14cbcSMatt Macy sudo "${ZFS_SH}" >/dev/null 2>&1 614eda14cbcSMatt Macyfi 615eda14cbcSMatt Macy 616eda14cbcSMatt Macy# 617eda14cbcSMatt Macy# Attempt to cleanup all previous state for a new test run. 618eda14cbcSMatt Macy# 619eda14cbcSMatt Macyif [ "$CLEANUPALL" = "yes" ]; then 620eda14cbcSMatt Macy cleanup_all 621eda14cbcSMatt Macyfi 622eda14cbcSMatt Macy 623eda14cbcSMatt Macy# 624eda14cbcSMatt Macy# By default preserve any existing pools 625eda14cbcSMatt Macy# 626eda14cbcSMatt Macyif [ -z "${KEEP}" ]; then 627716fd348SMartin Matuska KEEP="$(ASAN_OPTIONS=detect_leaks=false "$ZPOOL" list -Ho name | tr -s '[:space:]' ' ')" 628eda14cbcSMatt Macy if [ -z "${KEEP}" ]; then 629eda14cbcSMatt Macy KEEP="rpool" 630eda14cbcSMatt Macy fi 631eda14cbcSMatt Macyelse 632716fd348SMartin Matuska KEEP="$(echo "$KEEP" | tr -s '[:space:]' ' ')" 633eda14cbcSMatt Macyfi 634eda14cbcSMatt Macy 635eda14cbcSMatt Macy# 636eda14cbcSMatt Macy# NOTE: The following environment variables are undocumented 637eda14cbcSMatt Macy# and should be used for testing purposes only: 638eda14cbcSMatt Macy# 639eda14cbcSMatt Macy# __ZFS_POOL_EXCLUDE - don't iterate over the pools it lists 640eda14cbcSMatt Macy# __ZFS_POOL_RESTRICT - iterate only over the pools it lists 641eda14cbcSMatt Macy# 642eda14cbcSMatt Macy# See libzfs/libzfs_config.c for more information. 643eda14cbcSMatt Macy# 644716fd348SMartin Matuska__ZFS_POOL_EXCLUDE="$KEEP" 645eda14cbcSMatt Macy 646eda14cbcSMatt Macy. "$STF_SUITE/include/default.cfg" 647eda14cbcSMatt Macy 648eda14cbcSMatt Macy# 649eda14cbcSMatt Macy# No DISKS have been provided so a basic file or loopback based devices 650eda14cbcSMatt Macy# must be created for the test suite to use. 651eda14cbcSMatt Macy# 652eda14cbcSMatt Macyif [ -z "${DISKS}" ]; then 653eda14cbcSMatt Macy # 6541f88aa09SMartin Matuska # If this is a performance run, prevent accidental use of 6551f88aa09SMartin Matuska # loopback devices. 6561f88aa09SMartin Matuska # 6571f88aa09SMartin Matuska [ "$TAGS" = "perf" ] && fail "Running perf tests without disks." 6581f88aa09SMartin Matuska 6591f88aa09SMartin Matuska # 660eda14cbcSMatt Macy # Create sparse files for the test suite. These may be used 661eda14cbcSMatt Macy # directory or have loopback devices layered on them. 662eda14cbcSMatt Macy # 663eda14cbcSMatt Macy for TEST_FILE in ${FILES}; do 664eda14cbcSMatt Macy [ -f "$TEST_FILE" ] && fail "Failed file exists: ${TEST_FILE}" 665eda14cbcSMatt Macy truncate -s "${FILESIZE}" "${TEST_FILE}" || 666eda14cbcSMatt Macy fail "Failed creating: ${TEST_FILE} ($?)" 667eda14cbcSMatt Macy done 668eda14cbcSMatt Macy 669eda14cbcSMatt Macy # 670eda14cbcSMatt Macy # If requested setup loopback devices backed by the sparse files. 671eda14cbcSMatt Macy # 672eda14cbcSMatt Macy if [ "$LOOPBACK" = "yes" ]; then 673eda14cbcSMatt Macy test -x "$LOSETUP" || fail "$LOSETUP utility must be installed" 674eda14cbcSMatt Macy 675eda14cbcSMatt Macy for TEST_FILE in ${FILES}; do 676eda14cbcSMatt Macy if [ "$UNAME" = "FreeBSD" ] ; then 677eda14cbcSMatt Macy MDDEVICE=$(sudo "${LOSETUP}" -a -t vnode -f "${TEST_FILE}") 678eda14cbcSMatt Macy if [ -z "$MDDEVICE" ] ; then 679eda14cbcSMatt Macy fail "Failed: ${TEST_FILE} -> loopback" 680eda14cbcSMatt Macy fi 681eda14cbcSMatt Macy DISKS="$DISKS $MDDEVICE" 682eda14cbcSMatt Macy LOOPBACKS="$LOOPBACKS $MDDEVICE" 683eda14cbcSMatt Macy else 684716fd348SMartin Matuska TEST_LOOPBACK=$(sudo "${LOSETUP}" --show -f "${TEST_FILE}") || 685eda14cbcSMatt Macy fail "Failed: ${TEST_FILE} -> ${TEST_LOOPBACK}" 686dae17134SMartin Matuska BASELOOPBACK="${TEST_LOOPBACK##*/}" 687eda14cbcSMatt Macy DISKS="$DISKS $BASELOOPBACK" 688eda14cbcSMatt Macy LOOPBACKS="$LOOPBACKS $TEST_LOOPBACK" 689eda14cbcSMatt Macy fi 690eda14cbcSMatt Macy done 691eda14cbcSMatt Macy DISKS=${DISKS# } 692eda14cbcSMatt Macy LOOPBACKS=${LOOPBACKS# } 693eda14cbcSMatt Macy else 694eda14cbcSMatt Macy DISKS="$FILES" 695eda14cbcSMatt Macy fi 696eda14cbcSMatt Macyfi 697eda14cbcSMatt Macy 6981f88aa09SMartin Matuska# 6991f88aa09SMartin Matuska# It may be desirable to test with fewer disks than the default when running 7001f88aa09SMartin Matuska# the performance tests, but the functional tests require at least three. 7011f88aa09SMartin Matuska# 702eda14cbcSMatt MacyNUM_DISKS=$(echo "${DISKS}" | awk '{print NF}') 7031f88aa09SMartin Matuskaif [ "$TAGS" != "perf" ]; then 704eda14cbcSMatt Macy [ "$NUM_DISKS" -lt 3 ] && fail "Not enough disks ($NUM_DISKS/3 minimum)" 7051f88aa09SMartin Matuskafi 706eda14cbcSMatt Macy 707eda14cbcSMatt Macy# 708eda14cbcSMatt Macy# Disable SELinux until the ZFS Test Suite has been updated accordingly. 709eda14cbcSMatt Macy# 710716fd348SMartin Matuskaif command -v setenforce >/dev/null; then 711eda14cbcSMatt Macy sudo setenforce permissive >/dev/null 2>&1 712eda14cbcSMatt Macyfi 713eda14cbcSMatt Macy 714eda14cbcSMatt Macy# 715eda14cbcSMatt Macy# Enable internal ZFS debug log and clear it. 716eda14cbcSMatt Macy# 717eda14cbcSMatt Macyif [ -e /sys/module/zfs/parameters/zfs_dbgmsg_enable ]; then 718716fd348SMartin Matuska sudo sh -c "echo 1 >/sys/module/zfs/parameters/zfs_dbgmsg_enable" 719716fd348SMartin Matuska sudo sh -c "echo 0 >/proc/spl/kstat/zfs/dbgmsg" 720eda14cbcSMatt Macyfi 721eda14cbcSMatt Macy 7221f88aa09SMartin Matuskamsg 7231f88aa09SMartin Matuskamsg "--- Configuration ---" 7241f88aa09SMartin Matuskamsg "Runfiles: $RUNFILES" 7251f88aa09SMartin Matuskamsg "STF_TOOLS: $STF_TOOLS" 7261f88aa09SMartin Matuskamsg "STF_SUITE: $STF_SUITE" 7271f88aa09SMartin Matuskamsg "STF_PATH: $STF_PATH" 728eda14cbcSMatt Macymsg "FILEDIR: $FILEDIR" 729eda14cbcSMatt Macymsg "FILES: $FILES" 730eda14cbcSMatt Macymsg "LOOPBACKS: $LOOPBACKS" 731eda14cbcSMatt Macymsg "DISKS: $DISKS" 732eda14cbcSMatt Macymsg "NUM_DISKS: $NUM_DISKS" 733eda14cbcSMatt Macymsg "FILESIZE: $FILESIZE" 734eda14cbcSMatt Macymsg "ITERATIONS: $ITERATIONS" 735eda14cbcSMatt Macymsg "TAGS: $TAGS" 736eda14cbcSMatt Macymsg "STACK_TRACER: $STACK_TRACER" 737eda14cbcSMatt Macymsg "Keep pool(s): $KEEP" 738eda14cbcSMatt Macymsg "Missing util(s): $STF_MISSING_BIN" 739eda14cbcSMatt Macymsg "" 740eda14cbcSMatt Macy 741eda14cbcSMatt Macyexport STF_TOOLS 742eda14cbcSMatt Macyexport STF_SUITE 743eda14cbcSMatt Macyexport STF_PATH 744eda14cbcSMatt Macyexport DISKS 745eda14cbcSMatt Macyexport FILEDIR 746eda14cbcSMatt Macyexport KEEP 747eda14cbcSMatt Macyexport __ZFS_POOL_EXCLUDE 748eda14cbcSMatt Macyexport TESTFAIL_CALLBACKS 749eda14cbcSMatt Macy 750c03c5b1cSMartin Matuskamktemp_file() { 751eda14cbcSMatt Macy if [ "$UNAME" = "FreeBSD" ]; then 752c03c5b1cSMartin Matuska mktemp -u "${FILEDIR}/$1.XXXXXX" 753eda14cbcSMatt Macy else 754c03c5b1cSMartin Matuska mktemp -ut "$1.XXXXXX" -p "$FILEDIR" 755eda14cbcSMatt Macy fi 756c03c5b1cSMartin Matuska} 757c03c5b1cSMartin Matuskamkdir -p "$FILEDIR" || : 758c03c5b1cSMartin MatuskaRESULTS_FILE=$(mktemp_file zts-results) 759c03c5b1cSMartin MatuskaREPORT_FILE=$(mktemp_file zts-report) 760eda14cbcSMatt Macy 761eda14cbcSMatt Macy# 762eda14cbcSMatt Macy# Run all the tests as specified. 763eda14cbcSMatt Macy# 764c03c5b1cSMartin Matuskamsg "${TEST_RUNNER}" \ 765c03c5b1cSMartin Matuska "${QUIET:+-q}" \ 7660d4ad640SMartin Matuska "${DEBUG:+-D}" \ 767c03c5b1cSMartin Matuska "${KMEMLEAK:+-m}" \ 768da5137abSMartin Matuska "${KMSG:+-K}" \ 769eda14cbcSMatt Macy "-c \"${RUNFILES}\"" \ 770eda14cbcSMatt Macy "-T \"${TAGS}\"" \ 771eda14cbcSMatt Macy "-i \"${STF_SUITE}\"" \ 772eda14cbcSMatt Macy "-I \"${ITERATIONS}\"" 773716fd348SMartin Matuska{ PATH=$STF_PATH \ 774716fd348SMartin Matuska ${TEST_RUNNER} \ 775c03c5b1cSMartin Matuska ${QUIET:+-q} \ 7760d4ad640SMartin Matuska ${DEBUG:+-D} \ 777c03c5b1cSMartin Matuska ${KMEMLEAK:+-m} \ 778da5137abSMartin Matuska ${KMSG:+-K} \ 779eda14cbcSMatt Macy -c "${RUNFILES}" \ 780eda14cbcSMatt Macy -T "${TAGS}" \ 781eda14cbcSMatt Macy -i "${STF_SUITE}" \ 782eda14cbcSMatt Macy -I "${ITERATIONS}" \ 783c03c5b1cSMartin Matuska 2>&1; echo $? >"$REPORT_FILE"; } | tee "$RESULTS_FILE" 784c03c5b1cSMartin Matuskaread -r RUNRESULT <"$REPORT_FILE" 785c03c5b1cSMartin Matuska 786eda14cbcSMatt Macy# 787eda14cbcSMatt Macy# Analyze the results. 788eda14cbcSMatt Macy# 789681ce946SMartin Matuska${ZTS_REPORT} ${RERUN:+--no-maybes} "$RESULTS_FILE" >"$REPORT_FILE" 790eda14cbcSMatt MacyRESULT=$? 791681ce946SMartin Matuska 792681ce946SMartin Matuskaif [ "$RESULT" -eq "2" ] && [ -n "$RERUN" ]; then 793681ce946SMartin Matuska MAYBES="$($ZTS_REPORT --list-maybes)" 794c03c5b1cSMartin Matuska TEMP_RESULTS_FILE=$(mktemp_file zts-results-tmp) 795c03c5b1cSMartin Matuska TEST_LIST=$(mktemp_file test-list) 796681ce946SMartin Matuska grep "^Test:.*\[FAIL\]" "$RESULTS_FILE" >"$TEMP_RESULTS_FILE" 797681ce946SMartin Matuska for test_name in $MAYBES; do 798681ce946SMartin Matuska grep "$test_name " "$TEMP_RESULTS_FILE" >>"$TEST_LIST" 799681ce946SMartin Matuska done 800716fd348SMartin Matuska { PATH=$STF_PATH \ 801716fd348SMartin Matuska ${TEST_RUNNER} \ 802c03c5b1cSMartin Matuska ${QUIET:+-q} \ 8030d4ad640SMartin Matuska ${DEBUG:+-D} \ 804c03c5b1cSMartin Matuska ${KMEMLEAK:+-m} \ 805681ce946SMartin Matuska -c "${RUNFILES}" \ 806681ce946SMartin Matuska -T "${TAGS}" \ 807681ce946SMartin Matuska -i "${STF_SUITE}" \ 808681ce946SMartin Matuska -I "${ITERATIONS}" \ 809681ce946SMartin Matuska -l "${TEST_LIST}" \ 810c03c5b1cSMartin Matuska 2>&1; echo $? >"$REPORT_FILE"; } | tee "$RESULTS_FILE" 811c03c5b1cSMartin Matuska read -r RUNRESULT <"$REPORT_FILE" 812681ce946SMartin Matuska # 813681ce946SMartin Matuska # Analyze the results. 814681ce946SMartin Matuska # 815681ce946SMartin Matuska ${ZTS_REPORT} --no-maybes "$RESULTS_FILE" >"$REPORT_FILE" 816681ce946SMartin Matuska RESULT=$? 817681ce946SMartin Matuskafi 818681ce946SMartin Matuska 819681ce946SMartin Matuska 820eda14cbcSMatt Macycat "$REPORT_FILE" 821eda14cbcSMatt Macy 822eda14cbcSMatt MacyRESULTS_DIR=$(awk '/^Log directory/ { print $3 }' "$RESULTS_FILE") 823eda14cbcSMatt Macyif [ -d "$RESULTS_DIR" ]; then 824eda14cbcSMatt Macy cat "$RESULTS_FILE" "$REPORT_FILE" >"$RESULTS_DIR/results" 825eda14cbcSMatt Macyfi 826eda14cbcSMatt Macy 827716fd348SMartin Matuskarm -f "$RESULTS_FILE" "$REPORT_FILE" "$TEST_LIST" "$TEMP_RESULTS_FILE" 828eda14cbcSMatt Macy 829eda14cbcSMatt Macyif [ -n "$SINGLETEST" ]; then 830eda14cbcSMatt Macy rm -f "$RUNFILES" >/dev/null 2>&1 831eda14cbcSMatt Macyfi 832eda14cbcSMatt Macy 833c03c5b1cSMartin Matuska[ "$RUNRESULT" -gt 3 ] && exit "$RUNRESULT" || exit "$RESULT" 834