summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2022-05-31 09:46:55 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2022-05-31 09:46:55 +0000
commit8d2caf0c0775b5371185e801022ef0d761b60986 (patch)
treef201e1cdda832d26654794ce340653e0c5c2b648
parent563a9d379cfd330c61d33ef1465109222f360446 (diff)
Extend community unit test to also check community_count()
-rw-r--r--regress/usr.sbin/bgpd/unittests/rde_community_test.c53
-rw-r--r--regress/usr.sbin/bgpd/unittests/rde_community_test.h36
2 files changed, 77 insertions, 12 deletions
diff --git a/regress/usr.sbin/bgpd/unittests/rde_community_test.c b/regress/usr.sbin/bgpd/unittests/rde_community_test.c
index bb327069906..6c7c1156a02 100644
--- a/regress/usr.sbin/bgpd/unittests/rde_community_test.c
+++ b/regress/usr.sbin/bgpd/unittests/rde_community_test.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rde_community_test.c,v 1.4 2022/05/25 16:56:04 claudio Exp $ */
+/* $OpenBSD: rde_community_test.c,v 1.5 2022/05/31 09:46:54 claudio Exp $ */
/*
* Copyright (c) 2019 Claudio Jeker <claudio@openbsd.org>
@@ -129,21 +129,50 @@ test_filter(size_t num, struct testfilter *f)
}
}
- r = community_match(&comm, &filters[f->match], &peer);
- if (r != f->mout) {
- printf("Test %zu: community_match "
- "unexpected return %d != %d\n", num, r, f->mout);
- return -1;
+ if (f->match != -1) {
+ r = community_match(&comm, &filters[f->match], &peer);
+ if (r != f->mout) {
+ printf("Test %zu: community_match "
+ "unexpected return %d != %d\n", num, r, f->mout);
+ return -1;
+ }
}
- if (f->delete == -1)
- return 0;
+ if (f->delete != -1) {
+ community_delete(&comm, &filters[f->delete], &peer);
- community_delete(&comm, &filters[f->delete], &peer);
+ if (community_match(&comm, &filters[f->delete], &peer) != 0) {
+ printf("Test %zu: community_delete still around\n",
+ num);
+ return -1;
+ }
+ }
- if (community_match(&comm, &filters[f->delete], &peer) != 0) {
- printf("Test %zu: community_delete still around\n", num);
- return -1;
+ if (f->ncomm != 0) {
+ if (community_count(&comm, COMMUNITY_TYPE_BASIC) !=
+ f->ncomm - 1) {
+ printf("Test %zu: community_count unexpected "
+ "return %d != %d\n", num, r, f->ncomm - 1);
+ return -1;
+ }
+ }
+
+ if (f->next != 0) {
+ if (community_count(&comm, COMMUNITY_TYPE_EXT) !=
+ f->next - 1) {
+ printf("Test %zu: community_count unexpected "
+ "return %d != %d\n", num, r, f->next - 1);
+ return -1;
+ }
+ }
+
+ if (f->nlarge != 0) {
+ if (community_count(&comm, COMMUNITY_TYPE_LARGE) !=
+ f->nlarge - 1) {
+ printf("Test %zu: community_count unexpected "
+ "return %d != %d\n", num, r, f->nlarge - 1);
+ return -1;
+ }
}
return 0;
diff --git a/regress/usr.sbin/bgpd/unittests/rde_community_test.h b/regress/usr.sbin/bgpd/unittests/rde_community_test.h
index cd575fdc529..4a74072eebb 100644
--- a/regress/usr.sbin/bgpd/unittests/rde_community_test.h
+++ b/regress/usr.sbin/bgpd/unittests/rde_community_test.h
@@ -416,6 +416,9 @@ struct testfilter {
ssize_t delete;
ssize_t match;
int mout;
+ int ncomm;
+ int next;
+ int nlarge;
} testfilters[] = {
{
.in = { 1, 2, -1 },
@@ -519,4 +522,37 @@ struct testfilter {
.mout = 1,
.delete = 0,
},
+ {
+ .in = { -1 },
+ .match = 21,
+ .mout = 0,
+ .delete = -1,
+ .ncomm = 0 + 1,
+ .next = 0 + 1,
+ .nlarge = 0 + 1,
+ },
+ {
+ .in = { 0, 3, 6, -1 },
+ .match = -1,
+ .delete = -1,
+ .ncomm = 3 + 1,
+ .next = 0 + 1,
+ .nlarge = 0 + 1,
+ },
+ {
+ .in = { 0, 25, 26, 19, -1 },
+ .match = -1,
+ .delete = -1,
+ .ncomm = 1 + 1,
+ .next = 2 + 1,
+ .nlarge = 1 + 1,
+ },
+ { /* 20 */
+ .in = { 0, 10, 26, -1 },
+ .match = -1,
+ .delete = -1,
+ .ncomm = 1 + 1,
+ .next = 1 + 1,
+ .nlarge = 1 + 1,
+ },
};