mirror of
https://github.com/torvalds/linux.git
synced 2025-12-07 11:56:58 +00:00
Split run.sh into separate scripts (setup.sh, run.sh, cleanup.sh) to
enable multi-device testing, and prepare for VFIO selftests
automatically detecting which devices to use for testing by storing
device metadata on the filesystem.
- setup.sh takes one or more BDFs as arguments and sets up each device.
Metadata about each device is stored on the filesystem in the
directory:
${TMPDIR:-/tmp}/vfio-selftests-devices
Within this directory is a directory for each BDF, and then files in
those directories that cleanup.sh uses to cleanup the device.
- run.sh runs a selftest by passing it the BDFs of all set up devices.
- cleanup.sh takes zero or more BDFs as arguments and cleans up each
device. If no BDFs are provided, it cleans up all devices.
This split enables multi-device testing by allowing multiple BDFs to be
set up and passed into tests:
For example:
$ tools/testing/selftests/vfio/scripts/setup.sh <BDF1> <BDF2>
$ tools/testing/selftests/vfio/scripts/setup.sh <BDF3>
$ tools/testing/selftests/vfio/scripts/run.sh echo
<BDF1> <BDF2> <BDF3>
$ tools/testing/selftests/vfio/scripts/cleanup.sh
In the future, VFIO selftests can automatically detect set up devices by
inspecting ${TMPDIR:-/tmp}/vfio-selftests-devices. This will avoid the
need for the run.sh script.
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-3-dmatlack@google.com
Signed-off-by: Alex Williamson <alex@shazbot.org>
42 lines
797 B
Bash
Executable File
42 lines
797 B
Bash
Executable File
# SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
source $(dirname -- "${BASH_SOURCE[0]}")/lib.sh
|
|
|
|
function cleanup_devices() {
|
|
local device_bdf
|
|
local device_dir
|
|
|
|
for device_bdf in "$@"; do
|
|
device_dir=${DEVICES_DIR}/${device_bdf}
|
|
|
|
if [ -f ${device_dir}/vfio-pci ]; then
|
|
unbind ${device_bdf} vfio-pci
|
|
fi
|
|
|
|
if [ -f ${device_dir}/driver_override ]; then
|
|
clear_driver_override ${device_bdf}
|
|
fi
|
|
|
|
if [ -f ${device_dir}/driver ]; then
|
|
bind ${device_bdf} $(cat ${device_dir}/driver)
|
|
fi
|
|
|
|
if [ -f ${device_dir}/sriov_numvfs ]; then
|
|
set_sriov_numvfs ${device_bdf} $(cat ${device_dir}/sriov_numvfs)
|
|
fi
|
|
|
|
rm -rf ${device_dir}
|
|
done
|
|
}
|
|
|
|
function main() {
|
|
if [ $# = 0 ]; then
|
|
cleanup_devices $(ls ${DEVICES_DIR})
|
|
rmdir ${DEVICES_DIR}
|
|
else
|
|
cleanup_devices "$@"
|
|
fi
|
|
}
|
|
|
|
main "$@"
|