Unit test for broccoli vector support.

Broccoli clients can only recv events w/ vectors for now.

Also changed ordering of Bro type tag enum -- the addition of opaque
types changed the value of the vector type, making broccoli.h's
definition out of sync.  Probably could have just changed broccoli's
definition, but seems more correct to go back to using the same value
for vectors as they were before opaques.  It's also better in case
there's some other location I'm not aware of where the values are
replicated.
This commit is contained in:
Jon Siwek 2013-12-03 11:18:17 -06:00
parent dc52846b6f
commit 5aa04089af
5 changed files with 87 additions and 33 deletions

View file

@ -19,21 +19,32 @@ extern int generate_documentation;
const char* type_name(TypeTag t)
{
static const char* type_names[int(NUM_TYPES)] = {
"void",
"bool", "int", "count", "counter",
"double", "time", "interval",
"string", "pattern",
"enum",
"timer",
"port", "addr", "subnet",
"any",
"table", "union", "record", "types",
"func",
"file",
"opaque",
"vector",
"type",
"error",
"void", // 0
"bool", // 1
"int", // 2
"count", // 3
"counter", // 4
"double", // 5
"time", // 6
"interval", // 7
"string", // 8
"pattern", // 9
"enum", // 10
"timer", // 11
"port", // 12
"addr", // 13
"subnet", // 14
"any", // 15
"table", // 16
"union", // 17
"record", // 18
"types", // 19
"func", // 20
"file", // 21
"vector", // 22
"opaque", // 23
"type", // 24
"error", // 25
};
if ( int(t) >= NUM_TYPES )

View file

@ -15,24 +15,32 @@
// BRO types.
typedef enum {
TYPE_VOID,
TYPE_BOOL, TYPE_INT, TYPE_COUNT, TYPE_COUNTER, TYPE_DOUBLE,
TYPE_TIME, TYPE_INTERVAL,
TYPE_STRING, TYPE_PATTERN,
TYPE_ENUM,
TYPE_TIMER,
TYPE_PORT, TYPE_ADDR, TYPE_SUBNET,
TYPE_ANY,
TYPE_TABLE,
TYPE_UNION,
TYPE_RECORD,
TYPE_LIST,
TYPE_FUNC,
TYPE_FILE,
TYPE_OPAQUE,
TYPE_VECTOR,
TYPE_TYPE,
TYPE_ERROR
TYPE_VOID, // 0
TYPE_BOOL, // 1
TYPE_INT, // 2
TYPE_COUNT, // 3
TYPE_COUNTER, // 4
TYPE_DOUBLE, // 5
TYPE_TIME, // 6
TYPE_INTERVAL, // 7
TYPE_STRING, // 8
TYPE_PATTERN, // 9
TYPE_ENUM, // 10
TYPE_TIMER, // 11
TYPE_PORT, // 12
TYPE_ADDR, // 13
TYPE_SUBNET, // 14
TYPE_ANY, // 15
TYPE_TABLE, // 16
TYPE_UNION, // 17
TYPE_RECORD, // 18
TYPE_LIST, // 19
TYPE_FUNC, // 20
TYPE_FILE, // 21
TYPE_VECTOR, // 22
TYPE_OPAQUE, // 23
TYPE_TYPE, // 24
TYPE_ERROR // 25
#define NUM_TYPES (int(TYPE_ERROR) + 1)
} TypeTag;

View file

@ -0,0 +1,13 @@
handshake done with peer
bro_vector([a, b, c, d, e])
bro_vector([one, two, three])
broccoli_vector_element(0, a)
broccoli_vector_element(1, b)
broccoli_vector_element(2, c)
broccoli_vector_element(3, d)
broccoli_vector_element(4, e)
broccoli_vector_element(5, additional element)
broccoli_vector_element(0, one)
broccoli_vector_element(1, two)
broccoli_vector_element(2, three)
broccoli_vector_element(3, additional element)

View file

@ -0,0 +1,12 @@
Connected to Bro instance at: localhost:47757
Received bro_vector
0: a
1: b
2: c
3: d
4: e
Received bro_vector
0: one
1: two
2: three
Terminating

View file

@ -0,0 +1,10 @@
# @TEST-SERIALIZE: comm
#
# @TEST-REQUIRES: test -e $BUILD/aux/broccoli/src/libbroccoli.so || test -e $BUILD/aux/broccoli/src/libbroccoli.dylib
#
# @TEST-EXEC: btest-bg-run bro bro $DIST/aux/broccoli/test/broccoli-vectors.bro
# @TEST-EXEC: sleep 1
# @TEST-EXEC: btest-bg-run broccoli $BUILD/aux/broccoli/test/broccoli-vectors
# @TEST-EXEC: btest-bg-wait 20
# @TEST-EXEC: btest-diff bro/.stdout
# @TEST-EXEC: btest-diff broccoli/.stdout