From: claudio Date: Tue, 31 May 2022 09:46:54 +0000 (+0000) Subject: Extend community unit test to also check community_count() X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=6eadef58288bd5a84babe0fafeeb021a46e52653;p=openbsd Extend community unit test to also check community_count() --- 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 @@ -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, + }, };