git: 7fd8baee756e - main - test/libalias: Tests for instantiation
Lutz Donnerhacke
donner at FreeBSD.org
Tue May 18 20:19:43 UTC 2021
The branch main has been updated by donner:
URL: https://cgit.FreeBSD.org/src/commit/?id=7fd8baee756efa18b6bbb17cbf3a652eb2058d87
commit 7fd8baee756efa18b6bbb17cbf3a652eb2058d87
Author: Lutz Donnerhacke <donner at FreeBSD.org>
AuthorDate: 2021-05-16 21:37:37 +0000
Commit: Lutz Donnerhacke <donner at FreeBSD.org>
CommitDate: 2021-05-18 20:15:39 +0000
test/libalias: Tests for instantiation
In order to modify libalias for performance, the existing
functionality must not change. Enforce this.
Reviewed by: kp
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D30307
---
tests/sys/netinet/Makefile | 2 +
tests/sys/netinet/libalias/1_instance.c | 95 +++++++++++++++++++++++++++++++++
tests/sys/netinet/libalias/Makefile | 26 +++++++++
3 files changed, 123 insertions(+)
diff --git a/tests/sys/netinet/Makefile b/tests/sys/netinet/Makefile
index 56a1cf877135..ec2e6e679c18 100644
--- a/tests/sys/netinet/Makefile
+++ b/tests/sys/netinet/Makefile
@@ -5,6 +5,8 @@ PACKAGE= tests
TESTSDIR= ${TESTSBASE}/sys/netinet
BINDIR= ${TESTSDIR}
+TESTS_SUBDIRS+= libalias
+
ATF_TESTS_C= ip_reass_test \
so_reuseport_lb_test \
socket_afinet \
diff --git a/tests/sys/netinet/libalias/1_instance.c b/tests/sys/netinet/libalias/1_instance.c
new file mode 100644
index 000000000000..e9137eb99d50
--- /dev/null
+++ b/tests/sys/netinet/libalias/1_instance.c
@@ -0,0 +1,95 @@
+#include <atf-c.h>
+#include <alias.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+static int randcmp(const void *a, const void *b) {
+ int res, r = rand();
+
+ (void)a;
+ (void)b;
+ res = (r/4 < RAND_MAX/9) ? 1
+ : (r/5 < RAND_MAX/9) ? 0
+ : -1;
+ return (res);
+}
+
+ATF_TC(2_destroynull);
+ATF_TC_HEAD(2_destroynull, env)
+{
+ atf_tc_set_md_var(env, "descr", "Destroy the NULL instance");
+}
+ATF_TC_BODY(2_destroynull, dummy)
+{
+ atf_tc_expect_death("Code expects valid pointer.");
+ LibAliasUninit(NULL);
+}
+
+ATF_TC(1_singleinit);
+ATF_TC_HEAD(1_singleinit, env)
+{
+ atf_tc_set_md_var(env, "descr", "Create an instance");
+}
+ATF_TC_BODY(1_singleinit, dummy)
+{
+ struct libalias *la;
+
+ la = LibAliasInit(NULL);
+ ATF_CHECK_MSG(la != NULL, "Creating an instance failed.");
+ LibAliasUninit(la);
+}
+
+ATF_TC(3_multiinit);
+ATF_TC_HEAD(3_multiinit, env)
+{
+ atf_tc_set_md_var(env, "descr", "Recreate an instance multiple times");
+}
+ATF_TC_BODY(3_multiinit, dummy)
+{
+ struct libalias *la;
+ int i;
+
+ la = LibAliasInit(NULL);
+ for(i = 1; i < 30; i++) {
+ struct libalias *lo = la;
+
+ la = LibAliasInit(la);
+ ATF_CHECK_MSG(la == lo, "Recreating moved the instance around: %d", i);
+ }
+ LibAliasUninit(la);
+}
+
+ATF_TC(4_multiinstance);
+ATF_TC_HEAD(4_multiinstance, env)
+{
+ atf_tc_set_md_var(env, "descr", "Create and destoy multiple instances.");
+}
+ATF_TC_BODY(4_multiinstance, dummy)
+{
+ struct libalias *la[300];
+ int const num_instances = sizeof(la) / sizeof(*la);
+ int i;
+
+ for (i = 0; i < num_instances; i++) {
+ la[i] = LibAliasInit(NULL);
+ ATF_CHECK_MSG(la[i] != NULL, "Creating instance %d failed.", i);
+ }
+
+ qsort(la, num_instances, sizeof(*la), randcmp);
+
+ for (i = 0; i < num_instances; i++)
+ LibAliasUninit(la[i]);
+}
+
+ATF_TP_ADD_TCS(instance)
+{
+ /* Use "dd if=/dev/random bs=2 count=1 | od -x" to reproduce */
+ srand(0x5ac4);
+
+ ATF_TP_ADD_TC(instance, 2_destroynull);
+ ATF_TP_ADD_TC(instance, 1_singleinit);
+ ATF_TP_ADD_TC(instance, 3_multiinit);
+ ATF_TP_ADD_TC(instance, 4_multiinstance);
+
+ return atf_no_error();
+}
diff --git a/tests/sys/netinet/libalias/Makefile b/tests/sys/netinet/libalias/Makefile
new file mode 100644
index 000000000000..3b2a3b144298
--- /dev/null
+++ b/tests/sys/netinet/libalias/Makefile
@@ -0,0 +1,26 @@
+# $FreeBSD$
+
+.include <bsd.own.mk>
+
+PACKAGE= tests
+
+TESTSDIR= ${TESTSBASE}/sys/netinet/libalias
+BINDIR= ${TESTSDIR}
+
+ATF_TESTS_C+= 1_instance
+
+LIBADD+= alias
+
+.include <bsd.test.mk>
+
+#
+# Testing during development
+#
+test: all
+ cd ${.OBJDIR}; kyua test
+
+report:
+ cd ${.OBJDIR}; kyua report
+
+report-v:
+ cd ${.OBJDIR}; kyua report --verbose
More information about the dev-commits-src-main
mailing list