new btests to cover extended functionality & associatd errors

This commit is contained in:
Vern Paxson 2022-03-11 14:28:14 -08:00 committed by Tim Wojtulewicz
parent 64775a8192
commit ae75635c5a
4 changed files with 231 additions and 0 deletions

View file

@ -0,0 +1,55 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
init_key in state: 1
init_key2 in state2: 1
{
[worker-2] = [node_type=Cluster::WORKER, ip=127.0.0.1, p=7/tcp, manager=manager-1],
[worker-3] = [node_type=Cluster::WORKER, ip=1.2.3.4, p=9/udp, manager=<uninitialized>],
[manager-1] = [node_type=Cluster::MANAGER, ip=127.0.0.1, p=3/tcp, manager=<uninitialized>],
[worker-1] = [node_type=Cluster::WORKER, ip=127.0.0.1, p=5/udp, manager=manager-1]
}
{
[worker-3] = [node_type=Cluster::WORKER, ip=1.2.3.4, p=9/udp, manager=<uninitialized>],
[manager-1] = [node_type=Cluster::MANAGER, ip=127.0.0.1, p=3/tcp, manager=<uninitialized>],
[worker-1] = [node_type=Cluster::WORKER, ip=127.0.0.1, p=5/udp, manager=manager-1]
}
{
[worker-4] = [node_type=Cluster::WORKER, ip=2.3.4.5, zone_id=, p=13/udp, interface=<uninitialized>, manager=<uninitialized>, time_machine=<uninitialized>, id=<uninitialized>]
}
{
[worker-4] = [node_type=Cluster::WORKER, ip=2.3.4.5, zone_id=, p=13/udp, interface=<uninitialized>, manager=<uninitialized>, time_machine=<uninitialized>, id=<uninitialized>],
[worker-5] = [node_type=Cluster::WORKER, ip=3.4.5.6, zone_id=, p=15/tcp, interface=<uninitialized>, manager=<uninitialized>, time_machine=<uninitialized>, id=<uninitialized>]
}
{
[worker-4] = [node_type=Cluster::WORKER, ip=2.3.4.5, zone_id=, p=13/udp, interface=<uninitialized>, manager=<uninitialized>, time_machine=<uninitialized>, id=<uninitialized>],
[worker-6] = [node_type=Cluster::WORKER, ip=4.5.6.7, zone_id=, p=17/udp, interface=<uninitialized>, manager=<uninitialized>, time_machine=<uninitialized>, id=<uninitialized>]
}
{
[3.0, 4]
}
{
[3.0, 4]
}
{
}
{
[9.0, 4]
}
{
[3.0, 4.0] = 5.0
}
{
[3.0, 4.0] = 5.0
}
{
}
{
[bar, 1.2.0.0/19] ,
[foo, 5.6.0.0/21] ,
[foo, 1.2.0.0/19] ,
[bar, 5.6.0.0/21]
}
/(^?(^?(bar)$?)$?)|(^?(^?(foo)$?)$?)/
[1, 3, 5, 9, 2, 4, 6, 20, 21, 22, 23]
[[3, 2, 1], [1, 2, 3], [20, 21, 22, 23], [80, 81], [90, 91, 92]]

View file

@ -0,0 +1,21 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
error in <...>/init-mismatch.zeek, line 6: invalid constructor list on RHS of assignment (a = 3, 5)
error in <...>/init-mismatch.zeek, line 6: assignment of non-arithmetic value to arithmetic (count/types) (a = 3, 5)
warning in <...>/init-mismatch.zeek, line 7: initialization not preceded by =<...>/-= is deprecated (4, 6)
error in <...>/init-mismatch.zeek, line 13: different number of indices (list of count,count and list of count,count,count)
error in <...>/init-mismatch.zeek, line 14: table constructor element lacks '=' structure (bar)
error in <...>/init-mismatch.zeek, line 17: empty list in untyped initialization ()
error in <...>/init-mismatch.zeek, line 23: cannot expand constructor elements using a value that depends on local variables (subnets)
error in <...>/init-mismatch.zeek, line 23: type clash in assignment (my_subnets = set(foo, subnets))
error in <...>/init-mismatch.zeek, line 26: invalid constructor list on RHS of assignment (c += 2, 4)
error in <...>/init-mismatch.zeek, line 27: constructor list not allowed for -= operations on vectors (v -= 3, 5)
error in <...>/init-mismatch.zeek, line 29: RHS type mismatch for table/set += (s1 += s2)
error in <...>/init-mismatch.zeek, line 30: RHS type mismatch for table/set -= (s1 -= s2)
error in <...>/init-mismatch.zeek, line 32: table constructor used in a non-table context (3 = F)
error in double and <...>/init-mismatch.zeek, line 32: arithmetic mixed with non-arithmetic (double and 3 = F)
error in <...>/init-mismatch.zeek, line 32 and double: type mismatch (3 = F and double)
error in <...>/init-mismatch.zeek, line 32: inconsistent type in set constructor (set(3 = F))
error in <...>/init-mismatch.zeek, line 34: not a list of indices (s2)
error in <...>/init-mismatch.zeek, line 34: type clash in assignment (s3 = set(s2))
error in <...>/init-mismatch.zeek, line 36: pattern += op requires op to be a pattern (p += 3)
error in <...>/init-mismatch.zeek, line 38: illegal table constructor element (1.2.3.4)

View file

@ -0,0 +1,115 @@
# @TEST-EXEC: zeek -b %INPUT >out
# @TEST-EXEC: btest-diff out
# @TEST-EXEC: btest-diff .stderr
# A bunch of tests for the unification of global initializations and
# =/+=/-= expressions.
# This is used just to pull in an example that works for globals, to make
# sure it works for locals.
@load base/frameworks/cluster
# This first covers the bug that motivated the unification.
type Key: record {
k0: string;
k1: string &optional;
};
global init_key = [$k0="x"];
# This used to crash or produce an ASAN error.
global state: table[Key] of count = {
[init_key] = 5,
};
global my_subnets = { 1.2.3.4/19, 5.6.7.8/21 };
event zeek_init()
{
print(fmt("init_key in state: %d", init_key in state));
# Check that the local version works.
local init_key2 = [$k0="y"];
local state2: table[Key] of count = { [init_key2] = 6 };
print(fmt("init_key2 in state2: %d", init_key2 in state2));
# Now checking that a complex initialization that works for
# globals also works for locals.
local cluster_nodes = {
["manager-1"] = [$node_type=Cluster::MANAGER, $ip=127.0.0.1, $p=3/tcp],
["worker-1"] = [$node_type=Cluster::WORKER, $ip=127.0.0.1, $p=5/udp, $manager="manager-1"],
["worker-2"] = [$node_type=Cluster::WORKER, $ip=127.0.0.1, $p=7/tcp, $manager="manager-1"],
};
cluster_nodes += { ["worker-3"] = [$node_type=Cluster::WORKER, $ip=1.2.3.4, $p=9/udp] };
print cluster_nodes;
cluster_nodes -= { ["worker-2"] = [$node_type=Cluster::MANAGER, $ip=0.0.0.0, $p=11/tcp] };
print cluster_nodes;
# Similar, but without type inference.
local cluster_nodes2: table[string] of Cluster::Node;
cluster_nodes2 = { ["worker-4"] = [$node_type=Cluster::WORKER, $ip=2.3.4.5, $p=13/udp] };
local cluster_nodes3: table[string] of Cluster::Node = {
["worker-5"] = [$node_type=Cluster::WORKER, $ip=3.4.5.6, $p=15/tcp]
};
print cluster_nodes2;
cluster_nodes2 += cluster_nodes3;
print cluster_nodes2;
cluster_nodes2 -= cluster_nodes3;
cluster_nodes2 += table(["worker-6"] = Cluster::Node($node_type=Cluster::WORKER, $ip=4.5.6.7, $p=17/udp));
print cluster_nodes2;
# Test automatic type conversions.
local s: set[double, int];
s += { [3, 4] };
print s;
s -= { [3, 3] };
print s;
s -= { [3, 4] };
print s;
# Note, the following correctly generates a type-mismatch error
# if we use set([9, 4]) since that's a set[count, count], not
# a set[double, int].
s += set([9.0, +4]);
print s;
# Similar, for tables.
local t: table[double, double] of double;
t += { [3, 4] = 5 };
print t;
t -= { [3, 3] = 9 };
print t;
t -= { [3, 4] = 7 };
print t;
# Test use of sets for expansion. my_subnets needs to be a global,
# because expansion happens at compile-time.
local x: set[string, subnet];
x += { [["foo", "bar"], my_subnets] };
print x;
# Test adding to patterns dynamically.
local p = /foo/;
p += /bar/;
print p;
# Tests for vectors.
local v: vector of count;
local v2 = vector(20, 21, 22, 23);
v = { 1, 3, 5 };
v += 9;
v += { 2, 4, 6 };
v += v2;
print v;
local v3: vector of vector of count;
local v4 = vector(vector(80, 81), vector(90, 91, 92));
v3 += { vector(3,2,1), vector(1,2,3) };
v3 += v2;
v3 += v4;
print v3;
}

View file

@ -0,0 +1,40 @@
# @TEST-EXEC-FAIL: zeek -b %INPUT
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff .stderr
# Tests for various mismatches in initializations.
global a: count = [3, 5];
global b [4, 6];
global c = 9;
global s1: set[double];
global s2: set[int];
global s3: set[count, count];
global t: table[addr] of bool;
global t2 = { [1, 3] = F, [2, 4, 6] = T };
global t3 = table( ["foo"] = 3, "bar" );
global v: vector of count;
global p: pattern;
global x = { };
function foo()
{
local subnets = { 1.2.3.4/24, 2.3.4.5/5 };
local my_subnets: set[string, subnet];
my_subnets = { ["foo", subnets] };
}
c += { 2, 4 };
v -= { 3, 5 };
s1 += s2;
s1 -= s2;
s1 += { [3] = F };
s3 = { s2 };
p += 3;
t += { 1.2.3.4, F };
print a, b;