blob: fc3cec38a751c6f31cbf4a1a0a99877863724258 [file] [log] [blame]
mridgebb4c3462004-12-16 16:13:15 +00001#!/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
Chris Dearman37550cf2012-10-17 19:54:01 -070050echo "Remove the scsi_debug device..."
mridgebb4c3462004-12-16 16:13:15 +000051dev_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"
Chris Dearman37550cf2012-10-17 19:54:01 -070082else
mridgebb4c3462004-12-16 16:13:15 +000083 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..."
Chris Dearman37550cf2012-10-17 19:54:01 -0700107modprobe scsi_debug max_luns=2 num_tgts=2 add_host=2 dev_size_mb=20
mridgebb4c3462004-12-16 16:13:15 +0000108lsmod | 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
Chris Dearman37550cf2012-10-17 19:54:01 -0700161# check if the newly created scsi_debug partitions are in /proc/partitions file
mridgebb4c3462004-12-16 16:13:15 +0000162check_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
Chris Dearman37550cf2012-10-17 19:54:01 -0700183mkdir /test >/dev/null 2>&1
184mkdir /test/growfiles >/dev/null 2>&1
185mkdir /test/growfiles/ext2 >/dev/null 2>&1
mridgebb4c3462004-12-16 16:13:15 +0000186mkdir /test/growfiles/ext3 >/dev/null 2>&1
Chris Dearman37550cf2012-10-17 19:54:01 -0700187mkdir /test/growfiles/reiser >/dev/null 2>&1
188mkdir /test/growfiles/msdos >/dev/null 2>&1
mridgebb4c3462004-12-16 16:13:15 +0000189
190echo "----- make ext3 fs -----"
191mkfs -V -t ext3 /dev/$part1
192echo "----- make ext2 fs -----"
193mkfs -V -t ext2 /dev/$part2
194echo "----- make reiserfs fs -----"
Chris Dearman37550cf2012-10-17 19:54:01 -0700195mkreiserfs -f /dev/$part3
mridgebb4c3462004-12-16 16:13:15 +0000196echo "----- make msdos fs -----"
197mkfs -V -t msdos -I /dev/$part4
198
199echo "----- Mount partitions -----"
Chris Dearman37550cf2012-10-17 19:54:01 -0700200mount /dev/$part1 /test/growfiles/ext3
mridgebb4c3462004-12-16 16:13:15 +0000201mount /dev/$part2 /test/growfiles/ext2
Chris Dearman37550cf2012-10-17 19:54:01 -0700202mount /dev/$part3 /test/growfiles/reiser
mridgebb4c3462004-12-16 16:13:15 +0000203mount /dev/$part4 /test/growfiles/msdos
204
Chris Dearman37550cf2012-10-17 19:54:01 -0700205echo "----- Running tests ----- "
mridgebb4c3462004-12-16 16:13:15 +0000206echo "The test may take about 2 hours to finish..."
yaberauneyad8f1f5d2010-01-28 15:46:58 +0000207${LTPROOT}/bin/rand_lines -g ${LTPROOT}/runtest/scsi_debug.part1 > ${TMPBASE}/scsi_debug
Chris Dearman37550cf2012-10-17 19:54:01 -0700208
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
mridgebb4c3462004-12-16 16:13:15 +0000210
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..."