summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorQuentin Young <qlyoung@cumulusnetworks.com>2017-06-12 19:35:47 +0200
committerQuentin Young <qlyoung@cumulusnetworks.com>2017-11-30 22:18:03 +0100
commite9aac3a29a997e144cb51a66da491ce5ccfdabce (patch)
tree2048ebab17d43a3ccbbe2e1ec0a52254bb302369 /tests
parentbgpd: free notify packet after writing (diff)
downloadfrr-e9aac3a29a997e144cb51a66da491ce5ccfdabce.tar.xz
frr-e9aac3a29a997e144cb51a66da491ce5ccfdabce.zip
tests: update tests for bgp_packet changes
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/bgpd/test_aspath.c11
-rw-r--r--tests/bgpd/test_capability.c32
-rw-r--r--tests/bgpd/test_mp_attr.c14
3 files changed, 36 insertions, 21 deletions
diff --git a/tests/bgpd/test_aspath.c b/tests/bgpd/test_aspath.c
index 5a508760b..56808bc8a 100644
--- a/tests/bgpd/test_aspath.c
+++ b/tests/bgpd/test_aspath.c
@@ -1274,20 +1274,20 @@ static int handle_attr_test(struct aspath_tests *t)
asp = make_aspath(t->segment->asdata, t->segment->len, 0);
- peer.ibuf = stream_new(BGP_MAX_PACKET_SIZE);
+ peer.curr = stream_new(BGP_MAX_PACKET_SIZE);
peer.obuf = stream_fifo_new();
peer.bgp = &bgp;
peer.host = (char *)"none";
peer.fd = -1;
peer.cap = t->cap;
- stream_write(peer.ibuf, t->attrheader, t->len);
- datalen = aspath_put(peer.ibuf, asp, t->as4 == AS4_DATA);
+ stream_write(peer.curr, t->attrheader, t->len);
+ datalen = aspath_put(peer.curr, asp, t->as4 == AS4_DATA);
if (t->old_segment) {
char dummyaspath[] = {BGP_ATTR_FLAG_TRANS, BGP_ATTR_AS_PATH,
t->old_segment->len};
- stream_write(peer.ibuf, dummyaspath, sizeof(dummyaspath));
- stream_write(peer.ibuf, t->old_segment->asdata,
+ stream_write(peer.curr, dummyaspath, sizeof(dummyaspath));
+ stream_write(peer.curr, t->old_segment->asdata,
t->old_segment->len);
datalen += sizeof(dummyaspath) + t->old_segment->len;
}
@@ -1342,7 +1342,6 @@ int main(void)
master = bm->master;
bgp_option_set(BGP_OPT_NO_LISTEN);
bgp_attr_init();
- peer_writes_init();
while (test_segments[i].name) {
printf("test %u\n", i);
diff --git a/tests/bgpd/test_capability.c b/tests/bgpd/test_capability.c
index 05c409647..cf3c36804 100644
--- a/tests/bgpd/test_capability.c
+++ b/tests/bgpd/test_capability.c
@@ -796,14 +796,15 @@ static void parse_test(struct peer *peer, struct test_segment *t, int type)
int oldfailed = failed;
int len = t->len;
#define RANDOM_FUZZ 35
- stream_reset(peer->ibuf);
- stream_put(peer->ibuf, NULL, RANDOM_FUZZ);
- stream_set_getp(peer->ibuf, RANDOM_FUZZ);
+
+ stream_reset(peer->curr);
+ stream_put(peer->curr, NULL, RANDOM_FUZZ);
+ stream_set_getp(peer->curr, RANDOM_FUZZ);
switch (type) {
case CAPABILITY:
- stream_putc(peer->ibuf, BGP_OPEN_OPT_CAP);
- stream_putc(peer->ibuf, t->len);
+ stream_putc(peer->curr, BGP_OPEN_OPT_CAP);
+ stream_putc(peer->curr, t->len);
break;
case DYNCAP:
/* for (i = 0; i < BGP_MARKER_SIZE; i++)
@@ -812,7 +813,7 @@ static void parse_test(struct peer *peer, struct test_segment *t, int type)
stream_putc (s, BGP_MSG_CAPABILITY);*/
break;
}
- stream_write(peer->ibuf, t->data, t->len);
+ stream_write(peer->curr, t->data, t->len);
printf("%s: %s\n", t->name, t->desc);
@@ -825,7 +826,7 @@ static void parse_test(struct peer *peer, struct test_segment *t, int type)
as4 = peek_for_as4_capability(peer, len);
printf("peek_for_as4: as4 is %u\n", as4);
/* and it should leave getp as it found it */
- assert(stream_get_getp(peer->ibuf) == RANDOM_FUZZ);
+ assert(stream_get_getp(peer->curr) == RANDOM_FUZZ);
ret = bgp_open_option_parse(peer, len, &capability);
break;
@@ -837,7 +838,7 @@ static void parse_test(struct peer *peer, struct test_segment *t, int type)
exit(1);
}
- if (!ret && t->validate_afi) {
+ if (ret != BGP_Stop && t->validate_afi) {
afi_t afi;
safi_t safi;
@@ -865,10 +866,20 @@ static void parse_test(struct peer *peer, struct test_segment *t, int type)
failed++;
}
+ /* Some of the functions used return BGP_Stop on error and some return
+ * -1. If
+ * we have -1, keep it; if we have BGP_Stop, transform it to the correct
+ * pass/fail code */
+
+ if (ret != -1)
+ ret = (ret == BGP_Stop) ? -1 : 0;
+
printf("parsed?: %s\n", ret ? "no" : "yes");
- if (ret != t->parses)
+ if (ret != t->parses) {
+ printf("t->parses: %d\nret: %d\n", t->parses, ret);
failed++;
+ }
if (tty)
printf("%s",
@@ -903,7 +914,6 @@ int main(void)
bgp_master_init(master);
vrf_init(NULL, NULL, NULL, NULL);
bgp_option_set(BGP_OPT_NO_LISTEN);
- peer_writes_init();
if (fileno(stdout) >= 0)
tty = isatty(fileno(stdout));
@@ -920,6 +930,8 @@ int main(void)
peer->afc_adv[i][j] = 1;
}
+ peer->curr = stream_new(BGP_MAX_PACKET_SIZE);
+
i = 0;
while (mp_segments[i].name)
parse_test(peer, &mp_segments[i++], CAPABILITY);
diff --git a/tests/bgpd/test_mp_attr.c b/tests/bgpd/test_mp_attr.c
index 30d5fdd6c..86af70c72 100644
--- a/tests/bgpd/test_mp_attr.c
+++ b/tests/bgpd/test_mp_attr.c
@@ -36,6 +36,7 @@
#include "bgpd/bgp_packet.h"
#include "bgpd/bgp_mplsvpn.h"
#include "bgpd/bgp_nexthop.h"
+#include "bgpd/bgp_vty.h"
#define VT100_RESET "\x1b[0m"
#define VT100_RED "\x1b[31m"
@@ -1045,11 +1046,11 @@ static void parse_test(struct peer *peer, struct test_segment *t, int type)
.startp = BGP_INPUT_PNT(peer),
};
#define RANDOM_FUZZ 35
- stream_reset(peer->ibuf);
- stream_put(peer->ibuf, NULL, RANDOM_FUZZ);
- stream_set_getp(peer->ibuf, RANDOM_FUZZ);
+ stream_reset(peer->curr);
+ stream_put(peer->curr, NULL, RANDOM_FUZZ);
+ stream_set_getp(peer->curr, RANDOM_FUZZ);
- stream_write(peer->ibuf, t->data, t->len);
+ stream_write(peer->curr, t->data, t->len);
printf("%s: %s\n", t->name, t->desc);
@@ -1097,7 +1098,9 @@ int main(void)
term_bgp_debug_as4 = -1UL;
qobj_init();
- master = thread_master_create(NULL);
+ cmd_init(0);
+ bgp_vty_init();
+ master = thread_master_create();
bgp_master_init(master);
vrf_init(NULL, NULL, NULL, NULL);
bgp_option_set(BGP_OPT_NO_LISTEN);
@@ -1112,6 +1115,7 @@ int main(void)
peer = peer_create_accept(bgp);
peer->host = (char *)"foo";
peer->status = Established;
+ peer->curr = stream_new(BGP_MAX_PACKET_SIZE);
for (i = AFI_IP; i < AFI_MAX; i++)
for (j = SAFI_UNICAST; j < SAFI_MAX; j++) {