[Libsysio-commit] b_lustre: libsysio/tests README help.c helper.pm populator.pl sysio_stubs.c sysio_
Brought to you by:
lward
From: Mei <me...@us...> - 2003-08-15 07:48:59
|
Update of /cvsroot/libsysio/libsysio/tests In directory sc8-pr-cvs1:/tmp/cvs-serv25257/tests Modified Files: Tag: b_lustre Makefile.am test_copy.c test_getcwd.c test_list.c test_mounts.c test_path.c test_stats.c test_stdfd.c Added Files: Tag: b_lustre README help.c helper.pm populator.pl sysio_stubs.c sysio_tests.c test_all.pl test_copy.pl test_driver.c test_driver.h test_getcwd.pl test_list.pl test_path.pl test_stats.pl test_stdfd.pl verifier.pl Log Message: merge changes from HEAD to b_lustre --- NEW FILE --- To run the tests, just do ./test_all.pl (at some point I will integrate that into the build environment). This will run the 6 basic functionality tests (explained below) and report the total number of passes and failures. This is not currently working on alpha/cplant architectures, however. -----------------------SCRIPTS--------------------------------- There are a total of 8 scripts: test_copy.pl, test_list.pl, test_getcwd.pl, test_stats.pl, test_stdfd.pl, test_path.pl, populator.pl, and verifier.pl. All but the last two scripts are ran with the test_all.pl script. Here is an explanation of the scripts. All scripts take an optional "-alpha" arg for running the scripts in an alpha/cplant environment. The alpha arg makes certain assumptions about the running of the environment; for example, it does not initilization and it starts off the test driver with yod. test_copy.pl <src> <dest> : This copies a file from src to dest. : It runs a system cmp to verify that : the two files are equivalent test_list.pl [-p] <dir> : This comes in two forms. test_list.pl [-p] <fstype:mdir> <dir> : In the first form, it will : parse through the getdirentries : result in order to generate a : a listing. If the -p option is : given, it will print out the : listing. In the second form, it : mounts mdir into dir and then does : the listing test_getcwd.pl <dir> : Tests getcwd by verifying that setting the current : working directory to dir and then calling getcwd : returns dir test_stats.pl <file> : Verifies that the set of stat calls (stat, fstat, : fstatvfs, statvfs) return the same set of stats for file : and that the calls return the same items as Perl's stat : call (which would use a native library and not libsysio) test_stdfd.pl <file> : Verified that stdin, stdout, and stderr can be opened and : either written to or read from test_path.pl <path1> <path2> ... : Print each path listed and its type. : If no paths are given, paths are read : from stdin until a "quit" is given populator.pl [-seed seed] : Create a file and populate with random numbers. [-file filename] : Will use the given seed for the random number [-bytes bytes] : generator if it is given, otherwise it uses the : the current time as a seed. The seed used is : returned. If no filename is given, the file : will be named randfile.seed.procnum, where seed : is the seed used and procnum is the process number : of the script. If no bytes are given, 1024 bytes : are written. All write commands use libsysio verifier.pl <-seed seed> <-file fname> : Verifies that all bytes in the file fname : (which was created with populator) match the : random numbers which would have been used with : the populator, using the given seed. -----------------------------TEST DRIVER--------------------------------- There are 6 basic commands for the test driver, CALL, PRINT, ALLOC, FREE, HELP, and exit (EXIT, quit, or QUIT will also work). CALL is the main command for running libsysio calls. The format will depend on the particular libsysio command being ran. Basically, the format is CALL cmd args. The available commands used with CALL are (in no particular order): fstat iwrite read chdir fstatvfs iwritev readv chmod fsync list rmdir chown ftruncate lseek sizeof close getcwd lstat stat cmpstr getdirentries mkdir statvfs creat init mknod symlink debug ioctl mount truncate dup iodone open umask dup2 iowait umount endian ipread printline unlink ipreadv pread write fcntl ipwrite preadv writev fdatasync ipwritev pwritev fill iread pwrite ireadv The specifics of the commands are explained later. The return value from a command can be saved and referenced later by using a syntax similar to $foo = x. Commands can be combined, such as: CALL fstat ( $fd = CALL open foo ) ( $buf = ALLOC 128 ), with some cautionary notes. First, everything needs to be seperated by a space. File names with spaces in them need to be quoted, as in: $fd = CALL open "file with spaces" O_RDONLY Second, any value that is used needs to be identified with an identifier. In other words, the command: $buf = ALLOC ( CALL sizeof stat ) will not work, but the command $buf = ALLOC ( $size = CALL sizeof stat ) will. All commands return a 4 digit status code. The codes are: 0000 : Success. This does NOT necessarily mean that the libsysio : command returned success, only that there were no errors : in issuing the command to libsysio. To get the result of : the libsysio command, use PRINT $$ . PRINT $errno will return : the last error code. 0x001 : Invalid arguments given to command 0x002 : Invalid command issued 0x004 : Invalid variable identifier given ALLOC takes a size argument and an optional alignment argument. FREE takes the variable to free as an argument. HELP without any arguments displays the list of commands. HELP <cmd> will give information on the specific command PRINT take several forms. To just print out a variable, type PRINT $var-name. If the variable is an integer, it will return the integer. If it is a string, it will print out the string. If it is a buffer, it will print out the buffer as a series of hex digits. Note for most buffers, the test driver will not know what it contains--just because it should contain a string does not mean that the driver will know that. The other form of PRINT is: PRINT $var_name <offset> <length> <type> which will print out length units of the given type starting at the given offset. The length is the total length in bytes, so for an integer, a length of 4 would only print out one integer. The length argument is ignored for strings. Allowable types are INT SHORT CHAR and LONG. For most of the CALL commands, their format is similar to the related sysio call. The ones that do not have a corresponding sysio call are listed below: init: This MUST be called prior to any sysio calls. It initilizes : libsysio printline: If debugging is turned on, this will print a line number : with any debug lines fill <val> <type> <size> <offset> <buf>: Fills buffer buf with size : bytes of val starting at : buf+offset. The type of val : can be UINT. STR, or PTR and : is given by the type arg list <dir>: Lists contents of dir. If no dir is given, uses cwd debug <num>: Sets debug level to num sizeof <obj>: Gives the size of the obj. Valid objs are char, int, : long, flock, stat, and statvfs endian: returns 0 if the machine is little endian, one otherwise cmpstr <buf1> <buf2>: Issues a strcmp call on the two buffers to : see if they are the same. Returns 0 for a : match --- NEW FILE --- #include <stdio.h> #include "test_driver.h" void do_help() { int i, d, count = 0; fprintf(outfp, "libsysio test harness\n"); fprintf(outfp, "To get help on a specific command, use HELP <cmd>\n"); fprintf(outfp, "To exit, type exit or quit\n"); fprintf(outfp, "\nTo save the result from a function, use \"$res = CALL command\"\n"); fprintf(outfp, "To later use that res, do \"comm $res\"\n"); fprintf(outfp, "\n\nAvailable commands are (always preceded by CALL):\n\n"); /* Get total number of commands */ while (cmd_list[count].cmd) count++; d = count/4; if (count % 4) d++; for (i=0; i < d; i++) { if ( (i+d) < count ) { if ( (i + 2*d) < count) { if ( (i+3*d) < count) fprintf(outfp, "%-15s %-15s %-15s %-15s\n", cmd_list[i].cmd, cmd_list[i+d].cmd, cmd_list[i+2*d].cmd, cmd_list[i+3*d].cmd); else fprintf(outfp, "%-15s %-15s %-15s\n", cmd_list[i].cmd, cmd_list[i+d].cmd, cmd_list[i+2*d].cmd); } else fprintf(outfp, "%-15s %-15s\n", cmd_list[i].cmd, cmd_list[i+d].cmd); } else fprintf(outfp, "%-15s\n", cmd_list[i].cmd); } fprintf(outfp, "\n"); } void usage_setdebug() { fprintf(outfp, "setdebug [level]: Set debugging level to level\n"); } void usage_clear() { fprintf(outfp, "clear buf: zero out the buffer\n"); } void usage_printline() { fprintf(outfp, "printline [0|1]: Turn off (0) or on (1) the printing of line number\n"); fprintf(outfp, " : and file name with debug output\n"); } void usage_endian() { fprintf(outfp, "endian: returns 1 for bigendian machines and 0 for little endian machines\n"); } void usage_sizeof() { fprintf(outfp, "sizeof [type]: returns the size of the data type. Currently \n"); fprintf(outfp, " : supported types are char, int, long, flock, stat and \n"); fprintf(outfp, " : statvfs\n"); } void usage_get_buffer() { fprintf(outfp, "alloc [size] <align>: allocates a buffer of size bytes aligned to align\n"); fprintf(outfp, " : align is optional. If not there, buffer will be aligned on\n"); fprintf(outfp, " : a one-byte boundary. returns an index into an array that \n"); fprintf(outfp, " : holds the buffer\n"); } void usage_free_buffer() { fprintf(outfp, "free [bufidx]: frees buffer at bufidx. Returns 0 on success, -1 on failure\n"); } void usage_do_fillbuff() { fprintf(outfp, "fill [val] [type] [size] [offset] [buf] : Fills the buffer buf with size \n"); fprintf(outfp, " : bytes of val starting at buf+offset\n"); fprintf(outfp, " : The type of val is specified by type,\n"); fprintf(outfp, " : which can be UINT, STR, or PTR\n"); } void usage_do_printbuf() { fprintf(outfp, "printbuf [buf] : print out contents of the buffer stored in buf\n"); fprintf(outfp, " : Always returns 0\n"); } void usage_cmpbufs() { fprintf(outfp, "cmpstr [buf1] [buf2]: Compare the contents of buf1 with buf2 by issuing a \n"); fprintf(outfp, " strcmp call. Returns 0 if the buffers match\n"); } void usage_init() { fprintf(outfp, "init <driver> <path> <flags>: Without any arguments, initilizes libsysio\n"); fprintf(outfp, " : to default values for root directory and\n"); fprintf(outfp, " : current directory. Accepts optional\n"); fprintf(outfp, " : arguments for the root driver, the mount\n"); fprintf(outfp, " : path, and the mount flags. Must be called\n"); fprintf(outfp, " : before any other libsysio calls. Returns\n"); fprintf(outfp," : 0 on success, -1 on failure\n"); } void usage_list() { fprintf(outfp, "list <dir>: lists contents of dir. If dir is ommitted, will list contents\n"); fprintf(outfp, " : of the current working directory\n"); fprintf(outfp, " : Returns 0 on success, -1 on failure\n"); } void usage_chdir() { fprintf(outfp, "chdir [dir]: change the current working directory to dir\n"); fprintf(outfp, " : Returns 0 on success, -1 on failure\n"); } void usage_chmod() { fprintf(outfp, "chmod [newmode] [file]: change mode of file to newmode. newmode can be \n"); fprintf(outfp, " : specifed symbolically (eg, a+x), numerically \n"); fprintf(outfp, " : (eg, 0777), or using system defines \n"); fprintf(outfp, " : (eg S_IRUSR|S_IWUSR|S_IRGRP)\n"); fprintf(outfp, " : Returns 0 on success, -1 on failure\n"); } void usage_chown() { fprintf(outfp, "chown [newown[:newgrp]] [file]: change the owner of file to newown, the group\n"); fprintf(outfp, " : of file to newgrp, or both\n"); fprintf(outfp, " : Returns 0 on success, -1 on failure\n"); } void usage_open() { fprintf(outfp, "open [file] [flags] <mode>: open file with given flags. The mode is optional\n"); fprintf(outfp, " : can use defines for open, (eg, open foo O_RDONLY)\n"); fprintf(outfp, " : If flags are 0, file will be opened with O_RDWR\n"); fprintf(outfp, " : Returns the file descriptor for the opened file\n"); } void usage_close() { fprintf(outfp, "close [file]: closes the file. Returns 0 on success, -1 on failure\n"); } void usage_mount() { fprintf(outfp, "mount [fstype:source] [target]: mount source (which has fstype as its file\n"); fprintf(outfp, " : system type) onto target.\n"); fprintf(outfp, " : Returns 0 on success, -1 on failure\n"); } void usage_dup() { fprintf(outfp, "dup [oldfd]: Duplicate oldfd. Returns the duplicated file descriptor\n"); fprintf(outfp, " : Returns -1 on failure\n"); } void usage_dup2() { fprintf(outfp, "dup2 [oldfd] [newfd]: Make newfd be a copy of oldfd. Returns newfd on \n"); fprintf(outfp, " : success and -1 on failure\n"); } void usage_fcntl() { fprintf(outfp, "fcntl [fd] [cmd] <args> : execute fcntl cmd on file with file descriptor fd\n"); fprintf(outfp, " : using (optional) args. Accepted (but not \n"); fprintf(outfp, " : necesarily working) commands are F_DUPFD, \n"); fprintf(outfp, " : F_GETFD, F_GETFL, F_GETOWN, F_SETFD, F_SETFL,\n"); fprintf(outfp, " : F_SETOWN, F_SETLK, F_SETLKW, and F_GETLK. \n"); } void usage_fstat() { fprintf(outfp, "fstat [fd] [buf]: Get the stat structure for file descriptor fd and place it\n"); fprintf(outfp, " : in buf. Returns 0 on success, -1 on failure\n"); } void usage_fsync() { fprintf(outfp, "fsync [fd]: ensure all parts of file with file descriptor fd are output to\n"); fprintf(outfp, " : stable storage. Returns 0 on success, -1 on failure\n"); } void usage_fdatasync() { fprintf(outfp, "fdatasync [fd]: ensure all parts of file with file descriptor fd except the \n"); fprintf(outfp, " : metadata are output to stable storage. Returns 0 on \n"); fprintf(outfp, " : success, -1 on failure\n"); } void usage_ftruncate() { fprintf(outfp, "ftruncate [fd] [len]: truncate file with file descriptor fd to have be \n"); fprintf(outfp, " : len bytes in length. Returns 0 on success, -1 on \n"); fprintf(outfp, " : failure\n"); } void usage_getcwd() { fprintf(outfp, "getcwd [buf] [size]: get the current working directory and store it in buf\n"); fprintf(outfp, " : buf is size bytes in length. If buf is too short, an \n"); fprintf(outfp, " : error of ERANGE is returned. Returns 0 on success, -1\n"); fprintf(outfp, " : on failure\n"); } void usage_lseek() { fprintf(outfp, "lseek [fd] [offset] [whence]: Sets the offset of the file descriptor fd to\n"); fprintf(outfp, " : either offset if whence is SEEK_SET or offset\n"); fprintf(outfp, " : plus the current location if whence is SEEK_CUR\n"); fprintf(outfp, " : or offset plus the size of the file if whence\n"); fprintf(outfp, " : is SEEK_END. Returns 0 on success and -1 on \n"); fprintf(outfp, " : failure\n"); } void usage_lstat() { fprintf(outfp, "lstat [filename] [buf]: Get the stat structure for filename and return it in\n"); fprintf(outfp, " : buf. Returns 0 on success and -1 on failure\n"); } void usage_getdirentries() { fprintf(outfp, "getdirentries [fd] [buf] [nbytes] [basep]: Read dir entries from directory\n"); fprintf(outfp, " : with file descriptor fd into buf\n"); fprintf(outfp, " : At most nbytes are read. Reading\n"); fprintf(outfp, " : starts at basep, and basep is set\n"); fprintf(outfp, " : to new pos. Returns the number of \n"); fprintf(outfp, " : bytes read on success or 0 on\n"); fprintf(outfp, " : failure\n"); fprintf(outfp, "Note that basep does not have to be pre-allocated. Executing cmd: \n"); fprintf(outfp, "\"getdirentries $fd $buf 4096 $basep\", where $fd is the result of an open\n"); fprintf(outfp, "and $buf is the result of an alloc (but $basep is totally new) will work\n"); fprintf(outfp, "After the execution of the command, $basep holds the new offset and can be\n"); fprintf(outfp, "used again for any further getdirentries calls\n"); } void usage_mkdir() { fprintf(outfp, "mkdir [newdir] [mode]: make a new directory, newdir, with the permissions \n"); fprintf(outfp, " : specified in mode. Permissions can be symbolic \n"); fprintf(outfp, " : (eg, a+x), numeric (eg, 0777), or can use defines\n"); fprintf(outfp, " : (eg S_IRUSR|S_IWUSR|S_IRGRP). Returns 0 on success \n"); fprintf(outfp, " : -1 on failure.\n"); } void usage_creat() { fprintf(outfp, "creat [newfile] [mode]: create a new file, newfile, with the permissions \n"); fprintf(outfp, " : specified in mode. Permissions can be symbolic \n"); fprintf(outfp, " : (eg, a+x), numeric (eg, 0777), or can use defines\n"); fprintf(outfp, " : (eg S_IRUSR|S_IWUSR|S_IRGRP). Returns 0 on success \n"); fprintf(outfp, " : -1 on failure.\n"); } void usage_stat() { fprintf(outfp, "stat [filename] [buf]: Get the stat structure for filename and return it in\n"); fprintf(outfp, " : buf. Returns 0 on success and -1 on failure\n"); } void usage_statvfs() { fprintf(outfp, "statvfs [filename] [buf]: Get the statvfs structure for filename and return\n"); fprintf(outfp, " : it in buf. Returns 0 on success and -1 on failure\n"); } void usage_fstatvfs() { fprintf(outfp, "fstatvfs [fd] [buf]: Get the stat structure for file with file descriptor fd\n"); fprintf(outfp, " : and return it in buf. Returns 0 on success and -1 on\n"); fprintf(outfp, " : failure\n"); } void usage_truncate() { fprintf(outfp, "truncate [fname] [len]: truncate file with name fname to be exactly \n"); fprintf(outfp, " : len bytes in length. Returns 0 on success, -1 on \n"); fprintf(outfp, " : failure\n"); } void usage_rmdir() { fprintf(outfp, "rmdir [dirname]: Remove directory at dirname. Returns 0 on success, -1 on\n"); fprintf(outfp, " : failure.\n"); } void usage_symlink() { fprintf(outfp, "symlink [path1] [path2]: Make a symbolic link from path1 to path2. Returns\n"); fprintf(outfp, " : 0 on success, -1 on failure\n"); } void usage_unlink() { fprintf(outfp, "unlink [path]: Unlink path. If path is the last name to a file, the file is \n"); fprintf(outfp, " : is removed. If it was a symbolic link, the link is removed. \n"); fprintf(outfp, " : Returns 0 on success, -1 on failure\n"); } void usage_ioctl() { fprintf(outfp, "ioctl [fd] [cmd] <args> : Issue the ioctl command cmd on the file with file\n"); fprintf(outfp, " : descriptor fd. Any arguments are placed in args\n"); fprintf(outfp, " : At the moment, the only commands understand are the \n"); fprintf(outfp, " : ioctl commands found in /usr/include/linux/fs.h\n"); } void usage_umask() { fprintf(outfp, "ioctl [mask] : Sets the umask used by open to set initial file permissions on\n"); fprintf(outfp, " : a newly created file. Returnds the previous value of the mask\n"); } void usage_iodone() { fprintf(outfp, "iodone [ioid] : Poll for completion of the asynchronous request identifed by\n"); fprintf(outfp, " : ioid. Returns 1 if request finished\n"); } void usage_iowait() { fprintf(outfp, "iowait [ioid] : Wait for completion of the asynchronous request identifed by\n"); fprintf(outfp, " : ioid. Returns result of asynchronous request \n"); } void usage_ipreadv() { fprintf(outfp, "ipreadv [fd] [buf] [count] [off]: Reads data asynchrously to file descriptor fd \n"); fprintf(outfp, " : starting at offset off. Data comes from \n"); fprintf(outfp, " : buffer described by buf, which is a pointer to\n"); fprintf(outfp, " : an iovec strucutre. Number of buffers is \n"); fprintf(outfp, " : specified by count. Returns an iod_t on \n"); fprintf(outfp, " : success and -1 on failure\n"); } void usage_ipread() { fprintf(outfp, "ipread [fd] [buf] [count] [off]: Read asynchrously up to count bytes from file\n"); fprintf(outfp, " : with file descriptor fd starting at offset off\n"); fprintf(outfp, " : Read into buffer pointed at by buf. Returns\n"); fprintf(outfp, " : an iod_t on success and -1 on failure\n"); } void usage_preadv() { fprintf(outfp, "preadv [fd] [buf] [count] [off]: Reads data from file descriptor fd starting at\n"); fprintf(outfp, " : offset off. Data goes into buffer described\n"); fprintf(outfp, " : by buf, which is a pointer to an iovec \n"); fprintf(outfp, " : structure. Number of buffers is specified by\n"); fprintf(outfp, " : count. Returns the number of bytes read\n"); } void usage_pread() { fprintf(outfp, "preadv [fd] [buf] [count] [off]: Reads count bytes of data from file descriptor\n"); fprintf(outfp, " : fd starting at offset off. Data goes into buf.\n"); fprintf(outfp, " : Returns number of bytes read or -1 on failure\n"); } void usage_ireadv() { fprintf(outfp, "ireadv [fd] [buf] [count] : Reads data asynchrously to file descriptor fd \n"); fprintf(outfp, " : Data comes from buffer described by buf, which is \n"); fprintf(outfp, " : an pointer to an iovec structure. Number of\n"); fprintf(outfp, " : buffers is specified by count. Returns an iod_t\n"); fprintf(outfp, " : on success and -1 on failure\n"); } void usage_iread() { fprintf(outfp, "iread [fd] [buf] [count]: Read asynchrously up to count bytes from file with\n"); fprintf(outfp, " : file descriptor fd into buffer pointed at by buf\n"); fprintf(outfp, " : Returns an iod_t on success and -1 on failure\n"); } void usage_readv() { fprintf(outfp, "readv [fd] [buf] [count] : Reads data from file descriptor fd. Data comes from\n"); fprintf(outfp, " : the buffer described by buf, which is a pointer to an\n"); fprintf(outfp, " : an iovec structure. Number of buffers is specified\n"); fprintf(outfp, " : by count. Returns the number of bytes read on \n"); fprintf(outfp, " : on success and -1 on failure\n"); } void usage_read() { fprintf(outfp, "read [fd] [buf] [count]: Read up to count bytes from file with file \n"); fprintf(outfp, " : descriptor fd into buffer pointed at by buf\n"); fprintf(outfp, " : Returns number of bytes read on success or 0 on \n"); fprintf(outfp, " : on failure\n"); } void usage_ipwritev() { fprintf(outfp, "ipwritev [fd] [buf] [count] [off]: writes data asynchronously to file with file\n"); fprintf(outfp, " : descriptor fd starting at offset off. Data \n"); fprintf(outfp, " : comes from buffers described by buf, which\n"); fprintf(outfp, " : is a pointer to an iovec structure. Number \n"); fprintf(outfp, " : of buffers is specified by count. Returns\n"); fprintf(outfp, " : an iod_t on success and -1 on failure\n"); } void usage_ipwrite() { fprintf(outfp, "ipwrite [fd] [buf] [count] [off]: writes count bytes of data asynchronously to\n"); fprintf(outfp, " : file with file descriptor fd starting at \n"); fprintf(outfp, " : offset off. Data comes from buf. Returns an\n"); fprintf(outfp, " : iod_t on success and -1 on failure\n"); } void usage_pwritev() { fprintf(outfp, "pwritev [fd] [buf] [count] [off]: writes data to file with file descriptor fd\n"); fprintf(outfp, " : starting at offset off. Data comes from \n"); fprintf(outfp, " : buffers described by buf, which is a pointer\n"); fprintf(outfp, " : to an iovec structure. Number of buffers is\n"); fprintf(outfp, " : by count. Returns number of bytes read on \n"); fprintf(outfp, " : success and -1 on failure\n"); } void usage_pwrite() { fprintf(outfp, "pwrite [fd] [buf] [count] [off]: writes count bytes of data to file with file \n"); fprintf(outfp, " : descriptor fd starting at offset off. Data\n"); fprintf(outfp, " : Data comes from buf. Returns number of bytes\n"); fprintf(outfp, " : written on success and -1 on failure\n"); } void usage_iwritev() { fprintf(outfp, "iwritev [fd] [buf] [count] : writes data asynchronously to file with file\n"); fprintf(outfp, " : descriptor fd. Data comes from buffers described\n"); fprintf(outfp, " : by buf, which is a pointer to an iovec structure.\n"); fprintf(outfp, " : Number of buffers is specified by count. Returns\n"); fprintf(outfp, " : an iod_t on success and -1 on failure\n"); } void usage_iwrite() { fprintf(outfp, "iwrite [fd] [buf] [count] : writes count bytes of data asynchronously to\n"); fprintf(outfp, " : file with file descriptor fd. Data comes from buf.\n"); fprintf(outfp, " : Returns an iod_t on success and -1 on failure.\n"); } void usage_writev() { fprintf(outfp, "writev [fd] [buf] [count]: writes data to file descriptor fd. Data comes from\n"); fprintf(outfp, " : buffers described by buf, which is a pointer to a \n"); fprintf(outfp, " : iovec strucutre. Number of buffers is specified by \n"); fprintf(outfp, " : count \n"); } void usage_write() { fprintf(outfp, "write [fd] [buf] [count] : writes count bytes of data to file with file \n"); fprintf(outfp, " : descriptor fd. Data comes from buf. Returns number\n"); fprintf(outfp, " : of bytes written on success and -1 on failure.\n"); } void usage_mknod() { fprintf(outfp, "mknod [path] [mode] [dev] : creates a filesystem node named path with \n"); fprintf(outfp, " : specified mode using device special file dev\n"); fprintf(outfp, " : Returns 0 on sucess and -1 on failure\n"); } void usage_umount() { fprintf(outfp, "umount [path] : Umount file at path. Returns 0 on success and -1 on failure\n"); } void usage_exit() { } --- NEW FILE --- #!/usr/bin/perl -w # # Provides a set of helper routines for use in the Perl # test scripts # package helper; use strict; use Fcntl ':mode'; BEGIN{} # Print out a given error message, close the command file # and exit sub print_and_exit { my ($cmdfh, $outfh, $exit_num, $exit_str) = @_; print STDOUT "$exit_str"; # Clean up my $cmdstr = 'FREE $buf'; $cmdstr = $cmdstr."\n"; print $cmdfh $cmdstr; my $res = <$outfh>; chop($res); if ($res ne "0000 ") { print STDOUT "ERROR! Failed to free buf (code $res)\n"; } print $cmdfh "exit\n"; close $outfh; # Give test_driver time to finish sleep 0.000001; exit $exit_num; } # Output the given command and make sure that the exit # code for the command was valid sub send_cmd { my ($cmdfh, $outfh, $cmd, $cmdstr) = @_; print $cmdfh $cmdstr; my $res = <$outfh>; chop($res); if ($res ne "0000 ") { print_and_exit($cmdfh, $outfh, 1, "ERROR! Command $cmd failed with code $res\n"); } } # Check the return value from the last libsysio call sub verify_cmd { my ($cmdfh, $outfh, $cmd) = @_; # Verify the system call's output my $cmdstr = 'PRINT $$'; $cmdstr .= "\n"; send_cmd($cmdfh, $outfh, "PRINT", $cmdstr); my $res = <$outfh>; chop($res); if ($res eq "0xffffffff") { # Get the errno $cmdstr = 'PRINT $errno'; $cmdstr .= "\n"; send_cmd($cmdfh, $outfh, "PRINT", $cmdstr); my $err = <$outfh>; chop($err); print_and_exit($cmdfh, $outfh, 1, "ERROR! $cmd returned $err\n"); } return $res; } # Compares two numbers. Output error message and exit if # they differ sub cmp_nums { my ($cmdfh, $outfh, $ionum, $pnum, $desc) = @_; my $str; if (!defined($ionum)) { print_and_exit($cmdfh, $outfh, 1, "ERROR! ionum for $desc undefined"); } elsif (!defined($pnum)) { print_and_exit($cmdfh, $outfh, 1, "ERROR! pnum for $desc undefined"); } if ($ionum != $pnum) { my $str = sprintf("ERROR! Sysio's number %x does not match Perl's (%x)\n", $ionum, $pnum); $str = sprintf("%s Numbers were %s\n", $str, $desc); print_and_exit($cmdfh, $outfh, 1, $str); } } sub get_type { my $mode = $_[0]; my $t = '?'; if (S_ISDIR($mode)) { $t = 'd'; } elsif (S_ISCHR($mode)) { $t = 'c'; } elsif (S_ISBLK($mode)) { $t = 'b'; } elsif (S_ISREG($mode)) { $t = 'f'; } elsif (S_ISFIFO($mode)) { $t = 'p'; } elsif (S_ISLNK($mode)) { $t = 'S'; } elsif (S_ISSOCK($mode)) { $t = 's'; } return $t; } END{} 1; --- NEW FILE --- #!/usr/bin/perl -w use IPC::Open2; use strict; use helper; sub usage { print "Usage: ./populator.pl <-seed seed> :\n"; print " <-file filename> :\n"; print " <-bytes bytes> : Create a file, filename, that\n"; print " : is bytes long and populate with\n"; print " : random numbers using the given\n"; print " : seed. Will use defaults if args\n"; print " : not given\n"; exit(-1); } sub get_buf { my $MAX_SIZE = 2147483648; my $str; my $num; my $len = 0; while ($len < 512) { $num = rand $MAX_SIZE; my $tmpstr = sprintf("%d", $num); $str .= $tmpstr; $len += length $tmpstr; } return ($len, $str); } sub write_file { my ($cmdfh, $outfh, $filename, $bytes) = @_; # Allocate the read buffer my $cmd = '$buf = ALLOC 1024'."\n"; helper::send_cmd($cmdfh, $outfh, "alloc", $cmd); # Open (create) the new file $cmd = '$fd = CALL open '."$filename O_RDWR|O_CREAT S_IRWXU\n"; helper::send_cmd($cmdfh, $outfh, "open", $cmd); # Verify the system call's output helper::verify_cmd($cmdfh, $outfh, "open"); my $left_bytes = $bytes; while ($left_bytes > 0) { # Get a buffer filled with random numbers # Buffer will be no less than 512 bytes my ($len, $buf) = get_buf; if ($len > $left_bytes) { $len = $left_bytes; } # Need to fill $buf with the buffer $cmd = "CALL fill $buf STR $len 0 ".'$buf'."\n"; helper::send_cmd($cmdfh, $outfh, "fill", $cmd); # Write out $len bytes to $filename $cmd = 'CALL write $fd $buf '."$len\n"; helper::send_cmd($cmdfh, $outfh, "write", $cmd); my $written_bytes = helper::verify_cmd($cmdfh, $outfh, "write"); $written_bytes = oct($written_bytes); if ($written_bytes != $len) { helper::print_and_exit($cmdfh, $outfh, 1, "ERROR! Meant to print out $len but only printed $written_bytes\n"); } $left_bytes -= $len; } } sub populate_file { my ($filename, $bytes, $is_alpha) = @_; eval { if ($is_alpha == 0) { open2(\*OUTFILE, \*CMDFILE, "./test_driver --np"); } else { open2(\*OUTFILE, \*CMDFILE, "yod -batch -quiet -sz 1 ./test_driver --np"); } }; if ($@) { if ($@ =~ /^open2/) { warn "open2 failed: $!\n$@\n"; return; } die; } my $outfh = \*OUTFILE; my $cmdfh = \*CMDFILE; if ($is_alpha == 0) { helper::send_cmd($cmdfh, $outfh, "init", "CALL init\n"); } # Now write the file write_file($cmdfh, $outfh, $filename, $bytes); # Close the file my $cmd = 'CALL close $fd'."\n"; helper::send_cmd($cmdfh, $outfh, "close", $cmd); helper::verify_cmd($cmdfh, $outfh, "close"); # All done helper::print_and_exit($cmdfh, $outfh, 0, "File $filename successfully created\n"); } my $is_alpha = 0; my $seed = time; my $filename = "randfile.$seed.$$"; my $bytes = 1024; for (my $i = 0; $i < @ARGV; $i++) { if ($ARGV[$i] eq "-file") { $i++; $filename = $ARGV[$i]; } elsif ($ARGV[$i] eq "-seed") { $i++; $seed = $ARGV[$i]; } elsif ($ARGV[$i] eq "-alpha") { $is_alpha = 1; } elsif ($ARGV[$i] eq "-bytes") { $i++; $bytes = $ARGV[$i]; } } # seed the randome number generator srand $seed; populate_file($filename, $bytes, $is_alpha); exit $seed; --- NEW FILE --- #define _BSD_SOURCE #include <stdio.h> #include <stdlib.h> #include <string.h> #include <errno.h> #include <fcntl.h> #include <unistd.h> #include <sys/uio.h> #include <linux/fs.h> #include <sys/stat.h> #include <sys/statvfs.h> #include "test_driver.h" #include "sysio.h" /* * ################################################ * # Function stubs # [...2187 lines suppressed...] int do_umount(int argc, char **argv) { int err; if (argc != 1) { DBG(2, fprintf(outfp, "Invalid number (%d) of args for umount\n", argc)); return INVALID_ARGS; } err = umount(argv[0]); if (err) my_perror("umount"); my_errno = errno; last_ret_val = err; last_type = SINT; return SUCCESS; } --- NEW FILE --- #define _BSD_SOURCE #include <stdio.h> #include <stdlib.h> #include <string.h> #include <getopt.h> #include <errno.h> #include <ctype.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/statvfs.h> #include <fcntl.h> #include <sys/queue.h> #include <dirent.h> #include <pwd.h> #include <grp.h> #include "sysio.h" #include "mount.h" #include "test.h" #include "test_driver.h" /* * ################################################### * # Test functions # * # These functions are used to test libsysio. # * # Eventually, there should be one of these for # * # every function document in sysio.h # * ################################################### */ int initilize_sysio(char *root_driver, char *root_path, int mntflgs) { int err; char *wd; /* * Init sysio lib. */ _sysio_init(); /* * Init native file system driver and request mount of specified * source directory. */ err = drv_init_all(); if (err) { my_errno = err; my_perror("drv_init_all"); last_ret_val = errno; return SUCCESS; } err = _sysio_mount_root(root_path, root_driver, mntflgs, NULL); if (err) { my_errno = errno; my_perror("_sysio_mount_root"); perror("_sysio_mount_root"); last_ret_val = err; return SUCCESS; } /* * Attempt to set the cwd by getting it out of the * user's environment. If that does not work, set * it to / */ wd = getenv("PWD"); if (wd == NULL) { wd = malloc(5); strcpy(wd, "/"); } if (chdir(wd) != 0) { my_perror(wd); my_errno = errno; last_ret_val = errno; return SUCCESS; } DBG(3, sprintf(output, "Your current working directory is %s\n", wd)); last_ret_val = 0; return SUCCESS; } int sysio_list(char *path) { int fd; size_t n; struct dirent *buf, *dp; __off_t base; ssize_t cc; int numfiles = 0; fd = open(path, O_RDONLY); if (fd < 0) { my_errno = errno; last_ret_val = fd; my_perror(path); return SUCCESS; } n = 16 * 1024; buf = malloc(n); if (!buf) { my_perror(path); cc = -1; goto out; } base = 0; DBG(5, sprintf(output, "About to call getdirentries\n")); while ((cc = getdirentries(fd, (char *)buf, n, &base)) > 0) { dp = buf; while (cc > 0) { DBG(4, fprintf(outfp, "\t%s: ino %#08x off %#08x type %#08x\n", dp->d_name, (unsigned int)dp->d_ino, (unsigned int)dp->d_off, (int )dp->d_type)); sprintf(output, "%s\n", dp->d_name); cc -= dp->d_reclen; dp = (void *)dp + dp->d_reclen; numfiles++; } printf("Out of inner loop\n"); if (!base) break; } out: if (cc < 0) { DBG(2, sprintf(output, "cc barfed\n")); my_perror(path); } free(buf); { int oerrno = errno; if (close(fd) != 0) { DBG(2,sprintf(output, "close barfed\n")); my_perror(path); if (cc < 0) errno = oerrno; else cc = -1; } } last_ret_val = numfiles; my_errno = errno; return SUCCESS; } int sysio_mount(char *from, char *to) { int err; char *s; char *buf; char *cp; char *fstype, *source, *opts, *target; err = 0; /* * Copy everything to a buffer we can modify. */ s = buf = malloc(strlen(from) + 1); if (!buf) { my_perror(from); last_ret_val = -1; my_errno = errno; return SUCCESS; } (void )strcpy(s, from); /* * Eat leading white. */ while (*s && *s == ' ' && *s == '\t') s++; /* * Get fstype. */ fstype = cp = s; while (*cp && *cp != ':' && *cp != ' ' && *cp != '\t') cp++; if (fstype == cp || *cp != ':') { DBG(1, sprintf(output, "%s: Missing FS type\n", from)); err = -1; goto out; } *cp++ = '\0'; s = cp; /* * Eat leading white. */ while (*s && *s == ' ' && *s == '\t') s++; /* * Get source. */ source = cp = s; while (*cp && *cp != ' ' && *cp != '\t') cp++; if (source == cp) { DBG(1, sprintf(output, "%s: Missing source\n", from)); err = -1; goto out; } if (*cp) *cp++ = '\0'; s = to; /* * Eat leading white. */ while (*s && *s == ' ' && *s == '\t') s++; /* * Get opts. */ opts = cp = s; while (*cp && *cp != ' ' && *cp != '\t') cp++; if (opts == cp) { DBG(1,sprintf(output, "%s: Missing target\n", to)); err = -1; goto out; } if (*cp) *cp++ = '\0'; s = cp; /* * Eat leading white. */ while (*s && *s == ' ' && *s == '\t') s++; /* * Get target */ target = cp = s; while (*cp && *cp != ' ' && *cp != '\t') cp++; if (target == cp) { target = opts; opts = NULL; } if (*cp) *cp++ = '\0'; err = mount(source, target, fstype, 0, opts); if (err) my_perror(from); out: free(buf); last_ret_val = err; my_errno = errno; return SUCCESS; } int sysio_chdir(char *newdir) { char *buf; if (chdir(newdir) != 0) { my_perror(newdir); return -1; } /* buf = getcwd(NULL, 0); if (!buf) { my_perror(newdir); last_ret_val = -1; my_errno = errno; return SUCCESS; } DBG(4, sprintf(output, "New dir is %s\n", buf)); free(buf); */ return SUCCESS; } static mode_t get_mode(char *arg, int type, int start_mode); #define SYMBOLIC 0 #define DEFINED 1 #define NUMERIC 2 /* * Change the permissions on a given file * * sysio_chmod <filename> <permissions> * */ int sysio_chmod(char *mode_arg, const char *path) { int err; mode_t mode; struct stat st; /* Get the current mode */ err = stat(path, &st); /* Is the new mode symbolic? */ if (isalpha(mode_arg[0])) { /* Could be specifying defines */ if (mode_arg[0] == 'S') mode = get_mode(mode_arg, DEFINED, st.st_mode); else mode = get_mode(mode_arg, SYMBOLIC, st.st_mode); } else mode = get_mode(mode_arg, NUMERIC, st.st_mode); DBG(3,sprintf(output, "Using a mode of %o and a file of %s\n", mode, path)); if (mode == 0) { DBG(2,sprintf(output, "Invalid mode\n")); return INVALID_ARGS; } last_ret_val = chmod(path, mode); my_errno = errno; return SUCCESS; } #define USER_STATE 0 /* Specifies that the users are still being listed */ #define MODE_STATE_ADD 1 #define MODE_STATE_REMOVE 2 #define READ 00444 #define WRITE 00222 #define EXECUTE 00111 #define OWNER 00700 #define GROUP 00070 #define OTHER 00007 mode_t get_mode(char *arg, int type, int start_mode) { int i, j,digit, total; char c; int state = USER_STATE; int len = strlen(arg); unsigned int users = 0; unsigned int modes = 0; if (type == DEFINED) { char curr_word[10]; total = digit = 0; j = 0; DBG(4, sprintf(output, "len is %d\n", len)); for (i=0; i < len; i++) { if (arg[i] == '|') { curr_word[j] = '\0'; DBG(3, sprintf(output, "Got mode word %s\n", curr_word)); digit = get_obj(curr_word); if (digit < 0 ) { DBG(2, sprintf(output, "Unable to understand mode arg %s\n", curr_word)); return -1; } total |= digit; j = 0; } else curr_word[j++] = arg[i]; } curr_word[j] = '\0'; DBG(3, sprintf(output, "Got mode word %s\n", curr_word)); digit = get_obj(curr_word); if (digit < 0 ) { DBG(3, sprintf(output, "Unable to understand mode arg %s\n", curr_word)); return -1; } total |= digit; return total; } if (type == SYMBOLIC) { for (i=0; i < len; i++) { c = arg[i]; if (state == USER_STATE) { switch(c){ case 'u': users |= OWNER; break; case 'g': users |= GROUP; break; case 'o': users |= OTHER; break; case 'a': users |= (OWNER|GROUP|OTHER); break; case '+': state = MODE_STATE_ADD; break; case '-': state = MODE_STATE_REMOVE; break; default: return 0; } } else { switch(c){ case 'r': modes |= READ; break; case 'w': modes |= WRITE; break; case 'x': modes |= EXECUTE; break; default: return 0; } } } if (state == MODE_STATE_ADD) { return (start_mode | (users & modes)); } else { return (start_mode & ~(users & modes)); } } else { /* Digits should be octal digits, so should convert */ total = 0; for (i=0; i < len; i++) { c = arg[i]; digit = atoi(&c); if (digit > 7) return 0; for (j=len-i-1; j >0; j--) digit *= 8; total += digit; } return total; } } /* * Changes the ownership of the file. The new_id * is of the format owner:group. Either the owner * or the group may be omitted, but, in order to * change the group, the : must preced the group. */ int sysio_chown(char *new_id, char *file) { char *owner = NULL; char *group = NULL; struct group *g_ent = NULL; struct passwd *o_ent = NULL; uid_t o_id=-1, g_id=-1; int len, j, i=0; int state = 0; /* Correspond to getting owner name */ len = strlen(new_id); for (i=0; i < len; i++) { if (new_id[i] == ':') { /* Group name */ if (!group) group = malloc(strlen(new_id) -i +2); state = 1; /* Now getting group name */ j = 0; if (owner) owner[i] = '\0'; } if (!state) { /* Getting owner name */ if (!owner) owner = malloc(strlen(new_id) +1 ); owner[i] = new_id[i]; } else { /* Group name */ group[j] = new_id[i]; j++; } } if (group) group[i] = '\0'; else owner[i] = '\0'; /* Are the owner and/or group symbolic or numeric? */ if (owner) { if (isdigit(owner[0])) { /* Numeric -- just convert */ o_id = (uid_t) atoi(owner); /* Make sure it is valid */ if ((o_ent = getpwuid(o_id)) == NULL) { DBG(2, sprintf(output, "Error: uid %d not found \n", o_id)); return INVALID_ARGS; } } else { /* Get the id from the passwd file */ if ((o_ent = getpwnam(owner)) == NULL) { DBG(2, sprintf(output, "Error: name %s not found\n", owner)); return INVALID_ARGS; } o_id = o_ent->pw_uid; } } if (group) { if (isdigit(group[0])) { /* Numeric -- just convert */ g_id = (uid_t) atoi(group); /* Make sure it is valid */ if ((g_ent = getgrgid(g_id)) == NULL) { DBG(2, sprintf(output, "Error: gid %d not found \n", g_id)); return INVALID_ARGS; } } else { /* Find group in group file */ if ((g_ent = getgrnam(group)) == NULL) { DBG(2, sprintf(output, "Error: group %s not found \n", group)); return INVALID_ARGS; } g_id = g_ent->gr_gid; } } /* Now issue the syscall */ DBG(4, sprintf(output, "Changing owner of file %s to %d (group %d)\n", file, o_id, g_id)); last_ret_val = chown(file, o_id, g_id); my_errno = errno; return SUCCESS; } int sysio_open(char *path, int flags) { DBG(4, sprintf(output, "Opening file %s with flags %x\n", path, flags)); last_ret_val = open(path, flags); my_errno = errno; return SUCCESS; } int sysio_open3(char *path, int flags, char *mode_arg) { mode_t mode; /* Is the new mode symbolic? */ if (isalpha(mode_arg[0])) { /* Could be specifying defines */ if (mode_arg[0] == 'S') mode = get_mode(mode_arg, DEFINED, 0); else mode = get_mode(mode_arg, SYMBOLIC, 0); } else mode = get_mode(mode_arg, NUMERIC, 0); last_ret_val = open(path, flags, mode); my_errno = errno; return SUCCESS; } int sysio_close(int fd) { last_ret_val = close(fd); my_errno = errno; return SUCCESS; } int sysio_fcntl(int fd, struct cmd_map* cmdptr, char *arg) { int fd_new, index, cmd, flag; char *cmdname; void *buf; cmd = cmdptr->cmd; cmdname = cmdptr->cmd_name; switch(cmd) { case F_DUPFD: fd_new = get_obj(arg); last_ret_val = fcntl(fd, F_DUPFD, fd_new); my_errno = errno; return SUCCESS; break; case F_GETFD: case F_GETFL: case F_GETOWN: /* case F_GETSIG: case F_GETLEASE: */ last_ret_val= fcntl(fd, cmd); my_errno = errno; return SUCCESS; break; case F_SETFD: case F_SETFL: case F_SETOWN: /*case F_SETSIG: case F_SETLEASE: case F_NOTIFY: */ flag = atoi(arg); last_ret_val = fcntl(fd, cmd, flag); my_errno = errno; return SUCCESS; break; case F_SETLK: case F_SETLKW: case F_GETLK: /* Get the buffer to hold the lock structure */ index = get_obj(arg); if (index < 0) { sprintf(output, "Unable to find buffer %s\n", arg+1); return INVALID_VAR; } buf = buflist[index]; if (!buf) { sprintf(output, "Buffer at index %d (mapped by %s) is null\n", index, arg); return INVALID_VAR; } last_ret_val = fcntl(fd, cmd, (struct flock *)buf); my_errno = errno; return SUCCESS; default: /* THis should be impossible */ return INVALID_ARGS; } return INVALID_ARGS; } void print_stat(struct stat *st) { DBG(3, sprintf(output, "%sstruct stat: \n", output)); DBG(3, sprintf(output, "%s st_dev: %#16x\n", output, (unsigned int)st->st_dev)); DBG(3, sprintf(output, "%s st_ino: %#16x\n", output, (unsigned int) st->st_ino)); DBG(3, sprintf(output, "%s st_mode: %#16x\n", output, st->st_mode)); DBG(3, sprintf(output, "%s st_nlink: %#16x\n", output, st->st_nlink)); DBG(3, sprintf(output, "%s st_uid: %#16x\n", output, st->st_uid)); DBG(3, sprintf(output, "%s st_gid: %#16x\n", output, st->st_gid)); DBG(3, sprintf(output, "%s st_rdev: %#16x\n", output, (int)st->st_rdev)); DBG(3, sprintf(output, "%s st_size: %#16x\n", output, (int) st->st_size)); DBG(3, sprintf(output, "%s st_blksize: %#16x\n", output, (int) st->st_blksize)); DBG(3, sprintf(output, "%s st_blocks: %#16x\n", output, (int) st->st_blocks)); DBG(3, sprintf(output, "%s st_atime: %#16x\n", output, (unsigned int) st->st_atime)); DBG(3, sprintf(output, "%s st_mtime: %#16x\n", output, (unsigned int) st->st_mtime)); DBG(3, sprintf(output, "%s st_ctime: %#16x", output, (unsigned int) st->st_ctime)); } int sysio_fstat(int fd, void *buf) { int err; struct stat *st = (struct stat *)buf; err = fstat(fd, st); if (err < 0) { my_perror("fstat"); } my_errno = errno; last_ret_val = err; print_stat(st); return SUCCESS; } int sysio_lstat(char *filename, void *buf) { int err; struct stat *st = (struct stat *)buf; err = lstat(filename, st); if (err < 0) { my_perror("lstat"); } my_errno = errno; last_ret_val = err; print_stat(st); return SUCCESS; } int sysio_stat(char *filename, void *buf) { int err; struct stat *st = (struct stat *)buf; err = stat(filename, st); if (err < 0) { my_perror("stat"); } my_errno = errno; last_ret_val = err; print_stat(st); return SUCCESS; } int sysio_getdirentries(int fd, char *buf, size_t nbytes, off_t *basep) { int err; struct dirent *dp; err = getdirentries(fd, buf, nbytes, basep); last_ret_val = err; DBG(4, sprintf(output, "%sRead %d bytes\n", output, err)); dp = (struct dirent *)buf; while (err > 0) { DBG(3, sprintf(output, "%s\t%s: ino %llu off %llu len %x type %c\n", output, dp->d_name, (unsigned long long )dp->d_ino, (unsigned long long )dp->d_off, dp->d_reclen, (char )dp->d_type)); DBG(3, fprintf(outfp, "\t%s: ino %x off %x len %x type %x\n", dp->d_name, (unsigned long long )dp->d_ino, (unsigned long long )dp->d_off, dp->d_reclen, (char )dp->d_type)); err -= dp->d_reclen; dp = (void *)dp + dp->d_reclen; } my_errno = errno; return last_ret_val; } int sysio_mkdir(char *path, char *mode_arg) { int err; mode_t mode; struct stat st; /* Is the new mode symbolic? */ if (isalpha(mode_arg[0])) { /* Could be specifying defines */ if (mode_arg[0] == 'S') mode = get_mode(mode_arg, DEFINED, st.st_mode); else mode = get_mode(mode_arg, SYMBOLIC, st.st_mode); } else mode = get_mode(mode_arg, NUMERIC, st.st_mode); DBG(3, sprintf(output, "Using a mode of %o and a file of %s\n", mode, path)); if (mode == 0) { DBG(2, sprintf(output, "Invalid mode\n")); return INVALID_ARGS; } err = mkdir(path, mode); my_errno = errno; last_ret_val = err; return SUCCESS; } int sysio_creat(char *path, char *mode_arg) { mode_t mode; int err; /* Is the new mode symbolic? */ if (isalpha(mode_arg[0])) { /* Could be specifying defines */ if (mode_arg[0] == 'S') mode = get_mode(mode_arg, DEFINED, 0); else mode = get_mode(mode_arg, SYMBOLIC, 0); } else mode = get_mode(mode_arg, NUMERIC, 0); DBG(3, sprintf(output, "Using a mode of %o and a file of %s\n", mode, path)); if (mode == 0) { DBG(2, sprintf(output, "Invalid mode\n")); return INVALID_ARGS; } err = creat(path, mode); my_errno = errno; last_ret_val = err; return SUCCESS; } void print_statvfs(struct statvfs *st) { DBG(3, sprintf(output, "%sstruct statvfs: \n", output)); DBG(3, sprintf(output, "%s f_bsize: %x\n", output, (unsigned int) st->f_bsize)); DBG(3, sprintf(output, "%s f_frsize: %x\n", output, (unsigned int) st->f_frsize)); DBG(3, sprintf(output, "%s f_blocks: %x\n", output, (unsigned int) st->f_blocks)); DBG(3, sprintf(output, "%s f_bfree: %x\n", output, (unsigned int) st->f_bfree)); DBG(3, sprintf(output, "%s f_bavail: %x\n", output, (unsigned int) st->f_bavail)); DBG(3, sprintf(output, "%s f_files: %x\n", output, (unsigned int) st->f_files)); DBG(3, sprintf(output, "%s f_ffree: %x\n", output, (unsigned int) st->f_ffree)); DBG(3, sprintf(output, "%s f_favail: %x\n", output, (unsigned int) st->f_favail)); DBG(3, sprintf(output, "%s f_files: %x\n", output, (unsigned int) st->f_files)); DBG(3, sprintf(output, "%s f_fsid: %x\n", output, (unsigned int) st->f_fsid)); DBG(3, sprintf(output, "%s f_flag: %x\n", output, (unsigned int) st->f_flag)); DBG(3, sprintf(output, "%s f_fnamemax: %x\n", output, (unsigned int) st->f_namemax)); } int sysio_statvfs(char *filename, void *buf) { int err; struct statvfs *st = (struct statvfs *)buf; err = statvfs(filename, st); if ( err == -1) { my_perror("statvfs"); } my_errno = errno; last_ret_val = err; print_statvfs(st); return SUCCESS; } int sysio_fstatvfs(int fd, void *buf) { int err; struct statvfs *st = (struct statvfs *)buf; err = fstatvfs(fd, st); if (err == -1) { my_perror("fstatvfs"); } my_errno = errno; last_ret_val = err; print_statvfs(st); return SUCCESS; } int sysio_umask(char *mode_arg) { mode_t mode; /* Is the new mode symbolic? */ if (isalpha(mode_arg[0])) { /* Could be specifying defines */ if (mode_arg[0] == 'S') mode = get_mode(mode_arg, DEFINED, 0); else mode = get_mode(mode_arg, SYMBOLIC, 0); } else mode = get_mode(mode_arg, NUMERIC, 0); last_ret_val = umask(mode); my_errno = errno; return SUCCESS; } int sysio_mknod(char *path, char *mode_arg, dev_t dev) { int err; int mode; mode = get_obj(mode_arg); if (mode < 0) { DBG(2,sprintf(output, "Cant get mode from %s\n", mode_arg)); fprintf(stderr, "Cant get mode from %s\n", mode_arg); return INVALID_VAR; } err = mknod(path, (mode_t) mode, dev); if (err < 0) my_perror("mknod"); last_ret_val = err; my_errno = errno; return SUCCESS; } --- NEW FILE --- #!/usr/bin/perl -w # # VERY basic functionality test for sysio. To run, just type ./test_all.pl # Absolutely no guarantees for running on alpha/cplant # use strict; my $alpha_arg = ""; my $is_broke = 1; # Don't test certain areas known to not work on Cplant if ((@ARGV > 0) && ($ARGV[0] eq "-alpha")) { $alpha_arg = "-alpha"; } # Will use this directory... system("mkdir ./tmp_dir"); my $failures = 0; my $success = 0; # Get cwd.. my $cwd = $ENV{PWD}; # Get the sysio dir my $sysdir = $cwd; $sysdir =~ s/\/\w+$//; my $res; if (($alpha_arg eq "") || ($is_broke == 0)) { # Test getdirentries $res = `./test_list.pl $alpha_arg $sysdir`; chop($res); if ($res ne "list test successful") { print "Basic getdirentries test failed with message: $res\n"; $failures++; } else { print "test_list finished successfully\n"; $success++; } } # Test path my @resarr = `./test_path.pl $alpha_arg $sysdir $cwd $cwd/tmp_dir`; $res = $sysdir.": d\n"; if ($resarr[0] ne $res) { print "path test returned $resarr[0] instead of $res\n"; $failures++; } else { $res = $cwd.": d\n"; if ($resarr[1] ne $res) { print "path test returned $resarr[1] instead of $res\n"; $failures++; } else { $res = $cwd."/tmp_dir: d\n"; if ($resarr[2] ne $res) { print "path test returned $resarr[2] instead of $res\n"; $failures++; } else { print "test_path finished successfully\n"; $success++; } } } if (($alpha_arg eq "") || ($is_broke == 0)) { # Test mount $res = `./test_list.pl $alpha_arg -m native:$sysdir $cwd/tmp_dir`; chop($res); if ($res ne "list test successful") { print "Mount test failed with message: $res\n"; $failures++; } else { $success++; print "test_mount finished successfully\n"; } # Test getcwd $res = `./test_getcwd.pl $alpha_arg $sysdir`; chop($res); if ($res ne "getcwd test successful") { print "getcwd test failed with message: $res\n"; $failures++; } else { $success++; print "test_getcwd finished successfully\n"; } } # Test copy $res = `./test_copy.pl $alpha_arg $sysdir/README $cwd/tmp_dir/README`; chop($res); if ($res ne "copy test successful") { print "copy test failed with message: $res\n"; $failures++; } else { $success++; print "test_copy finished successfully\n"; } # Test stats $res = `./test_stats.pl $alpha_arg $cwd/tmp_dir/README`; chop($res); if ($res ne "stat test successful") { print "stat test failed with message: $res\n"; $failures++; } else { $success++; print "test_stats finished successfully\n"; } # Test stdfd $res = `./test_stdfd.pl $alpha_arg foo_dir`; chop($res); if ($res ne "test_stdfd successful") { print "stdfd test failed with message: $res\n"; $failures++; } else { $success++; print "test_stdfd finished successfully\n"; } print "$failures tests failed and $success tests succeeded\n"; # cleanup system(`rm -rf tmp_dir`); --- NEW FILE --- #!/usr/bin/perl -w # # copy test: Copy a file from src to dest and verify that the new file # : is the same as the old # use IPC::Open2; use strict; use helper; sub usage { print "Usage: ./test_copy.pl [-alpha] <src> <dest>: Copy a file from src to dest\n"; exit(-1); } sub process_cmd { my ($src, $dest, $is_alpha) = @_; eval { if ($is_alpha == 0) { open2(\*OUTFILE, \*CMDFILE, "./test_driver --np"); } else { open2(\*OUTFILE, \*CMDFILE, "yod -quiet -sz 1 ./test_driver --np"); } }; if ($@) { if ($@ =~ /^open2/) { warn "open2 failed: $!\n$@\n"; return; } die; } my $outfh = \*OUTFILE; my $cmdfh = \*CMDFILE; if ($is_alpha == 0) { helper::send_cmd($cmdfh, $outfh, "init", "CALL init\n"); } # Get the filesize of src my $size = -s $src; my $bufsize; if ( $size > 1024) { # Arbitrary limit $bufsize = 1024; } else { $bufsize = $size; } # Open src my $cmdstr = '$src = CALL open '."$src O_RDONLY\n"; helper::send_cmd($cmdfh, $outfh, "open", $cmdstr); # Open dest $cmdstr = '$dest = CALL open... [truncated message content] |