From 8cda0a538b60604b0befc109d8aebf9cd179e2c8 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Wed, 4 Oct 2000 17:39:54 +0000 Subject: Major facelift on the test area -- the beginnings of some real testing stuff so we can get this library into shape. -Erik --- test/stdlib/.cvsignore | 8 ++++ test/stdlib/Makefile | 104 ++++++++++++++++++++++++++++++++++++++++++++ test/stdlib/testmalloc.c | 98 ++++++++++++++++++++++++++++++++++++++++++ test/stdlib/teststrtol.c | 109 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 319 insertions(+) create mode 100644 test/stdlib/.cvsignore create mode 100644 test/stdlib/Makefile create mode 100644 test/stdlib/testmalloc.c create mode 100644 test/stdlib/teststrtol.c (limited to 'test/stdlib') diff --git a/test/stdlib/.cvsignore b/test/stdlib/.cvsignore new file mode 100644 index 000000000..4d8c58076 --- /dev/null +++ b/test/stdlib/.cvsignore @@ -0,0 +1,8 @@ +testmalloc +testmalloc.o +testmalloc_glibc +testmalloc_glibc.o +teststrtol +teststrtol.o +teststrtol.out +teststrtol_glibc.out diff --git a/test/stdlib/Makefile b/test/stdlib/Makefile new file mode 100644 index 000000000..e882d8f85 --- /dev/null +++ b/test/stdlib/Makefile @@ -0,0 +1,104 @@ +TOPDIR=../../ +include $(TOPDIR)Rules.make + +# Check if 'ls -sh' works or not +LSFLAGS = $(shell if ls -sh >/dev/null 2>&1; \ + then echo "-sh"; else echo "-s" ; fi) + +XCFLAGS = -Wall -Os -fomit-frame-pointer -fno-builtin -nostdinc \ + -I$(TOPDIR)include -I/usr/include/linux +XLDFLAGS = -nostdlib -s -gc-sections +EXTRA_LIBS=$(TOPDIR)libc.a + +YCFLAGS = -Wall -Os -fomit-frame-pointer +YLDFLAGS = -s --static + +# Allow alternative stripping tools to be used... +ifndef $(STRIPTOOL) + STRIPTOOL = strip +endif +STRIP = $(STRIPTOOL) --remove-section=.note --remove-section=.comment $@ + +TARGETS=testmalloc_source testmalloc testmalloc_glibc +TARGETS+=teststrtol_source teststrtol teststrtol_glibc teststrtol_diff + +all: $(TARGETS) + +testmalloc_source: + -@ echo "-------" + -@ echo "testmalloc.c source: " + -@ echo " " + -@ cat testmalloc.c + -@ echo " " + +testmalloc: testmalloc.c Makefile $(TOPDIR)libc.a + -@ echo "-------" + -@ echo " " + -@ echo "Compiling vs uC-Libc: " + -@ echo " " + $(CC) $(XCFLAGS) -c $< -o $@.o + $(CC) $(XLDFLAGS) $@.o -o $@ $(EXTRA_LIBS) + $(STRIP) + -ldd $@ + ls $(LSFLAGS) $@ + -./$@ + -@ echo " " + +testmalloc_glibc: testmalloc.c Makefile $(TOPDIR)libc.a + -@ echo "-------" + -@ echo " " + -@ echo "Compiling vs GNU libc: " + -@ echo " " + $(CC) $(YCFLAGS) -c $< -o $@.o + $(CC) $(YLDFLAGS) --static $@.o -o $@ + $(STRIP) + -ldd $@ + ls $(LSFLAGS) $@ + -./$@ + -@ echo " " + +teststrtol_source: + -@ echo "-------" + -@ echo "teststrtol.c source: " + -@ echo " " + -@ cat teststrtol.c + -@ echo " " + +teststrtol: teststrtol.c Makefile $(TOPDIR)libc.a + -@ echo "-------" + -@ echo " " + -@ echo "Compiling vs uC-Libc: " + -@ echo " " + $(CC) $(XCFLAGS) -c $< -o $@.o + $(CC) $(XLDFLAGS) $@.o -o $@ $(EXTRA_LIBS) + $(STRIP) + ldd $@ + ls -sh $@ + -./$@ | tee $@.out + -@ echo " " + +teststrtol_glibc: teststrtol.c Makefile $(TOPDIR)libc.a + -@ echo "-------" + -@ echo " " + -@ echo "Compiling vs GNU libc: " + -@ echo " " + $(CC) $(YCFLAGS) -c $< -o $@.o + $(CC) $(YLDFLAGS) --static $@.o -o $@ + $(STRIP) + ldd $@ + ls -sh $@ + -./$@ | tee $@.out + -@ echo " " + +teststrtol_diff: teststrtol_glibc teststrtol + -@ echo "-------" + -@ echo " " + -@ echo "Diffing output: " + -@ echo " " + -diff -u teststrtol_glibc.out teststrtol.out + -@ echo " " + +clean: + rm -f *.[oa] *~ core $(TARGETS) + + diff --git a/test/stdlib/testmalloc.c b/test/stdlib/testmalloc.c new file mode 100644 index 000000000..158bf4236 --- /dev/null +++ b/test/stdlib/testmalloc.c @@ -0,0 +1,98 @@ +#include +#include +#include + + +struct list { + struct list *next; +}; + +int main(void) +{ + int z=999; + int *y=&z; + int *x=NULL; + struct list *save; + struct list *lp; + int i; + + + printf("pointer to x is %p\n", x); + printf("pointer to y is %p\n", y); + x=malloc(sizeof(int)*2000); + printf("pointer to x is %p\n", x); + y=malloc(sizeof(int)*100); + printf("pointer to y is %p\n", y); + free(x); + free(y); + printf("about to free(0)\n"); + free(0); + + x=malloc(13); + printf("x = %p\n", x); + memcpy(x, "Small string", 13); + printf("0x%p test string1: %s\n", x, (char *)x); + y = realloc(x, 36); + printf("0x%p test string1: %s\n", y, (char *)y); + memcpy(y, "********** Larger string **********", 36); + printf("0x%p test string2: %s\n", y, (char *)y); + free(y); + + + printf("Allocate 100 nodes 500 bytes each\n"); + save = 0; + for (i=0; i<100; i++) { + lp = malloc(500); + if (lp == 0) { + printf("loop 1: malloc returned 0\n"); + goto Failed; + } + lp->next = save; + save = lp; + } + + printf("freeing 100 nodes\n"); + while (save) { + lp = save; + save = save->next; + free(lp); + } + + printf("try realloc 100 times \n"); + lp = 0; + for (i=1; i<=100; i++) { + lp = realloc(lp, i*200); + if (lp == 0) { + printf("loop 3: realloc returned 0\n"); + goto Failed; + } + } + realloc(lp, 0); + + printf("Allocate another 100 nodes 600 bytes each\n"); + save = 0; + for (i=0; i<100; i++) { + lp = malloc(600); + if (lp == 0) { + printf("loop 2: malloc returned 0\n"); + goto Failed; + } + lp->next = save; + save = lp; + } + + printf("freeing 100 nodes\n"); + while (save) { + lp = save; + save = save->next; + free(lp); + } + + + printf("alloc test PASSED\n"); + exit(0); + +Failed: + printf("!!!!!!!!!!!! alloc test FAILED. !!!!!!!!!!!!!!!\n"); + exit(1); +} diff --git a/test/stdlib/teststrtol.c b/test/stdlib/teststrtol.c new file mode 100644 index 000000000..d015b81b2 --- /dev/null +++ b/test/stdlib/teststrtol.c @@ -0,0 +1,109 @@ + +#include +#include + + +const char *strings[]={ + /* some simple stuff */ + "0", "1", "10", + "100", "1000", "10000", "100000", "1000000", + "10000000", "100000000", "1000000000", + + /* negative */ + "-0", "-1", "-10", + "-100", "-1000", "-10000", "-100000", "-1000000", + "-10000000", "-100000000", "-1000000000", + + /* test base>10 */ + "a", "b", "f", "g", "z", + + /* test hex */ + "0x0", "0x1", "0xa", "0xf", "0x10", + + /* test octal */ + "00", "01", "07", "08", "0a", "010", + + /* other */ + "0x8000000", + + /* check overflow cases: (for 32 bit) */ + "2147483645", + "2147483646", + "2147483647", + "2147483648", + "2147483649", + "-2147483645", + "-2147483646", + "-2147483647", + "-2147483648", + "-2147483649", + "4294967293", + "4294967294", + "4294967295", + "4294967296", + "4294967297", + "-4294967293", + "-4294967294", + "-4294967295", + "-4294967296", + "-4294967297", + + /* bad input tests */ + "", + "00", + "0x", + "0x0", + "-", + "+", + " ", + " -", + " - 0", +}; +int n_tests=sizeof(strings)/sizeof(strings[0]); + +void do_test(int base); +void do_utest(int base); + +int main(int argc,char *argv[]) +{ + do_test(0); + do_test(8); + do_test(10); + do_test(16); + do_test(36); + + do_utest(0); + do_utest(8); + do_utest(10); + do_utest(16); + do_utest(36); + + return 0; +} + +void do_test(int base) +{ + int i; + long n; + char *endptr; + + for(i=0;i