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