rwtest 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. #!/bin/bash
  2. # Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
  3. #
  4. # This program is free software; you can redistribute it and/or modify it
  5. # under the terms of version 2 of the GNU General Public License as
  6. # published by the Free Software Foundation.
  7. #
  8. # This program is distributed in the hope that it would be useful, but
  9. # WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. #
  12. # Further, this software is distributed without any warranty that it is
  13. # free of the rightful claim of any third person regarding infringement
  14. # or the like. Any license provided herein, whether implied or
  15. # otherwise, applies only to this software file. Patent licenses, if
  16. # any, provided herein do not apply to combinations of this program with
  17. # other software, or any other product whatsoever.
  18. #
  19. # You should have received a copy of the GNU General Public License along
  20. # with this program; if not, write the Free Software Foundation, Inc.,
  21. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  22. #
  23. # Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
  24. # Mountain View, CA 94043, or:
  25. #
  26. # http://www.sgi.com
  27. #
  28. # For further information regarding this notice, see:
  29. #
  30. # http://oss.sgi.com/projects/GenInfo/NoticeExplan/
  31. #
  32. # rwtest - a shell wrapper around iogen and doio
  33. #
  34. trap "exit 0" INT # Until the smarter signal handler is engaged, below.
  35. Prog=${0##*/}
  36. iOpts=""
  37. dOpts=""
  38. LockRegion=""
  39. Nprocs=1
  40. Files=""
  41. Remove_Test_Files=""
  42. Files_To_Remove=""
  43. MPPrun=""
  44. export TCID="rwtest"
  45. export TST_TOTAL=1
  46. export TST_COUNT=1
  47. usage()
  48. {
  49. echo "$Prog: [-chq] [-N name] [ iogen options ] [ doio options ] files" >&2
  50. }
  51. help()
  52. {
  53. echo "\
  54. -c Cleanup test files created by this invocation on exit.
  55. Default is to leave them.
  56. -h This help - ignore all other options/arguments
  57. -F Only process filenames - does not run iogen & doio.
  58. -P Places Not used
  59. -S Scenario Execute an internal scenario.
  60. -N Name Pan-style name to be printed with error messages.
  61. Options passed through to iogen:
  62. -[afiLmOstT] arg
  63. -o
  64. -q Set rwtest to be quiet and pass the flag on to iogen.
  65. Options passed through to doio:
  66. -D[rmMVUC] arg
  67. -D[aekv]
  68. -n nprocs # procs to do simultanious io to the test files.
  69. Default is 1. If -n is non-zero, doio's -k option (use
  70. file locking) is forced.
  71. files Files to test on. File names have the following format:
  72. [ size: ] path
  73. [ free% [ max size ] : ] path
  74. If no size is specified, the files must exist
  75. and the contents will be overwritten if testing write or
  76. writea system calls. If a size is supplied, an attempt to
  77. create/grow/shrink path to the desired size will be made.
  78. size is an integer which defaults to bytes, but may be
  79. suffixed by 'b', 'k', or 'm' for blocks (4096 byte units),
  80. kilobytes (1024 byte units), or megabytes (2^20 byte units).
  81. If the size is a percentage, df is used to find how much
  82. free space there is (in blocks), and uses that. The maximum
  83. size is implied to be in blocks.
  84. " >&2
  85. }
  86. killkids()
  87. {
  88. trap "killkids" INT
  89. if [[ -z $didkids ]]
  90. then
  91. didkids=done
  92. kill -INT -$$
  93. fi
  94. }
  95. cleanup_and_exit()
  96. {
  97. if [ -n "$Remove_Test_Files" ]
  98. then
  99. if [ -n "$Files_To_Remove" ]
  100. then
  101. rm -rf $Files_To_Remove
  102. fi
  103. fi
  104. if [ $1 -ne 0 ]
  105. then
  106. tst_resm TFAIL "Test failed"
  107. echo "Test failed"
  108. else
  109. tst_resm TPASS "Test passed"
  110. echo "Test passed"
  111. fi
  112. exit $1
  113. }
  114. while (( $# > 0 ))
  115. do case $1 in
  116. -c) Remove_Test_Files=yes
  117. ;;
  118. -d) debug=$2
  119. shift
  120. ;;
  121. -h) help
  122. exit 0
  123. ;;
  124. -F)
  125. opt_F="-F" # only process filenames
  126. ;;
  127. -P)
  128. PLACES=$2
  129. shift
  130. ;;
  131. -S) Scenario=$2
  132. shift
  133. opt_S="-S"
  134. ;;
  135. -N) Name="($2)"
  136. TCID=$2
  137. iOpts="$iOpts -N $2"
  138. dOpts="$dOpts -N $2"
  139. shift
  140. ;;
  141. # iogen Options to pass thru ... options with an argument
  142. -[afiLmOstT] )
  143. iOpts="$iOpts $1 $2"
  144. shift
  145. ;;
  146. # iogen Options to pass thru ... just the option
  147. -[o] )
  148. iOpts="$iOpts $1"
  149. ;;
  150. # iogen options to look at
  151. -q)
  152. iOpts="$iOpts $1"
  153. Quiet=$1
  154. ;;
  155. # doio Options to pass thru ... options with an argument
  156. -D[rmMVUC] )
  157. o=${1#-D}
  158. dOpts="$dOpts -$o $2"
  159. shift
  160. ;;
  161. # doio options to pass thru ... just the options
  162. -D[aekv] )
  163. o=${1#-D}
  164. dOpts="$dOpts -$o"
  165. ;;
  166. # doio options to look at
  167. -n | -Dn )
  168. dOpts="$dOpts $1 $2"
  169. # force file locking with > 1 process
  170. if [[ $2 > 1 ]]
  171. then
  172. dOpts="$dOpts -k"
  173. fi
  174. opt_n="-n"
  175. shift
  176. ;;
  177. \? | -*)
  178. echo "$Prog: Illegal option $1" >&2
  179. tst_resm TBROK "Illegal option $1"
  180. exit 1
  181. ;;
  182. *)
  183. break
  184. ;;
  185. esac
  186. shift
  187. done
  188. #
  189. # Hard-Coded Scenario Specifications
  190. #
  191. # FSA RAW I/O via FSA
  192. # MPPnnn Run as a <nnn> sized MPP application
  193. # userstripe create files using user striping
  194. #
  195. if [[ -n "$opt_S" ]]
  196. then
  197. case $Scenario in
  198. FSA )
  199. # I/O via FSA
  200. Flags="parallel"
  201. Nprocs=1
  202. LockRegion=""
  203. ;;
  204. MPP* )
  205. # use mpprun... to cooperate with a batch system, this
  206. # requires scanning mppview, etc.
  207. NPE=${Scenario#MPP}
  208. MPPrun=" mpprun -n $NPE "
  209. ;;
  210. userstripe)
  211. #create files using user striping
  212. Oflags=O_PLACE,0xffffffffffffffff,1000
  213. ;;
  214. places*)
  215. FSIZE=${Scenario#places-}
  216. oi="$IFS"
  217. IFS=":"
  218. set -- $PLACES
  219. if [ $# -eq 0 ]
  220. then
  221. # "this isn't supposed to happen"
  222. Files="25%:rwtest.$$"
  223. else
  224. IFS="$oi"
  225. PL=${*}
  226. for p in $PL
  227. do
  228. f="$f "${FSIZE}":"${p}"/rwtest$$"
  229. done
  230. set -- $f
  231. fi
  232. ;;
  233. esac
  234. fi
  235. #
  236. # If no files are specified ...
  237. # check if PLACES is set; if so, put one file in each place
  238. # otherwise generate one filename in the current directory.
  239. #
  240. if [ $# -eq 0 ]
  241. then
  242. # put one file in each of $PLACES
  243. Files="25%:rwtest.file"
  244. else
  245. Files=$*
  246. fi
  247. #
  248. # use 'df -PB' to see how many blocks are available, apply a hard limit of
  249. # 1,000,000 blocks if no limit is specified
  250. #
  251. case "$(uname -s)" in
  252. IRIX | IRIX64 ) dfOpts="-Pb" ;;
  253. Linux) dfOpts="-P" ;;
  254. *) dfOpts="-PB" ;;
  255. esac
  256. for f in $Files
  257. do
  258. file=${f##*:}
  259. if [ ! -f "$file" ]
  260. then
  261. Files_To_Remove="$Files_To_Remove $file"
  262. fi
  263. dir=$(dirname $file)
  264. # create directory for file if non-existent
  265. if [ ! -d "$dir" ]
  266. then
  267. mkdir -p $dir
  268. Files_To_Remove="$Files_To_Remove $dir"
  269. fi
  270. size=${f%%:*}
  271. if [[ $size = *%* ]]
  272. then
  273. typeset -i n=0
  274. while (( n < ${#szcache[*]} ))
  275. do
  276. if [[ szcache[$n] = $dir ]]; then
  277. break;
  278. fi
  279. n=n+1
  280. done
  281. if (( n < ${#szcache[*]} ))
  282. then
  283. blks=${szblks[$n]}
  284. else
  285. # If df is a symlink (to busybox) then do not pass the $dir and $dfOpts
  286. # parameters because they don't work as expected
  287. if test -h $(which df)
  288. then
  289. dir=""; dfOpts="";
  290. fi
  291. blks=$(df $dfOpts $dir |
  292. (while read fs blks used avail cap mountpoint
  293. do
  294. #echo $fs $blks $used $avail >&2
  295. b=$avail
  296. done
  297. echo $b) )
  298. # check if blks is a number, else set a default value for blks
  299. default_sz=1000000
  300. if [ $blks -eq $blks 2> /dev/null -a $blks -gt 0 ]
  301. then
  302. case $(uname) in
  303. Linux) blks=$( expr $blks / 2 ) ;;
  304. esac
  305. szcache[${#szcache[*]}+1]=$dir
  306. szblks[${#szblks[*]}+1]=$blks
  307. max=${size##*\%}
  308. [ "x$max" = "x" ] && max=$default_sz
  309. size=${size%%\%*}
  310. case $(uname) in
  311. IRIX*)
  312. sz=$( perl -le 'print int( '$blks' * '$size' / 100 )' )
  313. ;;
  314. *)
  315. sz=$(expr \( $blks '*' $size \) / 100)
  316. ;;
  317. esac
  318. if [ $sz -gt $max ]
  319. then
  320. sz=$max
  321. fi
  322. else
  323. sz=$default_sz
  324. fi
  325. fi
  326. f=$sz"b:"$file
  327. fi
  328. F[${#F[*]}+1]=$f
  329. done
  330. Files=${F[*]}
  331. if [[ -z ${dOpts} ]]; then
  332. dOpts=-av
  333. fi
  334. if [[ -n "$opt_F" ]]; then
  335. echo $Files
  336. else
  337. cmd="${LTPROOT}/testcases/bin/iogen ${iOpts} ${Files} | $MPPrun ${LTPROOT}/testcases/bin/doio ${dOpts}"
  338. if [[ -z "$Quiet" ]]; then
  339. echo $cmd
  340. fi
  341. trap "killkids" INT
  342. trap "cleanup_and_exit 2" HUP
  343. ( ${LTPROOT}/testcases/bin/iogen ${iOpts} ${Files}
  344. r=$?
  345. if [ $r -ne 0 ]
  346. then
  347. echo "$Prog$Name : iogen reported errors (r=$r)" >&2
  348. tst_resm TFAIL "iogen reported errors (r=$r)"
  349. kill -HUP $$
  350. fi
  351. ) | $MPPrun ${LTPROOT}/testcases/bin/doio ${dOpts}
  352. r=$?
  353. if [ $r -ne 0 ]
  354. then
  355. echo "$Prog$Name : doio reported errors (r=$r)" >&2
  356. tst_resm TFAIL "doio reported errors (r=$r)"
  357. fi
  358. cleanup_and_exit $r
  359. fi