Update of /cvsroot/libsysio/libsysio/tests
In directory sc8-pr-cvs1:/tmp/cvs-serv10077/tests
Modified Files:
Makefile.am
Added Files:
test_rename.c
Log Message:
Crafted new test for rename call. Fixed a few bugs in rename:
Path node parent at root is NULL, not a cycle.
Check for cross device renames, not simple cross mount.
Check to make sure that that the source is not covered and that neither
the source nor the destination is a mountpoint.
--- NEW FILE ---
/*
* This Cplant(TM) source code is the property of Sandia National
* Laboratories.
*
* This Cplant(TM) source code is copyrighted by Sandia National
* Laboratories.
*
* The redistribution of this Cplant(TM) source code is subject to the
* terms of the GNU Lesser General Public License
* (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html)
*
* Cplant(TM) Copyright 1998-2003 Sandia Corporation.
* Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
* license for use of this work by or on behalf of the US Government.
* Export of this program may require a license from the United States
* Government.
*/
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Questions or comments about this library should be sent to:
*
* Lee Ward
* Sandia National Laboratories, New Mexico
* P.O. Box 5800
* Albuquerque, NM 87185-1110
*
* le...@sa...
*/
#define _BSD_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#ifndef REDSTORM
#include <getopt.h>
#endif
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/queue.h>
#include "sysio.h"
#include "mount.h"
#include "fs_native.h"
#include "test.h"
/*
* Rename a file system object.
*
* Usage: test_rename [-a] [-r <source>] [-m <root-driver>] <src> <dest>
*/
char *root_driver = DEFAULT_DRIVER;
char *mntpath = "/";
unsigned mntflgs = 0;
void usage(void);
int rename_file(const char *spath, const char *dpath);
int
main(int argc, char * const argv[])
{
int i;
int err;
const char *spath, *dpath;
/*
* Parse command-line args.
*/
while ((i = getopt(argc,
argv,
#ifdef AUTOMOUNT_FILE_NAME
"a"
#endif
"r:m:")) != -1)
switch (i) {
#ifdef AUTOMOUNT_FILE_NAME
case 'a':
mntflgs |= MOUNT_F_AUTO;
break;
#endif
case 'r': /* set working dir */
mntpath = optarg;
break;
case 'm':
root_driver = optarg;
break;
default:
usage();
}
if (!(argc - optind))
usage();
#ifndef CPLANT_YOD
if (_sysio_init() != 0) {
perror("init sysio");
exit(1);
}
err = drv_init_all();
if (err) {
perror("init drivers");
exit(1);
}
err = _sysio_mount_root(mntpath, root_driver, mntflgs, NULL);
if (err) {
errno = -err;
perror(root_driver);
exit(1);
}
#endif
(void )umask(022);
/*
* Source
*/
spath = argv[optind++];
if (!(argc - optind))
usage();
/*
* Destination
*/
dpath = argv[optind++];
if (argc - optind)
usage();
if (rename(spath, dpath) != 0)
perror("rename");
#ifndef CPLANT_YOD
_sysio_shutdown();
#endif
return err;
}
void
usage()
{
(void )fprintf(stderr,
"Usage: test_rename "
#ifdef AUTOMOUNT_FILE_NAME
"[-a] "
#endif
"[-r <source>] [-m <fsname>]"
" source destination\n");
exit(1);
}
Index: Makefile.am
===================================================================
RCS file: /cvsroot/libsysio/libsysio/tests/Makefile.am,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -w -b -B -p -r1.13 -r1.14
--- Makefile.am 10 Oct 2003 18:50:31 -0000 1.13
+++ Makefile.am 13 Oct 2003 21:23:44 -0000 1.14
@@ -1,5 +1,5 @@
noinst_PROGRAMS = test_copy test_stats test_path test_mounts test_list \
- test_getcwd test_stdfd test_unlink test_driver
+ test_getcwd test_stdfd test_unlink test_rename test_driver
CLEANFILES=drv_data.c
@@ -101,6 +101,11 @@ test_unlink_SOURCES=test_unlink.c $(CMNS
test_unlink_CFLAGS=$(CFL)
test_unlink_LDADD=$(LIBS)
test_unlink_DEPENDENCIES=$(LIBS)
+
+test_rename_SOURCES=test_rename.c $(CMNSRC)
+test_rename_CFLAGS=$(CFL)
+test_rename_LDADD=$(LIBS)
+test_rename_DEPENDENCIES=$(LIBS)
test_driver_SOURCES=test_driver.c sysio_tests.c sysio_stubs.c help.c $(CMNSRC)
test_driver_CFLAGS=$(CFL)
|