From ba316f8199e3c46a4c2025dec2770fc5fe217f5a Mon Sep 17 00:00:00 2001 From: ross Date: Tue, 6 Dec 2005 08:14:48 +0000 Subject: [PATCH] Add memcpy test. --- regress/lib/libc/string/Makefile | 5 +- regress/lib/libc/string/memcpy/Makefile | 10 +++ regress/lib/libc/string/memcpy/memcpy_test.c | 65 ++++++++++++++++++++ 3 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 regress/lib/libc/string/memcpy/Makefile create mode 100644 regress/lib/libc/string/memcpy/memcpy_test.c diff --git a/regress/lib/libc/string/Makefile b/regress/lib/libc/string/Makefile index 9254b7cca559..d5f5ce98f1d0 100644 --- a/regress/lib/libc/string/Makefile +++ b/regress/lib/libc/string/Makefile @@ -1,5 +1,6 @@ -# $NetBSD: Makefile,v 1.7 2005/10/13 21:36:11 tnozaki Exp $ +# $NetBSD: Makefile,v 1.8 2005/12/06 08:14:48 ross Exp $ -SUBDIR+= memchr memmem strcat strchr strcmp strcpy strlen strrchr swab wcsncpy +SUBDIR+= memchr memmem strcat strchr strcmp strcpy strlen strrchr swab wcsncpy\ + memcpy .include diff --git a/regress/lib/libc/string/memcpy/Makefile b/regress/lib/libc/string/memcpy/Makefile new file mode 100644 index 000000000000..14af394217f4 --- /dev/null +++ b/regress/lib/libc/string/memcpy/Makefile @@ -0,0 +1,10 @@ +# $NetBSD: Makefile,v 1.1 2005/12/06 08:14:48 ross Exp $ + +PROG= memcpy_test +NOMAN= +WARNS?= 4 + +regress: ${PROG} + ./${PROG} + +.include diff --git a/regress/lib/libc/string/memcpy/memcpy_test.c b/regress/lib/libc/string/memcpy/memcpy_test.c new file mode 100644 index 000000000000..65fed702ae0d --- /dev/null +++ b/regress/lib/libc/string/memcpy/memcpy_test.c @@ -0,0 +1,65 @@ +#include + +#include +#include +#include +#include +#include + +#define ALIGNMENTS 16 +#define LENGTHS 4 +#define BLOCKTYPES 4 + +MD5_CTX mc[1]; + +typedef unsigned char testBlock_t[ALIGNMENTS * LENGTHS]; + +testBlock_t bss1, bss2; + +unsigned char *start[BLOCKTYPES] = { + bss1, bss2 +}; + +char result[100]; +const char goodResult[] = "7b405d24bc03195474c70ddae9e1f8fb"; + +void runTest(unsigned char *, unsigned char *); + +int +main(int ac, char **av) +{ + int i, j; + testBlock_t auto1, auto2; + + start[2] = auto1; + start[3] = auto2; + + srandom(0L); + MD5Init(mc); + for (i = 0; i < BLOCKTYPES; ++i) + for (j = 0; j < BLOCKTYPES; ++j) + if (i != j) + runTest(start[i], start[j]); + MD5End(mc, result); + return strcmp(result, goodResult); +} + +void runTest(unsigned char *b1, unsigned char *b2) +{ + int i, j, k, m, n; + + for (i = 0; i < ALIGNMENTS; ++i) { + for (j = 0; j < ALIGNMENTS; ++j) { + k = sizeof(testBlock_t) - (i > j ? i : j); + for (m = 0; m < k; ++m) { + for (n = 0; n < sizeof(testBlock_t); ++n) { + b1[n] = (unsigned char)random(); + b2[n] = (unsigned char)random(); + } + memcpy(b1 + i, b2 + j, m); + MD5Update(mc, b1, sizeof(testBlock_t)); + MD5Update(mc, b2, sizeof(testBlock_t)); + } + } + } +}