]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-client.git/commitdiff
vfio: selftests: Move run.sh into scripts directory
authorDavid Matlack <dmatlack@google.com>
Wed, 26 Nov 2025 23:17:16 +0000 (23:17 +0000)
committerAlex Williamson <alex@shazbot.org>
Fri, 28 Nov 2025 17:58:06 +0000 (10:58 -0700)
Move run.sh in a new sub-directory scripts/. This directory will be used
to house various helper scripts to be used by humans and automation for
running VFIO selftests.

Opportunistically also switch run.sh from TEST_PROGS_EXTENDED to
TEST_FILES. The former is for actual test executables that are just not
run by default. TEST_FILES is a better fit for helper scripts.

No functional change intended.

Reviewed-by: Alex Mastro <amastro@fb.com>
Tested-by: Alex Mastro <amastro@fb.com>
Reviewed-by: Raghavendra Rao Ananta <rananta@google.com>
Signed-off-by: David Matlack <dmatlack@google.com>
Link: https://lore.kernel.org/r/20251126231733.3302983-2-dmatlack@google.com
Signed-off-by: Alex Williamson <alex@shazbot.org>
tools/testing/selftests/vfio/Makefile
tools/testing/selftests/vfio/run.sh [deleted file]
tools/testing/selftests/vfio/scripts/run.sh [new file with mode: 0755]

index 324ba0175a333cc4f9eadc050c9c4bba9d6714c4..ad7fa4071c20531c45ea7b5e38ef2805702487e6 100644 (file)
@@ -3,7 +3,9 @@ TEST_GEN_PROGS += vfio_dma_mapping_test
 TEST_GEN_PROGS += vfio_iommufd_setup_test
 TEST_GEN_PROGS += vfio_pci_device_test
 TEST_GEN_PROGS += vfio_pci_driver_test
-TEST_PROGS_EXTENDED := run.sh
+
+TEST_FILES += scripts/run.sh
+
 include ../lib.mk
 include lib/libvfio.mk
 
diff --git a/tools/testing/selftests/vfio/run.sh b/tools/testing/selftests/vfio/run.sh
deleted file mode 100755 (executable)
index 0476b6d..0000000
+++ /dev/null
@@ -1,109 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0-or-later
-
-# Global variables initialized in main() and then used during cleanup() when
-# the script exits.
-declare DEVICE_BDF
-declare NEW_DRIVER
-declare OLD_DRIVER
-declare OLD_NUMVFS
-declare DRIVER_OVERRIDE
-
-function write_to() {
-       # Unfortunately set -x does not show redirects so use echo to manually
-       # tell the user what commands are being run.
-       echo "+ echo \"${2}\" > ${1}"
-       echo "${2}" > ${1}
-}
-
-function bind() {
-       write_to /sys/bus/pci/drivers/${2}/bind ${1}
-}
-
-function unbind() {
-       write_to /sys/bus/pci/drivers/${2}/unbind ${1}
-}
-
-function set_sriov_numvfs() {
-       write_to /sys/bus/pci/devices/${1}/sriov_numvfs ${2}
-}
-
-function set_driver_override() {
-       write_to /sys/bus/pci/devices/${1}/driver_override ${2}
-}
-
-function clear_driver_override() {
-       set_driver_override ${1} ""
-}
-
-function cleanup() {
-       if [ "${NEW_DRIVER}"      ]; then unbind ${DEVICE_BDF} ${NEW_DRIVER} ; fi
-       if [ "${DRIVER_OVERRIDE}" ]; then clear_driver_override ${DEVICE_BDF} ; fi
-       if [ "${OLD_DRIVER}"      ]; then bind ${DEVICE_BDF} ${OLD_DRIVER} ; fi
-       if [ "${OLD_NUMVFS}"      ]; then set_sriov_numvfs ${DEVICE_BDF} ${OLD_NUMVFS} ; fi
-}
-
-function usage() {
-       echo "usage: $0 [-d segment:bus:device.function] [-s] [-h] [cmd ...]" >&2
-       echo >&2
-       echo "  -d: The BDF of the device to use for the test (required)" >&2
-       echo "  -h: Show this help message" >&2
-       echo "  -s: Drop into a shell rather than running a command" >&2
-       echo >&2
-       echo "   cmd: The command to run and arguments to pass to it." >&2
-       echo "        Required when not using -s. The SBDF will be " >&2
-       echo "        appended to the argument list." >&2
-       exit 1
-}
-
-function main() {
-       local shell
-
-       while getopts "d:hs" opt; do
-               case $opt in
-                       d) DEVICE_BDF="$OPTARG" ;;
-                       s) shell=true ;;
-                       *) usage ;;
-               esac
-       done
-
-       # Shift past all optional arguments.
-       shift $((OPTIND - 1))
-
-       # Check that the user passed in the command to run.
-       [ ! "${shell}" ] && [ $# = 0 ] && usage
-
-       # Check that the user passed in a BDF.
-       [ "${DEVICE_BDF}" ] || usage
-
-       trap cleanup EXIT
-       set -e
-
-       test -d /sys/bus/pci/devices/${DEVICE_BDF}
-
-       if [ -f /sys/bus/pci/devices/${DEVICE_BDF}/sriov_numvfs ]; then
-               OLD_NUMVFS=$(cat /sys/bus/pci/devices/${DEVICE_BDF}/sriov_numvfs)
-               set_sriov_numvfs ${DEVICE_BDF} 0
-       fi
-
-       if [ -L /sys/bus/pci/devices/${DEVICE_BDF}/driver ]; then
-               OLD_DRIVER=$(basename $(readlink -m /sys/bus/pci/devices/${DEVICE_BDF}/driver))
-               unbind ${DEVICE_BDF} ${OLD_DRIVER}
-       fi
-
-       set_driver_override ${DEVICE_BDF} vfio-pci
-       DRIVER_OVERRIDE=true
-
-       bind ${DEVICE_BDF} vfio-pci
-       NEW_DRIVER=vfio-pci
-
-       echo
-       if [ "${shell}" ]; then
-               echo "Dropping into ${SHELL} with VFIO_SELFTESTS_BDF=${DEVICE_BDF}"
-               VFIO_SELFTESTS_BDF=${DEVICE_BDF} ${SHELL}
-       else
-               "$@" ${DEVICE_BDF}
-       fi
-       echo
-}
-
-main "$@"
diff --git a/tools/testing/selftests/vfio/scripts/run.sh b/tools/testing/selftests/vfio/scripts/run.sh
new file mode 100755 (executable)
index 0000000..0476b6d
--- /dev/null
@@ -0,0 +1,109 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+# Global variables initialized in main() and then used during cleanup() when
+# the script exits.
+declare DEVICE_BDF
+declare NEW_DRIVER
+declare OLD_DRIVER
+declare OLD_NUMVFS
+declare DRIVER_OVERRIDE
+
+function write_to() {
+       # Unfortunately set -x does not show redirects so use echo to manually
+       # tell the user what commands are being run.
+       echo "+ echo \"${2}\" > ${1}"
+       echo "${2}" > ${1}
+}
+
+function bind() {
+       write_to /sys/bus/pci/drivers/${2}/bind ${1}
+}
+
+function unbind() {
+       write_to /sys/bus/pci/drivers/${2}/unbind ${1}
+}
+
+function set_sriov_numvfs() {
+       write_to /sys/bus/pci/devices/${1}/sriov_numvfs ${2}
+}
+
+function set_driver_override() {
+       write_to /sys/bus/pci/devices/${1}/driver_override ${2}
+}
+
+function clear_driver_override() {
+       set_driver_override ${1} ""
+}
+
+function cleanup() {
+       if [ "${NEW_DRIVER}"      ]; then unbind ${DEVICE_BDF} ${NEW_DRIVER} ; fi
+       if [ "${DRIVER_OVERRIDE}" ]; then clear_driver_override ${DEVICE_BDF} ; fi
+       if [ "${OLD_DRIVER}"      ]; then bind ${DEVICE_BDF} ${OLD_DRIVER} ; fi
+       if [ "${OLD_NUMVFS}"      ]; then set_sriov_numvfs ${DEVICE_BDF} ${OLD_NUMVFS} ; fi
+}
+
+function usage() {
+       echo "usage: $0 [-d segment:bus:device.function] [-s] [-h] [cmd ...]" >&2
+       echo >&2
+       echo "  -d: The BDF of the device to use for the test (required)" >&2
+       echo "  -h: Show this help message" >&2
+       echo "  -s: Drop into a shell rather than running a command" >&2
+       echo >&2
+       echo "   cmd: The command to run and arguments to pass to it." >&2
+       echo "        Required when not using -s. The SBDF will be " >&2
+       echo "        appended to the argument list." >&2
+       exit 1
+}
+
+function main() {
+       local shell
+
+       while getopts "d:hs" opt; do
+               case $opt in
+                       d) DEVICE_BDF="$OPTARG" ;;
+                       s) shell=true ;;
+                       *) usage ;;
+               esac
+       done
+
+       # Shift past all optional arguments.
+       shift $((OPTIND - 1))
+
+       # Check that the user passed in the command to run.
+       [ ! "${shell}" ] && [ $# = 0 ] && usage
+
+       # Check that the user passed in a BDF.
+       [ "${DEVICE_BDF}" ] || usage
+
+       trap cleanup EXIT
+       set -e
+
+       test -d /sys/bus/pci/devices/${DEVICE_BDF}
+
+       if [ -f /sys/bus/pci/devices/${DEVICE_BDF}/sriov_numvfs ]; then
+               OLD_NUMVFS=$(cat /sys/bus/pci/devices/${DEVICE_BDF}/sriov_numvfs)
+               set_sriov_numvfs ${DEVICE_BDF} 0
+       fi
+
+       if [ -L /sys/bus/pci/devices/${DEVICE_BDF}/driver ]; then
+               OLD_DRIVER=$(basename $(readlink -m /sys/bus/pci/devices/${DEVICE_BDF}/driver))
+               unbind ${DEVICE_BDF} ${OLD_DRIVER}
+       fi
+
+       set_driver_override ${DEVICE_BDF} vfio-pci
+       DRIVER_OVERRIDE=true
+
+       bind ${DEVICE_BDF} vfio-pci
+       NEW_DRIVER=vfio-pci
+
+       echo
+       if [ "${shell}" ]; then
+               echo "Dropping into ${SHELL} with VFIO_SELFTESTS_BDF=${DEVICE_BDF}"
+               VFIO_SELFTESTS_BDF=${DEVICE_BDF} ${SHELL}
+       else
+               "$@" ${DEVICE_BDF}
+       fi
+       echo
+}
+
+main "$@"