3 BASE_DIR
=$
(readlink
-f $
(dirname $0))
4 [[ -z "$TEST_DIR" ]] && TEST_DIR
="$(cd $BASE_DIR/../../../../ && pwd)"
9 fio_jobs
="$BASE_DIR/fio_jobs/"
22 [[ ! -z $2 ]] && ( echo "$2"; echo ""; )
23 echo "Shortcut script for doing automated test"
24 echo "Usage: $(basename $1) [OPTIONS]"
26 echo "-h, --help print help and exit"
27 echo " --test-type=TYPE Perform specified test:"
28 echo " virtio - test host virtio-scsi-pci using file as disk image"
29 echo " kernel_vhost - use kernel driver vhost-scsi"
30 echo " spdk_vhost - use spdk vhost"
31 echo "-x set -x for script debug"
32 echo " --fio-bin=FIO Use specific fio binary (will be uploaded to VM)"
33 echo " --qemu-src=QEMU_DIR Location of the QEMU sources"
34 echo " --dpdk-src=DPDK_DIR Location of the DPDK sources"
35 echo " --fio-jobs= Fio configs to use for tests. Can point to a directory or"
36 echo " can point to a directory with regex mask, example: ./dir/*.job"
37 echo " All VMs will run the same fio job when FIO executes."
38 echo " (no unique jobs for specific VMs)"
39 echo " --work-dir=WORK_DIR Where to find build file. Must exist. [default: $TEST_DIR]"
40 echo " --dry-run Don't perform any tests, run only and wait for enter to terminate"
41 echo " --no-shutdown Don't shutdown at the end but leave envirionment working"
42 echo " --force-build Force SPDK rebuild with the specified DPDK path."
43 echo " --vm=NUM[,OS][,DISKS] VM configuration. This parameter might be used more than once:"
44 echo " NUM - VM number (mandatory)"
45 echo " OS - VM os disk path (optional)"
46 echo " DISKS - VM os test disks/devices path (virtio - optional, kernel_vhost - mandatory)"
47 echo " --disk-split By default all test types execute fio jobs on all disks which are available on guest"
48 echo " system. Use this option if only some of the disks should be used for testing."
49 echo " Example: --disk-split=4,1-3 will result in VM 1 using it's first disk (ex. /dev/sda)"
50 echo " and VM 2 using it's disks 1-3 (ex. /dev/sdb, /dev/sdc, /dev/sdd)"
51 echo " --max-sectors=NUM Set max_sectors_kb for test disk to NUM (default: $max_sectors_kb)"
55 #default raw file is NVMe drive
57 while getopts 'xh-:' optchar
; do
62 work-dir
=*) TEST_DIR
="${OPTARG#*=}" ;;
63 fio-bin
=*) fio_bin
="--fio-bin=${OPTARG#*=}" ;;
64 qemu-src
=*) QEMU_SRC_DIR
="${OPTARG#*=}" ;;
65 dpdk-src
=*) DPDK_SRC_DIR
="${OPTARG#*=}" ;;
66 fio-jobs
=*) fio_jobs
="${OPTARG#*=}" ;;
67 dry-run
) dry_run
=true
;;
68 no-shutdown
) no_shutdown
=true
;;
69 test-type
=*) test_type
="${OPTARG#*=}" ;;
70 force-build
) force_build
=true
;;
71 vm
=*) vms
+=("${OPTARG#*=}") ;;
72 disk-split
=*) disk_split
="${OPTARG#*=}" ;;
73 max-sectors
=*) max_sectors_kb
="${OPTARG#*=}" ;;
74 *) usage
$0 "Invalid argument '$OPTARG'" ;;
80 *) usage
$0 "Invalid argument '$OPTARG'"
83 shift $
(( OPTIND
- 1 ))
85 if [[ -d "$fio_jobs" ]]; then
86 fio_jobs
="$fio_jobs/*.job"
91 trap 'error_exit "${FUNCNAME}" "${LINENO}"' ERR
93 echo "==============="
94 echo "INFO: checking qemu"
96 if [[ ! -x $INSTALL_DIR/bin
/qemu-system-x86_64
]]; then
97 echo "INFO: can't find $INSTALL_DIR/bin/qemu-system-x86_64 - building and installing"
99 if [[ ! -d $QEMU_SRC_DIR ]]; then
100 echo "ERROR: Cannot find qemu source in $QEMU_SRC_DIR"
103 echo "INFO: qemu source exists $QEMU_SRC_DIR - building"
104 qemu_build_and_install
108 echo "==============="
110 echo "INFO: checking spdk"
113 if [[ ! -x $SPDK_BUILD_DIR/app
/vhost
/vhost
]] ||
$force_build ; then
114 echo "INFO: $SPDK_BUILD_DIR/app/vhost/vhost - building and installing"
115 spdk_build_and_install
120 if [[ $test_type == "spdk_vhost" ]]; then
121 echo "==============="
123 echo "INFO: running SPDK"
125 $BASE_DIR/run_vhost.sh
$x --work-dir=$TEST_DIR
129 echo "==============="
134 rpc_py
="python $SPDK_BUILD_DIR/scripts/rpc.py "
135 rpc_py
+="-s 127.0.0.1 "
137 for vm_conf
in ${vms[@]}; do
138 IFS
=',' read -ra conf
<<< "$vm_conf"
139 setup_cmd
="$BASE_DIR/vm_setup.sh $x --work-dir=$TEST_DIR --test-type=$test_type"
140 if [[ x
"${conf[0]}" == x
"" ]] ||
! assert_number
${conf[0]}; then
141 echo "ERROR: invalid VM configuration syntax $vm_conf"
145 # Sanity check if VM is not defined twice
146 for vm_num
in $used_vms; do
147 if [[ $vm_num -eq ${conf[0]} ]]; then
148 echo "ERROR: VM$vm_num defined more than twice ( $(printf "'%s' " "${vms[@]}"))!"
153 setup_cmd
+=" -f ${conf[0]}"
154 used_vms
+=" ${conf[0]}"
155 [[ x
"${conf[1]}" != x
"" ]] && setup_cmd
+=" --os=${conf[1]}"
156 [[ x
"${conf[2]}" != x
"" ]] && setup_cmd
+=" --disk=${conf[2]}"
158 if [[ $test_type == "spdk_vhost" ]]; then
159 echo "INFO: Adding device via RPC ..."
162 eval $
(grep "^vhost_reactor_mask=" $BASE_DIR/autotest.config
)
163 while IFS
=':' read -ra disks
; do
164 for disk
in "${disks[@]}"; do
165 $rpc_py construct_vhost_scsi_controller naa.
$disk.
${conf[0]} \
166 --cpumask $vhost_reactor_mask
167 $rpc_py add_vhost_scsi_lun naa.
$disk.
${conf[0]} 0 $disk
169 done <<< "${conf[2]}"
171 $rpc_py get_vhost_scsi_controllers
177 $BASE_DIR/vm_run.sh
$x --work-dir=$TEST_DIR $used_vms
178 vm_wait_for_boot
600 $used_vms
180 echo "==============="
182 echo "INFO: Testing..."
184 echo "INFO: Running fio jobs ..."
185 run_fio
="python $BASE_DIR/run_fio.py "
187 run_fio
+="--job-file="
188 for job
in $fio_jobs; do
191 run_fio
="${run_fio::-1}"
193 run_fio
+="--out=$TEST_DIR "
195 if [[ ! $disk_split == '' ]]; then
196 run_fio
+="--split-disks=$disk_split "
199 # Check if all VM have disk in tha same location
202 for vm_num
in $used_vms; do
203 vm_dir
=$VM_BASE_DIR/$vm_num
204 host_name
="VM-$vm_num-$(cat $BASE_DIR/autotest.config|grep qemu_mask|awk -F'=' '{print $2}'|sed "$
(($vm_num+1))q
;d
")"
205 echo "INFO: Setting up hostname: $host_name"
206 vm_ssh
$vm_num "hostname $host_name"
207 vm_start_fio_server
$fio_bin $readonly $vm_num
208 vm_check_scsi_location
$vm_num
210 SCSI_DISK
="${SCSI_DISK::-1}"
211 for DISK
in $SCSI_DISK; do
212 echo "INFO: VM$vm_num Setting max_sectors_kb=$max_sectors_kb on disk $DISK"
214 vm_ssh
$vm_num "echo $max_sectors_kb > /sys/block/$DISK/queue/max_sectors_kb"
217 vm_reset_scsi_devices
$vm_num $SCSI_DISK
219 run_fio
+="127.0.0.1:$(cat $vm_dir/fio_socket):"
220 for disk
in $SCSI_DISK; do
221 run_fio
+="/dev/$disk:"
223 run_fio
="${run_fio::-1}"
227 run_fio
="${run_fio%,}"
229 run_fio
="${run_fio::-1}"
234 read -p "Enter to kill evething" xx
242 for vm_num
in $used_vms; do
243 vm_reset_scsi_devices
$vm_num $SCSI_DISK
246 if ! $no_shutdown; then
247 echo "==============="
248 echo "INFO: Testing done -> shutting down"
250 echo "==============="
252 echo "==============="
254 echo "INFO: Leaving environment working!"
256 echo "==============="