1eda14cbcSMatt Macy#!/bin/sh 2eda14cbcSMatt Macy# 3eda14cbcSMatt Macy# CDDL HEADER START 4eda14cbcSMatt Macy# 5eda14cbcSMatt Macy# The contents of this file are subject to the terms of the 6eda14cbcSMatt Macy# Common Development and Distribution License, Version 1.0 only 7eda14cbcSMatt Macy# (the "License"). You may not use this file except in compliance 8eda14cbcSMatt Macy# with the License. 9eda14cbcSMatt Macy# 10eda14cbcSMatt Macy# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 11eda14cbcSMatt Macy# or http://www.opensolaris.org/os/licensing. 12eda14cbcSMatt Macy# See the License for the specific language governing permissions 13eda14cbcSMatt Macy# and limitations under the License. 14eda14cbcSMatt Macy# 15eda14cbcSMatt Macy# When distributing Covered Code, include this CDDL HEADER in each 16eda14cbcSMatt Macy# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 17eda14cbcSMatt Macy# If applicable, add the following below this CDDL HEADER, with the 18eda14cbcSMatt Macy# fields enclosed by brackets "[]" replaced with your own identifying 19eda14cbcSMatt Macy# information: Portions Copyright [yyyy] [name of copyright owner] 20eda14cbcSMatt Macy# 21eda14cbcSMatt Macy# CDDL HEADER END 22eda14cbcSMatt Macy# 23eda14cbcSMatt Macy 24eda14cbcSMatt MacyBASE_DIR=$(dirname "$0") 25eda14cbcSMatt MacySCRIPT_COMMON=common.sh 26eda14cbcSMatt Macyif [ -f "${BASE_DIR}/${SCRIPT_COMMON}" ]; then 27eda14cbcSMatt Macy. "${BASE_DIR}/${SCRIPT_COMMON}" 28eda14cbcSMatt Macyelse 29eda14cbcSMatt Macyecho "Missing helper script ${SCRIPT_COMMON}" && exit 1 30eda14cbcSMatt Macyfi 31eda14cbcSMatt Macy 32eda14cbcSMatt MacyPROG=zfs-tests.sh 33eda14cbcSMatt MacyVERBOSE="no" 34eda14cbcSMatt MacyQUIET="" 35eda14cbcSMatt MacyCLEANUP="yes" 36eda14cbcSMatt MacyCLEANUPALL="no" 37eda14cbcSMatt MacyLOOPBACK="yes" 38eda14cbcSMatt MacySTACK_TRACER="no" 39eda14cbcSMatt MacyFILESIZE="4G" 40eda14cbcSMatt MacyDEFAULT_RUNFILES="common.run,$(uname | tr '[:upper:]' '[:lower:]').run" 41eda14cbcSMatt MacyRUNFILES=${RUNFILES:-$DEFAULT_RUNFILES} 42eda14cbcSMatt MacyFILEDIR=${FILEDIR:-/var/tmp} 43eda14cbcSMatt MacyDISKS=${DISKS:-""} 44eda14cbcSMatt MacySINGLETEST="" 45eda14cbcSMatt MacySINGLETESTUSER="root" 46eda14cbcSMatt MacyTAGS="" 47eda14cbcSMatt MacyITERATIONS=1 48eda14cbcSMatt MacyZFS_DBGMSG="$STF_SUITE/callbacks/zfs_dbgmsg.ksh" 49eda14cbcSMatt MacyZFS_DMESG="$STF_SUITE/callbacks/zfs_dmesg.ksh" 50eda14cbcSMatt MacyUNAME=$(uname -s) 51eda14cbcSMatt Macy 52eda14cbcSMatt Macy# Override some defaults if on FreeBSD 53eda14cbcSMatt Macyif [ "$UNAME" = "FreeBSD" ] ; then 54eda14cbcSMatt Macy TESTFAIL_CALLBACKS=${TESTFAIL_CALLBACKS:-"$ZFS_DMESG"} 55eda14cbcSMatt Macy LOSETUP=/sbin/mdconfig 56eda14cbcSMatt Macy DMSETUP=/sbin/gpart 57eda14cbcSMatt Macyelse 58eda14cbcSMatt Macy ZFS_MMP="$STF_SUITE/callbacks/zfs_mmp.ksh" 59eda14cbcSMatt Macy TESTFAIL_CALLBACKS=${TESTFAIL_CALLBACKS:-"$ZFS_DBGMSG:$ZFS_DMESG:$ZFS_MMP"} 60eda14cbcSMatt Macy LOSETUP=${LOSETUP:-/sbin/losetup} 61eda14cbcSMatt Macy DMSETUP=${DMSETUP:-/sbin/dmsetup} 62eda14cbcSMatt Macyfi 63eda14cbcSMatt Macy 64eda14cbcSMatt Macy# 65eda14cbcSMatt Macy# Log an informational message when additional verbosity is enabled. 66eda14cbcSMatt Macy# 67eda14cbcSMatt Macymsg() { 68eda14cbcSMatt Macy if [ "$VERBOSE" = "yes" ]; then 69eda14cbcSMatt Macy echo "$@" 70eda14cbcSMatt Macy fi 71eda14cbcSMatt Macy} 72eda14cbcSMatt Macy 73eda14cbcSMatt Macy# 74eda14cbcSMatt Macy# Log a failure message, cleanup, and return an error. 75eda14cbcSMatt Macy# 76eda14cbcSMatt Macyfail() { 77eda14cbcSMatt Macy echo "$PROG: $1" >&2 78eda14cbcSMatt Macy cleanup 79eda14cbcSMatt Macy exit 1 80eda14cbcSMatt Macy} 81eda14cbcSMatt Macy 82eda14cbcSMatt Macycleanup_freebsd_loopback() { 83eda14cbcSMatt Macy for TEST_LOOPBACK in ${LOOPBACKS}; do 84eda14cbcSMatt Macy if [ -c "/dev/${TEST_LOOPBACK}" ]; then 85eda14cbcSMatt Macy sudo "${LOSETUP}" -d -u "${TEST_LOOPBACK}" || 86eda14cbcSMatt Macy echo "Failed to destroy: ${TEST_LOOPBACK}" 87eda14cbcSMatt Macy fi 88eda14cbcSMatt Macy done 89eda14cbcSMatt Macy} 90eda14cbcSMatt Macy 91eda14cbcSMatt Macycleanup_linux_loopback() { 92eda14cbcSMatt Macy for TEST_LOOPBACK in ${LOOPBACKS}; do 93eda14cbcSMatt Macy LOOP_DEV=$(basename "$TEST_LOOPBACK") 94eda14cbcSMatt Macy DM_DEV=$(sudo "${DMSETUP}" ls 2>/dev/null | \ 95eda14cbcSMatt Macy grep "${LOOP_DEV}" | cut -f1) 96eda14cbcSMatt Macy 97eda14cbcSMatt Macy if [ -n "$DM_DEV" ]; then 98eda14cbcSMatt Macy sudo "${DMSETUP}" remove "${DM_DEV}" || 99eda14cbcSMatt Macy echo "Failed to remove: ${DM_DEV}" 100eda14cbcSMatt Macy fi 101eda14cbcSMatt Macy 102eda14cbcSMatt Macy if [ -n "${TEST_LOOPBACK}" ]; then 103eda14cbcSMatt Macy sudo "${LOSETUP}" -d "${TEST_LOOPBACK}" || 104eda14cbcSMatt Macy echo "Failed to remove: ${TEST_LOOPBACK}" 105eda14cbcSMatt Macy fi 106eda14cbcSMatt Macy done 107eda14cbcSMatt Macy} 108eda14cbcSMatt Macy 109eda14cbcSMatt Macy# 110eda14cbcSMatt Macy# Attempt to remove loopback devices and files which where created earlier 111eda14cbcSMatt Macy# by this script to run the test framework. The '-k' option may be passed 112eda14cbcSMatt Macy# to the script to suppress cleanup for debugging purposes. 113eda14cbcSMatt Macy# 114eda14cbcSMatt Macycleanup() { 115eda14cbcSMatt Macy if [ "$CLEANUP" = "no" ]; then 116eda14cbcSMatt Macy return 0 117eda14cbcSMatt Macy fi 118eda14cbcSMatt Macy 119eda14cbcSMatt Macy 120eda14cbcSMatt Macy if [ "$LOOPBACK" = "yes" ]; then 121eda14cbcSMatt Macy if [ "$UNAME" = "FreeBSD" ] ; then 122eda14cbcSMatt Macy cleanup_freebsd_loopback 123eda14cbcSMatt Macy else 124eda14cbcSMatt Macy cleanup_linux_loopback 125eda14cbcSMatt Macy fi 126eda14cbcSMatt Macy fi 127eda14cbcSMatt Macy 128eda14cbcSMatt Macy for TEST_FILE in ${FILES}; do 129eda14cbcSMatt Macy rm -f "${TEST_FILE}" >/dev/null 2>&1 130eda14cbcSMatt Macy done 131eda14cbcSMatt Macy 132eda14cbcSMatt Macy if [ "$STF_PATH_REMOVE" = "yes" ] && [ -d "$STF_PATH" ]; then 133eda14cbcSMatt Macy rm -Rf "$STF_PATH" 134eda14cbcSMatt Macy fi 135eda14cbcSMatt Macy} 136eda14cbcSMatt Macytrap cleanup EXIT 137eda14cbcSMatt Macy 138eda14cbcSMatt Macy# 139eda14cbcSMatt Macy# Attempt to remove all testpools (testpool.XXX), unopened dm devices, 140eda14cbcSMatt Macy# loopback devices, and files. This is a useful way to cleanup a previous 141eda14cbcSMatt Macy# test run failure which has left the system in an unknown state. This can 142eda14cbcSMatt Macy# be dangerous and should only be used in a dedicated test environment. 143eda14cbcSMatt Macy# 144eda14cbcSMatt Macycleanup_all() { 145eda14cbcSMatt Macy TEST_POOLS=$(sudo "$ZPOOL" list -H -o name | grep testpool) 146eda14cbcSMatt Macy if [ "$UNAME" = "FreeBSD" ] ; then 147eda14cbcSMatt Macy TEST_LOOPBACKS=$(sudo "${LOSETUP}" -l) 148eda14cbcSMatt Macy else 149eda14cbcSMatt Macy TEST_LOOPBACKS=$(sudo "${LOSETUP}" -a|grep file-vdev|cut -f1 -d:) 150eda14cbcSMatt Macy fi 151eda14cbcSMatt Macy TEST_FILES=$(ls /var/tmp/file-vdev* 2>/dev/null) 152eda14cbcSMatt Macy 153eda14cbcSMatt Macy msg 154eda14cbcSMatt Macy msg "--- Cleanup ---" 155eda14cbcSMatt Macy msg "Removing pool(s): $(echo "${TEST_POOLS}" | tr '\n' ' ')" 156eda14cbcSMatt Macy for TEST_POOL in $TEST_POOLS; do 157eda14cbcSMatt Macy sudo "$ZPOOL" destroy "${TEST_POOL}" 158eda14cbcSMatt Macy done 159eda14cbcSMatt Macy 160eda14cbcSMatt Macy if [ "$UNAME" != "FreeBSD" ] ; then 161eda14cbcSMatt Macy msg "Removing dm(s): $(sudo "${DMSETUP}" ls | 162eda14cbcSMatt Macy grep loop | tr '\n' ' ')" 163eda14cbcSMatt Macy sudo "${DMSETUP}" remove_all 164eda14cbcSMatt Macy fi 165eda14cbcSMatt Macy 166eda14cbcSMatt Macy msg "Removing loopback(s): $(echo "${TEST_LOOPBACKS}" | tr '\n' ' ')" 167eda14cbcSMatt Macy for TEST_LOOPBACK in $TEST_LOOPBACKS; do 168eda14cbcSMatt Macy if [ "$UNAME" = "FreeBSD" ] ; then 169eda14cbcSMatt Macy sudo "${LOSETUP}" -d -u "${TEST_LOOPBACK}" 170eda14cbcSMatt Macy else 171eda14cbcSMatt Macy sudo "${LOSETUP}" -d "${TEST_LOOPBACK}" 172eda14cbcSMatt Macy fi 173eda14cbcSMatt Macy done 174eda14cbcSMatt Macy 175eda14cbcSMatt Macy msg "Removing files(s): $(echo "${TEST_FILES}" | tr '\n' ' ')" 176eda14cbcSMatt Macy for TEST_FILE in $TEST_FILES; do 177eda14cbcSMatt Macy sudo rm -f "${TEST_FILE}" 178eda14cbcSMatt Macy done 179eda14cbcSMatt Macy} 180eda14cbcSMatt Macy 181eda14cbcSMatt Macy# 182eda14cbcSMatt Macy# Takes a name as the only arguments and looks for the following variations 183eda14cbcSMatt Macy# on that name. If one is found it is returned. 184eda14cbcSMatt Macy# 185eda14cbcSMatt Macy# $RUNFILE_DIR/<name> 186eda14cbcSMatt Macy# $RUNFILE_DIR/<name>.run 187eda14cbcSMatt Macy# <name> 188eda14cbcSMatt Macy# <name>.run 189eda14cbcSMatt Macy# 190eda14cbcSMatt Macyfind_runfile() { 191eda14cbcSMatt Macy NAME=$1 192eda14cbcSMatt Macy RESULT="" 193eda14cbcSMatt Macy 194eda14cbcSMatt Macy if [ -f "$RUNFILE_DIR/$NAME" ]; then 195eda14cbcSMatt Macy RESULT="$RUNFILE_DIR/$NAME" 196eda14cbcSMatt Macy elif [ -f "$RUNFILE_DIR/$NAME.run" ]; then 197eda14cbcSMatt Macy RESULT="$RUNFILE_DIR/$NAME.run" 198eda14cbcSMatt Macy elif [ -f "$NAME" ]; then 199eda14cbcSMatt Macy RESULT="$NAME" 200eda14cbcSMatt Macy elif [ -f "$NAME.run" ]; then 201eda14cbcSMatt Macy RESULT="$NAME.run" 202eda14cbcSMatt Macy fi 203eda14cbcSMatt Macy 204eda14cbcSMatt Macy echo "$RESULT" 205eda14cbcSMatt Macy} 206eda14cbcSMatt Macy 207eda14cbcSMatt Macy# 208eda14cbcSMatt Macy# Symlink file if it appears under any of the given paths. 209eda14cbcSMatt Macy# 210eda14cbcSMatt Macycreate_links() { 211eda14cbcSMatt Macy dir_list="$1" 212eda14cbcSMatt Macy file_list="$2" 213eda14cbcSMatt Macy 214eda14cbcSMatt Macy [ -n "$STF_PATH" ] || fail "STF_PATH wasn't correctly set" 215eda14cbcSMatt Macy 216eda14cbcSMatt Macy for i in $file_list; do 217eda14cbcSMatt Macy for j in $dir_list; do 218eda14cbcSMatt Macy [ ! -e "$STF_PATH/$i" ] || continue 219eda14cbcSMatt Macy 220eda14cbcSMatt Macy if [ ! -d "$j/$i" ] && [ -e "$j/$i" ]; then 221eda14cbcSMatt Macy ln -sf "$j/$i" "$STF_PATH/$i" || \ 222eda14cbcSMatt Macy fail "Couldn't link $i" 223eda14cbcSMatt Macy break 224eda14cbcSMatt Macy fi 225eda14cbcSMatt Macy done 226eda14cbcSMatt Macy 227eda14cbcSMatt Macy [ ! -e "$STF_PATH/$i" ] && \ 228eda14cbcSMatt Macy STF_MISSING_BIN="$STF_MISSING_BIN $i" 229eda14cbcSMatt Macy done 230eda14cbcSMatt Macy STF_MISSING_BIN=${STF_MISSING_BIN# } 231eda14cbcSMatt Macy} 232eda14cbcSMatt Macy 233eda14cbcSMatt Macy# 234eda14cbcSMatt Macy# Constrain the path to limit the available binaries to a known set. 235eda14cbcSMatt Macy# When running in-tree a top level ./bin/ directory is created for 236eda14cbcSMatt Macy# convenience, otherwise a temporary directory is used. 237eda14cbcSMatt Macy# 238eda14cbcSMatt Macyconstrain_path() { 239eda14cbcSMatt Macy . "$STF_SUITE/include/commands.cfg" 240eda14cbcSMatt Macy 241eda14cbcSMatt Macy # On FreeBSD, base system zfs utils are in /sbin and OpenZFS utils 242eda14cbcSMatt Macy # install to /usr/local/sbin. To avoid testing the wrong utils we 243eda14cbcSMatt Macy # need /usr/local to come before / in the path search order. 244eda14cbcSMatt Macy SYSTEM_DIRS="/usr/local/bin /usr/local/sbin" 2457877fdebSMatt Macy SYSTEM_DIRS="$SYSTEM_DIRS /usr/bin /usr/sbin /bin /sbin $LIBEXEC_DIR" 246eda14cbcSMatt Macy 247eda14cbcSMatt Macy if [ "$INTREE" = "yes" ]; then 248eda14cbcSMatt Macy # Constrained path set to ./zfs/bin/ 249eda14cbcSMatt Macy STF_PATH="$BIN_DIR" 250eda14cbcSMatt Macy STF_PATH_REMOVE="no" 251eda14cbcSMatt Macy STF_MISSING_BIN="" 252eda14cbcSMatt Macy if [ ! -d "$STF_PATH" ]; then 253eda14cbcSMatt Macy mkdir "$STF_PATH" 254eda14cbcSMatt Macy chmod 755 "$STF_PATH" || fail "Couldn't chmod $STF_PATH" 255eda14cbcSMatt Macy fi 256eda14cbcSMatt Macy 257eda14cbcSMatt Macy # Special case links for standard zfs utilities 258eda14cbcSMatt Macy DIRS="$(find "$CMD_DIR" -type d \( ! -name .deps -a \ 259eda14cbcSMatt Macy ! -name .libs \) -print | tr '\n' ' ')" 260eda14cbcSMatt Macy create_links "$DIRS" "$ZFS_FILES" 261eda14cbcSMatt Macy 262eda14cbcSMatt Macy # Special case links for zfs test suite utilities 263eda14cbcSMatt Macy DIRS="$(find "$STF_SUITE" -type d \( ! -name .deps -a \ 264eda14cbcSMatt Macy ! -name .libs \) -print | tr '\n' ' ')" 265eda14cbcSMatt Macy create_links "$DIRS" "$ZFSTEST_FILES" 266eda14cbcSMatt Macy else 267eda14cbcSMatt Macy # Constrained path set to /var/tmp/constrained_path.* 2687877fdebSMatt Macy SYSTEMDIR=${SYSTEMDIR:-/var/tmp/constrained_path.XXXXXX} 269eda14cbcSMatt Macy STF_PATH=$(mktemp -d "$SYSTEMDIR") 270eda14cbcSMatt Macy STF_PATH_REMOVE="yes" 271eda14cbcSMatt Macy STF_MISSING_BIN="" 272eda14cbcSMatt Macy 273eda14cbcSMatt Macy chmod 755 "$STF_PATH" || fail "Couldn't chmod $STF_PATH" 274eda14cbcSMatt Macy 275eda14cbcSMatt Macy # Special case links for standard zfs utilities 276eda14cbcSMatt Macy create_links "$SYSTEM_DIRS" "$ZFS_FILES" 277eda14cbcSMatt Macy 278eda14cbcSMatt Macy # Special case links for zfs test suite utilities 279eda14cbcSMatt Macy create_links "$STF_SUITE/bin" "$ZFSTEST_FILES" 280eda14cbcSMatt Macy fi 281eda14cbcSMatt Macy 282eda14cbcSMatt Macy # Standard system utilities 283eda14cbcSMatt Macy SYSTEM_FILES="$SYSTEM_FILES_COMMON" 284eda14cbcSMatt Macy if [ "$UNAME" = "FreeBSD" ] ; then 285eda14cbcSMatt Macy SYSTEM_FILES="$SYSTEM_FILES $SYSTEM_FILES_FREEBSD" 286eda14cbcSMatt Macy else 287eda14cbcSMatt Macy SYSTEM_FILES="$SYSTEM_FILES $SYSTEM_FILES_LINUX" 288eda14cbcSMatt Macy fi 289eda14cbcSMatt Macy create_links "$SYSTEM_DIRS" "$SYSTEM_FILES" 290eda14cbcSMatt Macy 291eda14cbcSMatt Macy # Exceptions 292eda14cbcSMatt Macy ln -fs "$STF_PATH/awk" "$STF_PATH/nawk" 293eda14cbcSMatt Macy if [ "$UNAME" = "Linux" ] ; then 294eda14cbcSMatt Macy ln -fs /sbin/fsck.ext4 "$STF_PATH/fsck" 295eda14cbcSMatt Macy ln -fs /sbin/mkfs.ext4 "$STF_PATH/newfs" 296eda14cbcSMatt Macy ln -fs "$STF_PATH/gzip" "$STF_PATH/compress" 297eda14cbcSMatt Macy ln -fs "$STF_PATH/gunzip" "$STF_PATH/uncompress" 298eda14cbcSMatt Macy ln -fs "$STF_PATH/exportfs" "$STF_PATH/share" 299eda14cbcSMatt Macy ln -fs "$STF_PATH/exportfs" "$STF_PATH/unshare" 300eda14cbcSMatt Macy elif [ "$UNAME" = "FreeBSD" ] ; then 301eda14cbcSMatt Macy ln -fs /usr/local/bin/ksh93 "$STF_PATH/ksh" 302eda14cbcSMatt Macy fi 303eda14cbcSMatt Macy} 304eda14cbcSMatt Macy 305eda14cbcSMatt Macy# 306eda14cbcSMatt Macy# Output a useful usage message. 307eda14cbcSMatt Macy# 308eda14cbcSMatt Macyusage() { 309eda14cbcSMatt Macycat << EOF 310eda14cbcSMatt MacyUSAGE: 3112c48331dSMatt Macy$0 [-hvqxkfS] [-s SIZE] [-r RUNFILES] [-t PATH] [-u USER] 312eda14cbcSMatt Macy 313eda14cbcSMatt MacyDESCRIPTION: 314eda14cbcSMatt Macy ZFS Test Suite launch script 315eda14cbcSMatt Macy 316eda14cbcSMatt MacyOPTIONS: 317eda14cbcSMatt Macy -h Show this message 318eda14cbcSMatt Macy -v Verbose zfs-tests.sh output 319eda14cbcSMatt Macy -q Quiet test-runner output 320eda14cbcSMatt Macy -x Remove all testpools, dm, lo, and files (unsafe) 321eda14cbcSMatt Macy -k Disable cleanup after test failure 322eda14cbcSMatt Macy -f Use files only, disables block device tests 323eda14cbcSMatt Macy -S Enable stack tracer (negative performance impact) 324eda14cbcSMatt Macy -c Only create and populate constrained path 325eda14cbcSMatt Macy -n NFSFILE Use the nfsfile to determine the NFS configuration 326eda14cbcSMatt Macy -I NUM Number of iterations 327eda14cbcSMatt Macy -d DIR Use DIR for files and loopback devices 328eda14cbcSMatt Macy -s SIZE Use vdevs of SIZE (default: 4G) 329eda14cbcSMatt Macy -r RUNFILES Run tests in RUNFILES (default: ${DEFAULT_RUNFILES}) 330eda14cbcSMatt Macy -t PATH Run single test at PATH relative to test suite 331eda14cbcSMatt Macy -T TAGS Comma separated list of tags (default: 'functional') 332eda14cbcSMatt Macy -u USER Run single test as USER (default: root) 333eda14cbcSMatt Macy 334eda14cbcSMatt MacyEXAMPLES: 335eda14cbcSMatt Macy# Run the default (linux) suite of tests and output the configuration used. 336eda14cbcSMatt Macy$0 -v 337eda14cbcSMatt Macy 338eda14cbcSMatt Macy# Run a smaller suite of tests designed to run more quickly. 339eda14cbcSMatt Macy$0 -r linux-fast 340eda14cbcSMatt Macy 341eda14cbcSMatt Macy# Run a single test 342eda14cbcSMatt Macy$0 -t tests/functional/cli_root/zfs_bookmark/zfs_bookmark_cliargs.ksh 343eda14cbcSMatt Macy 344eda14cbcSMatt Macy# Cleanup a previous run of the test suite prior to testing, run the 345eda14cbcSMatt Macy# default (linux) suite of tests and perform no cleanup on exit. 346eda14cbcSMatt Macy$0 -x 347eda14cbcSMatt Macy 348eda14cbcSMatt MacyEOF 349eda14cbcSMatt Macy} 350eda14cbcSMatt Macy 351eda14cbcSMatt Macywhile getopts 'hvqxkfScn:d:s:r:?t:T:u:I:' OPTION; do 352eda14cbcSMatt Macy case $OPTION in 353eda14cbcSMatt Macy h) 354eda14cbcSMatt Macy usage 355eda14cbcSMatt Macy exit 1 356eda14cbcSMatt Macy ;; 357eda14cbcSMatt Macy v) 358eda14cbcSMatt Macy VERBOSE="yes" 359eda14cbcSMatt Macy ;; 360eda14cbcSMatt Macy q) 361eda14cbcSMatt Macy QUIET="yes" 362eda14cbcSMatt Macy ;; 363eda14cbcSMatt Macy x) 364eda14cbcSMatt Macy CLEANUPALL="yes" 365eda14cbcSMatt Macy ;; 366eda14cbcSMatt Macy k) 367eda14cbcSMatt Macy CLEANUP="no" 368eda14cbcSMatt Macy ;; 369eda14cbcSMatt Macy f) 370eda14cbcSMatt Macy LOOPBACK="no" 371eda14cbcSMatt Macy ;; 372eda14cbcSMatt Macy S) 373eda14cbcSMatt Macy STACK_TRACER="yes" 374eda14cbcSMatt Macy ;; 375eda14cbcSMatt Macy c) 376eda14cbcSMatt Macy constrain_path 377eda14cbcSMatt Macy exit 378eda14cbcSMatt Macy ;; 379eda14cbcSMatt Macy n) 380eda14cbcSMatt Macy nfsfile=$OPTARG 381eda14cbcSMatt Macy [ -f "$nfsfile" ] || fail "Cannot read file: $nfsfile" 382eda14cbcSMatt Macy export NFS=1 383eda14cbcSMatt Macy . "$nfsfile" 384eda14cbcSMatt Macy ;; 385eda14cbcSMatt Macy d) 386eda14cbcSMatt Macy FILEDIR="$OPTARG" 387eda14cbcSMatt Macy ;; 388eda14cbcSMatt Macy I) 389eda14cbcSMatt Macy ITERATIONS="$OPTARG" 390eda14cbcSMatt Macy if [ "$ITERATIONS" -le 0 ]; then 391eda14cbcSMatt Macy fail "Iterations must be greater than 0." 392eda14cbcSMatt Macy fi 393eda14cbcSMatt Macy ;; 394eda14cbcSMatt Macy s) 395eda14cbcSMatt Macy FILESIZE="$OPTARG" 396eda14cbcSMatt Macy ;; 397eda14cbcSMatt Macy r) 398eda14cbcSMatt Macy RUNFILES="$OPTARG" 399eda14cbcSMatt Macy ;; 400eda14cbcSMatt Macy t) 401eda14cbcSMatt Macy if [ -n "$SINGLETEST" ]; then 402eda14cbcSMatt Macy fail "-t can only be provided once." 403eda14cbcSMatt Macy fi 404eda14cbcSMatt Macy SINGLETEST="$OPTARG" 405eda14cbcSMatt Macy ;; 406eda14cbcSMatt Macy T) 407eda14cbcSMatt Macy TAGS="$OPTARG" 408eda14cbcSMatt Macy ;; 409eda14cbcSMatt Macy u) 410eda14cbcSMatt Macy SINGLETESTUSER="$OPTARG" 411eda14cbcSMatt Macy ;; 412eda14cbcSMatt Macy ?) 413eda14cbcSMatt Macy usage 414eda14cbcSMatt Macy exit 415eda14cbcSMatt Macy ;; 416eda14cbcSMatt Macy esac 417eda14cbcSMatt Macydone 418eda14cbcSMatt Macy 419eda14cbcSMatt Macyshift $((OPTIND-1)) 420eda14cbcSMatt Macy 421eda14cbcSMatt MacyFILES=${FILES:-"$FILEDIR/file-vdev0 $FILEDIR/file-vdev1 $FILEDIR/file-vdev2"} 422eda14cbcSMatt MacyLOOPBACKS=${LOOPBACKS:-""} 423eda14cbcSMatt Macy 424eda14cbcSMatt Macyif [ -n "$SINGLETEST" ]; then 425eda14cbcSMatt Macy if [ -n "$TAGS" ]; then 426eda14cbcSMatt Macy fail "-t and -T are mutually exclusive." 427eda14cbcSMatt Macy fi 428eda14cbcSMatt Macy RUNFILE_DIR="/var/tmp" 429eda14cbcSMatt Macy RUNFILES="zfs-tests.$$.run" 430eda14cbcSMatt Macy SINGLEQUIET="False" 431eda14cbcSMatt Macy 432eda14cbcSMatt Macy if [ -n "$QUIET" ]; then 433eda14cbcSMatt Macy SINGLEQUIET="True" 434eda14cbcSMatt Macy fi 435eda14cbcSMatt Macy 436eda14cbcSMatt Macy cat >$RUNFILE_DIR/$RUNFILES << EOF 437eda14cbcSMatt Macy[DEFAULT] 438eda14cbcSMatt Macypre = 439eda14cbcSMatt Macyquiet = $SINGLEQUIET 440eda14cbcSMatt Macypre_user = root 441eda14cbcSMatt Macyuser = $SINGLETESTUSER 442eda14cbcSMatt Macytimeout = 600 443eda14cbcSMatt Macypost_user = root 444eda14cbcSMatt Macypost = 445eda14cbcSMatt Macyoutputdir = /var/tmp/test_results 446eda14cbcSMatt MacyEOF 447eda14cbcSMatt Macy SINGLETESTDIR=$(dirname "$SINGLETEST") 448eda14cbcSMatt Macy SINGLETESTFILE=$(basename "$SINGLETEST") 449eda14cbcSMatt Macy SETUPSCRIPT= 450eda14cbcSMatt Macy CLEANUPSCRIPT= 451eda14cbcSMatt Macy 452eda14cbcSMatt Macy if [ -f "$STF_SUITE/$SINGLETESTDIR/setup.ksh" ]; then 453eda14cbcSMatt Macy SETUPSCRIPT="setup" 454eda14cbcSMatt Macy fi 455eda14cbcSMatt Macy 456eda14cbcSMatt Macy if [ -f "$STF_SUITE/$SINGLETESTDIR/cleanup.ksh" ]; then 457eda14cbcSMatt Macy CLEANUPSCRIPT="cleanup" 458eda14cbcSMatt Macy fi 459eda14cbcSMatt Macy 460eda14cbcSMatt Macy cat >>$RUNFILE_DIR/$RUNFILES << EOF 461eda14cbcSMatt Macy 462eda14cbcSMatt Macy[$SINGLETESTDIR] 463eda14cbcSMatt Macytests = ['$SINGLETESTFILE'] 464eda14cbcSMatt Macypre = $SETUPSCRIPT 465eda14cbcSMatt Macypost = $CLEANUPSCRIPT 466eda14cbcSMatt Macytags = ['functional'] 467eda14cbcSMatt MacyEOF 468eda14cbcSMatt Macyfi 469eda14cbcSMatt Macy 470eda14cbcSMatt Macy# 471eda14cbcSMatt Macy# Use default tag if none was specified 472eda14cbcSMatt Macy# 473eda14cbcSMatt MacyTAGS=${TAGS:='functional'} 474eda14cbcSMatt Macy 475eda14cbcSMatt Macy# 476eda14cbcSMatt Macy# Attempt to locate the runfiles describing the test workload. 477eda14cbcSMatt Macy# 478eda14cbcSMatt MacyR="" 479eda14cbcSMatt MacyIFS=, 480eda14cbcSMatt Macyfor RUNFILE in $RUNFILES; do 481eda14cbcSMatt Macy if [ -n "$RUNFILE" ]; then 482eda14cbcSMatt Macy SAVED_RUNFILE="$RUNFILE" 483eda14cbcSMatt Macy RUNFILE=$(find_runfile "$RUNFILE") 484eda14cbcSMatt Macy [ -z "$RUNFILE" ] && fail "Cannot find runfile: $SAVED_RUNFILE" 485eda14cbcSMatt Macy R="$R,$RUNFILE" 486eda14cbcSMatt Macy fi 487eda14cbcSMatt Macy 488eda14cbcSMatt Macy if [ ! -r "$RUNFILE" ]; then 489eda14cbcSMatt Macy fail "Cannot read runfile: $RUNFILE" 490eda14cbcSMatt Macy fi 491eda14cbcSMatt Macydone 492eda14cbcSMatt Macyunset IFS 493eda14cbcSMatt MacyRUNFILES=${R#,} 494eda14cbcSMatt Macy 495eda14cbcSMatt Macy# 496eda14cbcSMatt Macy# This script should not be run as root. Instead the test user, which may 497eda14cbcSMatt Macy# be a normal user account, needs to be configured such that it can 498eda14cbcSMatt Macy# run commands via sudo passwordlessly. 499eda14cbcSMatt Macy# 500eda14cbcSMatt Macyif [ "$(id -u)" = "0" ]; then 501eda14cbcSMatt Macy fail "This script must not be run as root." 502eda14cbcSMatt Macyfi 503eda14cbcSMatt Macy 504eda14cbcSMatt Macyif [ "$(sudo whoami)" != "root" ]; then 505eda14cbcSMatt Macy fail "Passwordless sudo access required." 506eda14cbcSMatt Macyfi 507eda14cbcSMatt Macy 508eda14cbcSMatt Macy# 509eda14cbcSMatt Macy# Constrain the available binaries to a known set. 510eda14cbcSMatt Macy# 511eda14cbcSMatt Macyconstrain_path 512eda14cbcSMatt Macy 513eda14cbcSMatt Macy# 514eda14cbcSMatt Macy# Check if ksh exists 515eda14cbcSMatt Macy# 516eda14cbcSMatt Macyif [ "$UNAME" = "FreeBSD" ]; then 517eda14cbcSMatt Macy sudo ln -fs /usr/local/bin/ksh93 /bin/ksh 518eda14cbcSMatt Macyfi 519eda14cbcSMatt Macy[ -e "$STF_PATH/ksh" ] || fail "This test suite requires ksh." 520eda14cbcSMatt Macy[ -e "$STF_SUITE/include/default.cfg" ] || fail \ 521eda14cbcSMatt Macy "Missing $STF_SUITE/include/default.cfg file." 522eda14cbcSMatt Macy 523eda14cbcSMatt Macy# 524eda14cbcSMatt Macy# Verify the ZFS module stack is loaded. 525eda14cbcSMatt Macy# 526eda14cbcSMatt Macyif [ "$STACK_TRACER" = "yes" ]; then 527eda14cbcSMatt Macy sudo "${ZFS_SH}" -S >/dev/null 2>&1 528eda14cbcSMatt Macyelse 529eda14cbcSMatt Macy sudo "${ZFS_SH}" >/dev/null 2>&1 530eda14cbcSMatt Macyfi 531eda14cbcSMatt Macy 532eda14cbcSMatt Macy# 533eda14cbcSMatt Macy# Attempt to cleanup all previous state for a new test run. 534eda14cbcSMatt Macy# 535eda14cbcSMatt Macyif [ "$CLEANUPALL" = "yes" ]; then 536eda14cbcSMatt Macy cleanup_all 537eda14cbcSMatt Macyfi 538eda14cbcSMatt Macy 539eda14cbcSMatt Macy# 540eda14cbcSMatt Macy# By default preserve any existing pools 541eda14cbcSMatt Macy# NOTE: Since 'zpool list' outputs a newline-delimited list convert $KEEP from 542eda14cbcSMatt Macy# space-delimited to newline-delimited. 543eda14cbcSMatt Macy# 544eda14cbcSMatt Macyif [ -z "${KEEP}" ]; then 545eda14cbcSMatt Macy KEEP="$(sudo "$ZPOOL" list -H -o name)" 546eda14cbcSMatt Macy if [ -z "${KEEP}" ]; then 547eda14cbcSMatt Macy KEEP="rpool" 548eda14cbcSMatt Macy fi 549eda14cbcSMatt Macyelse 550eda14cbcSMatt Macy KEEP="$(echo "$KEEP" | tr '[:blank:]' '\n')" 551eda14cbcSMatt Macyfi 552eda14cbcSMatt Macy 553eda14cbcSMatt Macy# 554eda14cbcSMatt Macy# NOTE: The following environment variables are undocumented 555eda14cbcSMatt Macy# and should be used for testing purposes only: 556eda14cbcSMatt Macy# 557eda14cbcSMatt Macy# __ZFS_POOL_EXCLUDE - don't iterate over the pools it lists 558eda14cbcSMatt Macy# __ZFS_POOL_RESTRICT - iterate only over the pools it lists 559eda14cbcSMatt Macy# 560eda14cbcSMatt Macy# See libzfs/libzfs_config.c for more information. 561eda14cbcSMatt Macy# 562eda14cbcSMatt Macyif [ "$UNAME" = "FreeBSD" ] ; then 563eda14cbcSMatt Macy __ZFS_POOL_EXCLUDE="$(echo "$KEEP" | tr -s '\n' ' ')" 564eda14cbcSMatt Macyelse 565eda14cbcSMatt Macy __ZFS_POOL_EXCLUDE="$(echo "$KEEP" | sed ':a;N;s/\n/ /g;ba')" 566eda14cbcSMatt Macyfi 567eda14cbcSMatt Macy 568eda14cbcSMatt Macy. "$STF_SUITE/include/default.cfg" 569eda14cbcSMatt Macy 570eda14cbcSMatt Macy# 571eda14cbcSMatt Macy# No DISKS have been provided so a basic file or loopback based devices 572eda14cbcSMatt Macy# must be created for the test suite to use. 573eda14cbcSMatt Macy# 574eda14cbcSMatt Macyif [ -z "${DISKS}" ]; then 575eda14cbcSMatt Macy # 576*1f88aa09SMartin Matuska # If this is a performance run, prevent accidental use of 577*1f88aa09SMartin Matuska # loopback devices. 578*1f88aa09SMartin Matuska # 579*1f88aa09SMartin Matuska [ "$TAGS" = "perf" ] && fail "Running perf tests without disks." 580*1f88aa09SMartin Matuska 581*1f88aa09SMartin Matuska # 582eda14cbcSMatt Macy # Create sparse files for the test suite. These may be used 583eda14cbcSMatt Macy # directory or have loopback devices layered on them. 584eda14cbcSMatt Macy # 585eda14cbcSMatt Macy for TEST_FILE in ${FILES}; do 586eda14cbcSMatt Macy [ -f "$TEST_FILE" ] && fail "Failed file exists: ${TEST_FILE}" 587eda14cbcSMatt Macy truncate -s "${FILESIZE}" "${TEST_FILE}" || 588eda14cbcSMatt Macy fail "Failed creating: ${TEST_FILE} ($?)" 589eda14cbcSMatt Macy done 590eda14cbcSMatt Macy 591eda14cbcSMatt Macy # 592eda14cbcSMatt Macy # If requested setup loopback devices backed by the sparse files. 593eda14cbcSMatt Macy # 594eda14cbcSMatt Macy if [ "$LOOPBACK" = "yes" ]; then 595eda14cbcSMatt Macy test -x "$LOSETUP" || fail "$LOSETUP utility must be installed" 596eda14cbcSMatt Macy 597eda14cbcSMatt Macy for TEST_FILE in ${FILES}; do 598eda14cbcSMatt Macy if [ "$UNAME" = "FreeBSD" ] ; then 599eda14cbcSMatt Macy MDDEVICE=$(sudo "${LOSETUP}" -a -t vnode -f "${TEST_FILE}") 600eda14cbcSMatt Macy if [ -z "$MDDEVICE" ] ; then 601eda14cbcSMatt Macy fail "Failed: ${TEST_FILE} -> loopback" 602eda14cbcSMatt Macy fi 603eda14cbcSMatt Macy DISKS="$DISKS $MDDEVICE" 604eda14cbcSMatt Macy LOOPBACKS="$LOOPBACKS $MDDEVICE" 605eda14cbcSMatt Macy else 606eda14cbcSMatt Macy TEST_LOOPBACK=$(sudo "${LOSETUP}" -f) 607eda14cbcSMatt Macy sudo "${LOSETUP}" "${TEST_LOOPBACK}" "${TEST_FILE}" || 608eda14cbcSMatt Macy fail "Failed: ${TEST_FILE} -> ${TEST_LOOPBACK}" 609eda14cbcSMatt Macy BASELOOPBACK=$(basename "$TEST_LOOPBACK") 610eda14cbcSMatt Macy DISKS="$DISKS $BASELOOPBACK" 611eda14cbcSMatt Macy LOOPBACKS="$LOOPBACKS $TEST_LOOPBACK" 612eda14cbcSMatt Macy fi 613eda14cbcSMatt Macy done 614eda14cbcSMatt Macy DISKS=${DISKS# } 615eda14cbcSMatt Macy LOOPBACKS=${LOOPBACKS# } 616eda14cbcSMatt Macy else 617eda14cbcSMatt Macy DISKS="$FILES" 618eda14cbcSMatt Macy fi 619eda14cbcSMatt Macyfi 620eda14cbcSMatt Macy 621*1f88aa09SMartin Matuska# 622*1f88aa09SMartin Matuska# It may be desirable to test with fewer disks than the default when running 623*1f88aa09SMartin Matuska# the performance tests, but the functional tests require at least three. 624*1f88aa09SMartin Matuska# 625eda14cbcSMatt MacyNUM_DISKS=$(echo "${DISKS}" | awk '{print NF}') 626*1f88aa09SMartin Matuskaif [ "$TAGS" != "perf" ]; then 627eda14cbcSMatt Macy [ "$NUM_DISKS" -lt 3 ] && fail "Not enough disks ($NUM_DISKS/3 minimum)" 628*1f88aa09SMartin Matuskafi 629eda14cbcSMatt Macy 630eda14cbcSMatt Macy# 631eda14cbcSMatt Macy# Disable SELinux until the ZFS Test Suite has been updated accordingly. 632eda14cbcSMatt Macy# 633eda14cbcSMatt Macyif [ -x "$STF_PATH/setenforce" ]; then 634eda14cbcSMatt Macy sudo setenforce permissive >/dev/null 2>&1 635eda14cbcSMatt Macyfi 636eda14cbcSMatt Macy 637eda14cbcSMatt Macy# 638eda14cbcSMatt Macy# Enable internal ZFS debug log and clear it. 639eda14cbcSMatt Macy# 640eda14cbcSMatt Macyif [ -e /sys/module/zfs/parameters/zfs_dbgmsg_enable ]; then 641eda14cbcSMatt Macy sudo /bin/sh -c "echo 1 >/sys/module/zfs/parameters/zfs_dbgmsg_enable" 642eda14cbcSMatt Macy sudo /bin/sh -c "echo 0 >/proc/spl/kstat/zfs/dbgmsg" 643eda14cbcSMatt Macyfi 644eda14cbcSMatt Macy 645*1f88aa09SMartin Matuskamsg 646*1f88aa09SMartin Matuskamsg "--- Configuration ---" 647*1f88aa09SMartin Matuskamsg "Runfiles: $RUNFILES" 648*1f88aa09SMartin Matuskamsg "STF_TOOLS: $STF_TOOLS" 649*1f88aa09SMartin Matuskamsg "STF_SUITE: $STF_SUITE" 650*1f88aa09SMartin Matuskamsg "STF_PATH: $STF_PATH" 651eda14cbcSMatt Macymsg "FILEDIR: $FILEDIR" 652eda14cbcSMatt Macymsg "FILES: $FILES" 653eda14cbcSMatt Macymsg "LOOPBACKS: $LOOPBACKS" 654eda14cbcSMatt Macymsg "DISKS: $DISKS" 655eda14cbcSMatt Macymsg "NUM_DISKS: $NUM_DISKS" 656eda14cbcSMatt Macymsg "FILESIZE: $FILESIZE" 657eda14cbcSMatt Macymsg "ITERATIONS: $ITERATIONS" 658eda14cbcSMatt Macymsg "TAGS: $TAGS" 659eda14cbcSMatt Macymsg "STACK_TRACER: $STACK_TRACER" 660eda14cbcSMatt Macymsg "Keep pool(s): $KEEP" 661eda14cbcSMatt Macymsg "Missing util(s): $STF_MISSING_BIN" 662eda14cbcSMatt Macymsg "" 663eda14cbcSMatt Macy 664eda14cbcSMatt Macyexport STF_TOOLS 665eda14cbcSMatt Macyexport STF_SUITE 666eda14cbcSMatt Macyexport STF_PATH 667eda14cbcSMatt Macyexport DISKS 668eda14cbcSMatt Macyexport FILEDIR 669eda14cbcSMatt Macyexport KEEP 670eda14cbcSMatt Macyexport __ZFS_POOL_EXCLUDE 671eda14cbcSMatt Macyexport TESTFAIL_CALLBACKS 672eda14cbcSMatt Macyexport PATH=$STF_PATH 673eda14cbcSMatt Macy 674eda14cbcSMatt Macyif [ "$UNAME" = "FreeBSD" ] ; then 675eda14cbcSMatt Macy mkdir -p "$FILEDIR" || true 6767877fdebSMatt Macy RESULTS_FILE=$(mktemp -u "${FILEDIR}/zts-results.XXXXXX") 6777877fdebSMatt Macy REPORT_FILE=$(mktemp -u "${FILEDIR}/zts-report.XXXXXX") 678eda14cbcSMatt Macyelse 6797877fdebSMatt Macy RESULTS_FILE=$(mktemp -u -t zts-results.XXXXXX -p "$FILEDIR") 6807877fdebSMatt Macy REPORT_FILE=$(mktemp -u -t zts-report.XXXXXX -p "$FILEDIR") 681eda14cbcSMatt Macyfi 682eda14cbcSMatt Macy 683eda14cbcSMatt Macy# 684eda14cbcSMatt Macy# Run all the tests as specified. 685eda14cbcSMatt Macy# 686eda14cbcSMatt Macymsg "${TEST_RUNNER} ${QUIET:+-q}" \ 687eda14cbcSMatt Macy "-c \"${RUNFILES}\"" \ 688eda14cbcSMatt Macy "-T \"${TAGS}\"" \ 689eda14cbcSMatt Macy "-i \"${STF_SUITE}\"" \ 690eda14cbcSMatt Macy "-I \"${ITERATIONS}\"" 691eda14cbcSMatt Macy${TEST_RUNNER} ${QUIET:+-q} \ 692eda14cbcSMatt Macy -c "${RUNFILES}" \ 693eda14cbcSMatt Macy -T "${TAGS}" \ 694eda14cbcSMatt Macy -i "${STF_SUITE}" \ 695eda14cbcSMatt Macy -I "${ITERATIONS}" \ 696eda14cbcSMatt Macy 2>&1 | tee "$RESULTS_FILE" 697eda14cbcSMatt Macy 698eda14cbcSMatt Macy# 699eda14cbcSMatt Macy# Analyze the results. 700eda14cbcSMatt Macy# 701eda14cbcSMatt Macy${ZTS_REPORT} "$RESULTS_FILE" >"$REPORT_FILE" 702eda14cbcSMatt MacyRESULT=$? 703eda14cbcSMatt Macycat "$REPORT_FILE" 704eda14cbcSMatt Macy 705eda14cbcSMatt MacyRESULTS_DIR=$(awk '/^Log directory/ { print $3 }' "$RESULTS_FILE") 706eda14cbcSMatt Macyif [ -d "$RESULTS_DIR" ]; then 707eda14cbcSMatt Macy cat "$RESULTS_FILE" "$REPORT_FILE" >"$RESULTS_DIR/results" 708eda14cbcSMatt Macyfi 709eda14cbcSMatt Macy 710eda14cbcSMatt Macyrm -f "$RESULTS_FILE" "$REPORT_FILE" 711eda14cbcSMatt Macy 712eda14cbcSMatt Macyif [ -n "$SINGLETEST" ]; then 713eda14cbcSMatt Macy rm -f "$RUNFILES" >/dev/null 2>&1 714eda14cbcSMatt Macyfi 715eda14cbcSMatt Macy 716eda14cbcSMatt Macyexit ${RESULT} 717