Added regress testing of libposix rename features, as per PR 5858

by Arne H. Juul <arnej@math.ntnu.no>, using the patch provided.
This commit is contained in:
mjl 1999-02-21 00:20:10 +00:00
parent 37a9e5bb67
commit cec782b5c0
7 changed files with 128 additions and 2 deletions

View File

@ -1,5 +1,5 @@
# $NetBSD: Makefile,v 1.4 1997/10/11 22:57:55 mycroft Exp $
# $NetBSD: Makefile,v 1.5 1999/02/21 00:20:10 mjl Exp $
SUBDIR+= libc
SUBDIR+= libc libposix
.include <bsd.subdir.mk>

View File

@ -0,0 +1,5 @@
# $NetBSD: Makefile,v 1.1 1999/02/21 00:20:11 mjl Exp $
SUBDIR= prn1 prn2 nrn
.include <bsd.subdir.mk>

View File

@ -0,0 +1,4 @@
# $NetBSD: Makefile.inc,v 1.1 1999/02/21 00:20:11 mjl Exp $
#
# do not install regression test programs
proginstall::

View File

@ -0,0 +1,15 @@
# $NetBSD: Makefile,v 1.1 1999/02/21 00:20:11 mjl Exp $
PROG= prn
NOMAN= t
CLEANFILES+= t1 t2
.PATH: ${.CURDIR}/..
CPPFLAGS+= -DBSD_RENAME
regress:
@echo Testing BSD rename
./prn
.include <bsd.prog.mk>

View File

@ -0,0 +1,71 @@
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
int main(void)
{
int errors = 0;
struct stat sb;
(void)unlink("t1");
(void)unlink("t2");
if (creat("t1", 0600) < 0) {
perror("create t1");
exit(1);
}
if (link("t1", "t2")) {
perror("link t1 t2");
exit(1);
}
/* Check if rename to same name works as expected */
if (rename("t1", "t1")) {
perror("rename t1 t1");
errors++;
}
if (stat("t1", &sb)) {
perror("rename removed file? stat t1");
exit(1);
}
if (rename("t1", "t2")) {
perror("rename t1 t2");
errors++;
}
#if BSD_RENAME
/* check if rename of hardlinked file works the BSD way */
if (stat("t1", &sb)) {
if (errno != ENOENT) {
perror("BSD rename should remove file! stat t1");
errors++;
}
} else {
fprintf(stderr, "BSD rename should remove file!");
errors++;
}
#else
/* check if rename of hardlinked file works as the standard says */
if (stat("t1", &sb)) {
perror("Posix rename should not remove file! stat t1");
errors++;
}
#endif
/* check if we get the expected error */
/* this also exercises icky shared libraries goo */
if (rename("no/such/file/or/dir", "no/such/file/or/dir")) {
if (errno != ENOENT) {
perror("rename no/such/file/or/dir");
errors++;
}
} else {
fprintf(stderr, "No error renaming no/such/file/or/dir\n");
errors++;
}
exit(errors ? 1 : 0);
}

View File

@ -0,0 +1,16 @@
# $NetBSD: Makefile,v 1.1 1999/02/21 00:20:11 mjl Exp $
PROG= prn
NOMAN= t
CLEANFILES+= t1 t2
.PATH: ${.CURDIR}/..
DPADD+= ${LIBPOSIX}
LDADD+= -lposix
regress:
@echo Testing posix rename with -lposix
./prn
.include <bsd.prog.mk>

View File

@ -0,0 +1,15 @@
# $NetBSD: Makefile,v 1.1 1999/02/21 00:20:11 mjl Exp $
PROG= prn
NOMAN= t
CLEANFILES+= t1 t2
.PATH: ${.CURDIR}/..
CPPFLAGS+= -D_POSIX_SOURCE
regress:
@echo Testing posix rename with -D_POSIX_SOURCE
./prn
.include <bsd.prog.mk>