CVS commit: src/regress/lib/libc/string

2010-12-25 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Sat Dec 25 21:13:40 UTC 2010

Modified Files:
src/regress/lib/libc/string: Makefile
Removed Files:
src/regress/lib/libc/string/memchr: Makefile memchr_test.c
src/regress/lib/libc/string/strcat: Makefile strcat_test.c
src/regress/lib/libc/string/strchr: Makefile strchr_test.c
src/regress/lib/libc/string/strcmp: Makefile strcmp_test.c
src/regress/lib/libc/string/strcpy: Makefile strcpy_test.c
src/regress/lib/libc/string/strlen: Makefile strlen_test.c
src/regress/lib/libc/string/strrchr: Makefile strrchr_test.c

Log Message:
Remove regress versions of str* tests - they have been atf-ified


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/regress/lib/libc/string/Makefile
cvs rdiff -u -r1.1 -r0 src/regress/lib/libc/string/memchr/Makefile
cvs rdiff -u -r1.2 -r0 src/regress/lib/libc/string/memchr/memchr_test.c
cvs rdiff -u -r1.1 -r0 src/regress/lib/libc/string/strcat/Makefile \
src/regress/lib/libc/string/strcat/strcat_test.c
cvs rdiff -u -r1.1 -r0 src/regress/lib/libc/string/strchr/Makefile
cvs rdiff -u -r1.4 -r0 src/regress/lib/libc/string/strchr/strchr_test.c
cvs rdiff -u -r1.1 -r0 src/regress/lib/libc/string/strcmp/Makefile \
src/regress/lib/libc/string/strcmp/strcmp_test.c
cvs rdiff -u -r1.1 -r0 src/regress/lib/libc/string/strcpy/Makefile \
src/regress/lib/libc/string/strcpy/strcpy_test.c
cvs rdiff -u -r1.1 -r0 src/regress/lib/libc/string/strlen/Makefile
cvs rdiff -u -r1.2 -r0 src/regress/lib/libc/string/strlen/strlen_test.c
cvs rdiff -u -r1.1 -r0 src/regress/lib/libc/string/strrchr/Makefile \
src/regress/lib/libc/string/strrchr/strrchr_test.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/regress/lib/libc/string/Makefile
diff -u src/regress/lib/libc/string/Makefile:1.9 src/regress/lib/libc/string/Makefile:1.10
--- src/regress/lib/libc/string/Makefile:1.9	Sat Aug 12 23:51:12 2006
+++ src/regress/lib/libc/string/Makefile	Sat Dec 25 21:13:37 2010
@@ -1,6 +1,5 @@
-# $NetBSD: Makefile,v 1.9 2006/08/12 23:51:12 christos Exp $
+# $NetBSD: Makefile,v 1.10 2010/12/25 21:13:37 pgoyette Exp $
 
-SUBDIR+= memchr memmem strcat strchr strcmp strcpy strlen strrchr swab wcsncpy\
-	memcpy stresep
+SUBDIR+= memmem swab wcsncpy memcpy stresep
 
 .include bsd.subdir.mk



CVS commit: src/regress/lib/libc/string/strchr

2009-07-18 Thread David Laight
Module Name:src
Committed By:   dsl
Date:   Sat Jul 18 09:20:46 UTC 2009

Modified Files:
src/regress/lib/libc/string/strchr: strchr_test.c

Log Message:
Add tests that scan for 0x0 and 0xff.
Remove the 'answers' section from the test definition, instead use our
own version of strchr() to determine the what the answer should be.
On error report which test we are doing, and the answer we got.
If symbol test_strchr exists, test that function instead of strchr().
(With a very dodgy strchr() other things fail badly.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/regress/lib/libc/string/strchr/strchr_test.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/regress/lib/libc/string/strchr/strchr_test.c
diff -u src/regress/lib/libc/string/strchr/strchr_test.c:1.3 src/regress/lib/libc/string/strchr/strchr_test.c:1.4
--- src/regress/lib/libc/string/strchr/strchr_test.c:1.3	Sat Jul 18 04:34:32 2009
+++ src/regress/lib/libc/string/strchr/strchr_test.c	Sat Jul 18 09:20:46 2009
@@ -28,232 +28,263 @@
 
 #include assert.h
 #include string.h
+#include stdio.h
+#include stdlib.h
+#include dlfcn.h
 
-extern char *xstrchr(const char *, int);
-void check_strchr(void);
+char * (*volatile strchr_fn)(const char *, int);
 
-/* try to trick the compiler */
-char * (*volatile f)(const char *, int);
+static int a;
+static int t;
 
-void
+static char *
+slow_strchr(char *buf, int ch)
+{
+unsigned char c = 1;
+
+ch = 0xff;
+
+for (; c != 0; buf++) {
+	c = *buf;
+	if (c == ch)
+	return buf;
+}
+return 0;
+}
+
+static void
+verify_strchr(char *buf, int ch)
+{
+const char *off, *ok_off;
+
+off = strchr_fn(buf, ch);
+ok_off = slow_strchr(buf, ch);
+if (off == ok_off)
+	return;
+
+fprintf(stderr, test_strchr(\%s\, %#x) gave %zd not %zd (test %d, alignment %d)\n,
+	buf, ch, off ? off - buf : -1, ok_off ? ok_off - buf : -1, t, a);
+
+exit(1);
+}
+
+static void
 check_strchr(void)
 {
-int a;
-int t;
-char* off;
+char *off;
 char buf[32];
 
-struct tab {
-	const char*	val;
-	char		match;
-	size_t		f_off;	/* offset of first match */
-	size_t		l_off;	/* offset of last match */
-};
+const char *tab[] = {
+	,
+	a,
+	aa,
+	abc,
+	abcd,
+	abcde,
+	abcdef,
+	abcdefg,
+	abcdefgh,
 
-const struct tab tab[] = {
-	{ ,			0, 0, 0 },
-	{ a,			0, 0, 0 },
-	{ aa,			0, 0, 0 },
-	{ abc,		0, 0, 0 },
-	{ abcd,		0, 0, 0 },
-	{ abcde,		0, 0, 0 },
-	{ abcdef,		0, 0, 0 },
-	{ abcdefg,		0, 0, 0 },
-	{ abcdefgh,		0, 0, 0 },
-
-	{ /,			1, 0, 0 },
-	{ //, 1, 0, 1 },
-	{ /a, 1, 0, 0 },
-	{ /a/,1, 0, 2 },
-	{ /ab,1, 0, 0 },
-	{ /ab/,   1, 0, 3 },
-	{ /abc,   1, 0, 0 },
-	{ /abc/,  1, 0, 4 },
-	{ /abcd,  1, 0, 0 },
-	{ /abcd/, 1, 0, 5 },
-	{ /abcde, 1, 0, 0 },
-	{ /abcde/,1, 0, 6 },
-	{ /abcdef,1, 0, 0 },
-	{ /abcdef/,   1, 0, 7 },
-	{ /abcdefg,   1, 0, 0 },
-	{ /abcdefg/,  1, 0, 8 },
-	{ /abcdefgh,  1, 0, 0 },
-	{ /abcdefgh/, 1, 0, 9 },
-	
-	{ a/, 1, 1, 1 },
-	{ a//,1, 1, 2 },
-	{ a/a,1, 1, 1 },
-	{ a/a/,   1, 1, 3 },
-	{ a/ab,   1, 1, 1 },
-	{ a/ab/,  1, 1, 4 },
-	{ a/abc,  1, 1, 1 },
-	{ a/abc/, 1, 1, 5 },
-	{ a/abcd, 1, 1, 1 },
-	{ a/abcd/,1, 1, 6 },
-	{ a/abcde,1, 1, 1 },
-	{ a/abcde/,   1, 1, 7 },
-	{ a/abcdef,   1, 1, 1 },
-	{ a/abcdef/,  1, 1, 8 },
-	{ a/abcdefg,  1, 1, 1 },
-	{ a/abcdefg/, 1, 1, 9 },
-	{ a/abcdefgh, 1, 1, 1 },
-	{ a/abcdefgh/,1, 1, 10 },
-	
-	{ ab/,1, 2, 2 },
-	{ ab//,   1, 2, 3 },
-	{ ab/a,   1, 2, 2 },
-	{ ab/a/,  1, 2, 4 },
-	{ ab/ab,  1, 2, 2 },
-	{ ab/ab/, 1, 2, 5 },
-	{ ab/abc, 1, 2, 2 },
-	{ ab/abc/,1, 2, 6 },
-	{ ab/abcd,1, 2, 2 },
-	{ ab/abcd/,   1, 2, 7 },
-	{ ab/abcde,   1, 2, 2 },
-	{ ab/abcde/,  1, 2, 8 },
-	{ ab/abcdef,  1, 2, 2 },
-	{ ab/abcdef/, 1, 2, 9 },
-	{ ab/abcdefg, 1, 2, 2 },
-	{ ab/abcdefg/,1, 2, 10 },
-	{ ab/abcdefgh,1, 2, 2 },
-	{ ab/abcdefgh/,   1, 2, 11 },
-	
-	{ abc/,   1, 3, 3 },
-	{ abc//,  1, 3, 4 },
-	{ abc/a,  1, 3, 3 },
-	{ abc/a/, 1, 3, 5 },
-	{ abc/ab, 1, 3, 3 },
-	{ abc/ab/,1, 3, 6 },
-	{ abc/abc,1, 3, 3 },
-	{ abc/abc/,   1, 3, 7 },
-	{ abc/abcd,   1, 3, 3 },
-	{ abc/abcd/,  1, 3, 8 },
-	{ abc/abcde,  1, 3, 3 },
-	{ abc/abcde/, 1, 3, 9 },
-	{ abc/abcdef, 1, 3, 3 },
-	{ abc/abcdef/,1, 3, 10 

CVS commit: src/regress/lib/libc/string/memchr

2009-07-18 Thread David Laight
Module Name:src
Committed By:   dsl
Date:   Sat Jul 18 16:34:47 UTC 2009

Modified Files:
src/regress/lib/libc/string/memchr: memchr_test.c

Log Message:
Start with alignment '1' and write the search char to the byte before
the buffer.
XXX needs tests searching for 0xff.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/regress/lib/libc/string/memchr/memchr_test.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/regress/lib/libc/string/memchr/memchr_test.c
diff -u src/regress/lib/libc/string/memchr/memchr_test.c:1.1 src/regress/lib/libc/string/memchr/memchr_test.c:1.2
--- src/regress/lib/libc/string/memchr/memchr_test.c:1.1	Tue Mar 15 15:57:58 2005
+++ src/regress/lib/libc/string/memchr/memchr_test.c	Sat Jul 18 16:34:47 2009
@@ -110,8 +110,9 @@
 	{ abc \xff\xff\xff\xff /,	8, 1, 7 },
 };
 
-for (a = 0; a  sizeof(long); ++a) {
+for (a = 1; a  1 + sizeof(long); ++a) {
 	for (t = 0; t  (sizeof(tab) / sizeof(tab[0])); ++t) {
+	buf[a-1] = '/';
 	strcpy(buf[a], tab[t].val);
 	
 	off = f(buf[a], '/', tab[t].len);



CVS commit: src/regress/lib/libc/string/strchr

2009-07-17 Thread David Laight
Module Name:src
Committed By:   dsl
Date:   Fri Jul 17 22:07:36 UTC 2009

Modified Files:
src/regress/lib/libc/string/strchr: strchr_test.c

Log Message:
Pollute the space either side of the string being compared with the test
pattern.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/regress/lib/libc/string/strchr/strchr_test.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/regress/lib/libc/string/strchr/strchr_test.c
diff -u src/regress/lib/libc/string/strchr/strchr_test.c:1.1 src/regress/lib/libc/string/strchr/strchr_test.c:1.2
--- src/regress/lib/libc/string/strchr/strchr_test.c:1.1	Tue Mar 15 15:57:58 2005
+++ src/regress/lib/libc/string/strchr/strchr_test.c	Fri Jul 17 22:07:36 2009
@@ -29,14 +29,15 @@
 #include assert.h
 #include string.h
 
+extern char *xstrchr(const char *, int);
 void check_strchr(void);
 
+/* try to trick the compiler */
+char * (*volatile f)((const char *, int);
+
 void
 check_strchr(void)
 {
-/* try to trick the compiler */
-char * (*f)(const char *, int) = strchr;
-
 int a;
 int t;
 char* off;
@@ -234,8 +235,16 @@
 
 
 for (a = 0; a  sizeof(long); ++a) {
+	if (a = 2) {
+		/* Put char and a \0 before the buffer */
+		buf[a-1] = '/';
+		buf[a-2] = '0';
+	}
 	for (t = 0; t  (sizeof(tab) / sizeof(tab[0])); ++t) {
-	strcpy(buf[a], tab[t].val);
+	int len = strlen(tab[t].val) + 1;
+	memcpy(buf[a], tab[t].val, len);
+	/* Put the char we are looking for after the \0 */
+	buf[a + len] = '/';
 	
 	off = f(buf[a], '/');
 	assert((tab[t].match == 0  off == 0) ||
@@ -252,6 +261,7 @@
 int
 main(void)
 {
+	f = strchr;
 	check_strchr();
 	return 0;
 }



CVS commit: src/regress/lib/libc/string/strlen

2009-07-11 Thread David Laight
Module Name:src
Committed By:   dsl
Date:   Sat Jul 11 11:45:17 UTC 2009

Modified Files:
src/regress/lib/libc/string/strlen: strlen_test.c

Log Message:
The local function pointer wasn't enough to stop gcc using the builtin
strlen!  Move to file scope and make 'volatile'.
When test fails use write (printf might be broken) to report info.
To aid testing new versions, use dlsym() for test_strlen defaulting to
strlen() so that the rest of the program doesn't use the broken version.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/regress/lib/libc/string/strlen/strlen_test.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/regress/lib/libc/string/strlen/strlen_test.c
diff -u src/regress/lib/libc/string/strlen/strlen_test.c:1.1 src/regress/lib/libc/string/strlen/strlen_test.c:1.2
--- src/regress/lib/libc/string/strlen/strlen_test.c:1.1	Tue Mar 15 15:57:58 2005
+++ src/regress/lib/libc/string/strlen/strlen_test.c	Sat Jul 11 11:45:16 2009
@@ -28,14 +28,34 @@
 
 #include assert.h
 #include string.h
+#include unistd.h
+#include stdlib.h
+#include dlfcn.h
 
 void check_strlen(void);
 
+size_t (*volatile strlen_fn)(const char *s);
+
+static void
+write_num(int val)
+{
+char buf[20];
+int i;
+for (i = sizeof buf; --i = 0;) {
+	buf[i] = '0' + val % 10;
+	val /= 10;
+	if (val == 0) {
+	write(2, buf + i, sizeof buf - i);
+	return;
+	}
+}
+write(2, overflow, 8);
+}
+
 void
 check_strlen(void)
 {
 /* try to trick the compiler */
-size_t (*f)(const char *s) = strlen;
 
 int a;
 int t;
@@ -102,9 +122,23 @@
 	for (t = 0; t  (sizeof(tab) / sizeof(tab[0])); ++t) {
 	
 	memcpy(buf[a], tab[t].val, tab[t].len + 1);
-	len = f(buf[a]);
+	len = strlen_fn(buf[a]);
 
-	assert(len == tab[t].len);
+	if (len != tab[t].len) {
+		/* Write error without using printf (and strlen) */
+		write(2, alignment , 10);
+		write_num(a);
+		write(2, , test , 7);
+		write_num(t);
+		write(2, , got len , 10);
+		write_num(len);
+		write(2, , not , 6);
+		write_num(tab[t].len);
+		write(2, , for ', 7);
+		write(2, tab[t].val, tab[t].len);
+		write(2, '\n, 2);
+		exit(1);
+	}
 	}
 }
 }
@@ -112,6 +146,11 @@
 int
 main(void)
 {
+	/* During testing it is useful have the rest of the program
+	 * use a known good version! */
+	strlen_fn = dlsym(dlopen(NULL, RTLD_LAZY), test_strlen);
+	if (!strlen_fn)
+		strlen_fn = strlen;
 	check_strlen();
 	return 0;
 }