Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Split out the string tests from t_string.c for consistency.



details:   https://anonhg.NetBSD.org/src/rev/30c2864265e0
branches:  trunk
changeset: 767041:30c2864265e0
user:      jruoho <jruoho%NetBSD.org@localhost>
date:      Thu Jul 07 08:59:30 2011 +0000

description:
Split out the string tests from t_string.c for consistency.

diffstat:

 distrib/sets/lists/tests/mi       |    20 +-
 tests/lib/libc/string/Makefile    |    12 +-
 tests/lib/libc/string/t_memchr.c  |   137 ++++
 tests/lib/libc/string/t_strcat.c  |   132 ++++
 tests/lib/libc/string/t_strchr.c  |   292 +++++++++
 tests/lib/libc/string/t_strcmp.c  |   106 +++
 tests/lib/libc/string/t_strcpy.c  |   124 ++++
 tests/lib/libc/string/t_string.c  |  1111 -------------------------------------
 tests/lib/libc/string/t_strlen.c  |   144 ++++
 tests/lib/libc/string/t_strrchr.c |   257 ++++++++
 10 files changed, 1219 insertions(+), 1116 deletions(-)

diffs (truncated from 2418 to 300 lines):

diff -r 83ff1ed03b4a -r 30c2864265e0 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Thu Jul 07 08:48:34 2011 +0000
+++ b/distrib/sets/lists/tests/mi       Thu Jul 07 08:59:30 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.367 2011/07/07 07:06:21 jruoho Exp $
+# $NetBSD: mi,v 1.368 2011/07/07 08:59:30 jruoho Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -449,13 +449,20 @@
 ./usr/libdata/debug/usr/tests/lib/libc/stdlib/t_strtol.debug           tests-lib-debug         debug,atf
 ./usr/libdata/debug/usr/tests/lib/libc/stdlib/t_strtox.debug           tests-obsolete          obsolete
 ./usr/libdata/debug/usr/tests/lib/libc/string                          tests-lib-debug
+./usr/libdata/debug/usr/tests/lib/libc/string/t_memchr.debug           tests-lib-debug         debug,atf
 ./usr/libdata/debug/usr/tests/lib/libc/string/t_memcpy.debug           tests-lib-debug         debug,atf
 ./usr/libdata/debug/usr/tests/lib/libc/string/t_memmem.debug           tests-lib-debug         debug,atf
 ./usr/libdata/debug/usr/tests/lib/libc/string/t_memset.debug           tests-lib-debug         debug,atf
 ./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_strcat.debug           tests-lib-debug         debug,atf
+./usr/libdata/debug/usr/tests/lib/libc/string/t_strchr.debug           tests-lib-debug         debug,atf
+./usr/libdata/debug/usr/tests/lib/libc/string/t_strcmp.debug           tests-lib-debug         debug,atf
+./usr/libdata/debug/usr/tests/lib/libc/string/t_strcpy.debug           tests-lib-debug         debug,atf
 ./usr/libdata/debug/usr/tests/lib/libc/string/t_strerror.debug         tests-lib-debug         debug,atf
 ./usr/libdata/debug/usr/tests/lib/libc/string/t_stresep.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/libc/string/t_string.debug           tests-obsolete          obsolete
+./usr/libdata/debug/usr/tests/lib/libc/string/t_strlen.debug           tests-lib-debug         debug,atf
+./usr/libdata/debug/usr/tests/lib/libc/string/t_strrchr.debug          tests-lib-debug         debug,atf
 ./usr/libdata/debug/usr/tests/lib/libc/string/t_swab.debug             tests-lib-debug         debug,atf
 ./usr/libdata/debug/usr/tests/lib/libc/sys                             tests-lib-debug
 ./usr/libdata/debug/usr/tests/lib/libc/sys/t_access.debug              tests-lib-debug         debug,atf
@@ -2019,13 +2026,20 @@
 ./usr/tests/lib/libc/stdlib/t_strtox           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_memchr           tests-lib-tests         atf
 ./usr/tests/lib/libc/string/t_memcpy           tests-lib-tests         atf
 ./usr/tests/lib/libc/string/t_memmem           tests-lib-tests         atf
 ./usr/tests/lib/libc/string/t_memset           tests-lib-tests         atf
 ./usr/tests/lib/libc/string/t_popcount         tests-lib-tests         atf
+./usr/tests/lib/libc/string/t_strcat           tests-lib-tests         atf
+./usr/tests/lib/libc/string/t_strchr           tests-lib-tests         atf
+./usr/tests/lib/libc/string/t_strcmp           tests-lib-tests         atf
+./usr/tests/lib/libc/string/t_strcpy           tests-lib-tests         atf
 ./usr/tests/lib/libc/string/t_strerror         tests-lib-tests         atf
 ./usr/tests/lib/libc/string/t_stresep          tests-lib-tests         atf
-./usr/tests/lib/libc/string/t_string           tests-lib-tests         atf
+./usr/tests/lib/libc/string/t_string           tests-obsolete          obsolete
+./usr/tests/lib/libc/string/t_strlen           tests-lib-tests         atf
+./usr/tests/lib/libc/string/t_strrchr          tests-lib-tests         atf
 ./usr/tests/lib/libc/string/t_swab             tests-lib-tests         atf
 ./usr/tests/lib/libc/sys                       tests-lib-tests
 ./usr/tests/lib/libc/sys/Atffile               tests-lib-tests         atf
diff -r 83ff1ed03b4a -r 30c2864265e0 tests/lib/libc/string/Makefile
--- a/tests/lib/libc/string/Makefile    Thu Jul 07 08:48:34 2011 +0000
+++ b/tests/lib/libc/string/Makefile    Thu Jul 07 08:59:30 2011 +0000
@@ -1,16 +1,24 @@
-# $NetBSD: Makefile,v 1.6 2011/06/03 06:39:52 jruoho Exp $
+# $NetBSD: Makefile,v 1.7 2011/07/07 08:59:33 jruoho Exp $
 
 .include <bsd.own.mk>
 
 TESTSDIR=      ${TESTSBASE}/lib/libc/string
 
+TESTS_C+=      t_memchr
 TESTS_C+=      t_memcpy
 TESTS_C+=      t_memmem
 TESTS_C+=      t_memset
 TESTS_C+=      t_popcount
+TESTS_C+=      t_strcat
+TESTS_C+=      t_strchr
+TESTS_C+=      t_strcmp
+TESTS_C+=      t_strcpy
 TESTS_C+=      t_strerror
 TESTS_C+=      t_stresep
-TESTS_C+=      t_string
+TESTS_C+=      t_strlen
+TESTS_C+=      t_strrchr
 TESTS_C+=      t_swab
 
+WARNS=         4
+
 .include <bsd.test.mk>
diff -r 83ff1ed03b4a -r 30c2864265e0 tests/lib/libc/string/t_memchr.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/lib/libc/string/t_memchr.c  Thu Jul 07 08:59:30 2011 +0000
@@ -0,0 +1,137 @@
+/* $NetBSD: t_memchr.c,v 1.1 2011/07/07 08:59:32 jruoho Exp $ */
+
+/*
+ * Written by J.T. Conklin <jtc%acorntoolworks.com@localhost>
+ * Public domain.
+ */
+
+#include <atf-c.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+ATF_TC(memchr_basic);
+ATF_TC_HEAD(memchr_basic, tc)
+{
+        atf_tc_set_md_var(tc, "descr", "Test memchr(3) results");
+}
+
+ATF_TC_BODY(memchr_basic, 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_TP_ADD_TCS(tp)
+{
+
+       ATF_TP_ADD_TC(tp, memchr_basic);
+
+       return atf_no_error();
+}
diff -r 83ff1ed03b4a -r 30c2864265e0 tests/lib/libc/string/t_strcat.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/lib/libc/string/t_strcat.c  Thu Jul 07 08:59:30 2011 +0000
@@ -0,0 +1,132 @@
+/* $NetBSD: t_strcat.c,v 1.1 2011/07/07 08:59:32 jruoho Exp $ */
+
+/*
+ * Written by J.T. Conklin <jtc%acorntoolworks.com@localhost>
+ * Public domain.
+ */
+
+#include <atf-c.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+ATF_TC(strcat_basic);
+ATF_TC_HEAD(strcat_basic, tc)
+{
+        atf_tc_set_md_var(tc, "descr", "Test strcat(3) results");
+}
+
+ATF_TC_BODY(strcat_basic, 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 },
+               { "abcdefghij",                 10 },
+               { "abcdefghijk",                11 },
+               { "abcdefghijkl",               12 },
+               { "abcdefghijklm",              13 },
+               { "abcdefghijklmn",             14 },
+               { "abcdefghijklmno",            15 },
+               { "abcdefghijklmnop",           16 },
+               { "abcdefghijklmnopq",          17 },
+               { "abcdefghijklmnopqr",         18 },
+               { "abcdefghijklmnopqrs",        19 },
+               { "abcdefghijklmnopqrst",       20 },
+               { "abcdefghijklmnopqrstu",      21 },
+               { "abcdefghijklmnopqrstuv",     22 },
+               { "abcdefghijklmnopqrstuvw",    23 },
+
+               /*
+                * patterns that check for the cases where the expression:
+                *
+                *      ((word - 0x7f7f..7f) & 0x8080..80)
+                *
+                * returns non-zero even though there are no zero bytes in
+                * the word.



Home | Main Index | Thread Index | Old Index