From 46de710e624b2e578d9adf3bf44de5513867fba3 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Tue, 28 Jan 2003 10:59:43 +0000 Subject: Add a couple of tests --- test/misc/.cvsignore | 9 ++++++ test/misc/Makefile | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++-- test/misc/dirent.c | 25 +++++++++++++++ test/misc/fdopen.c | 46 +++++++++++++++++++++++++++ 4 files changed, 166 insertions(+), 2 deletions(-) create mode 100644 test/misc/dirent.c create mode 100644 test/misc/fdopen.c diff --git a/test/misc/.cvsignore b/test/misc/.cvsignore index e31051723..b57daa876 100644 --- a/test/misc/.cvsignore +++ b/test/misc/.cvsignore @@ -1,2 +1,11 @@ outb sem +fdopen +dirent +dirent.out +dirent_glibc +dirent_glibc.out +dirent64 +dirent64.out +dirent64_glibc +dirent64_glibc.out diff --git a/test/misc/Makefile b/test/misc/Makefile index ae49a865a..d94e48747 100644 --- a/test/misc/Makefile +++ b/test/misc/Makefile @@ -19,7 +19,9 @@ TESTDIR=../ include $(TESTDIR)/Rules.mak -TARGETS=sem outb +CFLAGS64=-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 + +TARGETS=sem fdopen dirent_diff dirent64_diff #outb all: $(TARGETS) outb: outb.c ../testsuite.h Makefile $(TESTDIR)/Config $(TESTDIR)/Rules.mak $(CC) @@ -44,7 +46,89 @@ sem: sem.c Makefile $(TESTDIR)/Config $(TESTDIR)/Rules.mak $(CC) -./$@ -@ echo " " +fdopen: fdopen.c Makefile $(TESTDIR)/Config $(TESTDIR)/Rules.mak $(CC) + -@ echo "-------" + -@ echo " " + -@ echo "Compiling vs uClibc: " + -@ echo " " + $(CC) $(CFLAGS) -c $< -o $@.o + $(CC) $(LDFLAGS) $@.o -o $@ $(EXTRA_LIBS) + $(STRIPTOOL) -x -R .note -R .comment $@ + -./$@ + -@ echo " " + +dirent_source: + -@ rm -f $(TARGETS) + -@ echo "-------" + -@ echo "dirent.c source: " + -@ echo " " + -@ cat dirent.c + -@ echo " " + +dirent: dirent.c Makefile $(TESTDIR)/Config $(TESTDIR)/Rules.mak $(CC) + -@ echo "-------" + -@ echo " " + -@ echo "Compiling vs uClibc: " + -@ echo " " + $(CC) $(CFLAGS) -c $< -o $@.o + $(CC) $(LDFLAGS) $@.o -o $@ $(EXTRA_LIBS) + $(STRIPTOOL) -x -R .note -R .comment $@ + -./$@ dirent.c > $@.out + -@ echo " " + +dirent_glibc: dirent.c Makefile + -@ echo "-------" + -@ echo " " + -@ echo "Compiling vs GNU libc: " + -@ echo " " + $(HOSTCC) $(GLIBC_CFLAGS) -c $< -o $@.o + $(HOSTCC) $(GLIBC_LDFLAGS) $@.o -o $@ + $(STRIPTOOL) -x -R .note -R .comment $@ + -./$@ dirent.c > $@.out + -@ echo " " + +dirent_diff: dirent dirent_glibc + -@ echo "-------" + -@ echo " " + -@ echo "Diffing dirent output: " + -@ echo " " + -diff -u dirent_glibc.out dirent.out + -@ echo " " + +dirent64: dirent.c Makefile $(TESTDIR)/Config $(TESTDIR)/Rules.mak $(CC) + -@ echo "-------" + -@ echo " " + -@ echo "Compiling vs uClibc: " + -@ echo " " + $(CC) $(CFLAGS) $(CFLAGS64) -c $< -o $@.o + $(CC) $(LDFLAGS) $@.o -o $@ $(EXTRA_LIBS) + $(STRIPTOOL) -x -R .note -R .comment $@ + -./$@ dirent.c > $@.out + -@ echo " " + +dirent64_glibc: dirent.c Makefile + -@ echo "-------" + -@ echo " " + -@ echo "Compiling vs GNU libc: " + -@ echo " " + $(HOSTCC) $(GLIBC_CFLAGS) $(CFLAGS64) -c $< -o $@.o + $(HOSTCC) $(GLIBC_LDFLAGS) $@.o -o $@ + $(STRIPTOOL) -x -R .note -R .comment $@ + -./$@ dirent.c > $@.out + -@ echo " " + +dirent64_diff: dirent64 dirent64_glibc + -@ echo "-------" + -@ echo " " + -@ echo "Diffing dirent64 output: " + -@ echo " " + -diff -u dirent64_glibc.out dirent64.out + -@ echo " " + clean: - rm -f *.[oa] *~ core $(TARGETS) + rm -f *.[oa] *~ core dirent dirent_glibc dirent_glibc.out dirent.out \ + dirent64 dirent64_glibc dirent64_glibc.out dirent64.out \ + outb sem fdopen + diff --git a/test/misc/dirent.c b/test/misc/dirent.c new file mode 100644 index 000000000..885990bf2 --- /dev/null +++ b/test/misc/dirent.c @@ -0,0 +1,25 @@ +#include +#include +#include +#include + +int main(int argc, char **argv) +{ + + DIR *dirh; + struct dirent *dirp; + static char mydir[20] = "/tmp"; + + if ((dirh = opendir(mydir)) == NULL) { + perror("opendir"); + return 1; + } + + for (dirp = readdir(dirh); dirp != NULL; dirp = readdir(dirh)) { + printf("Got dir entry: %s\n",dirp->d_name); + } + + closedir(dirh); + return 0; +} + diff --git a/test/misc/fdopen.c b/test/misc/fdopen.c new file mode 100644 index 000000000..598a85a05 --- /dev/null +++ b/test/misc/fdopen.c @@ -0,0 +1,46 @@ +/* Test for fdopen bugs. */ + +#include +#include +#include + +#define assert(x) \ + if (!(x)) \ + { \ + fputs ("test failed: " #x "\n", stderr); \ + retval = 1; \ + goto the_end; \ + } + +char buffer[256]; + +int +main (int argc, char *argv[]) +{ + char *name; + FILE *fp = NULL; + int retval = 0; + int fd; + + name = tmpnam (NULL); + fp = fopen (name, "w"); + assert (fp != NULL) + fputs ("foobar and baz", fp); + fclose (fp); + fp = NULL; + + fd = open (name, O_RDWR|O_CREAT); + assert (fd != -1); + assert (lseek (fd, 5, SEEK_SET) == 5); + + fp = fdopen (fd, "a"); + assert (fp != NULL); + assert (ftell (fp) == 14); + +the_end: + if (fp != NULL) + fclose (fp); + unlink (name); + + return retval; +} -- cgit v1.2.3