summaryrefslogtreecommitdiffstats
path: root/test/string
diff options
context:
space:
mode:
Diffstat (limited to 'test/string')
-rw-r--r--test/string/Makefile105
-rw-r--r--test/string/bug-strcoll1.c24
-rw-r--r--test/string/bug-strncat1.c31
-rw-r--r--test/string/bug-strpbrk1.c19
-rw-r--r--test/string/bug-strspn1.c19
-rw-r--r--test/string/stratcliff.c349
-rw-r--r--test/string/test-ffs.c66
-rw-r--r--test/string/testcopy.c34
-rw-r--r--test/string/tester.c (renamed from test/string/string.c)172
-rw-r--r--test/string/tst-bswap.c74
-rw-r--r--test/string/tst-inlcall.c83
-rw-r--r--test/string/tst-strlen.c45
-rw-r--r--test/string/tst-strtok.c23
-rw-r--r--test/string/tst-strxfrm.c80
14 files changed, 1000 insertions, 124 deletions
diff --git a/test/string/Makefile b/test/string/Makefile
index 9bd7d90cf..a18d52e93 100644
--- a/test/string/Makefile
+++ b/test/string/Makefile
@@ -1,103 +1,6 @@
-# Makefile for uClibc
-#
-# Copyright (C) 2000,2001 Erik Andersen <andersen@uclibc.org>
-#
-# This program is free software; you can redistribute it and/or modify it under
-# the terms of the GNU Library 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 Library General Public License for more
-# details.
-#
-# You should have received a copy of the GNU Library 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
+# uClibc string tests
+# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
-include ../Rules.mak
+include ../Test.mak
-TARGETS=string string_glibc
-TARGETS+=testcopy testcopy_glibc
-TARGETS+=#strerror #strsignal
-
-all: $(TARGETS)
-
-string: string.c Makefile $(TESTDIR)/Rules.mak
- -@ echo "-------"
- -@ echo " "
- -@ echo "Compiling $@ vs uClibc: "
- -@ echo " "
- $(CC) $(CFLAGS) -c $< -o $@.o
- $(CC) $(LDFLAGS) $@.o -o $@ $(EXTRA_LIBS)
- $(STRIPTOOL) -x -R .note -R .comment $@
- ./$@
- -@ echo " "
-
-string_glibc: string.c Makefile
- -@ echo "-------"
- -@ echo " "
- -@ echo "Compiling $@ vs glibc: "
- -@ echo " "
- $(HOSTCC) $(GLIBC_CFLAGS) -c $< -o $@.o
- $(HOSTCC) $(GLIBC_LDFLAGS) $@.o -o $@
- $(STRIPTOOL) -x -R .note -R .comment $@
- ./$@
- -@ echo " "
-
-testcopy: testcopy.c Makefile $(TESTDIR)/Rules.mak
- -@ echo "-------"
- -@ echo " "
- -@ echo "Compiling $@ vs uClibc: "
- -@ echo " "
- $(CC) $(CFLAGS) -c $< -o $@.o
- $(CC) $(LDFLAGS) $@.o -o $@ $(EXTRA_LIBS)
- $(STRIPTOOL) -x -R .note -R .comment $@
- ./$@ > testcopy.out
- -@ echo " "
-
-testcopy_glibc: testcopy.c Makefile
- -@ echo "-------"
- -@ echo " "
- -@ echo "Compiling $@ vs glibc: "
- -@ echo " "
- $(HOSTCC) $(GLIBC_CFLAGS) -c $< -o $@.o
- $(HOSTCC) $(GLIBC_LDFLAGS) $@.o -o $@
- $(STRIPTOOL) -x -R .note -R .comment $@
- ./$@ > testcopy.gnu.out
- -@ echo " "
-
-testcopy_diff: testcopy testcopy_glibc
- -@ echo "-------"
- -@ echo " "
- -@ echo "Diffing output: "
- -@ echo " "
- -diff -u testcopy.gnu.out testcopy.out
- -@ echo " "
-
-
-strerror: ../../libc/string/strerror.c $(TESTDIR)/Rules.mak
- -@ echo "-------"
- -@ echo " "
- -@ echo "Compiling $@ vs uClibc: "
- -@ echo " "
- $(CC) $(CFLAGS) -DCHECK_BUF -c $< -o $@.o
- $(CC) $(LDFLAGS) $@.o -o $@ $(EXTRA_LIBS)
- $(STRIPTOOL) -x -R .note -R .comment $@
- ./$@
- -@ echo " "
-
-strsignal: ../../libc/string/strsignal.c
- -@ echo "-------"
- -@ echo " "
- -@ echo "Compiling $@ vs uClibc: "
- -@ echo " "
- $(CC) $(CFLAGS) -DCHECK_BUF -c $< -o $@.o
- $(CC) $(LDFLAGS) $@.o -o $@ $(EXTRA_LIBS)
- $(STRIPTOOL) -x -R .note -R .comment $@
- ./$@
- -@ echo " "
-
-clean:
- $(RM) *.[oa] *~ core $(TARGETS) testcopy.gnu.out testcopy.out
+EXTRA_CFLAGS := -fno-builtin
diff --git a/test/string/bug-strcoll1.c b/test/string/bug-strcoll1.c
new file mode 100644
index 000000000..b6510d926
--- /dev/null
+++ b/test/string/bug-strcoll1.c
@@ -0,0 +1,24 @@
+#include <stdio.h>
+#include <string.h>
+#include <locale.h>
+
+int
+main (void)
+{
+ const char t1[] = "0-0-0-0-0-0-0-0-0-0.COM";
+ const char t2[] = "00000-00000.COM";
+ int res1;
+ int res2;
+
+ setlocale (LC_ALL, "en_US.ISO-8859-1");
+
+ res1 = strcoll (t1, t2);
+ printf ("strcoll (\"%s\", \"%s\") = %d\n", t1, t2, res1);
+ res2 = strcoll (t2, t1);
+ printf ("strcoll (\"%s\", \"%s\") = %d\n", t2, t1, res2);
+
+ return ((res1 == 0 && res2 != 0)
+ || (res1 != 0 && res2 == 0)
+ || (res1 < 0 && res2 < 0)
+ || (res1 > 0 && res2 > 0));
+}
diff --git a/test/string/bug-strncat1.c b/test/string/bug-strncat1.c
new file mode 100644
index 000000000..f1b5c37c5
--- /dev/null
+++ b/test/string/bug-strncat1.c
@@ -0,0 +1,31 @@
+/* Test case by Joseph S. Myers <jsm28@cam.ac.uk>. */
+#undef __USE_STRING_INLINES
+#define __USE_STRING_INLINES
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+char d[3] = "\0\1\2";
+
+int
+main (void)
+{
+ strncat (d, "\5\6", 1);
+ if (d[0] != '\5')
+ {
+ puts ("d[0] != '\\5'");
+ exit (1);
+ }
+ if (d[1] != '\0')
+ {
+ puts ("d[1] != '\\0'");
+ exit (1);
+ }
+ if (d[2] != '\2')
+ {
+ puts ("d[2] != '\\2'");
+ exit (1);
+ }
+
+ return 0;
+}
diff --git a/test/string/bug-strpbrk1.c b/test/string/bug-strpbrk1.c
new file mode 100644
index 000000000..28238b0f5
--- /dev/null
+++ b/test/string/bug-strpbrk1.c
@@ -0,0 +1,19 @@
+/* Test case by Joseph S. Myers <jsm28@cam.ac.uk>. */
+#undef __USE_STRING_INLINES
+#define __USE_STRING_INLINES
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+int
+main (void)
+{
+ const char *a = "abc";
+ const char *b = a;
+
+ strpbrk (b++, "");
+ if (b != a + 1)
+ return 1;
+
+ return 0;
+}
diff --git a/test/string/bug-strspn1.c b/test/string/bug-strspn1.c
new file mode 100644
index 000000000..a657bafc4
--- /dev/null
+++ b/test/string/bug-strspn1.c
@@ -0,0 +1,19 @@
+/* Test case by Joseph S. Myers <jsm28@cam.ac.uk>. */
+#undef __USE_STRING_INLINES
+#define __USE_STRING_INLINES
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+int
+main (void)
+{
+ const char *a = "abc";
+ const char *b = a;
+
+ strspn (b++, "");
+ if (b != a + 1)
+ return 1;
+
+ return 0;
+}
diff --git a/test/string/stratcliff.c b/test/string/stratcliff.c
new file mode 100644
index 000000000..41e774681
--- /dev/null
+++ b/test/string/stratcliff.c
@@ -0,0 +1,349 @@
+/* Test for string function add boundaries of usable memory.
+ Copyright (C) 1996,1997,1999-2002,2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#define _GNU_SOURCE 1
+
+/* Make sure we don't test the optimized inline functions if we want to
+ test the real implementation. */
+#undef __USE_STRING_INLINES
+
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <sys/param.h>
+
+#ifndef MAX
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
+#endif
+
+int
+main (int argc, char *argv[])
+{
+ int size = sysconf (_SC_PAGESIZE);
+ char *adr, *dest;
+ int result = 0;
+
+ adr = (char *) mmap (NULL, 3 * size, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANON, -1, 0);
+ dest = (char *) mmap (NULL, 3 * size, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANON, -1, 0);
+ if (adr == MAP_FAILED || dest == MAP_FAILED)
+ {
+ if (errno == ENOSYS)
+ puts ("No test, mmap not available.");
+ else
+ {
+ printf ("mmap failed: %s", strerror(errno));
+ result = 1;
+ }
+ }
+ else
+ {
+ int inner, middle, outer;
+
+ mprotect(adr, size, PROT_NONE);
+ mprotect(adr + 2 * size, size, PROT_NONE);
+ adr += size;
+
+ mprotect(dest, size, PROT_NONE);
+ mprotect(dest + 2 * size, size, PROT_NONE);
+ dest += size;
+
+ memset (adr, 'T', size);
+
+ /* strlen test */
+ for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
+ {
+ for (inner = MAX (outer, size - 64); inner < size; ++inner)
+ {
+ adr[inner] = '\0';
+
+ if (strlen (&adr[outer]) != (size_t) (inner - outer))
+ {
+ printf ("strlen flunked for outer = %d, inner = %d\n",
+ outer, inner);
+ result = 1;
+ }
+
+ adr[inner] = 'T';
+ }
+ }
+
+ /* strchr test */
+ for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
+ {
+ for (middle = MAX (outer, size - 64); middle < size; ++middle)
+ {
+ for (inner = middle; inner < size; ++inner)
+ {
+ char *cp;
+ adr[middle] = 'V';
+ adr[inner] = '\0';
+
+ cp = strchr (&adr[outer], 'V');
+
+ if ((inner == middle && cp != NULL)
+ || (inner != middle
+ && (cp - &adr[outer]) != middle - outer))
+ {
+ printf ("strchr flunked for outer = %d, middle = %d, "
+ "inner = %d\n", outer, middle, inner);
+ result = 1;
+ }
+
+ adr[inner] = 'T';
+ adr[middle] = 'T';
+ }
+ }
+ }
+
+ /* Special test. */
+ adr[size - 1] = '\0';
+ if (strchr (&adr[size - 1], '\n') != NULL)
+ {
+ puts ("strchr flunked for test of empty string at end of page");
+ result = 1;
+ }
+
+ /* strrchr test */
+ for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
+ {
+ for (middle = MAX (outer, size - 64); middle < size; ++middle)
+ {
+ for (inner = middle; inner < size; ++inner)
+ {
+ char *cp;
+ adr[middle] = 'V';
+ adr[inner] = '\0';
+
+ cp = strrchr (&adr[outer], 'V');
+
+ if ((inner == middle && cp != NULL)
+ || (inner != middle
+ && (cp - &adr[outer]) != middle - outer))
+ {
+ printf ("strrchr flunked for outer = %d, middle = %d, "
+ "inner = %d\n", outer, middle, inner);
+ result = 1;
+ }
+
+ adr[inner] = 'T';
+ adr[middle] = 'T';
+ }
+ }
+ }
+
+ /* rawmemchr test */
+ for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
+ {
+ for (middle = MAX (outer, size - 64); middle < size; ++middle)
+ {
+ char *cp;
+ adr[middle] = 'V';
+
+ cp = rawmemchr (&adr[outer], 'V');
+
+ if (cp - &adr[outer] != middle - outer)
+ {
+ printf ("rawmemchr flunked for outer = %d, middle = %d\n",
+ outer, middle);
+ result = 1;
+ }
+
+ adr[middle] = 'T';
+ }
+ }
+
+ /* strcpy test */
+ for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
+ {
+ for (inner = MAX (outer, size - 64); inner < size; ++inner)
+ {
+ adr[inner] = '\0';
+
+ if (strcpy (dest, &adr[outer]) != dest
+ || strlen (dest) != (size_t) (inner - outer))
+ {
+ printf ("strcpy flunked for outer = %d, inner = %d\n",
+ outer, inner);
+ result = 1;
+ }
+
+ adr[inner] = 'T';
+ }
+ }
+
+ /* strncpy tests */
+ adr[size-1] = 'T';
+ for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
+ {
+ size_t len;
+
+ for (len = 0; len < size - outer; ++len)
+ {
+ if (strncpy (dest, &adr[outer], len) != dest
+ || memcmp (dest, &adr[outer], len) != 0)
+ {
+ printf ("outer strncpy flunked for outer = %d, len = %Zd\n",
+ outer, len);
+ result = 1;
+ }
+ }
+ }
+ adr[size-1] = '\0';
+
+ for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
+ {
+ for (inner = MAX (outer, size - 64); inner < size; ++inner)
+ {
+ size_t len;
+
+ adr[inner] = '\0';
+
+ for (len = 0; len < size - outer + 64; ++len)
+ {
+ if (strncpy (dest, &adr[outer], len) != dest
+ || memcmp (dest, &adr[outer],
+ MIN (inner - outer, len)) != 0
+ || (inner - outer < len
+ && strlen (dest) != (inner - outer)))
+ {
+ printf ("strncpy flunked for outer = %d, inner = %d, len = %Zd\n",
+ outer, inner, len);
+ result = 1;
+ }
+ if (strncpy (dest + 1, &adr[outer], len) != dest + 1
+ || memcmp (dest + 1, &adr[outer],
+ MIN (inner - outer, len)) != 0
+ || (inner - outer < len
+ && strlen (dest + 1) != (inner - outer)))
+ {
+ printf ("strncpy+1 flunked for outer = %d, inner = %d, len = %Zd\n",
+ outer, inner, len);
+ result = 1;
+ }
+ }
+
+ adr[inner] = 'T';
+ }
+ }
+
+ /* stpcpy test */
+ for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
+ {
+ for (inner = MAX (outer, size - 64); inner < size; ++inner)
+ {
+ adr[inner] = '\0';
+
+ if ((stpcpy (dest, &adr[outer]) - dest) != inner - outer)
+ {
+ printf ("stpcpy flunked for outer = %d, inner = %d\n",
+ outer, inner);
+ result = 1;
+ }
+
+ adr[inner] = 'T';
+ }
+ }
+
+ /* stpncpy test */
+ for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
+ {
+ for (middle = MAX (outer, size - 64); middle < size; ++middle)
+ {
+ adr[middle] = '\0';
+
+ for (inner = 0; inner < size - outer; ++ inner)
+ {
+ if ((stpncpy (dest, &adr[outer], inner) - dest)
+ != MIN (inner, middle - outer))
+ {
+ printf ("stpncpy flunked for outer = %d, middle = %d, "
+ "inner = %d\n", outer, middle, inner);
+ result = 1;
+ }
+ }
+
+ adr[middle] = 'T';
+ }
+ }
+
+ /* memcpy test */
+ for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
+ for (inner = 0; inner < size - outer; ++inner)
+ if (memcpy (dest, &adr[outer], inner) != dest)
+ {
+ printf ("memcpy flunked for outer = %d, inner = %d\n",
+ outer, inner);
+ result = 1;
+ }
+
+ /* mempcpy test */
+ for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
+ for (inner = 0; inner < size - outer; ++inner)
+ if (mempcpy (dest, &adr[outer], inner) != dest + inner)
+ {
+ printf ("mempcpy flunked for outer = %d, inner = %d\n",
+ outer, inner);
+ result = 1;
+ }
+
+ /* memccpy test */
+ memset (adr, '\0', size);
+ for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
+ for (inner = 0; inner < size - outer; ++inner)
+ if (memccpy (dest, &adr[outer], '\1', inner) != NULL)
+ {
+ printf ("memccpy flunked full copy for outer = %d, inner = %d\n",
+ outer, inner);
+ result = 1;
+ }
+ for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
+ for (middle = 0; middle < size - outer; ++middle)
+ {
+ memset (dest, '\2', middle + 1);
+ for (inner = 0; inner < middle; ++inner)
+ {
+ adr[outer + inner] = '\1';
+
+ if (memccpy (dest, &adr[outer], '\1', middle + 128)
+ != dest + inner + 1)
+ {
+ printf ("\
+memccpy flunked partial copy for outer = %d, middle = %d, inner = %d\n",
+ outer, middle, inner);
+ result = 1;
+ }
+ else if (dest[inner + 1] != '\2')
+ {
+ printf ("\
+memccpy copied too much for outer = %d, middle = %d, inner = %d\n",
+ outer, middle, inner);
+ result = 1;
+ }
+ adr[outer + inner] = '\0';
+ }
+ }
+ }
+
+ return result;
+}
diff --git a/test/string/test-ffs.c b/test/string/test-ffs.c
new file mode 100644
index 000000000..86e11758d
--- /dev/null
+++ b/test/string/test-ffs.c
@@ -0,0 +1,66 @@
+/* Copyright (C) 1994, 1997, 2000, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Joel Sherrill (jsherril@redstone-emh2.army.mil),
+ On-Line Applications Research Corporation.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+int
+main (void)
+{
+ int failures = 0;
+ int i;
+
+ auto void try (const char *name, long long int param, int value,
+ int expected);
+
+ void try (const char *name, long long int param, int value, int expected)
+ {
+ if (value != expected)
+ {
+ printf ("%s(%#llx) expected %d got %d\n",
+ name, param, expected, value);
+ ++failures;
+ }
+ else
+ printf ("%s(%#llx) as expected %d\n", name, param, value);
+ }
+
+#define TEST(fct, type) \
+ try (#fct, 0, fct ((type) 0), 0); \
+ for (i=0 ; i < 8 * sizeof (type); i++) \
+ try (#fct, 1ll << i, fct (((type) 1) << i), i + 1); \
+ for (i=0 ; i < 8 * sizeof (type) ; i++) \
+ try (#fct, (~((type) 0) >> i) << i, fct ((~((type) 0) >> i) << i), i + 1);\
+ try (#fct, 0x80008000, fct ((type) 0x80008000), 16)
+
+ TEST (ffs, int);
+/* Not implemented in uClibc (yet?)
+ TEST (ffsl, long int);
+ TEST (ffsll, long long int);
+*/
+
+ if (failures)
+ printf ("Test FAILED! %d failure%s.\n", failures, &"s"[failures == 1]);
+ else
+ puts ("Test succeeded.");
+
+ return failures;
+}
diff --git a/test/string/testcopy.c b/test/string/testcopy.c
index 02d193779..60039f790 100644
--- a/test/string/testcopy.c
+++ b/test/string/testcopy.c
@@ -1,29 +1,29 @@
-/* Copyright (C) 1990, 1991, 1992 Free Software Foundation, Inc.
+/* Copyright (C) 1990, 1991, 1992, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
Contributed by Torbjorn Granlund (tege@sics.se).
-This file is part of the GNU C Library.
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
-The GNU C Library is free software; you can redistribute it and/or
-modify it under the terms of the GNU Library General Public License as
-published by the Free Software Foundation; either version 2 of the
-License, or (at your option) any later version.
+ The GNU C Library 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
+ Lesser General Public License for more details.
-The GNU C Library 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
-Library General Public License for more details.
-
-You should have received a copy of the GNU Library General Public
-License along with the GNU C Library; see the file COPYING.LIB. If
-not, write to the Free Software Foundation, Inc., 675 Mass Ave,
-Cambridge, MA 02139, USA. */
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <malloc.h>
-int main(int argc, char **argv)
+int
+main (void)
{
char *mem, *memp;
char *rand_mem;
@@ -46,7 +46,7 @@ int main(int argc, char **argv)
{
int x;
do
- x = rand ();
+ x = random ();
while (x == 0);
rand_mem[i] = x;
}
diff --git a/test/string/string.c b/test/string/tester.c
index 60caddf99..f89cf01fa 100644
--- a/test/string/string.c
+++ b/test/string/tester.c
@@ -1,5 +1,5 @@
/* Tester for string functions.
- Copyright (C) 1995-2000, 2001 Free Software Foundation, Inc.
+ Copyright (C) 1995-2001, 2003, 2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -34,6 +34,12 @@
#include <strings.h>
#include <fcntl.h>
+#ifdef __UCLIBC__
+# define __TEST_BSD_FUNCS__
+#else
+# undef __TEST_BSD_FUNCS__
+#endif
+
#define STREQ(a, b) (strcmp((a), (b)) == 0)
const char *it = "<UNSET>"; /* Routine name for message routines. */
@@ -84,8 +90,8 @@ test_strcmp (void)
int k;
for (k = 0; k < 0x3f; k++)
{
- buf1[j] = '0' ^ (k & 4);
- buf2[j] = '4' ^ (k & 4);
+ buf1[k] = '0' ^ (k & 4);
+ buf2[k] = '4' ^ (k & 4);
}
buf1[i] = buf1[0x3f] = 0;
buf2[j] = buf2[0x3f] = 0;
@@ -168,6 +174,12 @@ test_strcpy (void)
SIMPLE_COPY(strcpy, 14, "44444444444444", 55);
SIMPLE_COPY(strcpy, 15, "555555555555555", 56);
SIMPLE_COPY(strcpy, 16, "6666666666666666", 57);
+
+ /* Simple test using implicitly coerced `void *' arguments. */
+ const void *src = "frobozz";
+ void *dst = one;
+ check (strcpy (dst, src) == dst, 1);
+ equal (dst, "frobozz", 2);
}
static void
@@ -343,6 +355,53 @@ test_strncat (void)
}
static void
+test_strlcat (void)
+{
+#ifdef __TEST_BSD_FUNCS__
+ /* First test it as strcat, with big counts, then test the count
+ mechanism. */
+ it = "strlcat";
+ (void) strcpy (one, "ijk");
+ check (strlcat (one, "lmn", 99) == 6, 1); /* Returned value. */
+ equal (one, "ijklmn", 2); /* Basic test. */
+
+ (void) strcpy (one, "x");
+ (void) strlcat (one, "yz", 99);
+ equal (one, "xyz", 3); /* Writeover. */
+ equal (one+4, "mn", 4); /* Wrote too much? */
+
+ (void) strcpy (one, "gh");
+ (void) strcpy (two, "ef");
+ (void) strlcat (one, two, 99);
+ equal (one, "ghef", 5); /* Basic test encore. */
+ equal (two, "ef", 6); /* Stomped on source? */
+
+ (void) strcpy (one, "");
+ (void) strlcat (one, "", 99);
+ equal (one, "", 7); /* Boundary conditions. */
+ (void) strcpy (one, "ab");
+ (void) strlcat (one, "", 99);
+ equal (one, "ab", 8);
+ (void) strcpy (one, "");
+ (void) strlcat (one, "cd", 99);
+ equal (one, "cd", 9);
+
+ (void) strcpy (one, "ab");
+ (void) strlcat (one, "cdef", 2);
+ equal (one, "ab", 10); /* Count-limited. */
+
+ (void) strlcat (one, "gh", 0);
+ equal (one, "ab", 11); /* Zero count. */
+
+ (void) strlcat (one, "gh", 4);
+ equal (one, "abg", 12); /* Count and length equal. */
+
+ (void) strlcat (one, "ij", (size_t)-1); /* set sign bit in count */
+ equal (one, "abgij", 13);
+#endif
+}
+
+static void
test_strncmp (void)
{
/* First test as strcmp with big counts, then test count code. */
@@ -360,7 +419,7 @@ test_strncmp (void)
check (strncmp ("abce", "abc", 3) == 0, 11); /* Count == length. */
check (strncmp ("abcd", "abce", 4) < 0, 12); /* Nudging limit. */
check (strncmp ("abc", "def", 0) == 0, 13); /* Zero count. */
- check (strncmp ("abc", "", (size_t)-1) > 0, 14); /* set sign bit in count */
+ check (strncmp ("abc", "", (size_t)-1) > 0, 14); /* set sign bit in count */
check (strncmp ("abc", "abc", (size_t)-2) == 0, 15);
}
@@ -407,6 +466,50 @@ test_strncpy (void)
}
static void
+test_strlcpy (void)
+{
+#ifdef __TEST_BSD_FUNCS__
+ /* Testing is a bit different because of odd semantics. */
+ it = "strlcpy";
+ check (strlcpy (one, "abc", sizeof(one)) == 3, 1); /* Returned value. */
+ equal (one, "abc", 2); /* Did the copy go right? */
+
+ (void) strcpy (one, "abcdefgh");
+ (void) strlcpy (one, "xyz", 2);
+ equal (one, "x\0cdefgh", 3); /* Copy cut by count. */
+
+ (void) strcpy (one, "abcdefgh");
+ (void) strlcpy (one, "xyz", 3); /* Copy cut just before NUL. */
+ equal (one, "xy\0defgh", 4);
+
+ (void) strcpy (one, "abcdefgh");
+ (void) strlcpy (one, "xyz", 4); /* Copy just includes NUL. */
+ equal (one, "xyz", 5);
+ equal (one+4, "efgh", 6); /* Wrote too much? */
+
+ (void) strcpy (one, "abcdefgh");
+ (void) strlcpy (one, "xyz", 5); /* Copy includes padding. */
+ equal (one, "xyz", 7);
+ equal (one+3, "", 8);
+ equal (one+4, "efgh", 9);
+
+ (void) strcpy (one, "abc");
+ (void) strlcpy (one, "xyz", 0); /* Zero-length copy. */
+ equal (one, "abc", 10);
+
+ (void) strlcpy (one, "", 2); /* Zero-length source. */
+ equal (one, "", 11);
+ equal (one+1, "bc", 12);
+ equal (one+2, "c", 13);
+
+ (void) strcpy (one, "hi there");
+ (void) strlcpy (two, one, 9);
+ equal (two, "hi there", 14); /* Just paranoia. */
+ equal (one, "hi there", 15); /* Stomped on source? */
+#endif
+}
+
+static void
test_strlen (void)
{
it = "strlen";
@@ -433,7 +536,7 @@ test_strnlen (void)
it = "strnlen";
check (strnlen ("", 10) == 0, 1); /* Empty. */
check (strnlen ("a", 10) == 1, 2); /* Single char. */
- check (strnlen ("abcd", 10) == 4, 3); /* Multiple chars. */
+ check (strnlen ("abcd", 10) == 4, 3); /* Multiple chars. */
check (strnlen ("foo", (size_t)-1) == 3, 4); /* limits of n. */
{
@@ -1325,6 +1428,52 @@ test_strerror (void)
check(strerror(ENOENT) != 0, 3);
}
+static void
+test_strcasecmp (void)
+{
+ it = "strcasecmp";
+ /* Note that the locale is "C". */
+ check(strcasecmp("a", "a") == 0, 1);
+ check(strcasecmp("a", "A") == 0, 2);
+ check(strcasecmp("A", "a") == 0, 3);
+ check(strcasecmp("a", "b") < 0, 4);
+ check(strcasecmp("c", "b") > 0, 5);
+ check(strcasecmp("abc", "AbC") == 0, 6);
+ check(strcasecmp("0123456789", "0123456789") == 0, 7);
+ check(strcasecmp("", "0123456789") < 0, 8);
+ check(strcasecmp("AbC", "") > 0, 9);
+ check(strcasecmp("AbC", "A") > 0, 10);
+ check(strcasecmp("AbC", "Ab") > 0, 11);
+ check(strcasecmp("AbC", "ab") > 0, 12);
+}
+
+static void
+test_strncasecmp (void)
+{
+ it = "strncasecmp";
+ /* Note that the locale is "C". */
+ check(strncasecmp("a", "a", 5) == 0, 1);
+ check(strncasecmp("a", "A", 5) == 0, 2);
+ check(strncasecmp("A", "a", 5) == 0, 3);
+ check(strncasecmp("a", "b", 5) < 0, 4);
+ check(strncasecmp("c", "b", 5) > 0, 5);
+ check(strncasecmp("abc", "AbC", 5) == 0, 6);
+ check(strncasecmp("0123456789", "0123456789", 10) == 0, 7);
+ check(strncasecmp("", "0123456789", 10) < 0, 8);
+ check(strncasecmp("AbC", "", 5) > 0, 9);
+ check(strncasecmp("AbC", "A", 5) > 0, 10);
+ check(strncasecmp("AbC", "Ab", 5) > 0, 11);
+ check(strncasecmp("AbC", "ab", 5) > 0, 12);
+ check(strncasecmp("0123456789", "AbC", 0) == 0, 13);
+ check(strncasecmp("AbC", "abc", 1) == 0, 14);
+ check(strncasecmp("AbC", "abc", 2) == 0, 15);
+ check(strncasecmp("AbC", "abc", 3) == 0, 16);
+ check(strncasecmp("AbC", "abcd", 3) == 0, 17);
+ check(strncasecmp("AbC", "abcd", 4) < 0, 18);
+ check(strncasecmp("ADC", "abcd", 1) == 0, 19);
+ check(strncasecmp("ADC", "abcd", 2) > 0, 20);
+}
+
int
main (void)
{
@@ -1348,12 +1497,18 @@ main (void)
/* strncat. */
test_strncat ();
+ /* strlcat. */
+ test_strlcat ();
+
/* strncmp. */
test_strncmp ();
/* strncpy. */
test_strncpy ();
+ /* strlcpy. */
+ test_strlcpy ();
+
/* strlen. */
test_strlen ();
@@ -1438,6 +1593,11 @@ main (void)
/* strerror - VERY system-dependent. */
test_strerror ();
+ /* strcasecmp. Without locale dependencies. */
+ test_strcasecmp ();
+
+ /* strncasecmp. Without locale dependencies. */
+ test_strncasecmp ();
if (errors == 0)
{
@@ -1447,7 +1607,7 @@ main (void)
else
{
status = EXIT_FAILURE;
- printf("%lu errors.\n", (unsigned long)errors);
+ printf("%Zd errors.\n", errors);
}
return status;
diff --git a/test/string/tst-bswap.c b/test/string/tst-bswap.c
new file mode 100644
index 000000000..b2b4ef08d
--- /dev/null
+++ b/test/string/tst-bswap.c
@@ -0,0 +1,74 @@
+/* Copyright (C) 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <byteswap.h>
+#include <stdio.h>
+
+extern unsigned long long int wash (unsigned long long int a);
+
+int
+main (void)
+{
+ int result = 0;
+
+ /* Test the functions with constant arguments. */
+ if (bswap_16 (0x1234) != 0x3412)
+ {
+ puts ("bswap_16 (constant) flunked");
+ result = 1;
+ }
+ if (bswap_32 (0x12345678) != 0x78563412)
+ {
+ puts ("bswap_32 (constant) flunked");
+ result = 1;
+ }
+ if (bswap_64 (0x1234567890abcdefULL) != 0xefcdab9078563412ULL)
+ {
+ puts ("bswap_64 (constant) flunked");
+ result = 1;
+ }
+
+ /* Test the functions with non-constant arguments. */
+ if (bswap_16 (wash (0x1234)) != 0x3412)
+ {
+ puts ("bswap_16 (non-constant) flunked");
+ result = 1;
+ }
+ if (bswap_32 (wash (0x12345678)) != 0x78563412)
+ {
+ puts ("bswap_32 (non-constant) flunked");
+ result = 1;
+ }
+ if (bswap_64 (wash (0x1234567890abcdefULL)) != 0xefcdab9078563412ULL)
+ {
+ puts ("bswap_64 (non-constant) flunked");
+ result = 1;
+ }
+
+ return result;
+}
+
+
+unsigned long long int
+wash (unsigned long long int a)
+{
+ /* Do nothing. This function simply exists to avoid that the compiler
+ regards the argument to the bswap_*() functions as constant. */
+ return a + 0;
+}
diff --git a/test/string/tst-inlcall.c b/test/string/tst-inlcall.c
new file mode 100644
index 000000000..2a4124ea5
--- /dev/null
+++ b/test/string/tst-inlcall.c
@@ -0,0 +1,83 @@
+/* Tester for calling inline string functions.
+ Copyright (C) 1998, 2000, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
+/* Make sure we test the optimized inline functions. */
+#define __USE_STRING_INLINES 1
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include <fcntl.h>
+
+
+int
+main (void)
+{
+ int status;
+ int errors = 0;
+ char buf1[1000];
+ char *cp;
+ char ch;
+
+ cp = strcpy (buf1, "hello world");
+ if (strcmp ("hello world", cp++) != 0)
+ {
+ puts ("strcmp test 1 failed");
+ ++errors;
+ }
+
+ cp = buf1;
+ if (strcmp (cp++, "hello world") != 0)
+ {
+ puts ("strcmp test 2 failed");
+ ++errors;
+ }
+
+ ch = 'h';
+ if (strchr ("hello world", ch++) == NULL)
+ {
+ puts ("strchr test 1 failed");
+ ++errors;
+ }
+
+ const char * const hw = "hello world";
+ if (strpbrk (hw, "o") - hw != 4)
+ {
+ puts ("strpbrk test 1 failed");
+ ++errors;
+ }
+
+ if (errors == 0)
+ {
+ status = EXIT_SUCCESS;
+ puts ("No errors.");
+ }
+ else
+ {
+ status = EXIT_FAILURE;
+ printf ("%d errors.\n", errors);
+ }
+ return status;
+}
diff --git a/test/string/tst-strlen.c b/test/string/tst-strlen.c
new file mode 100644
index 000000000..a1e115927
--- /dev/null
+++ b/test/string/tst-strlen.c
@@ -0,0 +1,45 @@
+/* Make sure we don't test the optimized inline functions if we want to
+ test the real implementation. */
+#undef __USE_STRING_INLINES
+
+#include <stdio.h>
+#include <string.h>
+
+int
+main(int argc, char *argv[])
+{
+ static const size_t lens[] = { 0, 1, 0, 2, 0, 1, 0, 3,
+ 0, 1, 0, 2, 0, 1, 0, 4 };
+ char basebuf[24 + 32];
+ size_t base;
+
+ for (base = 0; base < 32; ++base)
+ {
+ char *buf = basebuf + base;
+ size_t words;
+
+ for (words = 0; words < 4; ++words)
+ {
+ size_t last;
+ memset (buf, 'a', words * 4);
+
+ for (last = 0; last < 16; ++last)
+ {
+ buf[words * 4 + 0] = (last & 1) != 0 ? 'b' : '\0';
+ buf[words * 4 + 1] = (last & 2) != 0 ? 'c' : '\0';
+ buf[words * 4 + 2] = (last & 4) != 0 ? 'd' : '\0';
+ buf[words * 4 + 3] = (last & 8) != 0 ? 'e' : '\0';
+ buf[words * 4 + 4] = '\0';
+
+ if (strlen (buf) != words * 4 + lens[last]
+ || strnlen (buf, -1) != words * 4 + lens[last])
+ {
+ printf ("failed for base=%Zu, words=%Zu, and last=%Zu\n",
+ base, words, last);
+ return 1;
+ }
+ }
+ }
+ }
+ return 0;
+}
diff --git a/test/string/tst-strtok.c b/test/string/tst-strtok.c
new file mode 100644
index 000000000..7e34aeefa
--- /dev/null
+++ b/test/string/tst-strtok.c
@@ -0,0 +1,23 @@
+/* Testcase for strtok reported by Andrew Church <achurch@achurch.org>. */
+#include <stdio.h>
+#include <string.h>
+
+int
+main (void)
+{
+ char buf[1] = { 0 };
+ int result = 0;
+
+ if (strtok (buf, " ") != NULL)
+ {
+ puts ("first strtok call did not return NULL");
+ result = 1;
+ }
+ else if (strtok (NULL, " ") != NULL)
+ {
+ puts ("second strtok call did not return NULL");
+ result = 1;
+ }
+
+ return result;
+}
diff --git a/test/string/tst-strxfrm.c b/test/string/tst-strxfrm.c
new file mode 100644
index 000000000..ff1b396be
--- /dev/null
+++ b/test/string/tst-strxfrm.c
@@ -0,0 +1,80 @@
+/* Based on a test case by Paul Eggert. */
+#include <features.h>
+#ifdef __UCLIBC_HAS_XLOCALE__
+#include <locale.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+
+char const string[] = "";
+
+
+static int
+test (const char *locale)
+{
+ size_t bufsize;
+ size_t r;
+ size_t l;
+ char *buf;
+ locale_t loc;
+ int result = 0;
+
+ if (setlocale (LC_COLLATE, locale) == NULL)
+ {
+ printf ("cannot set locale \"%s\"\n", locale);
+ return 1;
+ }
+ bufsize = strxfrm (NULL, string, 0) + 1;
+ buf = malloc (bufsize);
+ if (buf == NULL)
+ {
+ printf ("cannot allocate %zd bytes\n", bufsize);
+ return 1;
+ }
+ r = strxfrm (buf, string, bufsize);
+ l = strlen (buf);
+ if (r != l)
+ {
+ printf ("locale \"%s\": strxfrm returned %zu, strlen returned %zu\n",
+ locale, r, l);
+ result = 1;
+ }
+
+ loc = newlocale (1 << LC_ALL, locale, NULL);
+
+ r = strxfrm_l (buf, string, bufsize, loc);
+ l = strlen (buf);
+ if (r != l)
+ {
+ printf ("locale \"%s\": strxfrm_l returned %zu, strlen returned %zu\n",
+ locale, r, l);
+ result = 1;
+ }
+
+ freelocale (loc);
+
+ free (buf);
+
+ return result;
+}
+
+
+int
+main (void)
+{
+ int result = 0;
+
+ result |= test ("C");
+ result |= test ("en_US.ISO-8859-1");
+ result |= test ("de_DE.UTF-8");
+
+ return result;
+}
+
+#else
+int main(void)
+{
+ return 0;
+}
+#endif