4 # Copyright (c) 2000-2001 Silicon Graphics, Inc. All Rights Reserved.
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of version 2 of the GNU General Public License as
8 # published by the Free Software Foundation.
10 # This program is distributed in the hope that it would be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 # Further, this software is distributed without any warranty that it is
15 # free of the rightful claim of any third person regarding infringement
16 # or the like. Any license provided herein, whether implied or
17 # otherwise, applies only to this software file. Patent licenses, if
18 # any, provided herein do not apply to combinations of this program with
19 # other software, or any other product whatsoever.
21 # You should have received a copy of the GNU General Public License along
22 # with this program; if not, write the Free Software Foundation, Inc., 59
23 # Temple Place - Suite 330, Boston MA 02111-1307, USA.
25 # Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
26 # Mountain View, CA 94043, or:
30 # For further information regarding this notice, see:
32 # http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
34 #-----------------------------------------------------------------#
35 # run_test: a ksh script for testing the DMAPI.
37 # USAGE: run_test [-p] [-x] [-u user]
38 # [-F fs_type -M fs_mtpt -R "real" directory]
39 # [-f datafile] [-s sleeptime]
40 # bindir testdir fsdir
42 # p: Causes pausing after every test (not just ones with errors).
44 # x: Prints an execution trace as the script runs.
46 # user: Most tests don't need root access, so they will be run
47 # under this username.
49 # (NOTE: the following three must be used together)
51 # fs_type: For NFS tests; the type of filesystem (ie nfs2, nfs3).
53 # fs_mtpt: For NFS tests, the path to the mount of your
55 # (ie, "mount -t nfs2 localhost:/dmitest $fs_mtpt")
57 # "real" directory: For NFS tests, the path to the "real" test directory.
59 # datafile: The name of the file which contains the tests to run.
61 # sleeptime: time, in seconds, for the daemon to sleep after
62 # responding to an event. (Useful for testing small
63 # outstanding-events queues.)
65 # bindir: The path to the directory that holds dm_test_daemon, send_msg,
66 # the datafile, and any other files required by the datafile.
68 # testdir: The path to the test directory. All DMAPI testing
69 # occurs here -- this is where the tests will actually
70 # be run. (For NFS tests, this will be an NFS mount
71 # of the "real" directory.)
73 # fsdir: The path name of the test filesystem. The daemon will start
74 # using this path, and the mount and unmount of the DMAPI
75 # filesystem will be done here. (Even for NFS tests, this
76 # should still be the same test filesystem.)
78 #-----------------------------------------------------------------#
80 # For most reads, we'll want spaces to be the field separators.
87 # To run tests that don't require root access, we'll change to
88 # a user specified by lname.
91 # Set the default external files to use.
98 # Parse the command-line options
99 while getopts :pxu:F:M:R:f:b:s: option
106 R) real_dir=$OPTARG;;
107 f) datafile=$OPTARG;;
109 s) sleeptime=$OPTARG;;
110 :) print -u2 "${0##*/}: $OPTARG requires a value"
112 \?) print -nu2 "USAGE: ${0##*/} [-p] [-x] [-u user] "
113 print -nu2 "[-F fs type -M mountpoint directory -R \"real\" directory] "
114 print -u2 "[-s sleeptime] [-f datafile] bindir testdir fsdir"
119 # Shift out the examined options, then check that we have
120 # exactly three arguments left: (the paths to the "bindir",
121 # the test directory, and the filesystem).
124 then print -nu2 "USAGE: ${0##*/} [-p] [-x] [-u user] "
125 print -nu2 "[-F fs type -M mountpoint directory -R \"real\" directory] "
126 print -u2 "[-s sleeptime] [-f datafile] bindir testdir fsdir"
130 # For NFS tests, $2 will be an NFS mount of the test directory;
131 # real_dir should be the test directory's actual path.
132 # Otherwise, real_dir should just be $2.
133 if [[ $real_dir = set_me_later ]]
137 # Check bindir for the existence of our three critical external files.
139 for i in dm_test_daemon send_msg $datafile
141 if [[ ! ( -r "$1/$i" ) ]]
142 then if ((error_count==0))
143 then print "Aborting: the directory $1/ is missing critical files:"
146 (( error_count = error_count + 1 ))
149 if (( error_count > 0 ))
153 # Open the datafile on file descriptor 3
156 # Read datafile and determine what files it needs from bindir;
157 # then, check for the existence of these files.
159 while read -u3 file_list
160 do case $file_list in
163 *) for i in $file_list
164 do if [[ ! ( -r "$1/$i" ) ]]
165 then if ((error_count==0))
166 then print "The directory $1/ is missing these files:"
169 (( error_count = error_count + 1 ))
174 if (( error_count > 0 ))
178 # Run initialization stuff without daemon.
187 # If we're testing over nfs, remount the filesystem to clear the cache.
189 nfs2) print "Clearing nfs2 cache by remounting filesystem..."
190 eval "umount $fs_mtpt"
191 eval "mount -t nfs2 localhost:$3 $fs_mtpt";;
192 nfs3) print "Clearing nfs3 cache by remounting filesystem..."
193 eval "umount $fs_mtpt"
194 eval "mount -t nfs3 localhost:$3 $fs_mtpt";;
195 *) if [[ $fs_type != "" ]]
196 then print "ERROR: $fs_type not a known or testable filesystem type"
201 # Check with the user before starting up daemon
202 print "\n** Using testfile ${datafile##*/} **"
203 print "** Using userid $lname for tests not requiring root access **"
204 print "Press enter to begin, or enter q or n to abort..."
211 # Now, the user will need ownership of the test directory
212 # ($2, not $real_dir, since real_dir is accessed only as root).
213 eval "chown $lname $2"
215 # Now it's time to begin running the daemon as a coprocess.
216 # The daemon will use a : as its internal field separator.
218 if (($sleeptime > 0)) then
219 $1/dm_test_daemon -s $sleeptime $3 |&
221 $1/dm_test_daemon $3 |&
224 #Keep track of the coprocess id... "$!" may change.
227 # Initialize the count of errors
230 # dm_test_daemon starts with a spurious line feed.
233 # Finally, we've reached the actual loop to read in the testfile.
243 ---*) clear; continue 2;;
263 if (( $root_flag == 1 ))
264 then print "Command to execute (as root):\n\n $cmd\n"
266 else print "Command to execute:\n\n $cmd\n"
267 eval "su $lname -c \"$cmd\""
270 # Note failure of the command. Also, send a message
271 # that the command is done. We will know we're done
272 # reading from the daemon when we see this message.
277 # Reset variables for reading this command.
279 unset contents event fs_handle handle length offset
280 unset media_designator mode mountpoint_handle
281 unset mountpoint_path msg_str name new_name new_parent
282 unset parent_handle ret_code root_handle sequence token
283 unset tries_left unmount_mode
285 # Read events, report them, and store their data.
288 read -p event[event_count]
289 case "${event[event_count]}" in
291 print "Report: found mount event."
292 read -p junk token[event_count]
293 read -p junk sequence[event_count]
294 read -p junk fs_handle[event_count]
295 read -p junk mountpoint_handle[event_count]
296 read -p junk mountpoint_path[event_count]
297 read -p junk media_designator[event_count]
298 read -p junk root_handle[event_count]
299 read -p junk mode[event_count]
302 print "Report: found preunmount event."
303 read -p junk token[event_count]
304 read -p junk sequence[event_count]
305 read -p junk fs_handle[event_count]
306 read -p junk root_handle[event_count]
307 read -p junk unmount_mode[event_count]
310 print "Report: found unmount event."
311 read -p junk token[event_count]
312 read -p junk sequence[event_count]
313 read -p junk fs_handle[event_count]
314 read -p junk unmount_mode[event_count]
315 read -p junk ret_code[event_count]
318 print "Report: found nospace event."
319 read -p junk token[event_count]
320 read -p junk sequence[event_count]
321 read -p junk fs_handle[event_count]
324 print "Report: found ${event[event_count]} event."
325 read -p junk token[event_count]
326 read -p junk sequence[event_count]
327 read -p junk parent_handle[event_count]
328 read -p junk name[event_count]
329 read -p junk mode[event_count]
332 print "Report: found postcreate event."
333 read -p junk token[event_count]
334 read -p junk sequence[event_count]
335 read -p junk parent_handle[event_count]
336 read -p junk handle[event_count]
337 read -p junk name[event_count]
338 read -p junk mode[event_count]
339 read -p junk ret_code[event_count]
342 print "Report: found postremove event."
343 read -p junk token[event_count]
344 read -p junk sequence[event_count]
345 read -p junk parent_handle[event_count]
346 read -p junk name[event_count]
347 read -p junk mode[event_count]
348 read -p junk ret_code[event_count]
351 print "Report: found rename event."
352 read -p junk token[event_count]
353 read -p junk sequence[event_count]
354 read -p junk parent_handle[event_count]
355 read -p junk new_parent[event_count]
356 read -p junk name[event_count]
357 read -p junk new_name[event_count]
360 print "Report: found postrename event."
361 read -p junk token[event_count]
362 read -p junk sequence[event_count]
363 read -p junk parent_handle[event_count]
364 read -p junk new_parent[event_count]
365 read -p junk name[event_count]
366 read -p junk new_name[event_count]
367 read -p junk ret_code[event_count]
370 print "Report: found symlink event."
371 read -p junk token[event_count]
372 read -p junk sequence[event_count]
373 read -p junk parent_handle[event_count]
374 read -p junk name[event_count]
375 read -p junk contents[event_count]
378 print "Report: found postsymlink event."
379 read -p junk token[event_count]
380 read -p junk sequence[event_count]
381 read -p junk parent_handle[event_count]
382 read -p junk handle[event_count]
383 read -p junk name[event_count]
384 read -p junk contents[event_count]
385 read -p junk ret_code[event_count]
388 print "Report: found link event."
389 read -p junk token[event_count]
390 read -p junk sequence[event_count]
391 read -p junk parent_handle[event_count]
392 read -p junk handle[event_count]
393 read -p junk name[event_count]
396 print "Report: found postlink event."
397 read -p junk token[event_count]
398 read -p junk sequence[event_count]
399 read -p junk parent_handle[event_count]
400 read -p junk handle[event_count]
401 read -p junk name[event_count]
402 read -p junk ret_code[event_count]
405 print "Report: found ${event[event_count]} event."
406 read -p junk token[event_count]
407 read -p junk sequence[event_count]
408 read -p junk handle[event_count]
409 read -p junk offset[event_count]
410 read -p junk length[event_count]
413 print "Report: found attribute event."
414 read -p junk token[event_count]
415 read -p junk sequence[event_count]
416 read -p junk handle[event_count]
419 print "Report: found destroy event."
420 read -p junk token[event_count]
421 read -p junk sequence[event_count]
422 read -p junk handle[event_count]
423 read -p junk name[event_count]
424 read -p junk contents[event_count]
427 read -p junk token[event_count]
428 read -p junk sequence[event_count]
429 read -p junk msg_str[event_count]
430 case "${msg_str[event_count]}" in
432 event[event_count]=end_of_tests
433 print "Report: found \"end of test\" user event. "
435 *) print "Report: found user event. "
439 read -p junk tries_left[event_count]
440 print -n "Report: process pending. "
441 print "Tries left: ${tries_left[event_count]}"
444 print -n "Report: found ${event[event_count]} event. "
445 print "(unknown to this version)"
446 while read -p msg_str[event_count]
447 do case "${msg_str[event_count]}" in
448 "end_of_message") break;;
453 ((event_count=event_count+1))
455 ((old_error_count=error_count));
459 while read -u3 val_one val_two val_tre
461 ---*) if [[ $fail_flag != -1 ]]
462 then if [[ $fail_flag != 0 ]]
463 then print -n "ERROR: command failed; it was "
464 print "expected to succeed."
465 ((error_count=error_count+1))
468 if (( error_count>old_error_count || pause_flag==1 ))
469 then print "\nEnter q to quit, or press enter to continue..."
479 if [[ $fail_flag = 0 ]]
480 then print "ERROR: command succeeded; it was expected to fail."
481 ((error_count=error_count+1))
482 else print "Note: command is expected to fail."
487 if [[ $(eval "print $"{$val_one}) = $(eval "print $"{$val_tre}) ]]
488 then print "Report: $val_one and $val_tre match; both are "
489 if [[ $(eval "print $"{$val_one}) = "" ]]
491 else print "$(eval "print $"{$val_one})"
493 else print -n "ERROR: $val_one was "
494 if [[ $(eval "print $"{$val_one}) = "" ]]
495 then print -n "unset "
496 else print -n "equal to $(eval "print $"{$val_one})"
498 print -n ", while $val_tre was "
499 if [[ $(eval "print $"{$val_tre}) = "" ]]
501 else print "equal to $(eval "print $"{$val_tre})."
503 ((error_count=error_count+1))
506 eval ${val_tre}=$(eval "print $"{$val_one})
507 print -n "Report: value of ${val_one} copied into "
508 print "${val_tre}.";;
510 if [[ $(eval "print $"{$val_one}) = $val_two ]]
512 else if [[ "$val_one" = event_count ]]
513 then print -n "ERROR: expected $val_two event(s), "
514 print "but found $event_count."
515 else print -n "ERROR: $val_one was "
516 if [[ $(eval "print $"{$val_one}) = "" ]]
517 then print -n "unset "
518 else print -n "equal to $(eval "print $"{$val_one}) "
520 print "rather than $val_two as expected."
522 ((error_count=error_count+1))
527 if [[ $fail_flag != -1 ]]
528 then if [[ $fail_flag != 0 ]]
529 then print -n "ERROR: command failed; it was "
530 print "expected to succeed."
531 ((error_count=error_count+1))
534 if (( error_count>old_error_count || pause_flag==1 ))
535 then print "\nTests complete. Press enter to quit..."
549 if ((error_count==1))
550 then print "Test result: 1 error found."
551 else print "Test result: $error_count errors found."