clean:
$(MAKE) -C src clean
-# SC2034: "VARIABLE appears unused". All test scripts use this for the test
-# metadata, and many helper functions define global variables.
# SC2119: "Use foo "$@" if function's $1 should mean script's $1". False
# positives on helpers like _init_scsi_debug.
-SHELLCHECK_EXCLUDE := SC2034,SC2119
+SHELLCHECK_EXCLUDE := SC2119
check:
shellcheck -x -e $(SHELLCHECK_EXCLUDE) -f gcc check new common/* \
tests/*/rc tests/*/[0-9]*[0-9]
- ! grep TODO tests/*/[0-9]*[0-9]
+ ! grep TODO tests/*/rc tests/*/[0-9]*[0-9]
.PHONY: all check
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-. common/rc
+shopt -s extglob
+
+_warning() {
+ echo "$0: $*" >&2
+}
+
+_error() {
+ echo "$0: $*" >&2
+ exit 1
+}
_found_test() {
local test_name="$1"
_call_test() {
local test_func="$1"
local seqres="${RESULTS_DIR}/${TEST_NAME}"
+ # shellcheck disable=SC2034
FULL="${seqres}.full"
declare -A TEST_DEV_QUEUE_SAVED
declare -A TEST_DEV_SYSFS_DIRS
_check() {
+ # shellcheck disable=SC2034
SRCDIR="$(realpath src)"
local test_dev
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+. common/shellcheck
+
# Also initializes the ALL_CPUS and HOTPLUGGABLE_CPUS arrays.
_have_cpu_hotplug() {
ALL_CPUS=()
if [[ -w ${cpu_dir}/online ]]; then
cpu="${cpu_dir#/sys/devices/system/cpu/cpu}"
HOTPLUGGABLE_CPUS+=("$cpu")
+ # shellcheck disable=SC2034
CPUS_ONLINE_SAVED["$cpu"]="$(cat "${cpu_dir}/online")"
fi
done
}
_online_cpu() {
+ # shellcheck disable=SC2034
RESTORE_CPUS_ONLINE=1
echo 1 > "/sys/devices/system/cpu/cpu$1/online"
}
_offline_cpu() {
+ # shellcheck disable=SC2034
RESTORE_CPUS_ONLINE=1
echo 0 > "/sys/devices/system/cpu/cpu$1/online"
}
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+. common/shellcheck
+
_have_fio() {
if ! _have_program fio; then
return 1
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+. common/shellcheck
+
_have_fio_with_poll() {
if ! _have_fio; then
return 1
+++ /dev/null
-#!/bin/bash
-#
-# NBD helper functions
-#
-# Copyright (C) 2018 Josef Bacik
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-_have_nbd() {
- if ! _have_module nbd; then
- return 1
- fi
- if ! _have_program nbd-server; then
- return 1
- fi
- if ! _have_program nbd-client; then
- return 1
- fi
- if ! nbd-client --help 2>&1 | grep -q -- -L; then
- SKIP_REASON="nbd-client does not have -nonetlink/-L option"
- return 1
- fi
- return 0
-}
-
-_have_nbd_netlink() {
- if ! _have_nbd; then
- return 1
- fi
- if ! _have_program genl-ctrl-list; then
- return 1
- fi
- if ! genl-ctrl-list | grep -q nbd; then
- SKIP_REASON="nbd does not support netlink"
- return 1
- fi
- return 0
-}
-
-_wait_for_nbd_connect() {
- for ((i = 0; i < 3; i++)); do
- if [[ -e /sys/kernel/debug/nbd/nbd0/tasks ]]; then
- return 0
- fi
- sleep 1
- done
- return 1
-}
-
-_wait_for_nbd_disconnect() {
- for ((i = 0; i < 3; i++)); do
- if [[ ! -e /sys/kernel/debug/nbd/nbd0/tasks ]]; then
- return 0
- fi
- sleep 1
- done
- return 1
-}
-
-_start_nbd_server() {
- truncate -s 10G "${TMPDIR}/export"
- cat > "${TMPDIR}/nbd.conf" << EOF
-[generic]
-[export]
-exportname=${TMPDIR}/export
-EOF
- nbd-server -p "${TMPDIR}/nbd.pid" -C "${TMPDIR}/nbd.conf"
-}
-
-_stop_nbd_server() {
- kill -SIGTERM "$(cat "${TMPDIR}/nbd.pid")"
- rm -f "${TMPDIR}/nbd.pid"
- rm -f "${TMPDIR}/export"
-}
+++ /dev/null
-#!/bin/bash
-#
-# Default helper functions for NVMe devices.
-#
-# Copyright (C) 2018 Johannes Thumshirn
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-NVMET_CFS="/sys/kernel/config/nvmet/"
-
-_test_dev_is_nvme() {
- if ! readlink -f "$TEST_DEV_SYSFS/device" | grep -q nvme; then
- SKIP_REASON="$TEST_DEV is not a NVMe device"
- return 1
- fi
- return 0
-}
-
-_create_nvmet_port() {
- local trtype="$1"
-
- local port
- for ((port = 0; ; port++)); do
- if [[ ! -e "${NVMET_CFS}/ports/${port}" ]]; then
- break
- fi
- done
-
- mkdir "${NVMET_CFS}/ports/${port}"
- echo "${trtype}" > "${NVMET_CFS}/ports/${port}/addr_trtype"
-
- echo "${port}"
-}
-
-_remove_nvmet_port() {
- local port="$1"
- rmdir "${NVMET_CFS}/ports/${port}"
-}
-
-_create_nvmet_ns() {
- local nvmet_subsystem="$1"
- local nsid="$2"
- local blkdev="$3"
- local uuid="00000000-0000-0000-0000-000000000000"
- local subsys_path="${NVMET_CFS}/subsystems/${nvmet_subsystem}"
- local ns_path="${subsys_path}/namespaces/${nsid}"
-
- if [[ $# -eq 4 ]]; then
- uuid="$4"
- fi
-
- mkdir "${ns_path}"
- printf "%s" "${blkdev}" > "${ns_path}/device_path"
- printf "%s" "${uuid}" > "${ns_path}/device_uuid"
- printf 1 > "${ns_path}/enable"
-}
-
-_create_nvmet_subsystem() {
- local nvmet_subsystem="$1"
- local blkdev="$2"
- local uuid=$3
- local cfs_path="${NVMET_CFS}/subsystems/${nvmet_subsystem}"
-
- mkdir -p "${cfs_path}"
- echo 1 > "${cfs_path}/attr_allow_any_host"
- _create_nvmet_ns "${nvmet_subsystem}" "1" "${blkdev}" "${uuid}"
-}
-
-_remove_nvmet_ns() {
- local nvmet_subsystem="$1"
- local nsid=$2
- local subsys_path="${NVMET_CFS}/subsystems/${nvmet_subsystem}"
- local nvmet_ns_path="${subsys_path}/namespaces/${nsid}"
-
- echo 0 > "${nvmet_ns_path}/enable"
- rmdir "${nvmet_ns_path}"
-}
-
-_remove_nvmet_subsystem() {
- local nvmet_subsystem="$1"
- local subsys_path="${NVMET_CFS}/subsystems/${nvmet_subsystem}"
-
- _remove_nvmet_ns "${nvmet_subsystem}" "1"
- rmdir "${subsys_path}"
-}
-
-_add_nvmet_subsys_to_port() {
- local port="$1"
- local nvmet_subsystem="$2"
-
- ln -s "${NVMET_CFS}/subsystems/${nvmet_subsystem}" \
- "${NVMET_CFS}/ports/${port}/subsystems/${nvmet_subsystem}"
-}
-
-_remove_nvmet_subsystem_from_port() {
- local port="$1"
- local nvmet_subsystem="$2"
-
- rm "${NVMET_CFS}/ports/${port}/subsystems/${nvmet_subsystem}"
-}
-
-_find_nvme_loop_dev() {
- local dev
- local transport
- for dev in /sys/class/nvme/nvme*; do
- dev="$(basename "$dev")"
- transport="$(cat "/sys/class/nvme/${dev}/transport")"
- if [[ "$transport" == "loop" ]]; then
- echo "$dev"
- fi
- done
-}
shopt -s extglob
+. common/shellcheck
# Include fio helpers by default.
. common/fio
-_warning() {
- echo "$0: $*" >&2
-}
-
-_error() {
- echo "$0: $*" >&2
- exit 1
-}
-
# If a test runs multiple "subtests", then each subtest should typically run
# for TIMEOUT / number of subtests.
_divide_timeout() {
+++ /dev/null
-#!/bin/bash
-#
-# SCSI generic helper functions.
-#
-# Copyright (C) 2017 Johannes Thumshirn
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-_have_scsi_generic() {
- _have_module sg
-}
-
-_test_dev_is_scsi() {
- if [[ ! -d ${TEST_DEV_SYSFS}/device/scsi_device ]]; then
- SKIP_REASON="$TEST_DEV is not a SCSI device"
- return 1
- fi
- return 0
-}
-
-_get_test_dev_sg() {
- echo "${TEST_DEV_SYSFS}"/device/scsi_generic/sg* | grep -Eo "sg[0-9]+"
-}
#!/bin/bash
#
-# Loop device helper functions.
+# Shellcheck workarounds.
#
-# Copyright (C) 2017 Omar Sandoval
+# Copyright (C) 2018 Omar Sandoval
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-_have_loop_set_block_size() {
- src/loblksize "$(losetup -f)" 512 &>/dev/null
- if [[ $? -eq 2 ]]; then
- SKIP_REASON="kernel does not support LOOP_SET_BLOCK_SIZE"
- return 1
- fi
- return 0
+# Suppress unused global variable warnings.
+_silence_sc2034() {
+ echo "$CHECK_DMESG $DESCRIPTION $DMESG_FILTER $FIO_PERF_FIELDS $FIO_PERF_PREFIX $QUICK $SKIP_REASON ${TEST_RUN[*]} $TIMED" > /dev/null
}
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set -e
+shopt -s extglob
-. common/rc
+_error() {
+ echo "$0: $*" >&2
+ exit 1
+}
prompt_yes_no() {
if [[ $2 =~ ^[Yy] ]]; then
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-# TODO: source any common helpers needed for this group. Anything sourced here
-# will also be available in the test scripts. Additionally, any functions
-# defined here will also be available in the test scripts. Note that common/rc
-# and common/fio are automatically sourced for all tests.
+. common/rc
+# TODO: source any more common helpers needed for this group.
# . common/foo
# TODO: if this test group has any extra requirements, it should define a
# group_device_requires() {
# _test_dev_is_foo && _test_dev_supports_bar
# }
+
+# TODO: define any helpers that are specific to this group.
EOF
echo "Created tests/${group}/rc"
fi
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+. tests/${group}/rc
+# TODO: source any more common helpers needed for this test.
+
# TODO: fill in a very brief description of what this test does. The
# description should complete the sentence "This test will...". For example,
# "run a mixed read/write workload" would be a good description.
# - Variables set and used by the testing framework are in caps with underscores.
# E.g., TEST_NAME and GROUPS. Variables local to the test are lowercase
# with underscores.
-# - Functions defined by the testing framework, including helpers, have a leading
-# underscore. E.g., _have_scsi_debug. Functions local to the test or group
-# should not have a leading underscore.
+# - Functions defined by the testing framework or group scripts, including
+# helpers, have a leading underscore. E.g., _have_scsi_debug. Functions local
+# to the test should not have a leading underscore.
# - Use the bash [[ ]] form of tests instead of [ ].
# - Always quote variable expansions unless the variable is a number or inside of
# a [[ ]] test.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+. tests/block/rc
. common/scsi_debug
DESCRIPTION="stress device hotplugging"
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+. tests/block/rc
. common/scsi_debug
DESCRIPTION="remove a device while running blktrace"
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+. tests/block/rc
+
DESCRIPTION="run various discard sizes"
TIMED=1
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+. tests/block/rc
+
DESCRIPTION="run lots of flushes"
TIMED=1
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+. tests/block/rc
+
DESCRIPTION="switch schedulers while doing IO"
TIMED=1
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+. tests/block/rc
+
DESCRIPTION="run null-blk in blocking mode"
TIMED=1
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+. tests/block/rc
. common/iopoll
DESCRIPTION="test classic and hybrid IO polling"
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+. tests/block/rc
. common/cpuhotplug
DESCRIPTION="do IO while hotplugging CPUs"
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-DESCRIPTION="check page-cache coherency after BLKDISCARD"
-
+. tests/block/rc
. common/scsi_debug
+DESCRIPTION="check page-cache coherency after BLKDISCARD"
+
requires() {
_have_scsi_debug && _have_program xfs_io
}
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+. tests/block/rc
+
DESCRIPTION="run I/O on null_blk with shared and non-shared tags"
TIMED=1
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+. tests/block/rc
+
DESCRIPTION="disable PCI device while doing I/O"
TIMED=1
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+. tests/block/rc
+
DESCRIPTION="check that a read-only block device fails writes"
TIMED=1
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+. tests/block/rc
+
DESCRIPTION="try BLKRRPART on a mounted device"
QUICK=1
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+. tests/block/rc
+
DESCRIPTION="run null-blk with timeout injection configured"
requires() {
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-DESCRIPTION="run null-blk on different schedulers with requeue injection configured"
+. tests/block/rc
+DESCRIPTION="run null-blk on different schedulers with requeue injection configured"
QUICK=1
requires() {
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+. tests/block/rc
+
DESCRIPTION="send a signal to a process waiting on a frozen queue"
QUICK=1
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+. tests/block/rc
+
DESCRIPTION="do I/O and check the inflight counter"
QUICK=1
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+. tests/block/rc
+
DESCRIPTION="do I/O and check iostats times"
QUICK=1
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+. tests/block/rc
+
DESCRIPTION="break PCI link device while doing I/O"
QUICK=1
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+. tests/block/rc
+
DESCRIPTION="run null-blk on different schedulers with only one hardware tag"
QUICK=1
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+. tests/block/rc
+
DESCRIPTION="read/write nr_requests on null-blk with different schedulers"
QUICK=1
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+. common/rc
+
group_requires() {
_have_root
}
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+. tests/loop/rc
+
DESCRIPTION="scan loop device partitions"
QUICK=1
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-. common/loop
+. tests/loop/rc
DESCRIPTION="try various loop device block sizes"
QUICK=1
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+. tests/loop/rc
+
DESCRIPTION="time opening and closing an unbound loop device"
QUICK=1
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-. common/loop
+. tests/loop/rc
. common/scsi_debug
DESCRIPTION="combine loop direct I/O mode and a custom block size"
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-DESCRIPTION="call LOOP_GET_STATUS{,64} with a NULL arg"
+. tests/loop/rc
+DESCRIPTION="call LOOP_GET_STATUS{,64} with a NULL arg"
QUICK=1
requires() {
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+. common/rc
+
group_requires() {
_have_root && _have_loop
}
+
+_have_loop_set_block_size() {
+ src/loblksize "$(losetup -f)" 512 &>/dev/null
+ if [[ $? -eq 2 ]]; then
+ SKIP_REASON="kernel does not support LOOP_SET_BLOCK_SIZE"
+ return 1
+ fi
+ return 0
+}
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+. tests/meta/rc
+
DESCRIPTION="do nothing"
test() {
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+. tests/meta/rc
+
DESCRIPTION="do nothing"
test_device() {
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+. tests/meta/rc
+
DESCRIPTION="exit with non-zero status"
test() {
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+. tests/meta/rc
+
DESCRIPTION="exit with non-zero status"
test_device() {
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+. tests/meta/rc
+
DESCRIPTION="produce bad output"
test() {
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+. tests/meta/rc
+
DESCRIPTION="produce lots of bad output"
test() {
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+. tests/meta/rc
+
DESCRIPTION="skip in requires()"
requires() {
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+. tests/meta/rc
+
DESCRIPTION="skip in device_requires()"
device_requires() {
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+. tests/meta/rc
+
DESCRIPTION="check dmesg"
requires() {
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+. tests/meta/rc
+
DESCRIPTION="disable check dmesg"
CHECK_DMESG=0
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+. tests/meta/rc
+
DESCRIPTION="filter dmesg"
DMESG_FILTER="grep -v BUG"
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+. tests/meta/rc
+
DESCRIPTION="record pid and random junk"
test() {
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+. common/rc
+
group_requires() {
if [[ -v META_REQUIRES_SKIP ]]; then
SKIP_REASON="META_REQUIRES_SKIP was set"
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+. tests/nbd/rc
+
DESCRIPTION="resize a connected nbd device"
QUICK=1
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+. tests/nbd/rc
+
DESCRIPTION="tests on partition handling for an nbd device"
QUICK=1
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-. common/nbd
+. common/rc
group_requires() {
_have_root && _have_nbd && modprobe nbd
}
+
+_have_nbd() {
+ if ! _have_module nbd; then
+ return 1
+ fi
+ if ! _have_program nbd-server; then
+ return 1
+ fi
+ if ! _have_program nbd-client; then
+ return 1
+ fi
+ if ! nbd-client --help 2>&1 | grep -q -- -L; then
+ SKIP_REASON="nbd-client does not have -nonetlink/-L option"
+ return 1
+ fi
+ return 0
+}
+
+_have_nbd_netlink() {
+ if ! _have_nbd; then
+ return 1
+ fi
+ if ! _have_program genl-ctrl-list; then
+ return 1
+ fi
+ if ! genl-ctrl-list | grep -q nbd; then
+ SKIP_REASON="nbd does not support netlink"
+ return 1
+ fi
+ return 0
+}
+
+_wait_for_nbd_connect() {
+ for ((i = 0; i < 3; i++)); do
+ if [[ -e /sys/kernel/debug/nbd/nbd0/tasks ]]; then
+ return 0
+ fi
+ sleep 1
+ done
+ return 1
+}
+
+_wait_for_nbd_disconnect() {
+ for ((i = 0; i < 3; i++)); do
+ if [[ ! -e /sys/kernel/debug/nbd/nbd0/tasks ]]; then
+ return 0
+ fi
+ sleep 1
+ done
+ return 1
+}
+
+_start_nbd_server() {
+ truncate -s 10G "${TMPDIR}/export"
+ cat > "${TMPDIR}/nbd.conf" << EOF
+[generic]
+[export]
+exportname=${TMPDIR}/export
+EOF
+ nbd-server -p "${TMPDIR}/nbd.pid" -C "${TMPDIR}/nbd.conf"
+}
+
+_stop_nbd_server() {
+ kill -SIGTERM "$(cat "${TMPDIR}/nbd.pid")"
+ rm -f "${TMPDIR}/nbd.pid"
+ rm -f "${TMPDIR}/export"
+}
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-DESCRIPTION="enable nvme_setup_nvm_cmd tracepoint and submit I/O to the device"
+. tests/nvme/rc
+DESCRIPTION="enable nvme_setup_nvm_cmd tracepoint and submit I/O to the device"
QUICK=1
requires() {
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+. tests/nvme/rc
+
DESCRIPTION="create many subsystems and test discovery"
requires() {
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-DESCRIPTION="test if we're sending keep-alives to a discovery controller"
+. tests/nvme/rc
+DESCRIPTION="test if we're sending keep-alives to a discovery controller"
QUICK=1
requires() {
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+. tests/nvme/rc
+
DESCRIPTION="test nvme and nvmet UUID NS descriptors"
QUICK=1
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-DESCRIPTION="reset local loopback target"
+. tests/nvme/rc
+DESCRIPTION="reset local loopback target"
QUICK=1
requires() {
# Author: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
#
+. tests/nvme/rc
+
DESCRIPTION="create an NVMeOF target with a block device-backed ns"
QUICK=1
# Author: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
#
+. tests/nvme/rc
+
DESCRIPTION="create an NVMeOF target with a file-backed ns"
QUICK=1
# Author: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
#
+. tests/nvme/rc
+
DESCRIPTION="create an NVMeOF host with a block device-backed ns"
QUICK=1
# Author: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
#
+. tests/nvme/rc
+
DESCRIPTION="create an NVMeOF host with a file-backed ns"
QUICK=1
# Author: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
#
+. tests/nvme/rc
+
DESCRIPTION="run data verification fio job on NVMeOF block device-backed ns"
TIMED=1
# Author: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
#
+. tests/nvme/rc
+
DESCRIPTION="run data verification fio job on NVMeOF file-backed ns"
TIMED=1
# Author: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
#
+. tests/nvme/rc
+
DESCRIPTION="run mkfs and data verification fio job on NVMeOF block device-backed ns"
TIMED=1
# Author: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
#
+. tests/nvme/rc
+
DESCRIPTION="run mkfs and data verification fio job on NVMeOF file-backed ns"
TIMED=1
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-. common/nvme
+. common/rc
group_requires() {
_have_root
group_device_requires() {
_test_dev_is_nvme
}
+
+NVMET_CFS="/sys/kernel/config/nvmet/"
+
+_test_dev_is_nvme() {
+ if ! readlink -f "$TEST_DEV_SYSFS/device" | grep -q nvme; then
+ SKIP_REASON="$TEST_DEV is not a NVMe device"
+ return 1
+ fi
+ return 0
+}
+
+_create_nvmet_port() {
+ local trtype="$1"
+
+ local port
+ for ((port = 0; ; port++)); do
+ if [[ ! -e "${NVMET_CFS}/ports/${port}" ]]; then
+ break
+ fi
+ done
+
+ mkdir "${NVMET_CFS}/ports/${port}"
+ echo "${trtype}" > "${NVMET_CFS}/ports/${port}/addr_trtype"
+
+ echo "${port}"
+}
+
+_remove_nvmet_port() {
+ local port="$1"
+ rmdir "${NVMET_CFS}/ports/${port}"
+}
+
+_create_nvmet_ns() {
+ local nvmet_subsystem="$1"
+ local nsid="$2"
+ local blkdev="$3"
+ local uuid="00000000-0000-0000-0000-000000000000"
+ local subsys_path="${NVMET_CFS}/subsystems/${nvmet_subsystem}"
+ local ns_path="${subsys_path}/namespaces/${nsid}"
+
+ if [[ $# -eq 4 ]]; then
+ uuid="$4"
+ fi
+
+ mkdir "${ns_path}"
+ printf "%s" "${blkdev}" > "${ns_path}/device_path"
+ printf "%s" "${uuid}" > "${ns_path}/device_uuid"
+ printf 1 > "${ns_path}/enable"
+}
+
+_create_nvmet_subsystem() {
+ local nvmet_subsystem="$1"
+ local blkdev="$2"
+ local uuid=$3
+ local cfs_path="${NVMET_CFS}/subsystems/${nvmet_subsystem}"
+
+ mkdir -p "${cfs_path}"
+ echo 1 > "${cfs_path}/attr_allow_any_host"
+ _create_nvmet_ns "${nvmet_subsystem}" "1" "${blkdev}" "${uuid}"
+}
+
+_remove_nvmet_ns() {
+ local nvmet_subsystem="$1"
+ local nsid=$2
+ local subsys_path="${NVMET_CFS}/subsystems/${nvmet_subsystem}"
+ local nvmet_ns_path="${subsys_path}/namespaces/${nsid}"
+
+ echo 0 > "${nvmet_ns_path}/enable"
+ rmdir "${nvmet_ns_path}"
+}
+
+_remove_nvmet_subsystem() {
+ local nvmet_subsystem="$1"
+ local subsys_path="${NVMET_CFS}/subsystems/${nvmet_subsystem}"
+
+ _remove_nvmet_ns "${nvmet_subsystem}" "1"
+ rmdir "${subsys_path}"
+}
+
+_add_nvmet_subsys_to_port() {
+ local port="$1"
+ local nvmet_subsystem="$2"
+
+ ln -s "${NVMET_CFS}/subsystems/${nvmet_subsystem}" \
+ "${NVMET_CFS}/ports/${port}/subsystems/${nvmet_subsystem}"
+}
+
+_remove_nvmet_subsystem_from_port() {
+ local port="$1"
+ local nvmet_subsystem="$2"
+
+ rm "${NVMET_CFS}/ports/${port}/subsystems/${nvmet_subsystem}"
+}
+
+_find_nvme_loop_dev() {
+ local dev
+ local transport
+ for dev in /sys/class/nvme/nvme*; do
+ dev="$(basename "$dev")"
+ transport="$(cat "/sys/class/nvme/${dev}/transport")"
+ if [[ "$transport" == "loop" ]]; then
+ echo "$dev"
+ fi
+ done
+}
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+. tests/scsi/rc
+
DESCRIPTION="try triggering a kernel GPF with 0 byte SG reads"
QUICK=1
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+. tests/scsi/rc
+
DESCRIPTION="perfom a SG_DXFER_FROM_DEV from the /dev/sg read-write interface"
QUICK=1
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+. tests/scsi/rc
+
DESCRIPTION="ensure re-reading the partition table keeps its read-only flag"
QUICK=1
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+. tests/scsi/rc
. common/scsi_debug
DESCRIPTION="ensure repeated TASK SET FULL results in EIO on timing out command"
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-. common/scsi
+. common/rc
group_requires() {
_have_root
group_device_requires() {
_test_dev_is_scsi
}
+
+_have_scsi_generic() {
+ _have_module sg
+}
+
+_test_dev_is_scsi() {
+ if [[ ! -d ${TEST_DEV_SYSFS}/device/scsi_device ]]; then
+ SKIP_REASON="$TEST_DEV is not a SCSI device"
+ return 1
+ fi
+ return 0
+}
+
+_get_test_dev_sg() {
+ echo "${TEST_DEV_SYSFS}"/device/scsi_generic/sg* | grep -Eo "sg[0-9]+"
+}