]> git.puffer.fish Git - mirror/frr.git/commitdiff
tests: update tests for bgp_packet changes
authorQuentin Young <qlyoung@cumulusnetworks.com>
Mon, 12 Jun 2017 17:35:47 +0000 (17:35 +0000)
committerQuentin Young <qlyoung@cumulusnetworks.com>
Thu, 30 Nov 2017 21:18:03 +0000 (16:18 -0500)
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
tests/bgpd/test_aspath.c
tests/bgpd/test_capability.c
tests/bgpd/test_mp_attr.c

index 5a508760b8a00aac4afbb9d47a2f8630435dc407..56808bc8ad05feeb40273450dbc2736486f1483b 100644 (file)
@@ -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);
index 05c409647f81492fdaa95c6415c530ff4c46955b..cf3c36804ba9c36bf0ea31506dfab79ad5ba274d 100644 (file)
@@ -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);
index 30d5fdd6cdbea6e5df0a0066180c6fa03597195d..86af70c72e048cd77e9f1f035beac51f37c7961c 100644 (file)
@@ -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++) {