17a7741afSMartin Matuska#!/usr/bin/env bash 2e92ffd9bSMartin Matuska# shellcheck disable=SC2154 37a7741afSMartin 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 155*d2a8fad3SMartin Matuska TEST_FILES=$(ls "${FILEDIR}"/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 2127a7741afSMartin Matuska# Given a TAGS with a format like "1/3" or "2/3" then divide up the test list 2137a7741afSMartin Matuska# into portions and print that portion. So "1/3" for "the first third of the 2147a7741afSMartin Matuska# test tags". 2157a7741afSMartin Matuska# 2167a7741afSMartin Matuska# 2177a7741afSMartin Matuskasplit_tags() { 2187a7741afSMartin Matuska # Get numerator and denominator 2197a7741afSMartin Matuska NUM=$(echo "$TAGS" | cut -d/ -f1) 2207a7741afSMartin Matuska DEN=$(echo "$TAGS" | cut -d/ -f2) 2217a7741afSMartin Matuska # At the point this is called, RUNFILES will contain a comma separated 2227a7741afSMartin Matuska # list of full paths to the runfiles, like: 2237a7741afSMartin Matuska # 2247a7741afSMartin Matuska # "/home/hutter/qemu/tests/runfiles/common.run,/home/hutter/qemu/tests/runfiles/linux.run" 2257a7741afSMartin Matuska # 2267a7741afSMartin Matuska # So to get tags for our selected tests we do: 2277a7741afSMartin Matuska # 2287a7741afSMartin Matuska # 1. Remove unneeded chars: [],\ 2297a7741afSMartin Matuska # 2. Print out the last field of each tag line. This will be the tag 2307a7741afSMartin Matuska # for the test (like 'zpool_add'). 2317a7741afSMartin Matuska # 3. Remove duplicates between the runfiles. If the same tag is defined 2327a7741afSMartin Matuska # in multiple runfiles, then when you do '-T <tag>' ZTS is smart 2337a7741afSMartin Matuska # enough to know to run the tag in each runfile. So '-T zpool_add' 2347a7741afSMartin Matuska # will run the zpool_add from common.run and linux.run. 2357a7741afSMartin Matuska # 4. Ignore the 'functional' tag since we only want individual tests 2367a7741afSMartin Matuska # 5. Print out the tests in our faction of all tests. This uses modulus 2377a7741afSMartin Matuska # so "1/3" will run tests 1,3,6,9 etc. That way the tests are 2387a7741afSMartin Matuska # interleaved so, say, "3/4" isn't running all the zpool_* tests that 2397a7741afSMartin Matuska # appear alphabetically at the end. 2407a7741afSMartin Matuska # 6. Remove trailing comma from list 2417a7741afSMartin Matuska # 2427a7741afSMartin Matuska # TAGS will then look like: 2437a7741afSMartin Matuska # 2447a7741afSMartin Matuska # "append,atime,bootfs,cachefile,checksum,cp_files,deadman,dos_attributes, ..." 2457a7741afSMartin Matuska 2467a7741afSMartin Matuska # Change the comma to a space for easy processing 2477a7741afSMartin Matuska _RUNFILES=${RUNFILES//","/" "} 2487a7741afSMartin Matuska # shellcheck disable=SC2002,SC2086 2497a7741afSMartin Matuska cat $_RUNFILES | tr -d "[],\'" | awk '/tags = /{print $NF}' | sort | \ 2507a7741afSMartin Matuska uniq | grep -v functional | \ 2517a7741afSMartin Matuska awk -v num="$NUM" -v den="$DEN" '{ if(NR % den == (num - 1)) {printf "%s,",$0}}' | \ 2527a7741afSMartin Matuska sed -E 's/,$//' 2537a7741afSMartin Matuska} 2547a7741afSMartin 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 311*d2a8fad3SMartin Matuska # Constrained path set to $FILEDIR/constrained_path.* 312*d2a8fad3SMartin Matuska SYSTEMDIR=${SYSTEMDIR:-$FILEDIR/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') 3787a7741afSMartin Matuska Alternately, specify a fraction like "1/3" or "2/3" to 3797a7741afSMartin Matuska run the first third of tests or 2nd third of the tests. This 3807a7741afSMartin Matuska is useful for splitting up the test amongst different 3817a7741afSMartin Matuska runners. 382eda14cbcSMatt Macy -u USER Run single test as USER (default: root) 383eda14cbcSMatt Macy 384eda14cbcSMatt MacyEXAMPLES: 3857a7741afSMartin 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 3987a7741afSMartin 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 495*d2a8fad3SMartin Matuska RUNFILE_DIR="$FILEDIR" 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 MacyEOF 5091719886fSMartin Matuska if [ "$SINGLETEST" = "${SINGLETEST%/*}" ] ; then 5101719886fSMartin Matuska NEWSINGLETEST=$(find "$STF_SUITE" -name "$SINGLETEST*" -print -quit) 5111719886fSMartin Matuska if [ -z "$NEWSINGLETEST" ] ; then 5121719886fSMartin Matuska fail "couldn't find test matching '$SINGLETEST'" 5131719886fSMartin Matuska fi 5141719886fSMartin Matuska SINGLETEST=$NEWSINGLETEST 5151719886fSMartin Matuska fi 516eda14cbcSMatt Macy 5171719886fSMartin Matuska SINGLETESTDIR="${SINGLETEST%/*}" 518716fd348SMartin Matuska SETUPDIR="$SINGLETESTDIR" 519716fd348SMartin Matuska [ "${SETUPDIR#/}" = "$SETUPDIR" ] && SETUPDIR="$STF_SUITE/$SINGLETESTDIR" 520716fd348SMartin Matuska [ -x "$SETUPDIR/setup.ksh" ] && SETUPSCRIPT="setup" || SETUPSCRIPT= 521716fd348SMartin Matuska [ -x "$SETUPDIR/cleanup.ksh" ] && CLEANUPSCRIPT="cleanup" || CLEANUPSCRIPT= 522eda14cbcSMatt Macy 523716fd348SMartin Matuska SINGLETESTFILE="${SINGLETEST##*/}" 524e92ffd9bSMartin Matuska cat >>"${RUNFILE_DIR}/${RUNFILES}" << EOF 525eda14cbcSMatt Macy 526eda14cbcSMatt Macy[$SINGLETESTDIR] 527eda14cbcSMatt Macytests = ['$SINGLETESTFILE'] 528eda14cbcSMatt Macypre = $SETUPSCRIPT 529eda14cbcSMatt Macypost = $CLEANUPSCRIPT 530eda14cbcSMatt Macytags = ['functional'] 531eda14cbcSMatt MacyEOF 532eda14cbcSMatt Macyfi 533eda14cbcSMatt Macy 534eda14cbcSMatt Macy# 535eda14cbcSMatt Macy# Use default tag if none was specified 536eda14cbcSMatt Macy# 537eda14cbcSMatt MacyTAGS=${TAGS:='functional'} 538eda14cbcSMatt Macy 5397a7741afSMartin Matuska 5407a7741afSMartin Matuska 541eda14cbcSMatt Macy# 542eda14cbcSMatt Macy# Attempt to locate the runfiles describing the test workload. 543eda14cbcSMatt Macy# 544eda14cbcSMatt MacyR="" 545eda14cbcSMatt MacyIFS=, 546eda14cbcSMatt Macyfor RUNFILE in $RUNFILES; do 547eda14cbcSMatt Macy if [ -n "$RUNFILE" ]; then 548eda14cbcSMatt Macy SAVED_RUNFILE="$RUNFILE" 549716fd348SMartin Matuska RUNFILE=$(find_runfile "$RUNFILE") || 550716fd348SMartin Matuska fail "Cannot find runfile: $SAVED_RUNFILE" 551eda14cbcSMatt Macy R="$R,$RUNFILE" 552eda14cbcSMatt Macy fi 553eda14cbcSMatt Macy 554eda14cbcSMatt Macy if [ ! -r "$RUNFILE" ]; then 555eda14cbcSMatt Macy fail "Cannot read runfile: $RUNFILE" 556eda14cbcSMatt Macy fi 557eda14cbcSMatt Macydone 558eda14cbcSMatt Macyunset IFS 559eda14cbcSMatt MacyRUNFILES=${R#,} 560eda14cbcSMatt Macy 5617a7741afSMartin Matuska# The tag can be a fraction to indicate which portion of ZTS to run, Like 5627a7741afSMartin Matuska# 5637a7741afSMartin Matuska# "1/3": Run first one third of all tests in runfiles 5647a7741afSMartin Matuska# "2/3": Run second one third of all test in runfiles 5657a7741afSMartin Matuska# "6/10": Run 6th tenth of all tests in runfiles 5667a7741afSMartin Matuska# 5677a7741afSMartin Matuska# This is useful for splitting up the test across multiple runners. 5687a7741afSMartin Matuska# 5697a7741afSMartin Matuska# After this code block, TAGS will be transformed from something like 5707a7741afSMartin Matuska# "1/3" to a comma separate taglist, like: 5717a7741afSMartin Matuska# 5727a7741afSMartin Matuska# "append,atime,bootfs,cachefile,checksum,cp_files,deadman,dos_attributes, ..." 5737a7741afSMartin Matuska# 5747a7741afSMartin Matuskaif echo "$TAGS" | grep -Eq '^[0-9]+/[0-9]+$' ; then 5757a7741afSMartin Matuska TAGS=$(split_tags) 5767a7741afSMartin Matuskafi 5777a7741afSMartin Matuska 578eda14cbcSMatt Macy# 579eda14cbcSMatt Macy# This script should not be run as root. Instead the test user, which may 580eda14cbcSMatt Macy# be a normal user account, needs to be configured such that it can 581eda14cbcSMatt Macy# run commands via sudo passwordlessly. 582eda14cbcSMatt Macy# 583eda14cbcSMatt Macyif [ "$(id -u)" = "0" ]; then 584eda14cbcSMatt Macy fail "This script must not be run as root." 585eda14cbcSMatt Macyfi 586eda14cbcSMatt Macy 587716fd348SMartin Matuskaif [ "$(sudo id -un)" != "root" ]; then 588eda14cbcSMatt Macy fail "Passwordless sudo access required." 589eda14cbcSMatt Macyfi 590eda14cbcSMatt Macy 591eda14cbcSMatt Macy# 592eda14cbcSMatt Macy# Constrain the available binaries to a known set. 593eda14cbcSMatt Macy# 594eda14cbcSMatt Macyconstrain_path 595eda14cbcSMatt Macy 596eda14cbcSMatt Macy# 597eda14cbcSMatt Macy# Check if ksh exists 598eda14cbcSMatt Macy# 599eda14cbcSMatt Macyif [ "$UNAME" = "FreeBSD" ]; then 600eda14cbcSMatt Macy sudo ln -fs /usr/local/bin/ksh93 /bin/ksh 601eda14cbcSMatt Macyfi 602eda14cbcSMatt Macy[ -e "$STF_PATH/ksh" ] || fail "This test suite requires ksh." 603eda14cbcSMatt Macy[ -e "$STF_SUITE/include/default.cfg" ] || fail \ 604eda14cbcSMatt Macy "Missing $STF_SUITE/include/default.cfg file." 605eda14cbcSMatt Macy 606eda14cbcSMatt Macy# 607eda14cbcSMatt Macy# Verify the ZFS module stack is loaded. 608eda14cbcSMatt Macy# 609eda14cbcSMatt Macyif [ "$STACK_TRACER" = "yes" ]; then 610eda14cbcSMatt Macy sudo "${ZFS_SH}" -S >/dev/null 2>&1 611eda14cbcSMatt Macyelse 612eda14cbcSMatt Macy sudo "${ZFS_SH}" >/dev/null 2>&1 613eda14cbcSMatt Macyfi 614eda14cbcSMatt Macy 615eda14cbcSMatt Macy# 616eda14cbcSMatt Macy# Attempt to cleanup all previous state for a new test run. 617eda14cbcSMatt Macy# 618eda14cbcSMatt Macyif [ "$CLEANUPALL" = "yes" ]; then 619eda14cbcSMatt Macy cleanup_all 620eda14cbcSMatt Macyfi 621eda14cbcSMatt Macy 622eda14cbcSMatt Macy# 623eda14cbcSMatt Macy# By default preserve any existing pools 624eda14cbcSMatt Macy# 625eda14cbcSMatt Macyif [ -z "${KEEP}" ]; then 626716fd348SMartin Matuska KEEP="$(ASAN_OPTIONS=detect_leaks=false "$ZPOOL" list -Ho name | tr -s '[:space:]' ' ')" 627eda14cbcSMatt Macy if [ -z "${KEEP}" ]; then 628eda14cbcSMatt Macy KEEP="rpool" 629eda14cbcSMatt Macy fi 630eda14cbcSMatt Macyelse 631716fd348SMartin Matuska KEEP="$(echo "$KEEP" | tr -s '[:space:]' ' ')" 632eda14cbcSMatt Macyfi 633eda14cbcSMatt Macy 634eda14cbcSMatt Macy# 635eda14cbcSMatt Macy# NOTE: The following environment variables are undocumented 636eda14cbcSMatt Macy# and should be used for testing purposes only: 637eda14cbcSMatt Macy# 638eda14cbcSMatt Macy# __ZFS_POOL_EXCLUDE - don't iterate over the pools it lists 639eda14cbcSMatt Macy# __ZFS_POOL_RESTRICT - iterate only over the pools it lists 640eda14cbcSMatt Macy# 641eda14cbcSMatt Macy# See libzfs/libzfs_config.c for more information. 642eda14cbcSMatt Macy# 643716fd348SMartin Matuska__ZFS_POOL_EXCLUDE="$KEEP" 644eda14cbcSMatt Macy 645eda14cbcSMatt Macy. "$STF_SUITE/include/default.cfg" 646eda14cbcSMatt Macy 647eda14cbcSMatt Macy# 648eda14cbcSMatt Macy# No DISKS have been provided so a basic file or loopback based devices 649eda14cbcSMatt Macy# must be created for the test suite to use. 650eda14cbcSMatt Macy# 651eda14cbcSMatt Macyif [ -z "${DISKS}" ]; then 652eda14cbcSMatt Macy # 6531f88aa09SMartin Matuska # If this is a performance run, prevent accidental use of 6541f88aa09SMartin Matuska # loopback devices. 6551f88aa09SMartin Matuska # 6561f88aa09SMartin Matuska [ "$TAGS" = "perf" ] && fail "Running perf tests without disks." 6571f88aa09SMartin Matuska 6581f88aa09SMartin Matuska # 659eda14cbcSMatt Macy # Create sparse files for the test suite. These may be used 660eda14cbcSMatt Macy # directory or have loopback devices layered on them. 661eda14cbcSMatt Macy # 662eda14cbcSMatt Macy for TEST_FILE in ${FILES}; do 663eda14cbcSMatt Macy [ -f "$TEST_FILE" ] && fail "Failed file exists: ${TEST_FILE}" 664eda14cbcSMatt Macy truncate -s "${FILESIZE}" "${TEST_FILE}" || 665eda14cbcSMatt Macy fail "Failed creating: ${TEST_FILE} ($?)" 666eda14cbcSMatt Macy done 667eda14cbcSMatt Macy 668eda14cbcSMatt Macy # 669eda14cbcSMatt Macy # If requested setup loopback devices backed by the sparse files. 670eda14cbcSMatt Macy # 671eda14cbcSMatt Macy if [ "$LOOPBACK" = "yes" ]; then 672eda14cbcSMatt Macy test -x "$LOSETUP" || fail "$LOSETUP utility must be installed" 673eda14cbcSMatt Macy 674eda14cbcSMatt Macy for TEST_FILE in ${FILES}; do 675eda14cbcSMatt Macy if [ "$UNAME" = "FreeBSD" ] ; then 676eda14cbcSMatt Macy MDDEVICE=$(sudo "${LOSETUP}" -a -t vnode -f "${TEST_FILE}") 677eda14cbcSMatt Macy if [ -z "$MDDEVICE" ] ; then 678eda14cbcSMatt Macy fail "Failed: ${TEST_FILE} -> loopback" 679eda14cbcSMatt Macy fi 680eda14cbcSMatt Macy DISKS="$DISKS $MDDEVICE" 681eda14cbcSMatt Macy LOOPBACKS="$LOOPBACKS $MDDEVICE" 682eda14cbcSMatt Macy else 683716fd348SMartin Matuska TEST_LOOPBACK=$(sudo "${LOSETUP}" --show -f "${TEST_FILE}") || 684eda14cbcSMatt Macy fail "Failed: ${TEST_FILE} -> ${TEST_LOOPBACK}" 685dae17134SMartin Matuska BASELOOPBACK="${TEST_LOOPBACK##*/}" 686eda14cbcSMatt Macy DISKS="$DISKS $BASELOOPBACK" 687eda14cbcSMatt Macy LOOPBACKS="$LOOPBACKS $TEST_LOOPBACK" 688eda14cbcSMatt Macy fi 689eda14cbcSMatt Macy done 690eda14cbcSMatt Macy DISKS=${DISKS# } 691eda14cbcSMatt Macy LOOPBACKS=${LOOPBACKS# } 692eda14cbcSMatt Macy else 693eda14cbcSMatt Macy DISKS="$FILES" 694eda14cbcSMatt Macy fi 695eda14cbcSMatt Macyfi 696eda14cbcSMatt Macy 6971f88aa09SMartin Matuska# 6981f88aa09SMartin Matuska# It may be desirable to test with fewer disks than the default when running 6991f88aa09SMartin Matuska# the performance tests, but the functional tests require at least three. 7001f88aa09SMartin Matuska# 701eda14cbcSMatt MacyNUM_DISKS=$(echo "${DISKS}" | awk '{print NF}') 7021f88aa09SMartin Matuskaif [ "$TAGS" != "perf" ]; then 703eda14cbcSMatt Macy [ "$NUM_DISKS" -lt 3 ] && fail "Not enough disks ($NUM_DISKS/3 minimum)" 7041f88aa09SMartin Matuskafi 705eda14cbcSMatt Macy 706eda14cbcSMatt Macy# 707eda14cbcSMatt Macy# Disable SELinux until the ZFS Test Suite has been updated accordingly. 708eda14cbcSMatt Macy# 709716fd348SMartin Matuskaif command -v setenforce >/dev/null; then 710eda14cbcSMatt Macy sudo setenforce permissive >/dev/null 2>&1 711eda14cbcSMatt Macyfi 712eda14cbcSMatt Macy 713eda14cbcSMatt Macy# 714eda14cbcSMatt Macy# Enable internal ZFS debug log and clear it. 715eda14cbcSMatt Macy# 716eda14cbcSMatt Macyif [ -e /sys/module/zfs/parameters/zfs_dbgmsg_enable ]; then 717716fd348SMartin Matuska sudo sh -c "echo 1 >/sys/module/zfs/parameters/zfs_dbgmsg_enable" 718716fd348SMartin Matuska sudo sh -c "echo 0 >/proc/spl/kstat/zfs/dbgmsg" 719eda14cbcSMatt Macyfi 720eda14cbcSMatt Macy 721*d2a8fad3SMartin Matuska# 722*d2a8fad3SMartin Matuska# Set TMPDIR. Some tests run mktemp, and we want those files contained to 723*d2a8fad3SMartin Matuska# the work dir the same as any other. 724*d2a8fad3SMartin Matuska# 725*d2a8fad3SMartin Matuskaexport TMPDIR="$FILEDIR" 726*d2a8fad3SMartin Matuska 7271f88aa09SMartin Matuskamsg 7281f88aa09SMartin Matuskamsg "--- Configuration ---" 7291f88aa09SMartin Matuskamsg "Runfiles: $RUNFILES" 7301f88aa09SMartin Matuskamsg "STF_TOOLS: $STF_TOOLS" 7311f88aa09SMartin Matuskamsg "STF_SUITE: $STF_SUITE" 7321f88aa09SMartin Matuskamsg "STF_PATH: $STF_PATH" 733eda14cbcSMatt Macymsg "FILEDIR: $FILEDIR" 734*d2a8fad3SMartin Matuskamsg "TMPDIR: $TMPDIR" 735eda14cbcSMatt Macymsg "FILES: $FILES" 736eda14cbcSMatt Macymsg "LOOPBACKS: $LOOPBACKS" 737eda14cbcSMatt Macymsg "DISKS: $DISKS" 738eda14cbcSMatt Macymsg "NUM_DISKS: $NUM_DISKS" 739eda14cbcSMatt Macymsg "FILESIZE: $FILESIZE" 740eda14cbcSMatt Macymsg "ITERATIONS: $ITERATIONS" 741eda14cbcSMatt Macymsg "TAGS: $TAGS" 742eda14cbcSMatt Macymsg "STACK_TRACER: $STACK_TRACER" 743eda14cbcSMatt Macymsg "Keep pool(s): $KEEP" 744eda14cbcSMatt Macymsg "Missing util(s): $STF_MISSING_BIN" 745eda14cbcSMatt Macymsg "" 746eda14cbcSMatt Macy 747eda14cbcSMatt Macyexport STF_TOOLS 748eda14cbcSMatt Macyexport STF_SUITE 749eda14cbcSMatt Macyexport STF_PATH 750eda14cbcSMatt Macyexport DISKS 751eda14cbcSMatt Macyexport FILEDIR 752eda14cbcSMatt Macyexport KEEP 753eda14cbcSMatt Macyexport __ZFS_POOL_EXCLUDE 754eda14cbcSMatt Macyexport TESTFAIL_CALLBACKS 755eda14cbcSMatt Macy 756c03c5b1cSMartin Matuskamktemp_file() { 757eda14cbcSMatt Macy if [ "$UNAME" = "FreeBSD" ]; then 758c03c5b1cSMartin Matuska mktemp -u "${FILEDIR}/$1.XXXXXX" 759eda14cbcSMatt Macy else 760c03c5b1cSMartin Matuska mktemp -ut "$1.XXXXXX" -p "$FILEDIR" 761eda14cbcSMatt Macy fi 762c03c5b1cSMartin Matuska} 763c03c5b1cSMartin Matuskamkdir -p "$FILEDIR" || : 764c03c5b1cSMartin MatuskaRESULTS_FILE=$(mktemp_file zts-results) 765c03c5b1cSMartin MatuskaREPORT_FILE=$(mktemp_file zts-report) 766eda14cbcSMatt Macy 767eda14cbcSMatt Macy# 768eda14cbcSMatt Macy# Run all the tests as specified. 769eda14cbcSMatt Macy# 770c03c5b1cSMartin Matuskamsg "${TEST_RUNNER}" \ 771c03c5b1cSMartin Matuska "${QUIET:+-q}" \ 7720d4ad640SMartin Matuska "${DEBUG:+-D}" \ 773c03c5b1cSMartin Matuska "${KMEMLEAK:+-m}" \ 774da5137abSMartin Matuska "${KMSG:+-K}" \ 775eda14cbcSMatt Macy "-c \"${RUNFILES}\"" \ 776eda14cbcSMatt Macy "-T \"${TAGS}\"" \ 777eda14cbcSMatt Macy "-i \"${STF_SUITE}\"" \ 778eda14cbcSMatt Macy "-I \"${ITERATIONS}\"" 779716fd348SMartin Matuska{ PATH=$STF_PATH \ 780716fd348SMartin Matuska ${TEST_RUNNER} \ 781c03c5b1cSMartin Matuska ${QUIET:+-q} \ 7820d4ad640SMartin Matuska ${DEBUG:+-D} \ 783c03c5b1cSMartin Matuska ${KMEMLEAK:+-m} \ 784da5137abSMartin Matuska ${KMSG:+-K} \ 785eda14cbcSMatt Macy -c "${RUNFILES}" \ 786eda14cbcSMatt Macy -T "${TAGS}" \ 787eda14cbcSMatt Macy -i "${STF_SUITE}" \ 788eda14cbcSMatt Macy -I "${ITERATIONS}" \ 789c03c5b1cSMartin Matuska 2>&1; echo $? >"$REPORT_FILE"; } | tee "$RESULTS_FILE" 790c03c5b1cSMartin Matuskaread -r RUNRESULT <"$REPORT_FILE" 791c03c5b1cSMartin Matuska 792eda14cbcSMatt Macy# 793eda14cbcSMatt Macy# Analyze the results. 794eda14cbcSMatt Macy# 795681ce946SMartin Matuska${ZTS_REPORT} ${RERUN:+--no-maybes} "$RESULTS_FILE" >"$REPORT_FILE" 796eda14cbcSMatt MacyRESULT=$? 797681ce946SMartin Matuska 798681ce946SMartin Matuskaif [ "$RESULT" -eq "2" ] && [ -n "$RERUN" ]; then 799681ce946SMartin Matuska MAYBES="$($ZTS_REPORT --list-maybes)" 800c03c5b1cSMartin Matuska TEMP_RESULTS_FILE=$(mktemp_file zts-results-tmp) 801c03c5b1cSMartin Matuska TEST_LIST=$(mktemp_file test-list) 802681ce946SMartin Matuska grep "^Test:.*\[FAIL\]" "$RESULTS_FILE" >"$TEMP_RESULTS_FILE" 803681ce946SMartin Matuska for test_name in $MAYBES; do 804681ce946SMartin Matuska grep "$test_name " "$TEMP_RESULTS_FILE" >>"$TEST_LIST" 805681ce946SMartin Matuska done 806716fd348SMartin Matuska { PATH=$STF_PATH \ 807716fd348SMartin Matuska ${TEST_RUNNER} \ 808c03c5b1cSMartin Matuska ${QUIET:+-q} \ 8090d4ad640SMartin Matuska ${DEBUG:+-D} \ 810c03c5b1cSMartin Matuska ${KMEMLEAK:+-m} \ 811681ce946SMartin Matuska -c "${RUNFILES}" \ 812681ce946SMartin Matuska -T "${TAGS}" \ 813681ce946SMartin Matuska -i "${STF_SUITE}" \ 814681ce946SMartin Matuska -I "${ITERATIONS}" \ 815681ce946SMartin Matuska -l "${TEST_LIST}" \ 816c03c5b1cSMartin Matuska 2>&1; echo $? >"$REPORT_FILE"; } | tee "$RESULTS_FILE" 817c03c5b1cSMartin Matuska read -r RUNRESULT <"$REPORT_FILE" 818681ce946SMartin Matuska # 819681ce946SMartin Matuska # Analyze the results. 820681ce946SMartin Matuska # 821681ce946SMartin Matuska ${ZTS_REPORT} --no-maybes "$RESULTS_FILE" >"$REPORT_FILE" 822681ce946SMartin Matuska RESULT=$? 823681ce946SMartin Matuskafi 824681ce946SMartin Matuska 825681ce946SMartin Matuska 826eda14cbcSMatt Macycat "$REPORT_FILE" 827eda14cbcSMatt Macy 828eda14cbcSMatt MacyRESULTS_DIR=$(awk '/^Log directory/ { print $3 }' "$RESULTS_FILE") 829eda14cbcSMatt Macyif [ -d "$RESULTS_DIR" ]; then 830eda14cbcSMatt Macy cat "$RESULTS_FILE" "$REPORT_FILE" >"$RESULTS_DIR/results" 831eda14cbcSMatt Macyfi 832eda14cbcSMatt Macy 833716fd348SMartin Matuskarm -f "$RESULTS_FILE" "$REPORT_FILE" "$TEST_LIST" "$TEMP_RESULTS_FILE" 834eda14cbcSMatt Macy 835eda14cbcSMatt Macyif [ -n "$SINGLETEST" ]; then 836eda14cbcSMatt Macy rm -f "$RUNFILES" >/dev/null 2>&1 837eda14cbcSMatt Macyfi 838eda14cbcSMatt Macy 839c03c5b1cSMartin Matuska[ "$RUNRESULT" -gt 3 ] && exit "$RUNRESULT" || exit "$RESULT" 840