aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/sys/Makefile1
-rw-r--r--tests/sys/devrandom/Makefile26
-rw-r--r--tests/sys/devrandom/uint128_test.c281
-rw-r--r--tests/sys/kern/Makefile1
-rw-r--r--tests/sys/kern/libkern_crc32.c7
-rwxr-xr-xtests/sys/net/if_clone_test.sh73
6 files changed, 371 insertions, 18 deletions
diff --git a/tests/sys/Makefile b/tests/sys/Makefile
index f8f6ff3925e3..44d1e03c6c73 100644
--- a/tests/sys/Makefile
+++ b/tests/sys/Makefile
@@ -10,6 +10,7 @@ TESTS_SUBDIRS+= ${_audit}
TESTS_SUBDIRS+= auditpipe
TESTS_SUBDIRS+= capsicum
TESTS_SUBDIRS+= ${_cddl}
+TESTS_SUBDIRS+= devrandom
TESTS_SUBDIRS+= fifo
TESTS_SUBDIRS+= file
TESTS_SUBDIRS+= fs
diff --git a/tests/sys/devrandom/Makefile b/tests/sys/devrandom/Makefile
new file mode 100644
index 000000000000..db9f9d42a470
--- /dev/null
+++ b/tests/sys/devrandom/Makefile
@@ -0,0 +1,26 @@
+# $FreeBSD$
+
+.include <src.opts.mk>
+
+SDEVRANDOM= ${SRCTOP}/sys/dev/random
+.PATH: ${SDEVRANDOM}
+
+TESTSDIR= ${TESTSBASE}/sys/devrandom
+WARNS?= 6
+
+CFLAGS+= -I${SRCTOP}/sys
+
+ATF_TESTS_C+= uint128_test
+
+# Test Chacha CTR behavior <-> uint128
+LDADD.uint128_test+= ${SDEVRANDOM}/hash.c
+LDFLAGS.uint128_test+= -Wno-unused-parameter
+
+# hash.c deps:
+LIBADD.uint128_test+= md # SHA256
+LDADD.uint128_test+= ${SRCTOP}/sys/crypto/rijndael/rijndael-alg-fst.c
+LDADD.uint128_test+= ${SRCTOP}/sys/crypto/rijndael/rijndael-api-fst.c
+LDFLAGS.uint128_test+= -Wno-cast-align
+
+
+.include <bsd.test.mk>
diff --git a/tests/sys/devrandom/uint128_test.c b/tests/sys/devrandom/uint128_test.c
new file mode 100644
index 000000000000..288e8a2e9f79
--- /dev/null
+++ b/tests/sys/devrandom/uint128_test.c
@@ -0,0 +1,281 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2019 Conrad Meyer <cem@FreeBSD.org>
+ * All rights reserved.
+ *
+ * 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 AUTHOR 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 AUTHOR 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 <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/random.h>
+
+#include <errno.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdbool.h>
+
+#include <crypto/chacha20/chacha.h>
+#include <crypto/rijndael/rijndael-api-fst.h>
+#include <crypto/sha2/sha256.h>
+
+#include <dev/random/hash.h>
+#include <dev/random/uint128.h>
+
+#include <atf-c.h>
+
+static void
+vec_u32_tole128(uint8_t dst[static 16], const uint32_t src[static 4])
+{
+ le32enc(dst, src[0]);
+ le32enc(&dst[4], src[1]);
+ le32enc(&dst[8], src[2]);
+ le32enc(&dst[12], src[3]);
+}
+
+static void
+le128_to_vec_u32(uint32_t dst[static 4], const uint8_t src[static 16])
+{
+ dst[0] = le32dec(src);
+ dst[1] = le32dec(&src[4]);
+ dst[2] = le32dec(&src[8]);
+ dst[3] = le32dec(&src[12]);
+}
+
+static void
+formatu128(char buf[static 52], uint128_t x)
+{
+ uint8_t le128x[16];
+ uint32_t vx[4];
+ size_t sz, i;
+ int rc;
+
+ le128enc(le128x, x);
+ le128_to_vec_u32(vx, le128x);
+
+ sz = 52;
+ for (i = 0; i < 4; i++) {
+ rc = snprintf(buf, sz, "0x%x ", vx[i]);
+ ATF_REQUIRE(rc > 0 && (size_t)rc < sz);
+
+ buf += rc;
+ sz -= rc;
+ }
+ /* Delete last trailing space */
+ buf[-1] = '\0';
+}
+
+static void
+u128_check_equality(uint128_t a, uint128_t b, const char *descr)
+{
+ char fmtbufa[52], fmtbufb[52];
+
+ formatu128(fmtbufa, a);
+ formatu128(fmtbufb, b);
+
+ ATF_CHECK_MSG(uint128_equals(a, b),
+ "Expected: [%s] != Actual: [%s]: %s", fmtbufa, fmtbufb, descr);
+}
+
+ATF_TC_WITHOUT_HEAD(uint128_inc);
+ATF_TC_BODY(uint128_inc, tc)
+{
+ static const struct u128_inc_tc {
+ uint32_t input[4];
+ uint32_t expected[4];
+ const char *descr;
+ } tests[] = {
+ {
+ .input = { 0, 0, 0, 0 },
+ .expected = { 1, 0, 0, 0 },
+ .descr = "0 -> 1",
+ },
+ {
+ .input = { 1, 0, 0, 0 },
+ .expected = { 2, 0, 0, 0 },
+ .descr = "0 -> 2",
+ },
+ {
+ .input = { 0xff, 0, 0, 0 },
+ .expected = { 0x100, 0, 0, 0 },
+ .descr = "0xff -> 0x100 (byte carry)",
+ },
+ {
+ .input = { UINT32_MAX, 0, 0, 0 },
+ .expected = { 0, 1, 0, 0 },
+ .descr = "2^32 - 1 -> 2^32 (word carry)",
+ },
+ {
+ .input = { UINT32_MAX, UINT32_MAX, 0, 0 },
+ .expected = { 0, 0, 1, 0 },
+ .descr = "2^64 - 1 -> 2^64 (u128t_word0 carry)",
+ },
+ {
+ .input = { UINT32_MAX, UINT32_MAX, UINT32_MAX, 0 },
+ .expected = { 0, 0, 0, 1 },
+ .descr = "2^96 - 1 -> 2^96 (word carry)",
+ },
+ };
+ uint8_t inputle[16], expectedle[16];
+ uint128_t a;
+ size_t i;
+
+ for (i = 0; i < nitems(tests); i++) {
+ vec_u32_tole128(inputle, tests[i].input);
+ vec_u32_tole128(expectedle, tests[i].expected);
+
+ a = le128dec(inputle);
+ uint128_increment(&a);
+ u128_check_equality(le128dec(expectedle), a, tests[i].descr);
+ }
+}
+
+ATF_TC_WITHOUT_HEAD(uint128_add64);
+ATF_TC_BODY(uint128_add64, tc)
+{
+ static const struct u128_add64_tc {
+ uint32_t input[4];
+ uint64_t addend;
+ uint32_t expected[4];
+ const char *descr;
+ } tests[] = {
+ {
+ .input = { 0, 0, 0, 0 },
+ .addend = 1,
+ .expected = { 1, 0, 0, 0 },
+ .descr = "0 + 1 -> 1",
+ },
+ {
+ .input = { 1, 0, 0, 0 },
+ .addend = UINT32_MAX,
+ .expected = { 0, 1, 0, 0 },
+ .descr = "1 + (2^32 - 1) -> 2^32 (word carry)",
+ },
+ {
+ .input = { 1, 0, 0, 0 },
+ .addend = UINT64_MAX,
+ .expected = { 0, 0, 1, 0 },
+ .descr = "1 + (2^64 - 1) -> 2^64 (u128t_word0 carry)",
+ },
+ {
+ .input = { 0x11111111, 0x11111111, 0, 0 },
+ .addend = 0xf0123456789abcdeULL,
+ .expected = { 0x89abcdef, 0x01234567, 1, 0 },
+ .descr = "0x1111_1111_1111_1111 +"
+ "0xf012_3456_789a_bcde ->"
+ "0x1_0123_4567_89ab_cdef",
+ },
+ {
+ .input = { 1, 0, UINT32_MAX, 0 },
+ .addend = UINT64_MAX,
+ .expected = { 0, 0, 0, 1 },
+ .descr = "Carry ~2^96",
+ },
+ };
+ uint8_t inputle[16], expectedle[16];
+ uint128_t a;
+ size_t i;
+
+ for (i = 0; i < nitems(tests); i++) {
+ vec_u32_tole128(inputle, tests[i].input);
+ vec_u32_tole128(expectedle, tests[i].expected);
+
+ a = le128dec(inputle);
+ uint128_add64(&a, tests[i].addend);
+ u128_check_equality(le128dec(expectedle), a, tests[i].descr);
+ }
+}
+
+/*
+ * Test assumptions about Chacha incrementing counter in the same way as
+ * uint128.h
+ */
+ATF_TC_WITHOUT_HEAD(uint128_chacha_ctr);
+ATF_TC_BODY(uint128_chacha_ctr, tc)
+{
+ static const struct u128_chacha_tc {
+ uint32_t input[4];
+ uint32_t expected[4];
+ const char *descr;
+ } tests[] = {
+ {
+ .input = { 0, 0, 0, 0 },
+ .expected = { 1, 0, 0, 0 },
+ .descr = "Single block",
+ },
+ {
+ .input = { 1, 0, 0, 0 },
+ .expected = { 2, 0, 0, 0 },
+ .descr = "0 -> 2",
+ },
+ {
+ .input = { 0xff, 0, 0, 0 },
+ .expected = { 0x100, 0, 0, 0 },
+ .descr = "0xff -> 0x100 (byte carry)",
+ },
+ {
+ .input = { UINT32_MAX, 0, 0, 0 },
+ .expected = { 0, 1, 0, 0 },
+ .descr = "2^32 - 1 -> 2^32 (word carry)",
+ },
+ {
+ .input = { UINT32_MAX, UINT32_MAX, 0, 0 },
+ .expected = { 0, 0, 1, 0 },
+ .descr = "2^64 - 1 -> 2^64 (u128t_word0 carry)",
+ },
+ {
+ .input = { UINT32_MAX, UINT32_MAX, UINT32_MAX, 0 },
+ .expected = { 0, 0, 0, 1 },
+ .descr = "2^96 - 1 -> 2^96 (word carry)",
+ },
+ };
+ union randomdev_key context;
+ uint8_t inputle[16], expectedle[16], trash[CHACHA_BLOCKLEN];
+ uint8_t notrandomkey[RANDOM_KEYSIZE] = { 0 };
+ uint128_t a;
+ size_t i;
+
+ random_chachamode = true;
+ randomdev_encrypt_init(&context, notrandomkey);
+
+ for (i = 0; i < nitems(tests); i++) {
+ vec_u32_tole128(inputle, tests[i].input);
+ vec_u32_tole128(expectedle, tests[i].expected);
+
+ a = le128dec(inputle);
+ randomdev_keystream(&context, &a, trash, sizeof(trash));
+ u128_check_equality(le128dec(expectedle), a, tests[i].descr);
+ }
+
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, uint128_inc);
+ ATF_TP_ADD_TC(tp, uint128_add64);
+ ATF_TP_ADD_TC(tp, uint128_chacha_ctr);
+ return (atf_no_error());
+}
diff --git a/tests/sys/kern/Makefile b/tests/sys/kern/Makefile
index cf2d04706a1c..180734f4d242 100644
--- a/tests/sys/kern/Makefile
+++ b/tests/sys/kern/Makefile
@@ -46,7 +46,6 @@ LIBADD.mqueue_test+= rt
${MACHINE_ARCH} == "i386" || \
${MACHINE_ARCH} == "aarch64"
ATF_TESTS_C+= libkern_crc32
-CFLAGS.libkern_crc32+= -DUSERSPACE_TESTING
.if ${MACHINE_ARCH} == "amd64" || ${MACHINE_ARCH} == "i386"
LDADD.libkern_crc32+= ${SRCTOP}/sys/libkern/x86/crc32_sse42.c
.else
diff --git a/tests/sys/kern/libkern_crc32.c b/tests/sys/kern/libkern_crc32.c
index 03d023124346..39cb8ca5aeeb 100644
--- a/tests/sys/kern/libkern_crc32.c
+++ b/tests/sys/kern/libkern_crc32.c
@@ -27,16 +27,13 @@
*/
#include <sys/param.h>
+#include <sys/gsb_crc32.h>
#include <stdint.h>
#include <atf-c.h>
-#if defined(__amd64__) || defined(__i386__)
-extern uint32_t sse42_crc32c(uint32_t, const unsigned char *, unsigned);
-#elif defined(__aarch64__)
-extern uint32_t armv8_crc32c(uint32_t, const unsigned char *, unsigned);
-#else
+#if !defined(__amd64__) && !defined(__i386__) && !defined(__aarch64__)
#error These tests are not supported on this platform
#endif
diff --git a/tests/sys/net/if_clone_test.sh b/tests/sys/net/if_clone_test.sh
index 02b5e8465b64..abe0ce2a0736 100755
--- a/tests/sys/net/if_clone_test.sh
+++ b/tests/sys/net/if_clone_test.sh
@@ -39,6 +39,52 @@
TESTLEN=10 # seconds
+atf_test_case epair_stress cleanup
+epair_stress_head()
+{
+ atf_set "descr" "Simultaneously create and destroy an epair(4)"
+ atf_set "require.user" "root"
+}
+epair_stress_body()
+{
+ do_stress "epair"
+}
+epair_stress_cleanup()
+{
+ cleanup_ifaces
+}
+
+atf_test_case epair_up_stress cleanup
+epair_up_stress_head()
+{
+ atf_set "descr" "Simultaneously up and detroy an epair(4)"
+ atf_set "require.user" "root"
+}
+epair_up_stress_body()
+{
+ do_up_stress "epair" "" ""
+}
+epair_up_stress_cleanup()
+{
+ cleanup_ifaces
+}
+
+atf_test_case epair_ipv6_up_stress cleanup
+epair_ipv6_up_stress_head()
+{
+ atf_set "descr" "Simultaneously up and destroy an epair(4) with IPv6"
+ atf_set "require.user" "root"
+}
+epair_ipv6_up_stress_body()
+{
+ atf_skip "Quickly panics: page fault in in6_unlink_ifa (PR 225438)"
+ do_up_stress "epair" "6" ""
+}
+epair_ipv6_up_stress_cleanup()
+{
+ cleanup_ifaces
+}
+
atf_test_case faith_stress cleanup
faith_stress_head()
{
@@ -369,7 +415,9 @@ vmnet_ipv6_up_stress_cleanup()
atf_init_test_cases()
{
- # TODO: add epair(4) tests, which need a different syntax
+ atf_add_test_case epair_ipv6_up_stress
+ atf_add_test_case epair_stress
+ atf_add_test_case epair_up_stress
atf_add_test_case faith_ipv6_up_stress
atf_add_test_case faith_stress
atf_add_test_case faith_up_stress
@@ -396,13 +444,13 @@ atf_init_test_cases()
do_stress()
{
- local IFACE
+ local IFACE CREATOR_PID DESTROYER_PID
IFACE=`get_iface $1`
# First thread: create the interface
while true; do
- ifconfig $IFACE create 2>/dev/null && \
+ ifconfig ${IFACE%a} create 2>/dev/null && \
echo -n . >> creator_count.txt
done &
CREATOR_PID=$!
@@ -417,7 +465,7 @@ do_stress()
sleep ${TESTLEN}
kill $CREATOR_PID
kill $DESTROYER_PID
- echo "Created $IFACE `stat -f %z creator_count.txt` times."
+ echo "Created ${IFACE%a} `stat -f %z creator_count.txt` times."
echo "Destroyed it `stat -f %z destroyer_count.txt` times."
}
@@ -428,7 +476,8 @@ do_stress()
# $3 p2p for point to point interfaces, anything else for normal interfaces
do_up_stress()
{
- local IFACE IPv6 MAC P2P SRCDIR
+ local ADDR DSTADDR MASK MEAN_SLEEP_SECONDS MAX_SLEEP_USECS \
+ IFACE IPV6 P2P SRCDIR LOOP_PID ipv6_cmd up_cmd
# Configure the interface to use an RFC5737 nonrouteable addresses
ADDR="192.0.2.2"
@@ -464,7 +513,7 @@ do_up_stress()
ifconfig $IFACE destroy &&
echo -n . >> destroy_count.txt ; } &
wait
- ifconfig $IFACE create
+ ifconfig ${IFACE%a} create
done &
LOOP_PID=$!
@@ -489,7 +538,11 @@ get_iface()
N=$(($N + 1))
fi
done
- local DEV=${CLASS}${N}
+ if [ ${CLASS} = "epair" ]; then
+ DEV=${CLASS}${N}a
+ else
+ DEV=${CLASS}${N}
+ fi
# Record the device so we can clean it up later
echo ${DEV} >> "devices_to_cleanup"
echo ${DEV}
@@ -501,11 +554,7 @@ cleanup_ifaces()
local DEV
for DEV in `cat "devices_to_cleanup"`; do
- if [ ${DEV%%[0-9]*a} = "epair" ]; then
- ifconfig ${DEV}a destroy
- else
- ifconfig ${DEV} destroy
- fi
+ ifconfig ${DEV} destroy
done
true
}