Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Migrate J.T.Conklin's public-domain str* tests from regress ...
details: https://anonhg.NetBSD.org/src/rev/202be9a34529
branches: trunk
changeset: 760077:202be9a34529
user: pgoyette <pgoyette%NetBSD.org@localhost>
date: Sat Dec 25 21:10:24 2010 +0000
description:
Migrate J.T.Conklin's public-domain str* tests from regress to atf.
While here, do some clean-up and knf.
diffstat:
distrib/sets/lists/tests/mi | 14 +-
etc/mtree/NetBSD.dist.tests | 4 +-
tests/lib/libc/Makefile | 7 +-
tests/lib/libc/string/Makefile | 8 +-
tests/lib/libc/string/t_string.c | 1111 ++++++++++++++++++++++++++++++++++++++
5 files changed, 1129 insertions(+), 15 deletions(-)
diffs (truncated from 1211 to 300 lines):
diff -r 63aa42d8f6b1 -r 202be9a34529 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi Sat Dec 25 20:50:36 2010 +0000
+++ b/distrib/sets/lists/tests/mi Sat Dec 25 21:10:24 2010 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.189 2010/12/25 01:04:27 pgoyette Exp $
+# $NetBSD: mi,v 1.190 2010/12/25 21:10:24 pgoyette Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -334,8 +334,9 @@
./usr/libdata/debug/usr/tests/lib/libc/stdlib/t_environment_pth.debug tests-lib-debug debug,atf
./usr/libdata/debug/usr/tests/lib/libc/stdlib/t_mi_vector_hash.debug tests-lib-debug debug,atf
./usr/libdata/debug/usr/tests/lib/libc/stdlib/t_strtox.debug tests-lib-debug debug,atf
-./usr/libdata/debug/usr/tests/lib/libc/string tests-obsolete obsolete
-./usr/libdata/debug/usr/tests/lib/libc/string/t_popcount.debug tests-obsolete obsolete
+./usr/libdata/debug/usr/tests/lib/libc/string tests-lib-debug
+#./usr/libdata/debug/usr/tests/lib/libc/string/t_popcount.debug tests-lib-debug debug,atf
+./usr/libdata/debug/usr/tests/lib/libc/string/t_string.debug tests-lib-debug debug,atf
./usr/libdata/debug/usr/tests/lib/libdes tests-lib-debug
./usr/libdata/debug/usr/tests/lib/libdes/t_des.debug tests-lib-debug debug,atf,crypto
./usr/libdata/debug/usr/tests/lib/semaphore tests-lib-debug
@@ -1558,9 +1559,10 @@
./usr/tests/lib/libc/stdio/t_fmemopen tests-lib-tests atf
./usr/tests/lib/libc/stdio/t_format tests-lib-tests atf
./usr/tests/lib/libc/stdio/t_popen tests-lib-tests atf
-./usr/tests/lib/libc/string tests-obsolete obsolete
-./usr/tests/lib/libc/string/Atffile tests-obsolete obsolete
-./usr/tests/lib/libc/string/t_popcount tests-obsolete obsolete
+./usr/tests/lib/libc/string tests-lib-tests
+./usr/tests/lib/libc/string/Atffile tests-lib-tests atf
+#./usr/tests/lib/libc/string/t_popcount tests-lib-tests atf
+./usr/tests/lib/libc/string/t_string tests-lib-tests atf
./usr/tests/lib/libdes tests-lib-tests
./usr/tests/lib/libdes/Atffile tests-lib-tests atf,crypto
./usr/tests/lib/libdes/t_des tests-lib-tests atf,crypto
diff -r 63aa42d8f6b1 -r 202be9a34529 etc/mtree/NetBSD.dist.tests
--- a/etc/mtree/NetBSD.dist.tests Sat Dec 25 20:50:36 2010 +0000
+++ b/etc/mtree/NetBSD.dist.tests Sat Dec 25 21:10:24 2010 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: NetBSD.dist.tests,v 1.6 2010/12/20 23:47:23 pgoyette Exp $
+# $NetBSD: NetBSD.dist.tests,v 1.7 2010/12/25 21:10:25 pgoyette Exp $
./usr/libdata/debug/usr/tests
./usr/libdata/debug/usr/tests/atf
@@ -49,6 +49,7 @@
./usr/libdata/debug/usr/tests/lib/libc/hash
./usr/libdata/debug/usr/tests/lib/libc/stdio
./usr/libdata/debug/usr/tests/lib/libc/stdlib
+./usr/libdata/debug/usr/tests/lib/libc/string
./usr/libdata/debug/usr/tests/lib/libdes
./usr/libdata/debug/usr/tests/lib/libevent
./usr/libdata/debug/usr/tests/lib/semaphore
@@ -141,6 +142,7 @@
./usr/tests/lib/libc/hash
./usr/tests/lib/libc/stdio
./usr/tests/lib/libc/stdlib
+./usr/tests/lib/libc/string
./usr/tests/lib/libdes
./usr/tests/lib/semaphore
./usr/tests/lib/semaphore/pthread
diff -r 63aa42d8f6b1 -r 202be9a34529 tests/lib/libc/Makefile
--- a/tests/lib/libc/Makefile Sat Dec 25 20:50:36 2010 +0000
+++ b/tests/lib/libc/Makefile Sat Dec 25 21:10:24 2010 +0000
@@ -1,11 +1,8 @@
-# $NetBSD: Makefile,v 1.8 2010/11/03 20:20:12 christos Exp $
+# $NetBSD: Makefile,v 1.9 2010/12/25 21:10:25 pgoyette Exp $
.include <bsd.own.mk>
-TESTS_SUBDIRS+= gen hash stdlib stdio
-
-# Disabled for now, only test in there is very expensive
-#SUBDIR+= string
+TESTS_SUBDIRS+= gen hash stdlib stdio string
TESTSDIR= ${TESTSBASE}/lib/libc
diff -r 63aa42d8f6b1 -r 202be9a34529 tests/lib/libc/string/Makefile
--- a/tests/lib/libc/string/Makefile Sat Dec 25 20:50:36 2010 +0000
+++ b/tests/lib/libc/string/Makefile Sat Dec 25 21:10:24 2010 +0000
@@ -1,10 +1,12 @@
-# $NetBSD: Makefile,v 1.2 2010/02/26 09:35:08 martin Exp $
+# $NetBSD: Makefile,v 1.3 2010/12/25 21:10:24 pgoyette Exp $
.include <bsd.own.mk>
TESTSDIR= ${TESTSBASE}/lib/libc/string
-# EXPENSIVE, REALY, REALY EXPENSIVE test!
-TESTS_C+= t_popcount
+TESTS_C+= t_string
+
+# EXPENSIVE, REALY, REALY EXPENSIVE test! Disable for now.
+#TESTS_C+= t_popcount
.include <bsd.test.mk>
diff -r 63aa42d8f6b1 -r 202be9a34529 tests/lib/libc/string/t_string.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/lib/libc/string/t_string.c Sat Dec 25 21:10:24 2010 +0000
@@ -0,0 +1,1111 @@
+/* $NetBSD: t_string.c,v 1.1 2010/12/25 21:10:24 pgoyette Exp $ */
+
+/*
+ * Written by J.T. Conklin <jtc%acorntoolworks.com@localhost>
+ * Public domain.
+ */
+
+/*
+ * str*() regression suite
+ *
+ * Trivial str*() implementations can be audited by hand. Optimized
+ * versions that unroll loops, use naturally-aligned memory acesses,
+ * and "magic" arithmetic sequences to detect zero-bytes, written in
+ * assembler are much harder to validate. This program attempts to
+ * catch the corner cases.
+ *
+ * BUGS:
+ * Misssing checks for strncpy, strncat, strncmp, etc.
+ *
+ * TODO:
+ * Use mmap/mprotect to ensure the functions don't access memory
+ * across page boundaries.
+ *
+ * Consider generating tables programmatically. It would reduce
+ * the size, but it's also one more thing to go wrong.
+ *
+ * Share tables between strlen, strcpy, and strcat?
+ * Share tables between strchr and strrchr?
+ */
+
+#include <atf-c.h>
+
+#include <assert.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <dlfcn.h>
+
+/* for strchr */
+char * (*volatile strchr_fn)(const char *, int);
+
+ATF_TC(check_memchr);
+
+ATF_TC_HEAD(check_memchr, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr", "Test memchr results");
+}
+
+ATF_TC_BODY(check_memchr, tc)
+{
+ /* try to trick the compiler */
+ void * (*f)(const void *, int, size_t) = memchr;
+
+ unsigned int a, t;
+ void *off, *off2;
+ char buf[32];
+
+ struct tab {
+ const char *val;
+ size_t len;
+ char match;
+ ssize_t off;
+ };
+
+ const struct tab tab[] = {
+ { "", 0, 0, 0 },
+
+ { "/", 0, 0, 0 },
+ { "/", 1, 1, 0 },
+ { "/a", 2, 1, 0 },
+ { "/ab", 3, 1, 0 },
+ { "/abc", 4, 1, 0 },
+ { "/abcd", 5, 1, 0 },
+ { "/abcde", 6, 1, 0 },
+ { "/abcdef", 7, 1, 0 },
+ { "/abcdefg", 8, 1, 0 },
+
+ { "a/", 1, 0, 0 },
+ { "a/", 2, 1, 1 },
+ { "a/b", 3, 1, 1 },
+ { "a/bc", 4, 1, 1 },
+ { "a/bcd", 5, 1, 1 },
+ { "a/bcde", 6, 1, 1 },
+ { "a/bcdef", 7, 1, 1 },
+ { "a/bcdefg", 8, 1, 1 },
+
+ { "ab/", 2, 0, 0 },
+ { "ab/", 3, 1, 2 },
+ { "ab/c", 4, 1, 2 },
+ { "ab/cd", 5, 1, 2 },
+ { "ab/cde", 6, 1, 2 },
+ { "ab/cdef", 7, 1, 2 },
+ { "ab/cdefg", 8, 1, 2 },
+
+ { "abc/", 3, 0, 0 },
+ { "abc/", 4, 1, 3 },
+ { "abc/d", 5, 1, 3 },
+ { "abc/de", 6, 1, 3 },
+ { "abc/def", 7, 1, 3 },
+ { "abc/defg", 8, 1, 3 },
+
+ { "abcd/", 4, 0, 0 },
+ { "abcd/", 5, 1, 4 },
+ { "abcd/e", 6, 1, 4 },
+ { "abcd/ef", 7, 1, 4 },
+ { "abcd/efg", 8, 1, 4 },
+
+ { "abcde/", 5, 0, 0 },
+ { "abcde/", 6, 1, 5 },
+ { "abcde/f", 7, 1, 5 },
+ { "abcde/fg", 8, 1, 5 },
+
+ { "abcdef/", 6, 0, 0 },
+ { "abcdef/", 7, 1, 6 },
+ { "abcdef/g", 8, 1, 6 },
+
+ { "abcdefg/", 7, 0, 0 },
+ { "abcdefg/", 8, 1, 7 },
+
+ { "\xff\xff\xff\xff" "efg/", 8, 1, 7 },
+ { "a" "\xff\xff\xff\xff" "fg/", 8, 1, 7 },
+ { "ab" "\xff\xff\xff\xff" "g/", 8, 1, 7 },
+ { "abc" "\xff\xff\xff\xff" "/", 8, 1, 7 },
+ };
+
+ 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);
+ if (tab[t].match == 0) {
+ if (off != 0) {
+ fprintf(stderr, "a = %d, t = %d\n",
+ a, t);
+ atf_tc_fail("should not have found "
+ " char past len");
+ }
+ } else if (tab[t].match == 1) {
+ if (tab[t].off != ((char*)off - &buf[a])) {
+ fprintf(stderr, "a = %d, t = %d\n",
+ a, t);
+ atf_tc_fail("char not found at "
+ "correct offset");
+ }
+ } else {
+ fprintf(stderr, "a = %d, t = %d\n", a, t);
+ atf_tc_fail("Corrupt test case data");
+ }
+
+ /* check zero extension of char arg */
+ off2 = f(&buf[a], 0xffffff00 | '/', tab[t].len);
+ if (off2 != off)
+ atf_tc_fail("zero extension of char arg "
+ "failed");
+ }
+ }
+}
+
+ATF_TC(check_strcat);
+
+ATF_TC_HEAD(check_strcat, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr", "Test strcat results");
+}
+
+ATF_TC_BODY(check_strcat, tc)
+{
+ /* try to trick the compiler */
+ char * (*f)(char *, const char *s) = strcat;
+
+ unsigned int a0, a1, t0, t1;
+ char buf0[64];
+ char buf1[64];
+ char *ret;
+
+ struct tab {
+ const char* val;
+ size_t len;
+ };
+
+ const struct tab tab[] = {
+ /*
+ * patterns that check for all combinations of leading and
+ * trailing unaligned characters (on a 64 bit processor)
+ */
+
+ { "", 0 },
+ { "a", 1 },
+ { "ab", 2 },
+ { "abc", 3 },
+ { "abcd", 4 },
+ { "abcde", 5 },
+ { "abcdef", 6 },
+ { "abcdefg", 7 },
+ { "abcdefgh", 8 },
+ { "abcdefghi", 9 },
Home |
Main Index |
Thread Index |
Old Index