diff options
author | Eric Andersen <andersen@codepoet.org> | 2000-10-04 17:39:54 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2000-10-04 17:39:54 +0000 |
commit | 8cda0a538b60604b0befc109d8aebf9cd179e2c8 (patch) | |
tree | 2e7adb36d681309a2f28e76b6e68a89eefedc561 /test | |
parent | 3259c862c11bfc2260cfbe86d823a3aea68b4e2d (diff) |
Major facelift on the test area -- the beginnings of some real testing
stuff so we can get this library into shape.
-Erik
Diffstat (limited to 'test')
-rw-r--r-- | test/Makefile | 194 | ||||
-rw-r--r-- | test/assert/.cvsignore | 2 | ||||
-rw-r--r-- | test/assert/Makefile | 50 | ||||
-rw-r--r-- | test/assert/assert.c | 49 | ||||
-rw-r--r-- | test/ctype/.cvsignore | 4 | ||||
-rw-r--r-- | test/ctype/Makefile | 50 | ||||
-rw-r--r-- | test/ctype/ctype.c | 292 | ||||
-rw-r--r-- | test/silly/.cvsignore | 4 | ||||
-rw-r--r-- | test/silly/Makefile | 63 | ||||
-rw-r--r-- | test/silly/hello.c | 8 | ||||
-rw-r--r-- | test/stdlib/.cvsignore | 8 | ||||
-rw-r--r-- | test/stdlib/Makefile | 104 | ||||
-rw-r--r-- | test/stdlib/testmalloc.c | 98 | ||||
-rw-r--r-- | test/stdlib/teststrtol.c | 109 | ||||
-rw-r--r-- | test/string/.cvsignore | 4 | ||||
-rw-r--r-- | test/string/Makefile | 50 | ||||
-rw-r--r-- | test/string/string.c | 993 | ||||
-rw-r--r-- | test/testsuite.h | 91 |
18 files changed, 2000 insertions, 173 deletions
diff --git a/test/Makefile b/test/Makefile index ddc53a5e9..e430cf8b4 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,183 +1,31 @@ -TOPDIR=../ -include $(TOPDIR)Rules.make +DIRS = assert ctype silly stdlib string -# Check if 'ls -sh' works or not -LSFLAGS = $(shell if ls -sh >/dev/null 2>&1; \ - then echo "-sh"; else echo "-s" ; fi) +all: $(DIRS) -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 +assert: dummy + make -C assert -YCFLAGS = -Wall -Os -fomit-frame-pointer -YLDFLAGS = -s --static +ctype: dummy + make -C ctype -# Allow alternative stripping tools to be used... -ifndef $(STRIPTOOL) - STRIPTOOL = strip -endif -STRIP = $(STRIPTOOL) --remove-section=.note --remove-section=.comment $@ +silly: dummy + make -C silly -TARGETS=string string_glibc -TARGETS+=ctype ctype_glibc -#TARGETS+=hello_source hello hello_glibc -#TARGETS+=testmalloc_source testmalloc testmalloc_glibc -#TARGETS+=teststrtol_source teststrtol teststrtol_glibc teststrtol_diff +stdlib: dummy + make -C stdlib -all: $(TARGETS) +string: dummy + make -C string -string: string.c Makefile $(TOPDIR)libc.a - -@ echo "-------" - -@ echo " " - -@ echo "Testing ctype functions: " - -@ echo " " - $(CC) $(XCFLAGS) -c $< -o $@.o - $(CC) $(XLDFLAGS) $@.o -o $@ $(EXTRA_LIBS) - -./$@ - -@ echo " " - -string_glibc: string.c testsuite.h Makefile $(TOPDIR)libc.a - -@ echo "-------" - -@ echo " " - -@ echo "Testing string functions: " - -@ echo " " - $(CC) $(YCFLAGS) -c $< -o $@.o - $(CC) $(YLDFLAGS) --static $@.o -o $@ - -./$@ - -./$@ - -@ echo " " - -ctype: ctype.c testsuite.h Makefile $(TOPDIR)libc.a - -@ echo "-------" - -@ echo " " - -@ echo "Testing ctype functions: " - -@ echo " " - $(CC) $(XCFLAGS) -c $< -o $@.o - $(CC) $(XLDFLAGS) $@.o -o $@ $(EXTRA_LIBS) - -./$@ - -@ echo " " - -ctype_glibc: ctype.c testsuite.h Makefile $(TOPDIR)libc.a - -@ echo "-------" - -@ echo " " - -@ echo "Testing ctype functions: " - -@ echo " " - $(CC) $(YCFLAGS) -c $< -o $@.o - $(CC) $(YLDFLAGS) --static $@.o -o $@ - -./$@ - -./$@ - -@ echo " " - -hello_source: - -@ rm -f $(TARGETS) - -@ echo "-------" - -@ echo "hello.c source: " - -@ echo " " - -@ cat hello.c - -@ echo " " - -hello: hello.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 " " - -hello_glibc: hello.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 " " - -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 " " +tags: + ctags -R + +dummy: clean: - rm -f *.[oa] *~ core $(TARGETS) - + make -C assert clean + make -C ctype clean + make -C silly clean + make -C stdlib clean + make -C string clean diff --git a/test/assert/.cvsignore b/test/assert/.cvsignore new file mode 100644 index 000000000..2dde1df2a --- /dev/null +++ b/test/assert/.cvsignore @@ -0,0 +1,2 @@ +assert +assert.o diff --git a/test/assert/Makefile b/test/assert/Makefile new file mode 100644 index 000000000..8fb90bd1c --- /dev/null +++ b/test/assert/Makefile @@ -0,0 +1,50 @@ +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=assert assert_glibc + +all: $(TARGETS) + +assert: assert.c Makefile $(TOPDIR)libc.a + -@ echo "-------" + -@ echo " " + -@ echo "Testing ctype functions: " + -@ echo " " + $(CC) $(XCFLAGS) -c $< -o $@.o + $(CC) $(XLDFLAGS) $@.o -o $@ $(EXTRA_LIBS) + -./$@ + -@ echo " " + +assert_glibc: assert.c Makefile $(TOPDIR)libc.a + -@ echo "-------" + -@ echo " " + -@ echo "Testing assert functions: " + -@ echo " " + $(CC) $(YCFLAGS) -c $< -o $@.o + $(CC) $(YLDFLAGS) --static $@.o -o $@ + -./$@ + -./$@ + -@ echo " " + +clean: + rm -f *.[oa] *~ core $(TARGETS) + + diff --git a/test/assert/assert.c b/test/assert/assert.c new file mode 100644 index 000000000..6ab4cac3e --- /dev/null +++ b/test/assert/assert.c @@ -0,0 +1,49 @@ +/* vi: set sw=4 ts=4: */ +/* + * Test application for functions defined in ctype.h + * + * Copyright (C) 2000 by Lineo, inc. + * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include <stdio.h> +#include <stdlib.h> +#include <assert.h> + + +int main( int argc, char **argv) +{ + + printf( "Testing functions defined in assert.h\n"); + + printf( "Testing \"assert(0==0)\"\n"); + assert(0==0); + + printf( "Testing \"assert(0==1)\" with NDEBUG disabled\n"); +#undef NDEBUG + assert(0==1); + +#define NDEBUG + printf( "Testing \"assert(0==1)\" with NDEBUG enabled\n"); +#undef NDEBUG + assert(0==1); + + printf( "Finished testing assert.h\n"); + + exit(0); +} diff --git a/test/ctype/.cvsignore b/test/ctype/.cvsignore new file mode 100644 index 000000000..8043b8e11 --- /dev/null +++ b/test/ctype/.cvsignore @@ -0,0 +1,4 @@ +ctype +ctype.o +ctype_glibc +ctype_glibc.o diff --git a/test/ctype/Makefile b/test/ctype/Makefile new file mode 100644 index 000000000..90594d863 --- /dev/null +++ b/test/ctype/Makefile @@ -0,0 +1,50 @@ +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=ctype ctype_glibc + +all: $(TARGETS) + +ctype: ctype.c ../testsuite.h Makefile $(TOPDIR)libc.a + -@ echo "-------" + -@ echo " " + -@ echo "Testing ctype functions: " + -@ echo " " + $(CC) $(XCFLAGS) -c $< -o $@.o + $(CC) $(XLDFLAGS) $@.o -o $@ $(EXTRA_LIBS) + -./$@ + -@ echo " " + +ctype_glibc: ctype.c ../testsuite.h Makefile $(TOPDIR)libc.a + -@ echo "-------" + -@ echo " " + -@ echo "Testing ctype functions: " + -@ echo " " + $(CC) $(YCFLAGS) -c $< -o $@.o + $(CC) $(YLDFLAGS) --static $@.o -o $@ + -./$@ + -./$@ + -@ echo " " + +clean: + rm -f *.[oa] *~ core $(TARGETS) + + diff --git a/test/ctype/ctype.c b/test/ctype/ctype.c new file mode 100644 index 000000000..7be8c0a79 --- /dev/null +++ b/test/ctype/ctype.c @@ -0,0 +1,292 @@ +/* vi: set sw=4 ts=4: */ +/* + * Test application for functions defined in ctype.h + * + * Copyright (C) 2000 by Lineo, inc. + * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include <stdio.h> +#include <stdlib.h> +#include <stdarg.h> +#include <ctype.h> +#include "../testsuite.h" + +#define TRUE 0 + +int main( int argc, char **argv) +{ + int i, c; + + + printf( "Testing functions defined in ctype.h\n"); + + + /* isalnum() */ + { + int buffer[]={ '1', '4', 'a', 'z', 'A', 'Z', '5', -1}; + for(i=0; buffer[i]!=-1; i++) { + c = buffer[i]; + TEST_SUCCESS( isalnum(c)==TRUE, + "isalnum(%c)", c); + } + } + { + int buffer[]={ 2, 128, 254, '\n', -1}; + for(i=0; buffer[i]!=-1; i++) { + c = buffer[i]; + TEST_SUCCESS( isalnum(c)!=TRUE, + "!isalnum(%d)", c); + } + } + + + + /* isalpha() */ + { + int buffer[]={ 'a', 'z', 'A', 'Z', -1}; + for(i=0; buffer[i]!=-1; i++) { + c = buffer[i]; + TEST_SUCCESS( isalpha(c)==TRUE, + "isalpha(%c)", c); + } + } + { + int buffer[]={ 2, 63, 128, 254, '\n', -1}; + for(i=0; buffer[i]!=-1; i++) { + c = buffer[i]; + TEST_SUCCESS( isalpha(c)!=TRUE, + "!isalpha(%d)", c); + } + } + + + + /* isascii() */ + { + int buffer[]={ 'a', 'z', 'A', 'Z', '\n', -1}; + for(i=0; buffer[i]!=-1; i++) { + c = buffer[i]; + TEST_SUCCESS( isascii(c)==TRUE, + "isascii(%d)", c); + } + } + { + int buffer[]={ 128, 254, -1}; + for(i=0; buffer[i]!=-1; i++) { + c = buffer[i]; + TEST_SUCCESS( isascii(c)!=TRUE, + "!isascii(%d)", c); + } + } + + + /* iscntrl() */ + { + int buffer[]={ 0x7F, 6, '\t', '\n', 0x7F, -1}; + for(i=0; buffer[i]!=-1; i++) { + c = buffer[i]; + TEST_SUCCESS( iscntrl(c)==TRUE, + "iscntrl(%d)", c); + } + } + { + int buffer[]={ 63, 128, 254, -1}; + for(i=0; buffer[i]!=-1; i++) { + c = buffer[i]; + TEST_SUCCESS( iscntrl(c)!=TRUE, + "!iscntrl(%d)", c); + } + } + + + /* isdigit() */ + { + int buffer[]={ '1', '5', '7', '9', -1}; + for(i=0; buffer[i]!=-1; i++) { + c = buffer[i]; + TEST_SUCCESS( isdigit(c)==TRUE, + "isdigit(%c)", c); + } + } + { + int buffer[]={ 2, 'a', 'z', 'A', 'Z', 63, 128, 254, '\n', -1}; + for(i=0; buffer[i]!=-1; i++) { + c = buffer[i]; + TEST_SUCCESS( isdigit(c)!=TRUE, + "!isdigit(%d)", c); + } + } + + + + /* isgraph() */ + { + int buffer[]={ ')', '~', '9', -1}; + for(i=0; buffer[i]!=-1; i++) { + c = buffer[i]; + TEST_SUCCESS( isgraph(c)==TRUE, + "isgraph(%d)", c); + } + } + { + int buffer[]={ 9, ' ', '\t', '\n', 200, 0x7F, -1}; + for(i=0; buffer[i]!=-1; i++) { + c = buffer[i]; + TEST_SUCCESS( isgraph(c)!=TRUE, + "!isgraph(%d)", c); + } + } + + + /* islower() */ + { + int buffer[]={ 'a', 'g', 'z', -1}; + for(i=0; buffer[i]!=-1; i++) { + c = buffer[i]; + TEST_SUCCESS( islower(c)==TRUE, + "islower(%c)", c); + } + } + { + int buffer[]={ 9, 'A', 'Z', 128, 254, ' ', '\t', '\n', 0x7F, -1}; + for(i=0; buffer[i]!=-1; i++) { + c = buffer[i]; + TEST_SUCCESS( islower(c)!=TRUE, + "!islower(%d)", c); + } + } + + + /* isprint() */ + { + int buffer[]={ ' ', ')', '~', '9', -1}; + for(i=0; buffer[i]!=-1; i++) { + c = buffer[i]; + TEST_SUCCESS( isprint(c)==TRUE, + "isprint(%c)", c); + } + } + { + int buffer[]={ '\b', '\t', '\n', 9, 128, 254, 200, 0x7F, -1}; + for(i=0; buffer[i]!=-1; i++) { + c = buffer[i]; + TEST_SUCCESS( isprint(c)!=TRUE, + "!isprint(%d)", c); + } + } + + + /* ispunct() */ + { + int buffer[]={ '.', '#', '@', ';', -1}; + for(i=0; buffer[i]!=-1; i++) { + c = buffer[i]; + TEST_SUCCESS( ispunct(c)==TRUE, + "ispunct(%c)", c); + } + } + { + int buffer[]={ 2, 'a', 'Z', '1', 128, 254, '\n', -1}; + for(i=0; buffer[i]!=-1; i++) { + c = buffer[i]; + TEST_SUCCESS( ispunct(c)!=TRUE, + "!ispunct(%d)", c); + } + } + + + /* isspace() */ + { + int buffer[]={ ' ', '\t', '\r', '\v', '\n', -1}; + for(i=0; buffer[i]!=-1; i++) { + c = buffer[i]; + TEST_SUCCESS( isspace(c)==TRUE, + "isspace(%d)", c); + } + } + { + int buffer[]={ 2, 'a', 'Z', '1', 128, 254, -1}; + for(i=0; buffer[i]!=-1; i++) { + c = buffer[i]; + TEST_SUCCESS( isspace(c)!=TRUE, + "!isspace(%d)", c); + } + } + + + /* isupper() */ + { + int buffer[]={ 'A', 'G', 'Z', -1}; + for(i=0; buffer[i]!=-1; i++) { + c = buffer[i]; + TEST_SUCCESS( isupper(c)==TRUE, + "isupper(%c)", c); + } + } + { + int buffer[]={ 2, 'a', 'z', '1', 128, 254, -1}; + for(i=0; buffer[i]!=-1; i++) { + c = buffer[i]; + TEST_SUCCESS( isupper(c)!=TRUE, + "!isupper(%d)", c); + } + } + + + + /* isxdigit() */ + { + int buffer[]={ 'f', 'A', '1', '8', -1}; + for(i=0; buffer[i]!=-1; i++) { + c = buffer[i]; + TEST_SUCCESS( isxdigit(c)==TRUE, + "isxdigit(%c)", c); + } + } + { + int buffer[]={ 2, 'g', 'G', 'x', '\n', -1}; + for(i=0; buffer[i]!=-1; i++) { + c = buffer[i]; + TEST_SUCCESS( isxdigit(c)!=TRUE, + "!isxdigit(%d)", c); + } + } + + + /* tolower() */ + c='A'; + TEST_NUMERIC_OUTPUT( tolower(c), 'a', "tolower(%c)=%c", c, tolower(c)); + c='a'; + TEST_NUMERIC_OUTPUT( tolower(c), 'a', "tolower(%c)=%c", c, tolower(c)); + c='#'; + TEST_NUMERIC_OUTPUT( tolower(c), c, "tolower(%c)=%c", c, tolower(c)); + + /* toupper() */ + c='a'; + TEST_NUMERIC_OUTPUT( toupper(c), 'A', "toupper(%c)=%c", c, toupper(c)); + c='A'; + TEST_NUMERIC_OUTPUT( toupper(c), 'A', "toupper(%c)=%c", c, toupper(c)); + c='#'; + TEST_NUMERIC_OUTPUT( toupper(c), c, "toupper(%c)=%c", c, toupper(c)); + + + printf( "Finished testing ctype.h\n"); + + stop_testing(); +} diff --git a/test/silly/.cvsignore b/test/silly/.cvsignore new file mode 100644 index 000000000..c6e0c6f72 --- /dev/null +++ b/test/silly/.cvsignore @@ -0,0 +1,4 @@ +hello +hello.o +hello_glibc +hello_glibc.o diff --git a/test/silly/Makefile b/test/silly/Makefile new file mode 100644 index 000000000..94f745d4d --- /dev/null +++ b/test/silly/Makefile @@ -0,0 +1,63 @@ +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=hello_source hello hello_glibc + +all: $(TARGETS) + +hello_source: + -@ rm -f $(TARGETS) + -@ echo "-------" + -@ echo "hello.c source: " + -@ echo " " + -@ cat hello.c + -@ echo " " + +hello: hello.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 " " + +hello_glibc: hello.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 " " + +clean: + rm -f *.[oa] *~ core $(TARGETS) + + diff --git a/test/silly/hello.c b/test/silly/hello.c new file mode 100644 index 000000000..4aba926e6 --- /dev/null +++ b/test/silly/hello.c @@ -0,0 +1,8 @@ +#include<stdio.h> +#include <stdlib.h> + +int main(void) +{ + printf("hello world\n"); + exit(42); +} 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 <stdio.h> +#include <stdlib.h> +#include <string.h> + + +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 <stdlib.h> +#include <stdio.h> + + +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<n_tests;i++){ + n=strtol(strings[i],&endptr,base); + printf("strtol(\"%s\",%d) len=%d res=%ld\n", + strings[i],base,endptr-strings[i],n); + } +} + +void do_utest(int base) +{ + int i; + unsigned long n; + char *endptr; + + for(i=0;i<n_tests;i++){ + n=strtoul(strings[i],&endptr,base); + printf("strtoul(\"%s\",%d) len=%d res=%lu\n", + strings[i],base,endptr-strings[i],n); + } +} + diff --git a/test/string/.cvsignore b/test/string/.cvsignore new file mode 100644 index 000000000..3f73ed9a9 --- /dev/null +++ b/test/string/.cvsignore @@ -0,0 +1,4 @@ +string +string.o +string_glibc +string_glibc.o diff --git a/test/string/Makefile b/test/string/Makefile new file mode 100644 index 000000000..40e026775 --- /dev/null +++ b/test/string/Makefile @@ -0,0 +1,50 @@ +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 = |