From: Omar Sandoval Date: Tue, 26 Jun 2018 18:27:11 +0000 (-0700) Subject: Make group/rc and common/rc sources explicit and reenable SC2034 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=4ec63eecdfd8b4f30d0f2355a7ab742f8d1f89f0;p=users%2Fsagi%2Fblktests.git Make group/rc and common/rc sources explicit and reenable SC2034 SC2034 (unused variable) is a useful warning, but we disabled it because we set a bunch of global variables as test metadata. However, this is easy to work around: as Bart demonstrated, an echo "$VAR" > /dev/null does the trick. However, we don't want to copy-and-paste this everywhere, so we need to source something everywhere. Bart's idea was to put this in common/shellcheck and source that everywhere. Sourcing a file just to appease the linter is silly, though, so instead, this adds explicit sources of tests/*/rc to each test, which in turn sources common/rc, which in turn sources common/shellcheck. Signed-off-by: Omar Sandoval --- diff --git a/Makefile b/Makefile index e3c379f..38b8ad1 100644 --- a/Makefile +++ b/Makefile @@ -4,15 +4,13 @@ all: 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 diff --git a/check b/check index afd0dcc..fd9f09c 100755 --- a/check +++ b/check @@ -15,7 +15,16 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -. common/rc +shopt -s extglob + +_warning() { + echo "$0: $*" >&2 +} + +_error() { + echo "$0: $*" >&2 + exit 1 +} _found_test() { local test_name="$1" @@ -303,6 +312,7 @@ _cleanup() { _call_test() { local test_func="$1" local seqres="${RESULTS_DIR}/${TEST_NAME}" + # shellcheck disable=SC2034 FULL="${seqres}.full" declare -A TEST_DEV_QUEUE_SAVED @@ -495,6 +505,7 @@ _find_sysfs_dir() { declare -A TEST_DEV_SYSFS_DIRS _check() { + # shellcheck disable=SC2034 SRCDIR="$(realpath src)" local test_dev diff --git a/common/cpuhotplug b/common/cpuhotplug index 70b284f..e5b314a 100644 --- a/common/cpuhotplug +++ b/common/cpuhotplug @@ -17,6 +17,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +. common/shellcheck + # Also initializes the ALL_CPUS and HOTPLUGGABLE_CPUS arrays. _have_cpu_hotplug() { ALL_CPUS=() @@ -29,6 +31,7 @@ _have_cpu_hotplug() { 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 @@ -41,11 +44,13 @@ _have_cpu_hotplug() { } _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" } diff --git a/common/fio b/common/fio index 0f93632..9497968 100644 --- a/common/fio +++ b/common/fio @@ -17,6 +17,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +. common/shellcheck + _have_fio() { if ! _have_program fio; then return 1 diff --git a/common/iopoll b/common/iopoll index affdd43..10ebd16 100644 --- a/common/iopoll +++ b/common/iopoll @@ -17,6 +17,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +. common/shellcheck + _have_fio_with_poll() { if ! _have_fio; then return 1 diff --git a/common/nbd b/common/nbd deleted file mode 100644 index 320f456..0000000 --- a/common/nbd +++ /dev/null @@ -1,85 +0,0 @@ -#!/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 . - -_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" -} diff --git a/common/nvme b/common/nvme deleted file mode 100644 index 044d7fe..0000000 --- a/common/nvme +++ /dev/null @@ -1,123 +0,0 @@ -#!/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 . - -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 -} diff --git a/common/rc b/common/rc index 7592400..57e1c50 100644 --- a/common/rc +++ b/common/rc @@ -19,18 +19,10 @@ 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() { diff --git a/common/scsi b/common/scsi deleted file mode 100644 index d9fcc0e..0000000 --- a/common/scsi +++ /dev/null @@ -1,34 +0,0 @@ -#!/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 . - -_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]+" -} diff --git a/common/loop b/common/shellcheck similarity index 71% rename from common/loop rename to common/shellcheck index 16cc321..347ad62 100644 --- a/common/loop +++ b/common/shellcheck @@ -1,8 +1,8 @@ #!/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 @@ -17,12 +17,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . - -_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 } diff --git a/new b/new index 1cd3233..5c6e1eb 100755 --- a/new +++ b/new @@ -16,8 +16,12 @@ # along with this program. If not, see . set -e +shopt -s extglob -. common/rc +_error() { + echo "$0: $*" >&2 + exit 1 +} prompt_yes_no() { if [[ $2 =~ ^[Yy] ]]; then @@ -84,10 +88,8 @@ if [[ ! -e tests/${group} ]]; then # You should have received a copy of the GNU General Public License # along with this program. If not, see . -# 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 @@ -117,6 +119,8 @@ group_requires() { # 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 @@ -159,6 +163,9 @@ cat << EOF > "tests/${test_name}" # You should have received a copy of the GNU General Public License # along with this program. If not, see . +. 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. @@ -254,9 +261,9 @@ test() { # - 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. diff --git a/tests/block/001 b/tests/block/001 index 7411a0c..7f794f2 100755 --- a/tests/block/001 +++ b/tests/block/001 @@ -19,6 +19,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +. tests/block/rc . common/scsi_debug DESCRIPTION="stress device hotplugging" diff --git a/tests/block/002 b/tests/block/002 index 57b4f89..8d95b57 100755 --- a/tests/block/002 +++ b/tests/block/002 @@ -18,6 +18,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +. tests/block/rc . common/scsi_debug DESCRIPTION="remove a device while running blktrace" diff --git a/tests/block/003 b/tests/block/003 index 87e30a3..38eb3e0 100755 --- a/tests/block/003 +++ b/tests/block/003 @@ -17,6 +17,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +. tests/block/rc + DESCRIPTION="run various discard sizes" TIMED=1 diff --git a/tests/block/004 b/tests/block/004 index 754d302..92a4b18 100755 --- a/tests/block/004 +++ b/tests/block/004 @@ -17,6 +17,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +. tests/block/rc + DESCRIPTION="run lots of flushes" TIMED=1 diff --git a/tests/block/005 b/tests/block/005 index fae5927..3bcdc25 100755 --- a/tests/block/005 +++ b/tests/block/005 @@ -17,6 +17,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +. tests/block/rc + DESCRIPTION="switch schedulers while doing IO" TIMED=1 diff --git a/tests/block/006 b/tests/block/006 index 0a47293..a5f1310 100755 --- a/tests/block/006 +++ b/tests/block/006 @@ -20,6 +20,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +. tests/block/rc + DESCRIPTION="run null-blk in blocking mode" TIMED=1 diff --git a/tests/block/007 b/tests/block/007 index e35649a..ae8b397 100755 --- a/tests/block/007 +++ b/tests/block/007 @@ -17,6 +17,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +. tests/block/rc . common/iopoll DESCRIPTION="test classic and hybrid IO polling" diff --git a/tests/block/008 b/tests/block/008 index fcd905a..9b41bf5 100755 --- a/tests/block/008 +++ b/tests/block/008 @@ -17,6 +17,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +. tests/block/rc . common/cpuhotplug DESCRIPTION="do IO while hotplugging CPUs" diff --git a/tests/block/009 b/tests/block/009 index cbeeb70..9727c12 100755 --- a/tests/block/009 +++ b/tests/block/009 @@ -19,10 +19,11 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -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 } diff --git a/tests/block/010 b/tests/block/010 index 97891d2..5b54e71 100644 --- a/tests/block/010 +++ b/tests/block/010 @@ -20,6 +20,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +. tests/block/rc + DESCRIPTION="run I/O on null_blk with shared and non-shared tags" TIMED=1 diff --git a/tests/block/011 b/tests/block/011 index 2461442..596bc0f 100755 --- a/tests/block/011 +++ b/tests/block/011 @@ -17,6 +17,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +. tests/block/rc + DESCRIPTION="disable PCI device while doing I/O" TIMED=1 diff --git a/tests/block/012 b/tests/block/012 index baabdd6..13d2e0e 100755 --- a/tests/block/012 +++ b/tests/block/012 @@ -17,6 +17,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +. tests/block/rc + DESCRIPTION="check that a read-only block device fails writes" TIMED=1 diff --git a/tests/block/013 b/tests/block/013 index 415b34d..8e24238 100755 --- a/tests/block/013 +++ b/tests/block/013 @@ -23,6 +23,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +. tests/block/rc + DESCRIPTION="try BLKRRPART on a mounted device" QUICK=1 diff --git a/tests/block/014 b/tests/block/014 index 882a9b9..1da604f 100755 --- a/tests/block/014 +++ b/tests/block/014 @@ -17,6 +17,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +. tests/block/rc + DESCRIPTION="run null-blk with timeout injection configured" requires() { diff --git a/tests/block/015 b/tests/block/015 index b236a6d..c44d4da 100755 --- a/tests/block/015 +++ b/tests/block/015 @@ -18,8 +18,9 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -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() { diff --git a/tests/block/016 b/tests/block/016 index 6ccfe98..bef3aa4 100755 --- a/tests/block/016 +++ b/tests/block/016 @@ -19,6 +19,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +. tests/block/rc + DESCRIPTION="send a signal to a process waiting on a frozen queue" QUICK=1 diff --git a/tests/block/017 b/tests/block/017 index 436a8f3..e1a8afd 100755 --- a/tests/block/017 +++ b/tests/block/017 @@ -19,6 +19,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +. tests/block/rc + DESCRIPTION="do I/O and check the inflight counter" QUICK=1 diff --git a/tests/block/018 b/tests/block/018 index 548f1ba..53cf584 100755 --- a/tests/block/018 +++ b/tests/block/018 @@ -17,6 +17,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +. tests/block/rc + DESCRIPTION="do I/O and check iostats times" QUICK=1 diff --git a/tests/block/019 b/tests/block/019 index 00830d0..ed005b5 100755 --- a/tests/block/019 +++ b/tests/block/019 @@ -17,6 +17,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +. tests/block/rc + DESCRIPTION="break PCI link device while doing I/O" QUICK=1 diff --git a/tests/block/020 b/tests/block/020 index 3614013..a744f64 100755 --- a/tests/block/020 +++ b/tests/block/020 @@ -19,6 +19,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +. tests/block/rc + DESCRIPTION="run null-blk on different schedulers with only one hardware tag" QUICK=1 diff --git a/tests/block/021 b/tests/block/021 index 74fa709..3210f58 100755 --- a/tests/block/021 +++ b/tests/block/021 @@ -19,6 +19,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +. tests/block/rc + DESCRIPTION="read/write nr_requests on null-blk with different schedulers" QUICK=1 diff --git a/tests/block/rc b/tests/block/rc index 689cafc..fdd8450 100644 --- a/tests/block/rc +++ b/tests/block/rc @@ -17,6 +17,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +. common/rc + group_requires() { _have_root } diff --git a/tests/loop/001 b/tests/loop/001 index 1f009bd..49caa9e 100755 --- a/tests/loop/001 +++ b/tests/loop/001 @@ -18,6 +18,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +. tests/loop/rc + DESCRIPTION="scan loop device partitions" QUICK=1 diff --git a/tests/loop/002 b/tests/loop/002 index 2a16dba..e89392b 100755 --- a/tests/loop/002 +++ b/tests/loop/002 @@ -22,7 +22,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -. common/loop +. tests/loop/rc DESCRIPTION="try various loop device block sizes" QUICK=1 diff --git a/tests/loop/003 b/tests/loop/003 index 22f49a8..c6570aa 100755 --- a/tests/loop/003 +++ b/tests/loop/003 @@ -18,6 +18,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +. tests/loop/rc + DESCRIPTION="time opening and closing an unbound loop device" QUICK=1 diff --git a/tests/loop/004 b/tests/loop/004 index 8dcc851..7b1d609 100755 --- a/tests/loop/004 +++ b/tests/loop/004 @@ -17,7 +17,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -. common/loop +. tests/loop/rc . common/scsi_debug DESCRIPTION="combine loop direct I/O mode and a custom block size" diff --git a/tests/loop/005 b/tests/loop/005 index b57ddb3..7ca8c4f 100755 --- a/tests/loop/005 +++ b/tests/loop/005 @@ -19,8 +19,9 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -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() { diff --git a/tests/loop/rc b/tests/loop/rc index 5d0a4e5..a48f9ea 100644 --- a/tests/loop/rc +++ b/tests/loop/rc @@ -17,6 +17,17 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +. 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 +} diff --git a/tests/meta/001 b/tests/meta/001 index 454fb22..78b9f3d 100755 --- a/tests/meta/001 +++ b/tests/meta/001 @@ -17,6 +17,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +. tests/meta/rc + DESCRIPTION="do nothing" test() { diff --git a/tests/meta/002 b/tests/meta/002 index 5a2cd53..6fafa00 100755 --- a/tests/meta/002 +++ b/tests/meta/002 @@ -17,6 +17,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +. tests/meta/rc + DESCRIPTION="do nothing" test_device() { diff --git a/tests/meta/003 b/tests/meta/003 index eb79bca..0e39bdd 100755 --- a/tests/meta/003 +++ b/tests/meta/003 @@ -17,6 +17,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +. tests/meta/rc + DESCRIPTION="exit with non-zero status" test() { diff --git a/tests/meta/004 b/tests/meta/004 index bafe6c5..dace17b 100755 --- a/tests/meta/004 +++ b/tests/meta/004 @@ -17,6 +17,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +. tests/meta/rc + DESCRIPTION="exit with non-zero status" test_device() { diff --git a/tests/meta/005 b/tests/meta/005 index c9909c6..445356f 100755 --- a/tests/meta/005 +++ b/tests/meta/005 @@ -17,6 +17,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +. tests/meta/rc + DESCRIPTION="produce bad output" test() { diff --git a/tests/meta/006 b/tests/meta/006 index 9d28bdc..027e324 100755 --- a/tests/meta/006 +++ b/tests/meta/006 @@ -17,6 +17,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +. tests/meta/rc + DESCRIPTION="produce lots of bad output" test() { diff --git a/tests/meta/007 b/tests/meta/007 index 2516796..20bb0fe 100755 --- a/tests/meta/007 +++ b/tests/meta/007 @@ -17,6 +17,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +. tests/meta/rc + DESCRIPTION="skip in requires()" requires() { diff --git a/tests/meta/008 b/tests/meta/008 index 5d24669..ca72fad 100755 --- a/tests/meta/008 +++ b/tests/meta/008 @@ -17,6 +17,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +. tests/meta/rc + DESCRIPTION="skip in device_requires()" device_requires() { diff --git a/tests/meta/009 b/tests/meta/009 index abeb56e..f2d6c0f 100755 --- a/tests/meta/009 +++ b/tests/meta/009 @@ -17,6 +17,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +. tests/meta/rc + DESCRIPTION="check dmesg" requires() { diff --git a/tests/meta/010 b/tests/meta/010 index c179dad..bc4b74f 100755 --- a/tests/meta/010 +++ b/tests/meta/010 @@ -17,6 +17,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +. tests/meta/rc + DESCRIPTION="disable check dmesg" CHECK_DMESG=0 diff --git a/tests/meta/011 b/tests/meta/011 index 010ba4b..e8ccad7 100755 --- a/tests/meta/011 +++ b/tests/meta/011 @@ -17,6 +17,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +. tests/meta/rc + DESCRIPTION="filter dmesg" DMESG_FILTER="grep -v BUG" diff --git a/tests/meta/012 b/tests/meta/012 index ab8c2a7..4e0a9b0 100755 --- a/tests/meta/012 +++ b/tests/meta/012 @@ -17,6 +17,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +. tests/meta/rc + DESCRIPTION="record pid and random junk" test() { diff --git a/tests/meta/rc b/tests/meta/rc index 8e3322e..190ee4a 100644 --- a/tests/meta/rc +++ b/tests/meta/rc @@ -17,6 +17,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +. common/rc + group_requires() { if [[ -v META_REQUIRES_SKIP ]]; then SKIP_REASON="META_REQUIRES_SKIP was set" diff --git a/tests/nbd/001 b/tests/nbd/001 index 73ccaec..415a48d 100644 --- a/tests/nbd/001 +++ b/tests/nbd/001 @@ -18,6 +18,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +. tests/nbd/rc + DESCRIPTION="resize a connected nbd device" QUICK=1 diff --git a/tests/nbd/002 b/tests/nbd/002 index c06c946..99acff7 100644 --- a/tests/nbd/002 +++ b/tests/nbd/002 @@ -24,6 +24,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +. tests/nbd/rc + DESCRIPTION="tests on partition handling for an nbd device" QUICK=1 diff --git a/tests/nbd/rc b/tests/nbd/rc index 0d4c1c4..83a7417 100644 --- a/tests/nbd/rc +++ b/tests/nbd/rc @@ -17,8 +17,75 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -. 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" +} diff --git a/tests/nvme/001 b/tests/nvme/001 index 0b5f241..cfe675e 100755 --- a/tests/nvme/001 +++ b/tests/nvme/001 @@ -18,8 +18,9 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -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() { diff --git a/tests/nvme/002 b/tests/nvme/002 index 786505e..7e1815a 100755 --- a/tests/nvme/002 +++ b/tests/nvme/002 @@ -18,6 +18,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +. tests/nvme/rc + DESCRIPTION="create many subsystems and test discovery" requires() { diff --git a/tests/nvme/003 b/tests/nvme/003 index 9634130..d22b8cf 100755 --- a/tests/nvme/003 +++ b/tests/nvme/003 @@ -18,8 +18,9 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -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() { diff --git a/tests/nvme/004 b/tests/nvme/004 index ad268e2..3394740 100755 --- a/tests/nvme/004 +++ b/tests/nvme/004 @@ -19,6 +19,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +. tests/nvme/rc + DESCRIPTION="test nvme and nvmet UUID NS descriptors" QUICK=1 diff --git a/tests/nvme/005 b/tests/nvme/005 index f993019..e00f8e0 100755 --- a/tests/nvme/005 +++ b/tests/nvme/005 @@ -18,8 +18,9 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -DESCRIPTION="reset local loopback target" +. tests/nvme/rc +DESCRIPTION="reset local loopback target" QUICK=1 requires() { diff --git a/tests/nvme/006 b/tests/nvme/006 index ecf0c33..977a363 100755 --- a/tests/nvme/006 +++ b/tests/nvme/006 @@ -20,6 +20,8 @@ # Author: Chaitanya Kulkarni # +. tests/nvme/rc + DESCRIPTION="create an NVMeOF target with a block device-backed ns" QUICK=1 diff --git a/tests/nvme/007 b/tests/nvme/007 index 0263313..78f7172 100755 --- a/tests/nvme/007 +++ b/tests/nvme/007 @@ -20,6 +20,8 @@ # Author: Chaitanya Kulkarni # +. tests/nvme/rc + DESCRIPTION="create an NVMeOF target with a file-backed ns" QUICK=1 diff --git a/tests/nvme/008 b/tests/nvme/008 index dd62b25..013928d 100755 --- a/tests/nvme/008 +++ b/tests/nvme/008 @@ -20,6 +20,8 @@ # Author: Chaitanya Kulkarni # +. tests/nvme/rc + DESCRIPTION="create an NVMeOF host with a block device-backed ns" QUICK=1 diff --git a/tests/nvme/009 b/tests/nvme/009 index 0372788..9ba46e7 100755 --- a/tests/nvme/009 +++ b/tests/nvme/009 @@ -20,6 +20,8 @@ # Author: Chaitanya Kulkarni # +. tests/nvme/rc + DESCRIPTION="create an NVMeOF host with a file-backed ns" QUICK=1 diff --git a/tests/nvme/010 b/tests/nvme/010 index 91e447c..3bdf57d 100755 --- a/tests/nvme/010 +++ b/tests/nvme/010 @@ -20,6 +20,8 @@ # Author: Chaitanya Kulkarni # +. tests/nvme/rc + DESCRIPTION="run data verification fio job on NVMeOF block device-backed ns" TIMED=1 diff --git a/tests/nvme/011 b/tests/nvme/011 index 8bf2074..1948476 100755 --- a/tests/nvme/011 +++ b/tests/nvme/011 @@ -20,6 +20,8 @@ # Author: Chaitanya Kulkarni # +. tests/nvme/rc + DESCRIPTION="run data verification fio job on NVMeOF file-backed ns" TIMED=1 diff --git a/tests/nvme/012 b/tests/nvme/012 index 21a3809..bdf3756 100755 --- a/tests/nvme/012 +++ b/tests/nvme/012 @@ -20,6 +20,8 @@ # Author: Chaitanya Kulkarni # +. tests/nvme/rc + DESCRIPTION="run mkfs and data verification fio job on NVMeOF block device-backed ns" TIMED=1 diff --git a/tests/nvme/013 b/tests/nvme/013 index 26efe24..7f42e49 100755 --- a/tests/nvme/013 +++ b/tests/nvme/013 @@ -20,6 +20,8 @@ # Author: Chaitanya Kulkarni # +. tests/nvme/rc + DESCRIPTION="run mkfs and data verification fio job on NVMeOF file-backed ns" TIMED=1 diff --git a/tests/nvme/rc b/tests/nvme/rc index 5e4e65c..fb5dbdf 100644 --- a/tests/nvme/rc +++ b/tests/nvme/rc @@ -17,7 +17,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -. common/nvme +. common/rc group_requires() { _have_root @@ -26,3 +26,108 @@ group_requires() { 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 +} diff --git a/tests/scsi/001 b/tests/scsi/001 index 17fc088..9b238ce 100755 --- a/tests/scsi/001 +++ b/tests/scsi/001 @@ -18,6 +18,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +. tests/scsi/rc + DESCRIPTION="try triggering a kernel GPF with 0 byte SG reads" QUICK=1 diff --git a/tests/scsi/002 b/tests/scsi/002 index da2d0cc..21e69e0 100755 --- a/tests/scsi/002 +++ b/tests/scsi/002 @@ -18,6 +18,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +. tests/scsi/rc + DESCRIPTION="perfom a SG_DXFER_FROM_DEV from the /dev/sg read-write interface" QUICK=1 diff --git a/tests/scsi/003 b/tests/scsi/003 index 81015f0..4ce7129 100755 --- a/tests/scsi/003 +++ b/tests/scsi/003 @@ -18,6 +18,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +. tests/scsi/rc + DESCRIPTION="ensure re-reading the partition table keeps its read-only flag" QUICK=1 diff --git a/tests/scsi/004 b/tests/scsi/004 index 8c61d1e..34ffbb7 100755 --- a/tests/scsi/004 +++ b/tests/scsi/004 @@ -25,6 +25,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +. tests/scsi/rc . common/scsi_debug DESCRIPTION="ensure repeated TASK SET FULL results in EIO on timing out command" diff --git a/tests/scsi/rc b/tests/scsi/rc index e8b3161..62033fa 100644 --- a/tests/scsi/rc +++ b/tests/scsi/rc @@ -17,7 +17,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -. common/scsi +. common/rc group_requires() { _have_root @@ -26,3 +26,19 @@ group_requires() { 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]+" +}