Migrate the last of the libc/string/ tests from regress to atf, and
re-enable building of t_popcount
This commit is contained in:
parent
a583a258c9
commit
3ca5a7db69
|
@ -1,4 +1,4 @@
|
||||||
# $NetBSD: mi,v 1.190 2010/12/25 21:10:24 pgoyette Exp $
|
# $NetBSD: mi,v 1.191 2010/12/26 13:35:54 pgoyette Exp $
|
||||||
#
|
#
|
||||||
# Note: don't delete entries from here - mark them as "obsolete" instead.
|
# Note: don't delete entries from here - mark them as "obsolete" instead.
|
||||||
#
|
#
|
||||||
|
@ -335,8 +335,12 @@
|
||||||
./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_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/stdlib/t_strtox.debug tests-lib-debug debug,atf
|
||||||
./usr/libdata/debug/usr/tests/lib/libc/string tests-lib-debug
|
./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_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_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/libc/string/t_string.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_swab.debug tests-lib-debug debug,atf
|
||||||
./usr/libdata/debug/usr/tests/lib/libdes tests-lib-debug
|
./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/libdes/t_des.debug tests-lib-debug debug,atf,crypto
|
||||||
./usr/libdata/debug/usr/tests/lib/semaphore tests-lib-debug
|
./usr/libdata/debug/usr/tests/lib/semaphore tests-lib-debug
|
||||||
|
@ -1561,8 +1565,12 @@
|
||||||
./usr/tests/lib/libc/stdio/t_popen tests-lib-tests atf
|
./usr/tests/lib/libc/stdio/t_popen tests-lib-tests atf
|
||||||
./usr/tests/lib/libc/string tests-lib-tests
|
./usr/tests/lib/libc/string tests-lib-tests
|
||||||
./usr/tests/lib/libc/string/Atffile tests-lib-tests atf
|
./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_memcpy tests-lib-tests atf
|
||||||
|
./usr/tests/lib/libc/string/t_memmem 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/libc/string/t_string tests-lib-tests atf
|
||||||
|
./usr/tests/lib/libc/string/t_stresep tests-lib-tests atf
|
||||||
|
./usr/tests/lib/libc/string/t_swab tests-lib-tests atf
|
||||||
./usr/tests/lib/libdes tests-lib-tests
|
./usr/tests/lib/libdes tests-lib-tests
|
||||||
./usr/tests/lib/libdes/Atffile tests-lib-tests atf,crypto
|
./usr/tests/lib/libdes/Atffile tests-lib-tests atf,crypto
|
||||||
./usr/tests/lib/libdes/t_des tests-lib-tests atf,crypto
|
./usr/tests/lib/libdes/t_des tests-lib-tests atf,crypto
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
# $NetBSD: Makefile,v 1.3 2010/12/25 21:10:24 pgoyette Exp $
|
# $NetBSD: Makefile,v 1.4 2010/12/26 13:35:54 pgoyette Exp $
|
||||||
|
|
||||||
.include <bsd.own.mk>
|
.include <bsd.own.mk>
|
||||||
|
|
||||||
TESTSDIR= ${TESTSBASE}/lib/libc/string
|
TESTSDIR= ${TESTSBASE}/lib/libc/string
|
||||||
|
|
||||||
|
TESTS_C+= t_memcpy
|
||||||
|
TESTS_C+= t_memmem
|
||||||
|
TESTS_C+= t_popcount
|
||||||
|
TESTS_C+= t_stresep
|
||||||
TESTS_C+= t_string
|
TESTS_C+= t_string
|
||||||
|
TESTS_C+= t_swab
|
||||||
# EXPENSIVE, REALY, REALY EXPENSIVE test! Disable for now.
|
|
||||||
#TESTS_C+= t_popcount
|
|
||||||
|
|
||||||
.include <bsd.test.mk>
|
.include <bsd.test.mk>
|
||||||
|
|
|
@ -0,0 +1,113 @@
|
||||||
|
/* $NetBSD: t_memcpy.c,v 1.1 2010/12/26 13:35:54 pgoyette Exp $ */
|
||||||
|
|
||||||
|
/*-
|
||||||
|
* Copyright (c) 2010 The NetBSD Foundation, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This code is derived from software contributed to The NetBSD Foundation
|
||||||
|
* by
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||||
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||||
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||||
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <atf-c.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <md5.h>
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#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";
|
||||||
|
|
||||||
|
static void
|
||||||
|
runTest(unsigned char *b1, unsigned char *b2)
|
||||||
|
{
|
||||||
|
int i, j, k, m;
|
||||||
|
size_t 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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ATF_TC(check_memcpy);
|
||||||
|
|
||||||
|
ATF_TC_HEAD(check_memcpy, tc)
|
||||||
|
{
|
||||||
|
|
||||||
|
atf_tc_set_md_var(tc, "descr", "Test memcpy results");
|
||||||
|
}
|
||||||
|
|
||||||
|
ATF_TC_BODY(check_memcpy, tc)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
ATF_REQUIRE_EQ(strcmp(result, goodResult), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
ATF_TP_ADD_TCS(tp)
|
||||||
|
{
|
||||||
|
|
||||||
|
ATF_TP_ADD_TC(tp, check_memcpy);
|
||||||
|
|
||||||
|
return atf_no_error();
|
||||||
|
}
|
|
@ -0,0 +1,101 @@
|
||||||
|
/* $NetBSD: t_memmem.c,v 1.1 2010/12/26 13:35:54 pgoyette Exp $ */
|
||||||
|
|
||||||
|
/*-
|
||||||
|
* Copyright (c) 2005 The NetBSD Foundation, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This code is derived from software contributed to The NetBSD Foundation
|
||||||
|
* by Perry E. Metzger of Metzger, Dowdeswell & Co. LLC.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||||
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||||
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||||
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <atf-c.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
char p0[] = "";
|
||||||
|
int lp0 = 0;
|
||||||
|
char p1[] = "0123";
|
||||||
|
int lp1 = 4;
|
||||||
|
char p2[] = "456";
|
||||||
|
int lp2 = 3;
|
||||||
|
char p3[] = "789";
|
||||||
|
int lp3 = 3;
|
||||||
|
char p4[] = "abc";
|
||||||
|
int lp4 = 3;
|
||||||
|
char p5[] = "0";
|
||||||
|
int lp5 = 1;
|
||||||
|
char p6[] = "9";
|
||||||
|
int lp6 = 1;
|
||||||
|
char p7[] = "654";
|
||||||
|
int lp7 = 3;
|
||||||
|
|
||||||
|
char b0[] = "";
|
||||||
|
int lb0 = 0;
|
||||||
|
char b1[] = "0";
|
||||||
|
int lb1 = 1;
|
||||||
|
char b2[] = "0123456789";
|
||||||
|
int lb2 = 10;
|
||||||
|
|
||||||
|
#define expect(b) \
|
||||||
|
if (!(b)) { \
|
||||||
|
fprintf(stderr, "failed on line %d\n", __LINE__); \
|
||||||
|
atf_tc_fail("Check stderr for test id/line"); \
|
||||||
|
}
|
||||||
|
|
||||||
|
ATF_TC(check_memmem);
|
||||||
|
|
||||||
|
ATF_TC_HEAD(check_memmem, tc)
|
||||||
|
{
|
||||||
|
|
||||||
|
atf_tc_set_md_var(tc, "descr", "Test memmem results");
|
||||||
|
}
|
||||||
|
|
||||||
|
ATF_TC_BODY(check_memmem, tc)
|
||||||
|
{
|
||||||
|
|
||||||
|
expect(memmem(b2, lb2, p0, lp0) == b2);
|
||||||
|
expect(memmem(b0, lb0, p0, lp0) == b0);
|
||||||
|
expect(memmem(b0, lb0, p1, lp1) == NULL);
|
||||||
|
expect(memmem(b1, lb1, p1, lp1) == NULL);
|
||||||
|
|
||||||
|
expect(memmem(b2, lb2, p1, lp1) == b2);
|
||||||
|
expect(memmem(b2, lb2, p2, lp2) == (b2 + 4));
|
||||||
|
expect(memmem(b2, lb2, p3, lp3) == (b2 + 7));
|
||||||
|
|
||||||
|
expect(memmem(b2, lb2, p5, lp5) == b2);
|
||||||
|
expect(memmem(b2, lb2, p6, lp6) == (b2 + 9));
|
||||||
|
|
||||||
|
expect(memmem(b2, lb2, p4, lp4) == NULL);
|
||||||
|
expect(memmem(b2, lb2, p7, lp7) == NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
ATF_TP_ADD_TCS(tp)
|
||||||
|
{
|
||||||
|
|
||||||
|
ATF_TP_ADD_TC(tp, check_memmem);
|
||||||
|
|
||||||
|
return atf_no_error();
|
||||||
|
}
|
|
@ -0,0 +1,73 @@
|
||||||
|
/* $NetBSD: t_stresep.c,v 1.1 2010/12/26 13:35:54 pgoyette Exp $ */
|
||||||
|
|
||||||
|
/*-
|
||||||
|
* Copyright (c) 2005 The NetBSD Foundation, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This code is derived from software contributed to The NetBSD Foundation
|
||||||
|
* by Christos Zoulas.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||||
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||||
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||||
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <atf-c.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#define expect(a) \
|
||||||
|
if ((p = stresep(&q, " ", '\\')) == NULL || strcmp(p, a)) { \
|
||||||
|
fprintf(stderr, "failed on line %d: %s != %s\n", \
|
||||||
|
__LINE__, p, a); \
|
||||||
|
atf_tc_fail("Check stderr for test id/line"); \
|
||||||
|
}
|
||||||
|
|
||||||
|
ATF_TC(check_stresep);
|
||||||
|
|
||||||
|
ATF_TC_HEAD(check_stresep, tc)
|
||||||
|
{
|
||||||
|
|
||||||
|
atf_tc_set_md_var(tc, "descr", "Test stresep results");
|
||||||
|
}
|
||||||
|
|
||||||
|
ATF_TC_BODY(check_stresep, tc)
|
||||||
|
{
|
||||||
|
char brk[] = "foo\\ \\ bar baz bar\\ foo\\ bar\\ \\ foo \\ \\ \\ "
|
||||||
|
"baz bar\\ \\ ";
|
||||||
|
char *p, *q = brk;
|
||||||
|
|
||||||
|
expect("foo bar");
|
||||||
|
expect("baz");
|
||||||
|
expect("bar foo ");
|
||||||
|
expect("bar foo");
|
||||||
|
expect(" baz");
|
||||||
|
expect("bar ");
|
||||||
|
}
|
||||||
|
|
||||||
|
ATF_TP_ADD_TCS(tp)
|
||||||
|
{
|
||||||
|
|
||||||
|
ATF_TP_ADD_TC(tp, check_stresep);
|
||||||
|
|
||||||
|
return atf_no_error();
|
||||||
|
}
|
|
@ -0,0 +1,96 @@
|
||||||
|
/* $NetBSD: t_swab.c,v 1.1 2010/12/26 13:35:54 pgoyette Exp $ */
|
||||||
|
|
||||||
|
/*-
|
||||||
|
* Copyright (c) 2001 The NetBSD Foundation, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This code was contributed to The NetBSD Foundation by Christos Zoulas.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||||
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||||
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||||
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
#include <atf-c.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <err.h>
|
||||||
|
|
||||||
|
#define MAXCHK 100
|
||||||
|
|
||||||
|
static void
|
||||||
|
build(char *a, char *b, size_t n) {
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
n >>= 1;
|
||||||
|
for (i = 0; i < n; i += 2) {
|
||||||
|
b[i+1] = a[i] = (char)i;
|
||||||
|
b[i] = a[i+1] = (char)(i+1);
|
||||||
|
}
|
||||||
|
for (n <<= 1; n < MAXCHK; n++)
|
||||||
|
a[n] = b[n] = (char)~0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
dump(const char *f, char *b, size_t l)
|
||||||
|
{
|
||||||
|
|
||||||
|
printf("%s ", f);
|
||||||
|
while (l--)
|
||||||
|
printf("%.2x ", (unsigned char)*b++);
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
ATF_TC(check_swab);
|
||||||
|
|
||||||
|
ATF_TC_HEAD(check_swab, tc)
|
||||||
|
{
|
||||||
|
|
||||||
|
atf_tc_set_md_var(tc, "descr", "Test swab results");
|
||||||
|
}
|
||||||
|
|
||||||
|
ATF_TC_BODY(check_swab, tc)
|
||||||
|
{
|
||||||
|
char a[MAXCHK], b[MAXCHK], r[MAXCHK];
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
for (i = 0; i < MAXCHK; i += 2) {
|
||||||
|
build(a, b, i);
|
||||||
|
(void)memset(r, ~0, MAXCHK);
|
||||||
|
swab(a, r, i);
|
||||||
|
if (memcmp(b, r, MAXCHK) != 0) {
|
||||||
|
fprintf(stderr, "pattern mismatch at %lu bytes",
|
||||||
|
(unsigned long)i);
|
||||||
|
dump("expect:", b, MAXCHK);
|
||||||
|
dump("result:", r, MAXCHK);
|
||||||
|
atf_tc_fail("Check stderr for details");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ATF_TP_ADD_TCS(tp)
|
||||||
|
{
|
||||||
|
ATF_TP_ADD_TC(tp, check_swab);
|
||||||
|
|
||||||
|
return atf_no_error();
|
||||||
|
}
|
Loading…
Reference in New Issue