fs_di 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. #! /bin/sh
  2. #
  3. # Copyright (c) International Business Machines Corp., 2005
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implie; warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  13. # the GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. #
  19. #
  20. #
  21. # FILE : fs_di
  22. #
  23. # PURPOSE: FileSystem Data Integrity
  24. # 1. Creates a data file of specified or random size and copies
  25. # the file to a random directory depth on a specified filesystem
  26. # The two files are compared and checked for differences.
  27. # If the files differ, then the test fails. By default, this
  28. # test creates a 30Mb file and runs for ten loops.
  29. # 2. Creates a datafile of size half of the partition size. Creates
  30. # two fragmented files on the specified partition and copies datafile
  31. # to them. Then compares both the fragmented files with datafile. If
  32. # files differ, then test fails.
  33. #
  34. # SETUP: None
  35. #
  36. #
  37. # HISTORY:
  38. # 28/07/09 Jyoti Vantagodi (jyotiv@linux.vnet.ibm.com)
  39. # Added point two of above PURPOSE
  40. # 04/11/05 Robbie Williamson (robbiew@us.ibm.com)
  41. # -Written
  42. #
  43. #***********************************************************************
  44. #Uncomment line below for debug output.
  45. #trace_logic=${trace_logic:-"set -x"}
  46. $trace_logic
  47. #-----------------------------------------------------------------------
  48. # Initialize local variables
  49. #-----------------------------------------------------------------------
  50. TC=${TC:=fs_di}
  51. TCbin=${TCbin:=`pwd`}
  52. TCtmp=${TCtmp:=$TMPDIR/$TC$$}
  53. export PATH=$PATH:$TCbin:../../../bin
  54. export TCID=$TC
  55. export TST_TOTAL=1
  56. export TST_COUNT=1
  57. # If CLEANUP is not set; set it to "ON"
  58. CLEANUP=${CLEANUP:="ON"}
  59. usage()
  60. {
  61. cat <<-EOF >&2
  62. usage: ./${0##*/} -d TMPDIR [-h] [-l # of LOOPS ] [-s SIZE in Mb][-S partition SIZE in Mb]
  63. -d TMPDIR Directory where temporary files will be created.
  64. -h Help. Prints all available options.
  65. -l # of LOOPS The number of times to run the test. Default=10.
  66. -s SIZE in Mb The size of the data file to create. Default=30Mb. A "0" means random sizes from 10-500Mb.
  67. -S SIZE in Mb Size of usable partition (in MBs) on which the testing is carried out (needs to be passed
  68. for fragmented file test)
  69. -v Verbose output.
  70. example: ./${0##*/} -d /mnt/cifsmount -l 20 -s 100 -S 200
  71. example: ./${0##*/} -d /mnt/cifsmount -l 20 -s 100
  72. EOF
  73. exit 0
  74. }
  75. #=============================================================================
  76. # FUNCTION NAME: end_testcase
  77. #
  78. # FUNCTION DESCRIPTION: Clean up
  79. #
  80. # PARAMETERS: None.
  81. #
  82. # RETURNS: None.
  83. #=============================================================================
  84. end_testcase()
  85. {
  86. $trace_logic
  87. if [ "$CLEANUP" = "ON" ]; then
  88. rm -rf $TCtmp
  89. rm -rf ${TESTFS}
  90. rm -f $TCtmp/testfile*
  91. fi
  92. [ $# = 0 ] && { tst_resm TPASS "Test Successful"; exit 0; }
  93. tst_resm TFAIL "Test Failed: $@"
  94. exit 1
  95. }
  96. #=============================================================================
  97. # FUNCTION NAME: setup_testcase
  98. #
  99. # FUNCTION DESCRIPTION: Perform the setup function for the testcase.
  100. #
  101. # PARAMETERS: None.
  102. #
  103. # RETURNS: None.
  104. #=============================================================================
  105. $trace_logic
  106. TMPBASE=0
  107. LOOPS=10
  108. SIZE=30
  109. RANDOM_SIZE=0
  110. DISK_SIZE=0
  111. while getopts d:hl:s:S:v arg
  112. do
  113. case $arg in
  114. d) # append $$ to TMP, as it is recursively
  115. # removed at end of script.
  116. export TMPBASE=$OPTARG
  117. TMP="${TMPBASE}/fs_di-$$"
  118. export TESTFS="$TMP";;
  119. h) usage
  120. exit 0;;
  121. l) # Execute user defined number of loops.
  122. LOOPS=$OPTARG;;
  123. s) # Size of data file to create
  124. SIZE=$OPTARG
  125. if [ $SIZE -eq 0 ]; then
  126. RANDOM_SIZE=1
  127. fi;;
  128. v) # Verbose
  129. trace_logic=${trace_logic:-"set -x"};;
  130. S) # Size of usable partition, which is used for creating creating the files
  131. DISK_SIZE=$OPTARG;;
  132. \?) usage
  133. exit 0;;
  134. esac
  135. done
  136. if [ $TMPBASE = "0" ]; then
  137. tst_resm TBROK "You must specify the target directory [-d]"
  138. exit 1
  139. fi
  140. export TST_COUNT=$LOOPS
  141. echo ""
  142. echo "Test Options:"
  143. echo " Tested Filesystem: $TESTFS"
  144. echo " Loops: $LOOPS"
  145. if [ $RANDOM_SIZE -eq 0 ];then
  146. echo " Data File Size: $SIZE"
  147. else
  148. echo " Data File Size: Random"
  149. fi
  150. sleep 5
  151. $trace_logic
  152. mkdir -p $TCtmp || end_testcase "Could not create $TCtmp"
  153. chmod 777 $TCtmp
  154. mkdir -p $TESTFS || end_testcase "Could not create $TESTFS"
  155. chmod 777 $TESTFS
  156. #=============================================================================
  157. # FUNCTION NAME: main
  158. #
  159. # FUNCTION DESCRIPTION: Perform the test
  160. #
  161. # PARAMETERS: None.
  162. #
  163. # RETURNS: None.
  164. #=============================================================================
  165. loopcount=0
  166. tst_resm TINFO "Test Started"
  167. while [ $loopcount -lt $LOOPS ]
  168. do
  169. if [ $RANDOM_SIZE -eq 1 ]; then
  170. SIZE=$RANDOM
  171. let "SIZE %= 500"
  172. while [ $SIZE -lt 10 ]
  173. do
  174. SIZE=$RANDOM
  175. let "SIZE %= 500"
  176. done
  177. fi
  178. create_datafile $SIZE $TCtmp/testfile >/dev/null
  179. if [ $? != 0 ]; then
  180. end_testcase "Could not create testfile of size ${SIZE}Mb"
  181. fi
  182. RANDOM_DEPTH=$RANDOM
  183. : $(( RANDOM_DEPTH %= 500 ))
  184. RANDOM_LENGTH=$RANDOM
  185. : $(( RANDOM_LENGTH %= 500 ))
  186. RANDOM_LENGTH=$(( $RANDOM_LENGTH / 10 ))
  187. NameCount=0
  188. DepthCount=0
  189. FILEPATH=""
  190. while [ $DepthCount -lt $RANDOM_DEPTH ]
  191. do
  192. if [ $NameCount -lt $RANDOM_LENGTH ]; then
  193. FILEPATH=${FILEPATH}X
  194. NameCount=$(( $NameCount + 1 ))
  195. else
  196. FILEPATH=${FILEPATH}/
  197. NameCount=0
  198. fi
  199. DepthCount=$(( $DepthCount + 1 ))
  200. done
  201. mkdir -p ${TESTFS}/${FILEPATH} || end_testcase "Could not create ${TESTFS}/${FILEPATH}"
  202. chmod -R 777 $TESTFS
  203. cp $TCtmp/testfile ${TESTFS}/${FILEPATH}
  204. cmp $TCtmp/testfile ${TESTFS}/${FILEPATH}/testfile
  205. retval=$?
  206. if [ "$retval" != 0 ]; then
  207. end_testcase "Error in loop $loopcount: cmp after write FAILED"
  208. fi
  209. cp ${TESTFS}/${FILEPATH}/testfile $TCtmp/testfile_copy
  210. cmp $TCtmp/testfile $TCtmp/testfile_copy
  211. retval=$?
  212. if [ "$retval" != 0 ]; then
  213. end_testcase "Error in loop $loopcount: cmp after read FAILED"
  214. fi
  215. rm -rf ${TESTFS}/${FILEPATH}
  216. rm -f $TCtmp/testfile*
  217. loopcount=$(( $loopcount + 1 ))
  218. tst_resm TINFO "Completed Loop $loopcount"
  219. done
  220. if [ "$DISK_SIZE" != 0 ]; then
  221. #Create a datafile of size half of the disk size
  222. tst_resm TINFO "Creating fragmented files. Please wait..."
  223. DISK_SIZE=$(( $DISK_SIZE / 2 ))
  224. if [ "$DISK_SIZE" == 0 ]; then
  225. DISK_SIZE=1
  226. fi
  227. create_datafile $DISK_SIZE $TCtmp/testfile >/dev/null
  228. retval=$?
  229. if [ "$retval" != 0 ]; then
  230. end_testcase "Error in creating data file"
  231. fi
  232. #Invoke frag to create 2 fragmented files and copy data file to both the files
  233. frag $TCtmp/testfile $TMPBASE
  234. retval=$?
  235. if [ "$retval" != 0 ]; then
  236. end_testcase "Error in creating frag files"
  237. fi
  238. tst_resm TINFO "Created fragmented files"
  239. #Compare both frag files with data file
  240. cmp $TCtmp/testfile $TMPBASE/frag1
  241. retval=$?
  242. if [ "$retval" != 0 ]; then
  243. end_testcase "frag1 and datafile are not matching"
  244. fi
  245. if [ "$retval" != 0 ]; then
  246. end_testcase "frag2 and datafile are not matching"
  247. fi
  248. tst_resm TINFO "Completed test with fragmented files"
  249. rm -rf $TMPBASE/*
  250. rm -f $TCtmp/testfile*
  251. fi
  252. end_testcase