1#!/bin/bash 2 3# Check if scsi_debug module was built or not 4export kernel=$(uname -r) 5 6ls /lib/modules/$kernel/kernel/drivers/scsi | grep scsi_debug > /dev/null 2>&1 7if [ $? -ne 0 ]; 8then 9 echo "scsi_debug was not built in the kernel as a module" 10 echo "Build scsi_debug as a module first before running the test" 11fi 12 13# Unload scsi_debug moudle if it was already loaded: 14lsmod | grep scsi_debug > /dev/null 2>&1 15if [ $? -eq 0 ]; 16then 17 echo "The scsi_debug module was already loaded, unload it before test..." 18 rmmod -f scsi_debug 19fi 20lsmod | grep scsi_debug > /dev/null 2>&1 21if [ $? -eq 0 ]; 22then 23 echo "The scsi_debug module was not unloaded - unload error" 24else 25 echo "The scsi_debug module was unloaded successfully" 26 echo "start testing..." 27fi 28 29orig_count=$(cat /proc/partitions | wc -l) 30 31echo " Load the scsi_debug module..." 32modprobe scsi_debug 33if [ $? -ne 0 ]; 34then 35 echo "Can't load scsi_debug modules" 36 exit 37fi 38 39echo "Check if scsi_debug was loaded..." 40lsmod | grep scsi_debug > /dev/null 2>&1 41if [ $? -eq 0 ]; 42then 43 echo "scsi_debug module was loaded successfully" 44else 45 echo "scsi_debug module was not loaded" 46 exit 47fi 48 49 50echo "Remove the scsi_debug device..." 51dev_name=$(ls /proc/scsi/scsi_debug) 52# echo $dev_name 53rm_dev=$dev_name:0:0:0 54# echo $rm_dev 55echo 1 > /sys/class/scsi_device/$rm_dev/device/delete 56 57echo "Check if the scsi_debug device was removed..." 58ls /sys/class/scsi_device | grep $rm_dev > /dev/null 2>&1 59if [ $? -eq 0 ]; 60then 61 echo "The device was not removed - remove error" 62else 63 echo "The device $dev_name was removed successfully" 64fi 65 66echo "Add the device back..." 67echo "0 0 0" > /sys/class/scsi_host/host$dev_name/scan 68ls /sys/class/scsi_device | grep $rm_dev > /dev/null 2>&1 69if [ $? -ne 0 ]; 70then 71 echo "The device was not added - add device error" 72else 73 echo "The device $dev_name was added back successfully" 74fi 75 76echo "Add a new host..." 77echo 1 > /sys/bus/pseudo/drivers/scsi_debug/add_host 78num_host=$(cat /sys/bus/pseudo/drivers/scsi_debug/add_host) 79if [ $num_host -ne 2 ]; 80then 81 echo "The new host was not added - add host error" 82else 83 echo "The new host was added successfully" 84fi 85 86echo "Romove hosts..." 87echo -2 > /sys/bus/pseudo/drivers/scsi_debug/add_host 88num_host=$(cat /sys/bus/pseudo/drivers/scsi_debug/add_host) 89if [ $num_host -ne 0 ]; 90then 91 echo "The hosts were not removed - remove hosts error" 92else 93 echo "The hosts were removed successfully" 94fi 95 96echo "Unload scsi_debug moudle..." 97rmmod -f scsi_debug 98lsmod | grep scsi_debug > /dev/null 2>&1 99if [ $? -eq 0 ]; 100then 101 echo "The scsi_debug module was not unloaded - unload error" 102else 103 echo "The scsi_debug module was unloaded successfully" 104fi 105 106echo "Load scsi_debug with multiple hosts..." 107modprobe scsi_debug max_luns=2 num_tgts=2 add_host=2 dev_size_mb=20 108lsmod | grep scsi_debug > /dev/null 2>&1 109if [ $? -eq 0 ]; 110then 111 echo "The multiple scsi_debug modules were loaded successfully" 112else 113 echo "The multiple scsi_debug modules were not loaded - load error" 114fi 115 116echo "Check if modules were loaded as required by premeters..." 117max_luns=$(cat /sys/bus/pseudo/drivers/scsi_debug/max_luns) 118add_host=$(cat /sys/bus/pseudo/drivers/scsi_debug/add_host) 119num_tgts=$(cat /sys/bus/pseudo/drivers/scsi_debug/num_tgts) 120# echo "max_lunx is $max_luns" 121# echo "add_host is $add_host" 122# echo "num_tgts is $num_tgts" 123 124premeter_err_ct=0; 125 126if [ $max_luns -ne 2 ]; 127then 128 echo "max_luns was not correct" 129 premeter_err_ct=$premeter_err_ct+1; 130fi 131if [ $add_host -ne 2 ]; 132then 133 echo "add_host was not correct" 134 premeter_err_ct=$premeter_err_ct+1; 135fi 136if [ $num_tgts -ne 2 ]; 137then 138 echo "num_tgts was not correct" 139 premeter_err_ct=$premeter_err_ct+1; 140fi 141if [ $premeter_err_ct -eq 0 ]; 142then 143 echo "multiple scsi_debug was loaded as required premeters" 144else 145 echo "multip.e scsi_debug was not loaded as required premeters" 146fi 147echo "scsi_debug first part of test has been done." 148 149echo "Now we are doing fs test for scsi_debug driver..." 150 151cd `dirname $0` 152export LTPROOT=${PWD} 153echo $LTPROOT | grep testscripts > /dev/null 2>&1 154if [ $? -eq 0 ]; then 155 cd .. 156 export LTPROOT=${PWD} 157fi 158 159export TMPBASE="/tmp" 160 161# check if the newly created scsi_debug partitions are in /proc/partitions file 162check_count=$(cat /proc/partitions | wc -l) 163save_count=$(( $check_count - $orig_count )) 164if [ $save_count -lt 4 ]; then 165 echo "Not enough scsi_debug partitions to run the test" 166 exit 167fi 168 169# Get the 4 partitions created by scsi_debug for testing 170cat /proc/partitions | awk '{print $4}' | tail -n 4 > $TMPBASE/partition-test 171echo "The 4 partitions used to run the test are:" 172part1=$(cat $TMPBASE/partition-test | tail -n 1) 173echo $part1 174part2=$(cat $TMPBASE/partition-test | head -n 3 | tail -n 1) 175echo $part2 176part3=$(cat $TMPBASE/partition-test | head -n 2 | tail -n 1) 177echo $part3 178part4=$(cat $TMPBASE/partition-test | head -n 1) 179echo $part4 180 181export PATH="${PATH}:${LTPROOT}/testcases/bin" 182 183mkdir /test >/dev/null 2>&1 184mkdir /test/growfiles >/dev/null 2>&1 185mkdir /test/growfiles/ext2 >/dev/null 2>&1 186mkdir /test/growfiles/ext3 >/dev/null 2>&1 187mkdir /test/growfiles/reiser >/dev/null 2>&1 188mkdir /test/growfiles/msdos >/dev/null 2>&1 189 190echo "----- make ext3 fs -----" 191mkfs -V -t ext3 /dev/$part1 192echo "----- make ext2 fs -----" 193mkfs -V -t ext2 /dev/$part2 194echo "----- make reiserfs fs -----" 195mkreiserfs -f /dev/$part3 196echo "----- make msdos fs -----" 197mkfs -V -t msdos -I /dev/$part4 198 199echo "----- Mount partitions -----" 200mount /dev/$part1 /test/growfiles/ext3 201mount /dev/$part2 /test/growfiles/ext2 202mount /dev/$part3 /test/growfiles/reiser 203mount /dev/$part4 /test/growfiles/msdos 204 205echo "----- Running tests ----- " 206echo "The test may take about 2 hours to finish..." 207sort -R ${LTPROOT}/runtest/scsi_debug.part1 -o ${TMPBASE}/scsi_debug 208 209${LTPROOT}/bin/ltp-pan -e -S -a scsi_debug -n scsi_debug -l ${TMPBASE}/fs-scsi_debug.log -o ${TMPBASE}/fs-scsi_debug.out -f ${TMPBASE}/scsi_debug 210 211wait $! 212 213umount -v /dev/$part1 214umount -v /dev/$part2 215umount -v /dev/$part3 216umount -v /dev/$part4 217 218echo "Look into /tmp/fs-scsi_debug.log and /tmp/fs-scsi_debug.out for detail results..." 219