mirror of git://sourceware.org/git/glibc.git
* string/test-strchr.c (stupid_strchr): New function.
(do_random_tests): Make sure the string is zero terminated. * string/test-strpbrk.c (stupid_strpbrk): New function. (do_random_tests): Make sure the string is zero terminated. * string/test-strcmp.c (stupid_strcmp): New function. (do_random_tests): Make sure the strings are zero terminated. * string/test-strspn.c (stupid_strspn): New function. (simple_strspn): Rename rej argument to acc. (do_random_tests): Make sure the string is zero terminated. * string/test-strcspn.c (stupid_strcspn): New function. * string/test-strncpy.c (stupid_strncpy): New function. * string/test-stpncpy.c (stupid_stpncpy): New function. * string/test-strncmp.c (stupid_strncmp): New function. (do_random_tests): Make sure the strings are zero terminated. * string/test-string.h (impl_t): Change test into long. (IMPL): Add __attribute__((aligned (sizeof (void *)))).
This commit is contained in:
parent
e0bc9a8d13
commit
e8c1660f7b
22
ChangeLog
22
ChangeLog
|
@ -1,3 +1,22 @@
|
||||||
|
2002-11-08 Jakub Jelinek <jakub@redhat.com>
|
||||||
|
|
||||||
|
* string/test-strchr.c (stupid_strchr): New function.
|
||||||
|
(do_random_tests): Make sure the string is zero terminated.
|
||||||
|
* string/test-strpbrk.c (stupid_strpbrk): New function.
|
||||||
|
(do_random_tests): Make sure the string is zero terminated.
|
||||||
|
* string/test-strcmp.c (stupid_strcmp): New function.
|
||||||
|
(do_random_tests): Make sure the strings are zero terminated.
|
||||||
|
* string/test-strspn.c (stupid_strspn): New function.
|
||||||
|
(simple_strspn): Rename rej argument to acc.
|
||||||
|
(do_random_tests): Make sure the string is zero terminated.
|
||||||
|
* string/test-strcspn.c (stupid_strcspn): New function.
|
||||||
|
* string/test-strncpy.c (stupid_strncpy): New function.
|
||||||
|
* string/test-stpncpy.c (stupid_stpncpy): New function.
|
||||||
|
* string/test-strncmp.c (stupid_strncmp): New function.
|
||||||
|
(do_random_tests): Make sure the strings are zero terminated.
|
||||||
|
* string/test-string.h (impl_t): Change test into long.
|
||||||
|
(IMPL): Add __attribute__((aligned (sizeof (void *)))).
|
||||||
|
|
||||||
2002-11-08 Roland McGrath <roland@redhat.com>
|
2002-11-08 Roland McGrath <roland@redhat.com>
|
||||||
|
|
||||||
* sysdeps/ia64/elf/configure.in: Add TLS check.
|
* sysdeps/ia64/elf/configure.in: Add TLS check.
|
||||||
|
@ -11,9 +30,6 @@
|
||||||
[_LIBC] (_IO_do_write): Define as macro for _IO_new_do_write and
|
[_LIBC] (_IO_do_write): Define as macro for _IO_new_do_write and
|
||||||
#undef before versioned_symbol use.
|
#undef before versioned_symbol use.
|
||||||
|
|
||||||
* string/test-string.h (test_init): Fill BUF1 and BUF2 with nonzero
|
|
||||||
characters.
|
|
||||||
|
|
||||||
2002-11-07 Richard Henderson <rth@redhat.com>
|
2002-11-07 Richard Henderson <rth@redhat.com>
|
||||||
|
|
||||||
* configure.in (ASM_ALPHA_NG_SYMBOL_PREFIX): Remove test.
|
* configure.in (ASM_ALPHA_NG_SYMBOL_PREFIX): Remove test.
|
||||||
|
|
|
@ -23,7 +23,9 @@
|
||||||
#include "test-string.h"
|
#include "test-string.h"
|
||||||
|
|
||||||
char *simple_stpncpy (char *, const char *, size_t);
|
char *simple_stpncpy (char *, const char *, size_t);
|
||||||
|
char *stupid_stpncpy (char *, const char *, size_t);
|
||||||
|
|
||||||
|
IMPL (stupid_stpncpy, 0)
|
||||||
IMPL (simple_stpncpy, 0)
|
IMPL (simple_stpncpy, 0)
|
||||||
IMPL (stpncpy, 1)
|
IMPL (stpncpy, 1)
|
||||||
|
|
||||||
|
@ -42,4 +44,17 @@ simple_stpncpy (char *dst, const char *src, size_t n)
|
||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
stupid_stpncpy (char *dst, const char *src, size_t n)
|
||||||
|
{
|
||||||
|
size_t ns = strlen (src);
|
||||||
|
size_t i, nc = n < ns ? n : ns;
|
||||||
|
|
||||||
|
for (i = 0; i < nc; ++i)
|
||||||
|
dst[i] = src[i];
|
||||||
|
for (; i < n; ++i)
|
||||||
|
dst[i] = '\0';
|
||||||
|
return dst + nc;
|
||||||
|
}
|
||||||
|
|
||||||
#include "test-strncpy.c"
|
#include "test-strncpy.c"
|
||||||
|
|
|
@ -23,7 +23,9 @@
|
||||||
|
|
||||||
typedef char *(*proto_t) (const char *, int);
|
typedef char *(*proto_t) (const char *, int);
|
||||||
char *simple_strchr (const char *, int);
|
char *simple_strchr (const char *, int);
|
||||||
|
char *stupid_strchr (const char *, int);
|
||||||
|
|
||||||
|
IMPL (stupid_strchr, 0)
|
||||||
IMPL (simple_strchr, 0)
|
IMPL (simple_strchr, 0)
|
||||||
IMPL (strchr, 1)
|
IMPL (strchr, 1)
|
||||||
|
|
||||||
|
@ -36,6 +38,17 @@ simple_strchr (const char *s, int c)
|
||||||
return (char *) s;
|
return (char *) s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
stupid_strchr (const char *s, int c)
|
||||||
|
{
|
||||||
|
size_t n = strlen (s) + 1;
|
||||||
|
|
||||||
|
while (n--)
|
||||||
|
if (*s++ == (char) c)
|
||||||
|
return (char *) s - 1;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
do_one_test (impl_t *impl, const char *s, int c, char *exp_res)
|
do_one_test (impl_t *impl, const char *s, int c, char *exp_res)
|
||||||
{
|
{
|
||||||
|
@ -115,15 +128,18 @@ do_random_tests (void)
|
||||||
{
|
{
|
||||||
align = random () & 15;
|
align = random () & 15;
|
||||||
pos = random () & 511;
|
pos = random () & 511;
|
||||||
|
seek_char = random () & 255;
|
||||||
if (pos + align >= 511)
|
if (pos + align >= 511)
|
||||||
pos = 510 - align - (random () & 7);
|
pos = 510 - align - (random () & 7);
|
||||||
len = random () & 511;
|
len = random () & 511;
|
||||||
if (pos >= len)
|
if ((pos == len && seek_char)
|
||||||
len = pos + (random () & 7);
|
|| (pos > len && (random () & 1)))
|
||||||
|
len = pos + 1 + (random () & 7);
|
||||||
if (len + align >= 512)
|
if (len + align >= 512)
|
||||||
len = 511 - align - (random () & 7);
|
len = 511 - align - (random () & 7);
|
||||||
seek_char = random () & 255;
|
if (pos == len && seek_char)
|
||||||
j = len + align + 64;
|
len = pos + 1;
|
||||||
|
j = (pos > len ? pos : len) + align + 64;
|
||||||
if (j > 512)
|
if (j > 512)
|
||||||
j = 512;
|
j = 512;
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,9 @@
|
||||||
|
|
||||||
typedef int (*proto_t) (const char *, const char *);
|
typedef int (*proto_t) (const char *, const char *);
|
||||||
int simple_strcmp (const char *, const char *);
|
int simple_strcmp (const char *, const char *);
|
||||||
|
int stupid_strcmp (const char *, const char *);
|
||||||
|
|
||||||
|
IMPL (stupid_strcmp, 0)
|
||||||
IMPL (simple_strcmp, 0)
|
IMPL (simple_strcmp, 0)
|
||||||
IMPL (strcmp, 1)
|
IMPL (strcmp, 1)
|
||||||
|
|
||||||
|
@ -37,6 +39,19 @@ simple_strcmp (const char *s1, const char *s2)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
stupid_strcmp (const char *s1, const char *s2)
|
||||||
|
{
|
||||||
|
size_t ns1 = strlen (s1) + 1, ns2 = strlen (s2) + 1;
|
||||||
|
size_t n = ns1 < ns2 ? ns1 : ns2;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
while (n--)
|
||||||
|
if ((ret = *(unsigned char *) s1++ - *(unsigned char *) s2++) != 0)
|
||||||
|
break;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
do_one_test (impl_t *impl, const char *s1, const char *s2, int exp_result)
|
do_one_test (impl_t *impl, const char *s1, const char *s2, int exp_result)
|
||||||
{
|
{
|
||||||
|
@ -110,7 +125,7 @@ do_test (size_t align1, size_t align2, size_t len, int max_char,
|
||||||
static void
|
static void
|
||||||
do_random_tests (void)
|
do_random_tests (void)
|
||||||
{
|
{
|
||||||
size_t i, j, n, align1, align2, pos, len;
|
size_t i, j, n, align1, align2, pos, len1, len2;
|
||||||
int result, r;
|
int result, r;
|
||||||
unsigned char *p1 = buf1 + page_size - 512;
|
unsigned char *p1 = buf1 + page_size - 512;
|
||||||
unsigned char *p2 = buf2 + page_size - 512;
|
unsigned char *p2 = buf2 + page_size - 512;
|
||||||
|
@ -123,22 +138,25 @@ do_random_tests (void)
|
||||||
else
|
else
|
||||||
align2 = align1 + (random () & 24);
|
align2 = align1 + (random () & 24);
|
||||||
pos = random () & 511;
|
pos = random () & 511;
|
||||||
j = align1;
|
j = align1 > align2 ? align1 : align2;
|
||||||
if (align2 > j)
|
|
||||||
j = align2;
|
|
||||||
if (pos + j >= 511)
|
if (pos + j >= 511)
|
||||||
pos = 510 - j - (random () & 7);
|
pos = 510 - j - (random () & 7);
|
||||||
len = random () & 511;
|
len1 = random () & 511;
|
||||||
if (pos >= len)
|
if (pos >= len1 && (random () & 1))
|
||||||
len = pos + (random () & 7);
|
len1 = pos + (random () & 7);
|
||||||
if (len + j >= 512)
|
if (len1 + j >= 512)
|
||||||
len = 511 - j - (random () & 7);
|
len1 = 511 - j - (random () & 7);
|
||||||
j = len + align1 + 64;
|
if (pos >= len1)
|
||||||
if (j > 512) j = 512;
|
len2 = len1;
|
||||||
|
else
|
||||||
|
len2 = len1 + (len1 != 511 - j ? random () % (511 - j - len1) : 0);
|
||||||
|
j = (pos > len2 ? pos : len2) + align1 + 64;
|
||||||
|
if (j > 512)
|
||||||
|
j = 512;
|
||||||
for (i = 0; i < j; ++i)
|
for (i = 0; i < j; ++i)
|
||||||
{
|
{
|
||||||
p1[i] = random () & 255;
|
p1[i] = random () & 255;
|
||||||
if (i < len + align1 && !p1[i])
|
if (i < len1 + align1 && !p1[i])
|
||||||
{
|
{
|
||||||
p1[i] = random () & 255;
|
p1[i] = random () & 255;
|
||||||
if (!p1[i])
|
if (!p1[i])
|
||||||
|
@ -148,7 +166,7 @@ do_random_tests (void)
|
||||||
for (i = 0; i < j; ++i)
|
for (i = 0; i < j; ++i)
|
||||||
{
|
{
|
||||||
p2[i] = random () & 255;
|
p2[i] = random () & 255;
|
||||||
if (i < len + align2 && !p2[i])
|
if (i < len2 + align2 && !p2[i])
|
||||||
{
|
{
|
||||||
p2[i] = random () & 255;
|
p2[i] = random () & 255;
|
||||||
if (!p2[i])
|
if (!p2[i])
|
||||||
|
@ -158,12 +176,7 @@ do_random_tests (void)
|
||||||
|
|
||||||
result = 0;
|
result = 0;
|
||||||
memcpy (p2 + align2, p1 + align1, pos);
|
memcpy (p2 + align2, p1 + align1, pos);
|
||||||
if (pos >= len)
|
if (pos < len1)
|
||||||
{
|
|
||||||
p1[len + align1] = 0;
|
|
||||||
p2[len + align2] = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
if (p2[align2 + pos] == p1[align1 + pos])
|
if (p2[align2 + pos] == p1[align1 + pos])
|
||||||
{
|
{
|
||||||
|
@ -177,6 +190,8 @@ do_random_tests (void)
|
||||||
else
|
else
|
||||||
result = 1;
|
result = 1;
|
||||||
}
|
}
|
||||||
|
p1[len1 + align1] = 0;
|
||||||
|
p2[len2 + align2] = 0;
|
||||||
|
|
||||||
FOR_EACH_IMPL (impl, 1)
|
FOR_EACH_IMPL (impl, 1)
|
||||||
{
|
{
|
||||||
|
@ -185,8 +200,8 @@ do_random_tests (void)
|
||||||
|| (r < 0 && result >= 0)
|
|| (r < 0 && result >= 0)
|
||||||
|| (r > 0 && result <= 0))
|
|| (r > 0 && result <= 0))
|
||||||
{
|
{
|
||||||
error (0, 0, "Iteration %zd - wrong result in function %s (%zd, %zd, %zd, %zd) %d != %d, p1 %p p2 %p",
|
error (0, 0, "Iteration %zd - wrong result in function %s (%zd, %zd, %zd, %zd, %zd) %d != %d, p1 %p p2 %p",
|
||||||
n, impl->name, align1, align2, len, pos, r, result, p1, p2);
|
n, impl->name, align1, align2, len1, len2, pos, r, result, p1, p2);
|
||||||
ret = 1;
|
ret = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,9 @@
|
||||||
|
|
||||||
typedef size_t (*proto_t) (const char *, const char *);
|
typedef size_t (*proto_t) (const char *, const char *);
|
||||||
size_t simple_strcspn (const char *, const char *);
|
size_t simple_strcspn (const char *, const char *);
|
||||||
|
size_t stupid_strcspn (const char *, const char *);
|
||||||
|
|
||||||
|
IMPL (stupid_strcspn, 0)
|
||||||
IMPL (simple_strcspn, 0)
|
IMPL (simple_strcspn, 0)
|
||||||
IMPL (strcspn, 1)
|
IMPL (strcspn, 1)
|
||||||
|
|
||||||
|
@ -34,7 +36,7 @@ simple_strcspn (const char *s, const char *rej)
|
||||||
{
|
{
|
||||||
const char *r, *str = s;
|
const char *r, *str = s;
|
||||||
char c;
|
char c;
|
||||||
|
|
||||||
while ((c = *s++) != '\0')
|
while ((c = *s++) != '\0')
|
||||||
for (r = rej; *r != '\0'; ++r)
|
for (r = rej; *r != '\0'; ++r)
|
||||||
if (*r == c)
|
if (*r == c)
|
||||||
|
@ -42,4 +44,17 @@ simple_strcspn (const char *s, const char *rej)
|
||||||
return s - str - 1;
|
return s - str - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t
|
||||||
|
stupid_strcspn (const char *s, const char *rej)
|
||||||
|
{
|
||||||
|
size_t ns = strlen (s), nrej = strlen (rej);
|
||||||
|
size_t i, j;
|
||||||
|
|
||||||
|
for (i = 0; i < ns; ++i)
|
||||||
|
for (j = 0; j < nrej; ++j)
|
||||||
|
if (s[i] == rej[j])
|
||||||
|
return i;
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
#include "test-strpbrk.c"
|
#include "test-strpbrk.c"
|
||||||
|
|
|
@ -22,13 +22,13 @@ typedef struct
|
||||||
{
|
{
|
||||||
const char *name;
|
const char *name;
|
||||||
void (*fn) (void);
|
void (*fn) (void);
|
||||||
int test;
|
long test;
|
||||||
} impl_t;
|
} impl_t;
|
||||||
extern impl_t __start_impls[], __stop_impls[];
|
extern impl_t __start_impls[], __stop_impls[];
|
||||||
|
|
||||||
#define IMPL(name, test) \
|
#define IMPL(name, test) \
|
||||||
impl_t tst_ ## name \
|
impl_t tst_ ## name \
|
||||||
__attribute__ ((section ("impls"))) \
|
__attribute__ ((section ("impls"), aligned (sizeof (void *)))) \
|
||||||
= { #name, (void (*) (void))name, test };
|
= { #name, (void (*) (void))name, test };
|
||||||
|
|
||||||
#ifdef TEST_MAIN
|
#ifdef TEST_MAIN
|
||||||
|
|
|
@ -23,7 +23,9 @@
|
||||||
|
|
||||||
typedef int (*proto_t) (const char *, const char *, size_t);
|
typedef int (*proto_t) (const char *, const char *, size_t);
|
||||||
int simple_strncmp (const char *, const char *, size_t);
|
int simple_strncmp (const char *, const char *, size_t);
|
||||||
|
int stupid_strncmp (const char *, const char *, size_t);
|
||||||
|
|
||||||
|
IMPL (stupid_strncmp, 0)
|
||||||
IMPL (simple_strncmp, 0)
|
IMPL (simple_strncmp, 0)
|
||||||
IMPL (strncmp, 1)
|
IMPL (strncmp, 1)
|
||||||
|
|
||||||
|
@ -37,6 +39,18 @@ simple_strncmp (const char *s1, const char *s2, size_t n)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
stupid_strncmp (const char *s1, const char *s2, size_t n)
|
||||||
|
{
|
||||||
|
size_t ns1 = strlen (s1) + 1, ns2 = strlen (s2) + 1;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
n = ns1 < n ? ns1 : n;
|
||||||
|
n = ns2 < n ? ns2 : n;
|
||||||
|
while (n-- && (ret = *(unsigned char *) s1++ - * (unsigned char *) s2++) == 0);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
do_one_test (impl_t *impl, const char *s1, const char *s2, size_t n,
|
do_one_test (impl_t *impl, const char *s1, const char *s2, size_t n,
|
||||||
int exp_result)
|
int exp_result)
|
||||||
|
@ -117,7 +131,7 @@ do_test (size_t align1, size_t align2, size_t len, size_t n, int max_char,
|
||||||
static void
|
static void
|
||||||
do_random_tests (void)
|
do_random_tests (void)
|
||||||
{
|
{
|
||||||
size_t i, j, n, align1, align2, pos, len, size;
|
size_t i, j, n, align1, align2, pos, len1, len2, size;
|
||||||
int result, r;
|
int result, r;
|
||||||
unsigned char *p1 = buf1 + page_size - 512;
|
unsigned char *p1 = buf1 + page_size - 512;
|
||||||
unsigned char *p2 = buf2 + page_size - 512;
|
unsigned char *p2 = buf2 + page_size - 512;
|
||||||
|
@ -131,22 +145,25 @@ do_random_tests (void)
|
||||||
align2 = align1 + (random () & 24);
|
align2 = align1 + (random () & 24);
|
||||||
pos = random () & 511;
|
pos = random () & 511;
|
||||||
size = random () & 511;
|
size = random () & 511;
|
||||||
j = align1;
|
j = align1 > align2 ? align1 : align2;
|
||||||
if (align2 > j)
|
|
||||||
j = align2;
|
|
||||||
if (pos + j >= 511)
|
if (pos + j >= 511)
|
||||||
pos = 510 - j - (random () & 7);
|
pos = 510 - j - (random () & 7);
|
||||||
len = random () & 511;
|
len1 = random () & 511;
|
||||||
if (pos >= len)
|
if (pos >= len1 && (random () & 1))
|
||||||
len = pos + (random () & 7);
|
len1 = pos + (random () & 7);
|
||||||
if (len + j >= 512)
|
if (len1 + j >= 512)
|
||||||
len = 511 - j - (random () & 7);
|
len1 = 511 - j - (random () & 7);
|
||||||
j = len + align1 + 64;
|
if (pos >= len1)
|
||||||
if (j > 512) j = 512;
|
len2 = len1;
|
||||||
|
else
|
||||||
|
len2 = len1 + (len1 != 511 - j ? random () % (511 - j - len1) : 0);
|
||||||
|
j = (pos > len2 ? pos : len2) + align1 + 64;
|
||||||
|
if (j > 512)
|
||||||
|
j = 512;
|
||||||
for (i = 0; i < j; ++i)
|
for (i = 0; i < j; ++i)
|
||||||
{
|
{
|
||||||
p1[i] = random () & 255;
|
p1[i] = random () & 255;
|
||||||
if (i < len + align1 && !p1[i])
|
if (i < len1 + align1 && !p1[i])
|
||||||
{
|
{
|
||||||
p1[i] = random () & 255;
|
p1[i] = random () & 255;
|
||||||
if (!p1[i])
|
if (!p1[i])
|
||||||
|
@ -156,7 +173,7 @@ do_random_tests (void)
|
||||||
for (i = 0; i < j; ++i)
|
for (i = 0; i < j; ++i)
|
||||||
{
|
{
|
||||||
p2[i] = random () & 255;
|
p2[i] = random () & 255;
|
||||||
if (i < len + align2 && !p2[i])
|
if (i < len2 + align2 && !p2[i])
|
||||||
{
|
{
|
||||||
p2[i] = random () & 255;
|
p2[i] = random () & 255;
|
||||||
if (!p2[i])
|
if (!p2[i])
|
||||||
|
@ -166,12 +183,7 @@ do_random_tests (void)
|
||||||
|
|
||||||
result = 0;
|
result = 0;
|
||||||
memcpy (p2 + align2, p1 + align1, pos);
|
memcpy (p2 + align2, p1 + align1, pos);
|
||||||
if (pos >= len)
|
if (pos < len1)
|
||||||
{
|
|
||||||
p1[len + align1] = 0;
|
|
||||||
p2[len + align2] = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
if (p2[align2 + pos] == p1[align1 + pos])
|
if (p2[align2 + pos] == p1[align1 + pos])
|
||||||
{
|
{
|
||||||
|
@ -188,6 +200,8 @@ do_random_tests (void)
|
||||||
result = 1;
|
result = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
p1[len1 + align1] = 0;
|
||||||
|
p2[len2 + align2] = 0;
|
||||||
|
|
||||||
FOR_EACH_IMPL (impl, 1)
|
FOR_EACH_IMPL (impl, 1)
|
||||||
{
|
{
|
||||||
|
@ -196,8 +210,8 @@ do_random_tests (void)
|
||||||
|| (r < 0 && result >= 0)
|
|| (r < 0 && result >= 0)
|
||||||
|| (r > 0 && result <= 0))
|
|| (r > 0 && result <= 0))
|
||||||
{
|
{
|
||||||
error (0, 0, "Iteration %zd - wrong result in function %s (%zd, %zd, %zd, %zd, %zd) %d != %d, p1 %p p2 %p",
|
error (0, 0, "Iteration %zd - wrong result in function %s (%zd, %zd, %zd, %zd, %zd, %zd) %d != %d, p1 %p p2 %p",
|
||||||
n, impl->name, align1, align2, len, pos, size, r, result, p1, p2);
|
n, impl->name, align1, align2, len1, len2, pos, size, r, result, p1, p2);
|
||||||
ret = 1;
|
ret = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,9 @@
|
||||||
# include "test-string.h"
|
# include "test-string.h"
|
||||||
|
|
||||||
char *simple_strncpy (char *, const char *, size_t);
|
char *simple_strncpy (char *, const char *, size_t);
|
||||||
|
char *stupid_strncpy (char *, const char *, size_t);
|
||||||
|
|
||||||
|
IMPL (stupid_strncpy, 0)
|
||||||
IMPL (simple_strncpy, 0)
|
IMPL (simple_strncpy, 0)
|
||||||
IMPL (strncpy, 1)
|
IMPL (strncpy, 1)
|
||||||
|
|
||||||
|
@ -41,6 +43,19 @@ simple_strncpy (char *dst, const char *src, size_t n)
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
stupid_strncpy (char *dst, const char *src, size_t n)
|
||||||
|
{
|
||||||
|
size_t ns = strlen (src);
|
||||||
|
size_t i, nc = n < ns ? n : ns;
|
||||||
|
|
||||||
|
for (i = 0; i < nc; ++i)
|
||||||
|
dst[i] = src[i];
|
||||||
|
for (; i < n; ++i)
|
||||||
|
dst[i] = '\0';
|
||||||
|
return dst;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef char *(*proto_t) (char *, const char *, size_t);
|
typedef char *(*proto_t) (char *, const char *, size_t);
|
||||||
|
|
|
@ -26,7 +26,9 @@
|
||||||
|
|
||||||
typedef char *(*proto_t) (const char *, const char *);
|
typedef char *(*proto_t) (const char *, const char *);
|
||||||
char *simple_strpbrk (const char *, const char *);
|
char *simple_strpbrk (const char *, const char *);
|
||||||
|
char *stupid_strpbrk (const char *, const char *);
|
||||||
|
|
||||||
|
IMPL (stupid_strpbrk, 0)
|
||||||
IMPL (simple_strpbrk, 0)
|
IMPL (simple_strpbrk, 0)
|
||||||
IMPL (strpbrk, 1)
|
IMPL (strpbrk, 1)
|
||||||
|
|
||||||
|
@ -42,6 +44,19 @@ simple_strpbrk (const char *s, const char *rej)
|
||||||
return (char *) s - 1;
|
return (char *) s - 1;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
stupid_strpbrk (const char *s, const char *rej)
|
||||||
|
{
|
||||||
|
size_t ns = strlen (s), nrej = strlen (rej);
|
||||||
|
size_t i, j;
|
||||||
|
|
||||||
|
for (i = 0; i < ns; ++i)
|
||||||
|
for (j = 0; j < nrej; ++j)
|
||||||
|
if (s[i] == rej[j])
|
||||||
|
return (char *) s + i;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -127,7 +142,7 @@ do_test (size_t align, size_t pos, size_t len)
|
||||||
static void
|
static void
|
||||||
do_random_tests (void)
|
do_random_tests (void)
|
||||||
{
|
{
|
||||||
size_t i, j, n, align, pos, len;
|
size_t i, j, n, align, pos, len, rlen;
|
||||||
RES_TYPE result;
|
RES_TYPE result;
|
||||||
int c;
|
int c;
|
||||||
unsigned char *p = buf1 + page_size - 512;
|
unsigned char *p = buf1 + page_size - 512;
|
||||||
|
@ -139,12 +154,17 @@ do_random_tests (void)
|
||||||
pos = random () & 511;
|
pos = random () & 511;
|
||||||
if (pos + align >= 511)
|
if (pos + align >= 511)
|
||||||
pos = 510 - align - (random () & 7);
|
pos = 510 - align - (random () & 7);
|
||||||
|
len = random () & 511;
|
||||||
|
if (pos >= len && (random () & 1))
|
||||||
|
len = pos + 1 + (random () & 7);
|
||||||
|
if (len + align >= 512)
|
||||||
|
len = 511 - align - (random () & 7);
|
||||||
if (random () & 1)
|
if (random () & 1)
|
||||||
len = random () & 63;
|
rlen = random () & 63;
|
||||||
else
|
else
|
||||||
len = random () & 15;
|
rlen = random () & 15;
|
||||||
rej = buf2 + page_size - len - 1 - (random () & 7);
|
rej = buf2 + page_size - rlen - 1 - (random () & 7);
|
||||||
for (i = 0; i < len; ++i)
|
for (i = 0; i < rlen; ++i)
|
||||||
{
|
{
|
||||||
rej[i] = random () & 255;
|
rej[i] = random () & 255;
|
||||||
if (!rej[i])
|
if (!rej[i])
|
||||||
|
@ -156,14 +176,16 @@ do_random_tests (void)
|
||||||
for (c = 1; c <= 255; ++c)
|
for (c = 1; c <= 255; ++c)
|
||||||
if (strchr (rej, c) == NULL)
|
if (strchr (rej, c) == NULL)
|
||||||
break;
|
break;
|
||||||
j = pos + align + 64;
|
j = (pos > len ? pos : len) + align + 64;
|
||||||
if (j > 512)
|
if (j > 512)
|
||||||
j = 512;
|
j = 512;
|
||||||
|
|
||||||
for (i = 0; i < j; i++)
|
for (i = 0; i < j; i++)
|
||||||
{
|
{
|
||||||
if (i == pos + align)
|
if (i == len + align)
|
||||||
p[i] = rej[random () % (len + 1)];
|
p[i] = '\0';
|
||||||
|
else if (i == pos + align)
|
||||||
|
p[i] = rej[random () % (rlen + 1)];
|
||||||
else if (i < align || i > pos + align)
|
else if (i < align || i > pos + align)
|
||||||
p[i] = random () & 255;
|
p[i] = random () & 255;
|
||||||
else
|
else
|
||||||
|
@ -178,13 +200,13 @@ do_random_tests (void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result = STRPBRK_RESULT (p + align, pos);
|
result = STRPBRK_RESULT (p + align, pos < len ? pos : len);
|
||||||
|
|
||||||
FOR_EACH_IMPL (impl, 1)
|
FOR_EACH_IMPL (impl, 1)
|
||||||
if (CALL (impl, p + align, rej) != result)
|
if (CALL (impl, p + align, rej) != result)
|
||||||
{
|
{
|
||||||
error (0, 0, "Iteration %zd - wrong result in function %s (%zd, %p, %zd, %zd) %p != %p",
|
error (0, 0, "Iteration %zd - wrong result in function %s (%zd, %p, %zd, %zd, %zd) %p != %p",
|
||||||
n, impl->name, align, rej, len, pos,
|
n, impl->name, align, rej, rlen, pos, len,
|
||||||
(void *) CALL (impl, p + align, rej), (void *) result);
|
(void *) CALL (impl, p + align, rej), (void *) result);
|
||||||
ret = 1;
|
ret = 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,19 +23,21 @@
|
||||||
|
|
||||||
typedef size_t (*proto_t) (const char *, const char *);
|
typedef size_t (*proto_t) (const char *, const char *);
|
||||||
size_t simple_strspn (const char *, const char *);
|
size_t simple_strspn (const char *, const char *);
|
||||||
|
size_t stupid_strspn (const char *, const char *);
|
||||||
|
|
||||||
|
IMPL (stupid_strspn, 0)
|
||||||
IMPL (simple_strspn, 0)
|
IMPL (simple_strspn, 0)
|
||||||
IMPL (strspn, 1)
|
IMPL (strspn, 1)
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
simple_strspn (const char *s, const char *rej)
|
simple_strspn (const char *s, const char *acc)
|
||||||
{
|
{
|
||||||
const char *r, *str = s;
|
const char *r, *str = s;
|
||||||
char c;
|
char c;
|
||||||
|
|
||||||
while ((c = *s++) != '\0')
|
while ((c = *s++) != '\0')
|
||||||
{
|
{
|
||||||
for (r = rej; *r != '\0'; ++r)
|
for (r = acc; *r != '\0'; ++r)
|
||||||
if (*r == c)
|
if (*r == c)
|
||||||
break;
|
break;
|
||||||
if (*r == '\0')
|
if (*r == '\0')
|
||||||
|
@ -44,6 +46,23 @@ simple_strspn (const char *s, const char *rej)
|
||||||
return s - str - 1;
|
return s - str - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t
|
||||||
|
stupid_strspn (const char *s, const char *acc)
|
||||||
|
{
|
||||||
|
size_t ns = strlen (s), nacc = strlen (acc);
|
||||||
|
size_t i, j;
|
||||||
|
|
||||||
|
for (i = 0; i < ns; ++i)
|
||||||
|
{
|
||||||
|
for (j = 0; j < nacc; ++j)
|
||||||
|
if (s[i] == acc[j])
|
||||||
|
break;
|
||||||
|
if (j == nacc)
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
do_one_test (impl_t *impl, const char *s, const char *acc, size_t exp_res)
|
do_one_test (impl_t *impl, const char *s, const char *acc, size_t exp_res)
|
||||||
{
|
{
|
||||||
|
@ -115,7 +134,7 @@ do_test (size_t align, size_t pos, size_t len)
|
||||||
static void
|
static void
|
||||||
do_random_tests (void)
|
do_random_tests (void)
|
||||||
{
|
{
|
||||||
size_t i, j, n, align, pos, len;
|
size_t i, j, n, align, pos, alen, len;
|
||||||
unsigned char *p = buf1 + page_size - 512;
|
unsigned char *p = buf1 + page_size - 512;
|
||||||
unsigned char *acc;
|
unsigned char *acc;
|
||||||
|
|
||||||
|
@ -123,17 +142,20 @@ do_random_tests (void)
|
||||||
{
|
{
|
||||||
align = random () & 15;
|
align = random () & 15;
|
||||||
if (random () & 1)
|
if (random () & 1)
|
||||||
len = random () & 63;
|
alen = random () & 63;
|
||||||
else
|
else
|
||||||
len = random () & 15;
|
alen = random () & 15;
|
||||||
if (!len)
|
if (!alen)
|
||||||
pos = 0;
|
pos = 0;
|
||||||
else
|
else
|
||||||
pos = random () & 511;
|
pos = random () & 511;
|
||||||
if (pos + align >= 511)
|
if (pos + align >= 511)
|
||||||
pos = 510 - align - (random () & 7);
|
pos = 510 - align - (random () & 7);
|
||||||
acc = buf2 + page_size - len - 1 - (random () & 7);
|
len = random () & 511;
|
||||||
for (i = 0; i < len; ++i)
|
if (len + align >= 512)
|
||||||
|
len = 511 - align - (random () & 7);
|
||||||
|
acc = buf2 + page_size - alen - 1 - (random () & 7);
|
||||||
|
for (i = 0; i < alen; ++i)
|
||||||
{
|
{
|
||||||
acc[i] = random () & 255;
|
acc[i] = random () & 255;
|
||||||
if (!acc[i])
|
if (!acc[i])
|
||||||
|
@ -142,35 +164,32 @@ do_random_tests (void)
|
||||||
acc[i] = 1 + (random () & 127);
|
acc[i] = 1 + (random () & 127);
|
||||||
}
|
}
|
||||||
acc[i] = '\0';
|
acc[i] = '\0';
|
||||||
j = pos + align + 64;
|
j = (pos > len ? pos : len) + align + 64;
|
||||||
if (j > 512)
|
if (j > 512)
|
||||||
j = 512;
|
j = 512;
|
||||||
|
|
||||||
for (i = 0; i < j; i++)
|
for (i = 0; i < j; i++)
|
||||||
{
|
{
|
||||||
if (i == pos + align)
|
if (i == len + align)
|
||||||
|
p[i] = '\0';
|
||||||
|
else if (i == pos + align)
|
||||||
{
|
{
|
||||||
if ((random () & 7) == 0)
|
p[i] = random () & 255;
|
||||||
|
if (strchr (acc, p[i]))
|
||||||
p[i] = '\0';
|
p[i] = '\0';
|
||||||
else
|
|
||||||
{
|
|
||||||
p[i] = random () & 255;
|
|
||||||
if (strchr (acc, p[i]))
|
|
||||||
p[i] = '\0';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (i < align || i > pos + align)
|
else if (i < align || i > pos + align)
|
||||||
p[i] = random () & 255;
|
p[i] = random () & 255;
|
||||||
else
|
else
|
||||||
p[i] = acc [random () % len];
|
p[i] = acc [random () % alen];
|
||||||
}
|
}
|
||||||
|
|
||||||
FOR_EACH_IMPL (impl, 1)
|
FOR_EACH_IMPL (impl, 1)
|
||||||
if (CALL (impl, p + align, acc) != pos)
|
if (CALL (impl, p + align, acc) != (pos < len ? pos : len))
|
||||||
{
|
{
|
||||||
error (0, 0, "Iteration %zd - wrong result in function %s (%zd, %p, %zd) %zd != %zd",
|
error (0, 0, "Iteration %zd - wrong result in function %s (%zd, %p, %zd, %zd, %zd) %zd != %zd",
|
||||||
n, impl->name, align, acc, len,
|
n, impl->name, align, acc, alen, pos, len,
|
||||||
CALL (impl, p + align, acc), pos);
|
CALL (impl, p + align, acc), (pos < len ? pos : len));
|
||||||
ret = 1;
|
ret = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue