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