9b0a0ba9e6
- Unit Testing Framework (BirdTest) - Integration of BirdTest into the BIRD build system - Tests for several BIRD modules Based on squashed Pavel Tvrdik's int-test branch, updated for current int-new branch.
966 lines
No EOL
19 KiB
Text
966 lines
No EOL
19 KiB
Text
/*
|
|
* This is unit testing configuration file for testing filters
|
|
*
|
|
* FIXME: add all examples from docs here.
|
|
*/
|
|
|
|
router id 62.168.0.1;
|
|
|
|
/* We have to setup any protocol */
|
|
protocol static { ipv4; }
|
|
|
|
|
|
|
|
|
|
/*
|
|
* Common definitions and functions
|
|
* --------------------------------
|
|
*/
|
|
|
|
define one = 1;
|
|
define ten = 10;
|
|
|
|
function onef(int a)
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
* Testing empty lists/paths
|
|
* -------------------------
|
|
*/
|
|
|
|
function t_empty()
|
|
{
|
|
bt_assert(+empty+ = +empty+);
|
|
bt_assert(+empty+ != -empty-);
|
|
bt_assert(+empty+ != --empty--);
|
|
|
|
bt_assert(-empty- = -empty-);
|
|
bt_assert(-empty- != --empty--);
|
|
|
|
bt_assert(--empty-- = --empty--);
|
|
}
|
|
|
|
bt_test_suite(t_empty, "Testing +empty+, -empty-, --empty--");
|
|
|
|
|
|
|
|
|
|
/*
|
|
* Testing Paths
|
|
* -------------
|
|
*/
|
|
|
|
function mkpath(int a; int b)
|
|
{
|
|
return [= a b 3 2 1 =];
|
|
}
|
|
|
|
function t_path()
|
|
bgpmask pm1;
|
|
bgpmask pm2;
|
|
bgppath p2;
|
|
{
|
|
pm1 = / 4 3 2 1 /;
|
|
pm2 = [= 4 3 2 1 =];
|
|
|
|
p2 = prepend( + empty +, 1 );
|
|
p2 = prepend( p2, 2 );
|
|
p2 = prepend( p2, 3 );
|
|
p2 = prepend( p2, 4 );
|
|
|
|
print "Testing paths: ", p2;
|
|
bt_assert(p2.len = 4);
|
|
bt_assert(p2 ~ pm1);
|
|
bt_assert(p2 ~ pm2);
|
|
bt_assert(3 ~ p2);
|
|
bt_assert(p2 ~ [2, 10..20]);
|
|
bt_assert(p2 ~ [4, 10..20]);
|
|
|
|
p2 = prepend(p2, 5);
|
|
bt_assert(p2 !~ pm1);
|
|
bt_assert(p2 !~ pm2);
|
|
bt_assert(10 !~ p2);
|
|
bt_assert(p2 !~ [8, ten..(2*ten)]);
|
|
bt_assert(p2 ~ / ? 4 3 2 1 /);
|
|
bt_assert(p2 ~ [= * 4 3 * 1 =]);
|
|
bt_assert(p2 ~ [= (3+2) (2*2) 3 2 1 =]);
|
|
bt_assert(p2 ~ mkpath(5, 4));
|
|
|
|
bt_assert(p2.len = 5);
|
|
bt_assert(p2.first = 5);
|
|
bt_assert(p2.last = 1);
|
|
|
|
bt_assert(p2.len = 5);
|
|
bt_assert(delete(p2, 3) = prepend(prepend(prepend(prepend(+empty+, 1), 2), 4), 5));
|
|
bt_assert(filter(p2, [1..3]) = prepend(prepend(prepend(+empty+, 1), 2), 3));
|
|
|
|
pm1 = [= 1 2 * 3 4 5 =];
|
|
p2 = prepend( + empty +, 5 );
|
|
p2 = prepend( p2, 4 );
|
|
p2 = prepend( p2, 3 );
|
|
p2 = prepend( p2, 3 );
|
|
p2 = prepend( p2, 2 );
|
|
p2 = prepend( p2, 1 );
|
|
|
|
bt_assert(p2 ~ pm1);
|
|
bt_assert(delete(p2, 3) = prepend(prepend(prepend(prepend(+empty+, 5), 4), 2), 1));
|
|
bt_assert(delete(p2, [4..5]) = prepend(prepend(prepend(prepend(+empty+, 3), 3), 2), 1));
|
|
}
|
|
|
|
bt_test_suite(t_path, "Testing paths");
|
|
|
|
|
|
|
|
|
|
/*
|
|
* Testing Community List
|
|
* ----------------------
|
|
*/
|
|
|
|
define p23 = (2, 3);
|
|
|
|
function t_community_list()
|
|
clist l;
|
|
clist l2;
|
|
{
|
|
/* XXX: add((x,y)) works as prepend */
|
|
|
|
l = - empty -;
|
|
bt_assert(l !~ [(*,*)]);
|
|
bt_assert((l ~ [(*,*)]) != (l !~ [(*,*)]));
|
|
|
|
l = add( l, (one,2) );
|
|
bt_assert(l ~ [(*,*)]);
|
|
l = add( l, (2,one+2) );
|
|
print "Community list (1,2) (2,3) ", l;
|
|
|
|
bt_assert((2,3) ~ l);
|
|
bt_assert(l ~ [(1,*)]);
|
|
bt_assert(l ~ [p23]);
|
|
bt_assert(l ~ [(2,2..3)]);
|
|
bt_assert(l ~ [(1,1..2)]);
|
|
bt_assert(l ~ [(1,1)..(1,2)]);
|
|
|
|
l = add(l, (2,5));
|
|
l = add(l, (5,one));
|
|
l = add(l, (6,one));
|
|
l = add(l, (one,one));
|
|
l = delete(l, [(5,1),(6,one),(one,1)]);
|
|
l = delete(l, [(5,one),(6,one)]);
|
|
l = filter(l, [(1,*)]);
|
|
bt_assert(l = add(-empty-, (1,2)));
|
|
|
|
bt_assert((2,3) !~ l);
|
|
bt_assert(l !~ [(2,*)]);
|
|
bt_assert(l !~ [(one,3..6)]);
|
|
bt_assert(l ~ [(*,*)]);
|
|
|
|
l = add(l, (3,one));
|
|
l = add(l, (one+one+one,one+one));
|
|
l = add(l, (3,3));
|
|
l = add(l, (3,4));
|
|
l = add(l, (3,5));
|
|
l2 = filter(l, [(3,*)]);
|
|
l = delete(l, [(3,2..4)]);
|
|
bt_assert(l = add(add(add(-empty-, (1,2)), (3,1)), (3,5)));
|
|
bt_assert(l.len = 3);
|
|
|
|
l = add(l, (3,2));
|
|
l = add(l, (4,5));
|
|
bt_assert(l = add(add(add(add(add(-empty-, (1,2)), (3,1)), (3,5)), (3,2)), (4,5)));
|
|
|
|
bt_assert(l.len = 5);
|
|
bt_assert(l ~ [(*,2)]);
|
|
bt_assert(l ~ [(*,5)]);
|
|
bt_assert(l ~ [(*, one)]);
|
|
bt_assert(l !~ [(*,3)]);
|
|
bt_assert(l !~ [(*,(one+6))]);
|
|
bt_assert(l !~ [(*, (one+one+one))]);
|
|
|
|
l = delete(l, [(*,(one+onef(3)))]);
|
|
l = delete(l, [(*,(4+one))]);
|
|
bt_assert(l = add(-empty-, (3,1)));
|
|
|
|
l = delete(l, [(*,(onef(5)))]);
|
|
bt_assert(l = -empty-);
|
|
|
|
l2 = add(l2, (3,6));
|
|
l = filter(l2, [(3,1..4)]);
|
|
l2 = filter(l2, [(3,3..6)]);
|
|
|
|
print "clist A (1..4): ", l;
|
|
bt_assert(l = add(add(add(add(-empty-, (3,1)), (3,2)), (3,3)), (3,4)));
|
|
|
|
print "clist B (3..6): ", l2;
|
|
bt_assert(l2 = add(add(add(add(-empty-, (3,3)), (3,4)), (3,5)), (3,6)));
|
|
|
|
print "clist A union B: ", add( l, l2 );
|
|
bt_assert(add(l, l2) = add(add(add(add(add(add(-empty-, (3,1)), (3,2)), (3,3)), (3,4)), (3,5)), (3,6)));
|
|
|
|
print "clist A isect B: ", filter( l, l2 );
|
|
bt_assert(filter(l, l2) = add(add(-empty-, (3,3)), (3,4)));
|
|
|
|
print "clist A \ B: ", delete( l, l2 );
|
|
bt_assert(delete(l, l2) = add(add(-empty-, (3,1)), (3,2)));
|
|
}
|
|
|
|
bt_test_suite(t_community_list, "Testing communities and lists");
|
|
|
|
|
|
|
|
|
|
/*
|
|
* Testing Extended Community List
|
|
* -------------------------------
|
|
*/
|
|
|
|
function t_extended_community_list()
|
|
eclist el;
|
|
eclist el2;
|
|
{
|
|
el = -- empty --;
|
|
el = add(el, (rt, 10, 20));
|
|
el = add(el, (ro, 10.20.30.40, 100));
|
|
el = add(el, (ro, 11.21.31.41.mask(16), 200));
|
|
|
|
print "EC list (rt, 10, 20) (ro, 10.20.30.40, 100) (ro, 11.21.0.0, 200):";
|
|
print el;
|
|
bt_assert(el.len = 3);
|
|
el = delete(el, (rt, 10, 20));
|
|
el = delete(el, (rt, 10, 30));
|
|
bt_assert(el = add(add(--empty--, (ro, 10.20.30.40, 100)), (ro, 11.21.0.0, 200)));
|
|
el = add(el, (unknown 2, ten, 1));
|
|
el = add(el, (unknown 5, ten, 1));
|
|
el = add(el, (rt, ten, one+one));
|
|
el = add(el, (rt, 10, 3));
|
|
el = add(el, (rt, 10, 4));
|
|
el = add(el, (rt, 10, 5));
|
|
el = add(el, (generic, 0x2000a, 3*ten));
|
|
el = delete(el, [(rt, 10, 2..ten)]);
|
|
bt_assert(el = add(add(add(add(add(--empty--, (ro, 10.20.30.40, 100)), (ro, 11.21.0.0, 200)), (rt, 10, 1)), (unknown 5, 10, 1)), (rt, 10, 30)));
|
|
|
|
el = filter(el, [(rt, 10, *)]);
|
|
bt_assert(el = add(add(--empty--, (rt, 10, 1)), (rt, 10, 30)));
|
|
bt_assert((rt, 10, 1) ~ el);
|
|
bt_assert(el ~ [(rt, 10, ten..40)]);
|
|
bt_assert((rt, 10, 20) !~ el);
|
|
bt_assert((ro, 10.20.30.40, 100) !~ el);
|
|
bt_assert(el !~ [(rt, 10, 35..40)]);
|
|
bt_assert(el !~ [(ro, 10, *)]);
|
|
|
|
el = add(el, (rt, 10, 40));
|
|
el2 = filter(el, [(rt, 10, 20..40)] );
|
|
el2 = add(el2, (rt, 10, 50));
|
|
|
|
print "eclist A (1,30,40): ", el;
|
|
bt_assert(el = add(add(add(--empty--, (rt, 10, 1)), (rt, 10, 30)), (rt, 10, 40)));
|
|
|
|
print "eclist B (30,40,50): ", el2;
|
|
bt_assert(el2 = add(add(add(--empty--, (rt, 10, 30)), (rt, 10, 40)), (rt, 10, 50)));
|
|
|
|
print "eclist A union B: ", add(el2, el);
|
|
bt_assert(add(el2, el) = add(add(add(add(--empty--, (rt, 10, 30)), (rt, 10, 40)), (rt, 10, 50)), (rt, 10, 1)));
|
|
|
|
print "eclist A isect B: ", filter(el, el2);
|
|
bt_assert(filter(el, el2) = add(add(--empty--, (rt, 10, 30)), (rt, 10, 40)));
|
|
|
|
print "eclist A \ B: ", delete(el, el2);
|
|
bt_assert(delete(el, el2) = add(--empty--, (rt, 10, 1)));
|
|
}
|
|
|
|
bt_test_suite(t_extended_community_list, "Testing extended communities and lists");
|
|
|
|
|
|
|
|
|
|
/*
|
|
* Testing defined() function
|
|
* --------------------------
|
|
*/
|
|
|
|
function test_undef(int a)
|
|
int b;
|
|
{
|
|
if a = 3 then {
|
|
b = 4;
|
|
bt_assert(defined(b));
|
|
}
|
|
else {
|
|
bt_assert(!defined(b));
|
|
}
|
|
}
|
|
|
|
function t_define()
|
|
int i;
|
|
{
|
|
test_undef(2);
|
|
test_undef(3);
|
|
test_undef(2);
|
|
|
|
bt_assert(defined(1));
|
|
bt_assert(defined(1.2.3.4));
|
|
}
|
|
|
|
bt_test_suite(t_define, "Testing defined() function");
|
|
|
|
|
|
|
|
|
|
/*
|
|
* Testing quads
|
|
* -------------
|
|
*/
|
|
|
|
function t_quad()
|
|
quad qq;
|
|
{
|
|
qq = 1.2.3.4;
|
|
print "Testinq quad: 1.2.3.4 = ", qq;
|
|
bt_assert(qq = 1.2.3.4);
|
|
bt_assert(qq != 4.3.2.1);
|
|
}
|
|
|
|
bt_test_suite(t_quad, "Testing quads");
|
|
|
|
|
|
|
|
|
|
/*
|
|
* Testing sets of quads
|
|
* ---------------------
|
|
*/
|
|
|
|
function t_quad_set()
|
|
quad qq;
|
|
{
|
|
qq = 1.2.3.4;
|
|
bt_assert(qq ~ [1.2.3.4, 5.6.7.8]);
|
|
bt_assert(qq !~ [1.2.1.1, 1.2.3.5]);
|
|
}
|
|
|
|
bt_test_suite(t_quad_set, "Testing sets of quads");
|
|
|
|
|
|
|
|
|
|
/*
|
|
* Testing Extended Communities
|
|
* ----------------------------
|
|
*/
|
|
|
|
function t_ec()
|
|
ec cc;
|
|
{
|
|
cc = (rt, 12345, 200000);
|
|
print "Testing EC: ", cc;
|
|
|
|
bt_assert(cc = (rt, 12345, 200000));
|
|
bt_assert(cc < (rt, 12345, 200010));
|
|
bt_assert(cc != (rt, 12346, 200000));
|
|
bt_assert(cc != (ro, 12345, 200000));
|
|
bt_assert(!(cc > (rt, 12345, 200010)));
|
|
|
|
print "Testing EC: (ro, 100000, 20000) = ", (ro, 100000, 20000);
|
|
}
|
|
|
|
bt_test_suite(t_ec, "Testing Extended Communities");
|
|
|
|
|
|
|
|
|
|
/*
|
|
* Testing sets of Extended Communities
|
|
* ------------------------------------
|
|
*/
|
|
|
|
define ecs2 = [(rt, ten, (one+onef(0))*10), (ro, 100000, 100..200), (rt, 12345, *)];
|
|
|
|
function t_ec_set()
|
|
ec set ecs;
|
|
{
|
|
ecs = [(rt, ten, (one+onef(0))*10), (ro, 100000, 100..200), (rt, 12345, *)];
|
|
print "EC set (rt, 10, 20) (ro, 100000, 100..200), (rt, 12345, *):";
|
|
print ecs;
|
|
print ecs2;
|
|
|
|
bt_assert((rt, 10, 20) ~ ecs);
|
|
bt_assert((ro, 100000, 100) ~ ecs);
|
|
bt_assert((ro, 100000, 128) ~ ecs);
|
|
bt_assert((ro, 100000, 200) ~ ecs);
|
|
bt_assert((rt, 12345, 0) ~ ecs);
|
|
bt_assert((rt, 12345, 200000) ~ ecs);
|
|
bt_assert((rt, 12345, 4000000) ~ ecs);
|
|
bt_assert((ro, 10, 20) !~ ecs);
|
|
bt_assert((rt, 10, 21) !~ ecs);
|
|
bt_assert((ro, 100000, 99) !~ ecs);
|
|
bt_assert((ro, 12345, 10) !~ ecs);
|
|
bt_assert((rt, 12346, 0) !~ ecs);
|
|
bt_assert((ro, 0.1.134.160, 150) !~ ecs);
|
|
}
|
|
|
|
bt_test_suite(t_ec_set, "Testing sets of Extended Communities");
|
|
|
|
|
|
|
|
|
|
/*
|
|
* Testing integers
|
|
* ----------------
|
|
*/
|
|
|
|
define four = 4;
|
|
define xyzzy = (120+10);
|
|
define '1a-a1' = (xyzzy-100);
|
|
|
|
function t_int()
|
|
int i;
|
|
{
|
|
bt_assert(xyzzy = 130);
|
|
bt_assert('1a-a1' = 30);
|
|
|
|
i = four;
|
|
i = 12*100 + 60/2 + i;
|
|
i = (i + 0);
|
|
bt_assert(i = 1234);
|
|
|
|
if (i = 4) then
|
|
bt_assert(false);
|
|
else
|
|
bt_assert(true);
|
|
|
|
if !(i = 3) then
|
|
bt_assert(true);
|
|
else
|
|
bt_assert(false);
|
|
|
|
if 1234 = i then
|
|
bt_assert(true);
|
|
else
|
|
bt_assert(false);
|
|
|
|
if 1 <= 1 then
|
|
bt_assert(true);
|
|
else
|
|
bt_assert(false);
|
|
|
|
if 1234 < 1234 then
|
|
bt_assert(false);
|
|
else
|
|
bt_assert(true);
|
|
|
|
i = 4200000000;
|
|
bt_assert(i = 4200000000);
|
|
bt_assert(i > 4100000000);
|
|
bt_assert(!(i > 4250000000));
|
|
|
|
bt_assert(1 = 1);
|
|
bt_assert(!(1 != 1));
|
|
|
|
bt_assert(1 != 2);
|
|
bt_assert(1 <= 2);
|
|
|
|
bt_assert(1 != "a");
|
|
bt_assert(1 != (0,1));
|
|
}
|
|
|
|
bt_test_suite(t_int, "Testing integers");
|
|
|
|
|
|
|
|
|
|
/*
|
|
* Testing sets of integers
|
|
* ------------------------
|
|
*/
|
|
|
|
define is1 = [ one, (2+1), (6-one), 8, 11, 15, 17, 19];
|
|
define is2 = [(17+2), 17, 15, 11, 8, 5, 3, 2];
|
|
define is3 = [5, 17, 2, 11, 8, 15, 3, 19];
|
|
|
|
function t_int_set()
|
|
int set is;
|
|
{
|
|
bt_assert(1 ~ [1,2,3]);
|
|
bt_assert(5 ~ [1..20]);
|
|
bt_assert(2 ~ [ 1, 2, 3 ]);
|
|
bt_assert(5 ~ [ 4 .. 7 ]);
|
|
bt_assert(1 !~ [ 2, 3, 4 ]);
|
|
|
|
is = [ 2, 3, 4, 7..11 ];
|
|
bt_assert(10 ~ is);
|
|
bt_assert(5 !~ is);
|
|
|
|
bt_assert(1 ~ is1);
|
|
bt_assert(3 ~ is1);
|
|
bt_assert(5 ~ is1);
|
|
bt_assert((one+2) ~ is1);
|
|
bt_assert(2 ~ is2);
|
|
bt_assert(2 ~ is3);
|
|
bt_assert(4 !~ is1);
|
|
bt_assert(4 !~ is2);
|
|
bt_assert(4 !~ is3);
|
|
bt_assert(10 !~ is1);
|
|
bt_assert(10 !~ is2);
|
|
bt_assert(10 !~ is3);
|
|
bt_assert(15 ~ is1);
|
|
bt_assert(15 ~ is2);
|
|
bt_assert(15 ~ is3);
|
|
bt_assert(18 !~ is1);
|
|
bt_assert(18 !~ is2);
|
|
bt_assert(18 !~ is3);
|
|
bt_assert(19 ~ is1);
|
|
bt_assert(19 ~ is2);
|
|
bt_assert(19 ~ is3);
|
|
bt_assert(20 !~ is1);
|
|
bt_assert(20 !~ is2);
|
|
bt_assert(20 !~ is3);
|
|
|
|
bt_assert([1,2] != [1,3]);
|
|
bt_assert([1,4..10,20] = [1,4..10,20]);
|
|
|
|
print "What will this do? ", [ 1, 2, 1, 1, 1, 3, 4, 1, 1, 1, 5 ];
|
|
}
|
|
|
|
bt_test_suite(t_int_set, "Testing sets of integers");
|
|
|
|
|
|
|
|
|
|
/*
|
|
* Testing ip address
|
|
* ------------------
|
|
*/
|
|
|
|
define onetwo = 1.2.3.4;
|
|
|
|
function t_ip()
|
|
ip p;
|
|
{
|
|
p = 127.1.2.3;
|
|
bt_assert(p.mask(8) = 127.0.0.0);
|
|
bt_assert(1.2.3.4 = 1.2.3.4);
|
|
bt_assert(1.2.3.4 = onetwo);
|
|
print "1.2.3.4 = ", onetwo;
|
|
}
|
|
|
|
bt_test_suite(t_ip, "Testing ip address");
|
|
|
|
|
|
|
|
|
|
/*
|
|
* Testing sets of ip address
|
|
* --------------------------
|
|
*/
|
|
|
|
function t_ip_set()
|
|
{
|
|
bt_assert(1.2.3.4 !~ [ 1.2.3.3, 1.2.3.5 ]);
|
|
bt_assert(1.2.3.4 ~ [ 1.2.3.3..1.2.3.5 ]);
|
|
}
|
|
|
|
bt_test_suite(t_ip_set, "Testing sets of ip address");
|
|
|
|
|
|
|
|
|
|
/*
|
|
* Testing enums
|
|
* -------------
|
|
*/
|
|
|
|
function t_enum()
|
|
{
|
|
print "Testing enums: ", RTS_DUMMY, " ", RTS_STATIC;
|
|
bt_assert(RTS_STATIC ~ [RTS_STATIC, RTS_DEVICE]);
|
|
bt_assert(RTS_BGP !~ [RTS_STATIC, RTS_DEVICE]);
|
|
}
|
|
|
|
bt_test_suite(t_enum, "Testing enums");
|
|
|
|
|
|
|
|
|
|
/*
|
|
* Testing pairs
|
|
* -------------
|
|
*/
|
|
|
|
function 'mkpair-a'(int a)
|
|
{
|
|
return (1, a);
|
|
}
|
|
|
|
function t_pair()
|
|
pair pp;
|
|
{
|
|
pp = (1, 2);
|
|
bt_assert((1,2) = pp);
|
|
bt_assert((1,1+1) = pp);
|
|
bt_assert('mkpair-a'(2) = pp);
|
|
bt_assert((1,2) = (1,1+1));
|
|
bt_assert(((1,2) < (2,2)));
|
|
bt_assert(!((1,1) > (1,1)));
|
|
}
|
|
|
|
bt_test_suite(t_pair, "Testing pairs");
|
|
|
|
|
|
|
|
|
|
/*
|
|
* Testing sets of pairs
|
|
* ---------------------
|
|
*/
|
|
|
|
function t_pair_set()
|
|
pair pp;
|
|
pair set ps;
|
|
{
|
|
pp = (1, 2);
|
|
ps = [(1,(one+one)), (3,4)..(4,8), (5,*), (6,3..6)];
|
|
print "Pair set: ", ps;
|
|
bt_assert(pp ~ ps);
|
|
bt_assert((3,5) ~ ps);
|
|
bt_assert((4,1) ~ ps);
|
|
bt_assert((5,4) ~ ps);
|
|
bt_assert((5,65535) ~ ps);
|
|
bt_assert((6,4) ~ ps);
|
|
bt_assert((3, 10000) ~ ps);
|
|
bt_assert((3,3) !~ ps);
|
|
bt_assert((4,9) !~ ps);
|
|
bt_assert((4,65535) !~ ps);
|
|
bt_assert((6,2) !~ ps);
|
|
bt_assert((6,6+one) !~ ps);
|
|
bt_assert(((one+6),2) !~ ps);
|
|
bt_assert((1,1) !~ ps);
|
|
|
|
ps = [(20..150, 200..300), (50100..50200, 1000..50000), (*, 5+5)];
|
|
print "Pair set: ", ps;
|
|
bt_assert((100,200) ~ ps);
|
|
bt_assert((150,300) ~ ps);
|
|
bt_assert((50180,1200) ~ ps);
|
|
bt_assert((50110,49000) ~ ps);
|
|
bt_assert((0,10) ~ ps);
|
|
bt_assert((64000,10) ~ ps);
|
|
bt_assert((20,199) !~ ps);
|
|
bt_assert((151,250) !~ ps);
|
|
bt_assert((50050,2000) !~ ps);
|
|
bt_assert((50150,50050) !~ ps);
|
|
bt_assert((10,9) !~ ps);
|
|
bt_assert((65535,11) !~ ps);
|
|
}
|
|
|
|
bt_test_suite(t_pair_set, "Testing sets of pairs");
|
|
|
|
|
|
|
|
|
|
/*
|
|
* Testing string matching
|
|
* -----------------------
|
|
*/
|
|
|
|
function t_string()
|
|
string st;
|
|
{
|
|
st = "Hello";
|
|
print "Testing string: ", st;
|
|
bt_assert(st ~ "Hell*");
|
|
bt_assert(st ~ "?ello");
|
|
bt_assert(st ~ "Hello");
|
|
bt_assert(st ~ "Hell?");
|
|
bt_assert(st !~ "ell*");
|
|
}
|
|
|
|
bt_test_suite(t_string, "Testing string matching");
|
|
|
|
|
|
|
|
|
|
/*
|
|
* Testing boolean expressions
|
|
* ---------------------------
|
|
*/
|
|
|
|
function t_bool()
|
|
bool b;
|
|
{
|
|
b = true;
|
|
bt_assert(b);
|
|
bt_assert(!!b);
|
|
|
|
if ( b = true ) then
|
|
bt_assert(b);
|
|
else
|
|
bt_assert(false);
|
|
|
|
bt_assert(true && true);
|
|
bt_assert(true || false);
|
|
bt_assert(! false && ! false && true);
|
|
bt_assert(1 < 2 && 1 != 3);
|
|
bt_assert(true && true && ! false);
|
|
bt_assert(true || 1+"a");
|
|
bt_assert(!(false && 1+"a"));
|
|
bt_assert(!(true && false));
|
|
}
|
|
|
|
bt_test_suite(t_bool, "Testing boolean expressions");
|
|
|
|
|
|
|
|
|
|
/*
|
|
* Testing prefixes
|
|
* ----------------
|
|
*/
|
|
|
|
define netdoc = 2001:db8::/32;
|
|
|
|
function t_prefix()
|
|
prefix px;
|
|
{
|
|
px = 1.2.0.0/18;
|
|
print "Testing prefixes: 1.2.0.0/18 = ", px;
|
|
bt_assert(192.168.0.0/16 ~ 192.168.0.0/16);
|
|
bt_assert(192.168.0.0/17 ~ 192.168.0.0/16);
|
|
bt_assert(192.168.254.0/24 ~ 192.168.0.0/16);
|
|
bt_assert(netdoc ~ 2001::/16);
|
|
bt_assert(192.168.0.0/15 !~ 192.168.0.0/16);
|
|
bt_assert(192.160.0.0/17 !~ 192.168.0.0/16);
|
|
bt_assert(px !~ netdoc);
|
|
|
|
bt_assert(1.2.3.4 ~ 1.0.0.0/8);
|
|
bt_assert(1.0.0.0/8 ~ 1.0.0.0/8);
|
|
}
|
|
|
|
bt_test_suite(t_prefix, "Testing prefixes");
|
|
|
|
|
|
|
|
|
|
/*
|
|
* Testing prefix sets
|
|
* -------------------
|
|
*/
|
|
|
|
define net10 = 10.0.0.0/8;
|
|
define pxs2 = [ 10.0.0.0/16{8,12}, 20.0.0.0/16{24,28} ];
|
|
|
|
function test_pxset(prefix set pxs)
|
|
{
|
|
print pxs;
|
|
|
|
bt_assert(net10 ~ pxs);
|
|
bt_assert(10.0.0.0/10 ~ pxs);
|
|
bt_assert(10.0.0.0/12 ~ pxs);
|
|
bt_assert(20.0.0.0/24 ~ pxs);
|
|
bt_assert(20.0.40.0/24 ~ pxs);
|
|
bt_assert(20.0.0.0/26 ~ pxs);
|
|
bt_assert(20.0.100.0/26 ~ pxs);
|
|
bt_assert(20.0.0.0/28 ~ pxs);
|
|
bt_assert(20.0.255.0/28 ~ pxs);
|
|
|
|
bt_assert(10.0.0.0/7 !~ pxs);
|
|
bt_assert(10.0.0.0/13 !~ pxs);
|
|
bt_assert(10.0.0.0/16 !~ pxs);
|
|
bt_assert(20.0.0.0/16 !~ pxs);
|
|
bt_assert(20.0.0.0/23 !~ pxs);
|
|
bt_assert(20.0.0.0/29 !~ pxs);
|
|
bt_assert(11.0.0.0/10 !~ pxs);
|
|
bt_assert(20.1.0.0/26 !~ pxs);
|
|
|
|
bt_assert(1.0.0.0/8 ~ [ 1.0.0.0/8+ ]);
|
|
bt_assert(1.0.0.0/9 !~ [ 1.0.0.0/8- ]);
|
|
bt_assert(1.2.0.0/17 !~ [ 1.0.0.0/8{ 15 , 16 } ]);
|
|
|
|
bt_assert([ 10.0.0.0/8{ 15 , 17 } ] = [ 10.0.0.0/8{ 15 , 17 } ]);
|
|
}
|
|
|
|
function t_prefix_sets()
|
|
prefix set pxs;
|
|
{
|
|
pxs = [ 1.2.0.0/16, 1.4.0.0/16+];
|
|
print "Testing prefix sets: ", pxs;
|
|
bt_assert(1.2.0.0/16 ~ pxs);
|
|
bt_assert(1.4.0.0/16 ~ pxs);
|
|
bt_assert(1.4.0.0/18 ~ pxs);
|
|
bt_assert(1.4.0.0/32 ~ pxs);
|
|
bt_assert(1.1.0.0/16 !~ pxs);
|
|
bt_assert(1.3.0.0/16 !~ pxs);
|
|
bt_assert(1.2.0.0/15 !~ pxs);
|
|
bt_assert(1.2.0.0/17 !~ pxs);
|
|
bt_assert(1.2.0.0/32 !~ pxs);
|
|
bt_assert(1.4.0.0/15 !~ pxs);
|
|
|
|
test_pxset(pxs2);
|
|
test_pxset([ 10.0.0.0/16{8,12}, 20.0.0.0/16{24,28} ]);
|
|
|
|
bt_assert(1.2.0.0/16 ~ [ 1.0.0.0/8{ 15 , 17 } ]);
|
|
bt_assert([ 10.0.0.0/8{ 15 , 17 } ] != [ 11.0.0.0/8{ 15 , 17 } ]);
|
|
}
|
|
|
|
bt_test_suite(t_prefix_sets, "Testing prefix sets");
|
|
|
|
|
|
|
|
|
|
/*
|
|
* Testing IP sets
|
|
* ---------------
|
|
*/
|
|
|
|
define ip1222 = 1.2.2.2;
|
|
|
|
function t_ip_sets()
|
|
ip set ips;
|
|
{
|
|
ips = [ 1.1.1.0 .. 1.1.1.255, ip1222];
|
|
print "Testing IP sets: ", ips;
|
|
bt_assert(1.1.1.0 ~ ips);
|
|
bt_assert(1.1.1.100 ~ ips);
|
|
bt_assert(1.2.2.2 ~ ips);
|
|
bt_assert(1.1.0.255 !~ ips);
|
|
bt_assert(1.1.2.0 !~ ips);
|
|
bt_assert(1.2.2.3 !~ ips);
|
|
bt_assert(192.168.1.1 !~ ips);
|
|
}
|
|
|
|
bt_test_suite(t_ip_sets, "Testing IP sets");
|
|
|
|
|
|
|
|
|
|
/*
|
|
* Testing calling functions
|
|
* -------------------------
|
|
*/
|
|
|
|
function callme(int arg1; int arg2)
|
|
int i;
|
|
{
|
|
case arg1 {
|
|
1, 42: return 42;
|
|
else: return arg1 * arg2;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
function fifteen()
|
|
{
|
|
return 15;
|
|
}
|
|
|
|
function t_call_function()
|
|
{
|
|
bt_assert(fifteen() = 15);
|
|
|
|
bt_assert(callme(1, 2) = 42);
|
|
bt_assert(callme(42, 2) = 42);
|
|
|
|
bt_assert(callme(2, 2) = 4);
|
|
bt_assert(callme(3, 2) = 6);
|
|
bt_assert(callme(4, 4) = 16);
|
|
bt_assert(callme(7, 2) = 14);
|
|
}
|
|
|
|
bt_test_suite(t_call_function, "Testing calling functions");
|
|
|
|
|
|
|
|
|
|
/*
|
|
* Test including another config file
|
|
* ----------------------------------
|
|
*/
|
|
|
|
function t_include()
|
|
int i;
|
|
{
|
|
print "Testing include";
|
|
i = 1;
|
|
include "test.conf.inc";
|
|
bt_assert(i = 42);
|
|
}
|
|
|
|
bt_test_suite(t_include, "Test including another config file");
|
|
|
|
|
|
|
|
|
|
/*
|
|
* Unused functions -- testing only parsing
|
|
* ----------------------------------------
|
|
*/
|
|
|
|
function __test1()
|
|
{
|
|
if source ~ [ RTS_BGP, RTS_STATIC ] then {
|
|
# ospf_metric1 = 65535;
|
|
# ospf_metric2 = 1000;
|
|
ospf_tag = 0x12345678;
|
|
accept;
|
|
}
|
|
reject;
|
|
}
|
|
|
|
function __test2()
|
|
{
|
|
if source ~ [ RTS_BGP, RTS_STATIC ] then {
|
|
# ospf_metric1 = 65535;
|
|
# ospf_metric2 = 1000;
|
|
ospf_tag = 0x12345678;
|
|
accept;
|
|
}
|
|
reject;
|
|
}
|
|
|
|
filter testf
|
|
int j;
|
|
{
|
|
print "Heya, filtering route to ", net.ip, " prefixlen ", net.len, " source ", source;
|
|
print "This route was from ", from;
|
|
j = 7;
|
|
j = 17;
|
|
if rip_metric > 15 then {
|
|
reject "RIP Metric is more than infinity";
|
|
}
|
|
rip_metric = 14;
|
|
unset(rip_metric);
|
|
|
|
accept "ok I take that";
|
|
}
|
|
|
|
/*
|
|
roa table rl
|
|
{
|
|
roa 10.110.0.0/16 max 16 as 1000;
|
|
roa 10.120.0.0/16 max 24 as 1000;
|
|
roa 10.130.0.0/16 max 24 as 2000;
|
|
roa 10.130.128.0/18 max 24 as 3000;
|
|
}
|
|
|
|
function test_roa()
|
|
{
|
|
# cannot be tested in __startup(), sorry
|
|
print "Testing ROA";
|
|
print "Should be true: ", roa_check(rl, 10.10.0.0/16, 1000) = ROA_UNKNOWN,
|
|
" ", roa_check(rl, 10.0.0.0/8, 1000) = ROA_UNKNOWN,
|
|
" ", roa_check(rl, 10.110.0.0/16, 1000) = ROA_VALID,
|
|
" ", roa_check(rl, 10.110.0.0/16, 2000) = ROA_INVALID,
|
|
" ", roa_check(rl, 10.110.32.0/20, 1000) = ROA_INVALID,
|
|
" ", roa_check(rl, 10.120.32.0/20, 1000) = ROA_VALID;
|
|
print "Should be true: ", roa_check(rl, 10.120.32.0/20, 2000) = ROA_INVALID,
|
|
" ", roa_check(rl, 10.120.32.32/28, 1000) = ROA_INVALID,
|
|
" ", roa_check(rl, 10.130.130.0/24, 1000) = ROA_INVALID,
|
|
" ", roa_check(rl, 10.130.130.0/24, 2000) = ROA_VALID,
|
|
" ", roa_check(rl, 10.130.30.0/24, 3000) = ROA_INVALID,
|
|
" ", roa_check(rl, 10.130.130.0/24, 3000) = ROA_VALID;
|
|
}
|
|
*/ |