utest: adapt parser tests for struct/enum params, wildcards
will add more tests for the new features later
diff --git a/utest/test_frontend.py b/utest/test_frontend.py
index 609a262..9249273 100755
--- a/utest/test_frontend.py
+++ b/utest/test_frontend.py
@@ -81,26 +81,26 @@
# Not testing the parser, just making sure the AST is what we expect
expected_ast = [
['metadata', 'version', '1'],
- ['enum', 'ofp_port_config', [
- ['OFPPC_PORT_DOWN', 1],
- ['OFPPC_NO_STP', 2],
- ['OFPPC_NO_RECV', 4],
- ['OFPPC_NO_RECV_STP', 8],
- ['OFPPC_NO_FLOOD', 16],
- ['OFPPC_NO_FWD', 32],
- ['OFPPC_NO_PACKET_IN', 64]]],
+ ['enum', 'ofp_port_config', [], [
+ ['OFPPC_PORT_DOWN', [], 1],
+ ['OFPPC_NO_STP', [], 2],
+ ['OFPPC_NO_RECV', [], 4],
+ ['OFPPC_NO_RECV_STP', [], 8],
+ ['OFPPC_NO_FLOOD', [], 16],
+ ['OFPPC_NO_FWD', [], 32],
+ ['OFPPC_NO_PACKET_IN', [], 64]]],
['metadata', 'version', '2'],
- ['struct', 'of_echo_reply', None, [
+ ['struct', 'of_echo_reply', [], None, [
['data', 'uint8_t', 'version'],
['type', 'uint8_t', 'type', 3],
['data', 'uint16_t', 'length'],
['data', 'uint32_t', 'xid'],
['data', 'of_octets_t', 'data']]],
- ['enum', 'ofp_queue_op_failed_code', [
- ['OFPQOFC_BAD_PORT', 0],
- ['OFPQOFC_BAD_QUEUE', 1],
- ['OFPQOFC_EPERM', 2]]],
- ['struct', 'of_packet_queue', None, [
+ ['enum', 'ofp_queue_op_failed_code', [], [
+ ['OFPQOFC_BAD_PORT', [], 0],
+ ['OFPQOFC_BAD_QUEUE', [], 1],
+ ['OFPQOFC_EPERM', [], 2]]],
+ ['struct', 'of_packet_queue', [], None, [
['data', 'uint32_t', 'queue_id'],
['data', 'uint16_t', 'len'],
['pad', 2],
@@ -111,32 +111,32 @@
ofinput = frontend.create_ofinput(ast)
self.assertEquals(set([1, 2]), ofinput.wire_versions)
expected_classes = [
- OFClass('of_echo_reply', None, [
+ OFClass(name='of_echo_reply', superclass=None, members=[
OFDataMember('version', 'uint8_t'), # XXX
OFTypeMember('type', 'uint8_t', 3),
OFLengthMember('length', 'uint16_t'),
OFDataMember('xid', 'uint32_t'),
- OFDataMember('data', 'of_octets_t')]),
- OFClass('of_packet_queue', None, [
+ OFDataMember('data', 'of_octets_t')], virtual=False, params={}),
+ OFClass(name='of_packet_queue', superclass=None, members=[
OFDataMember('queue_id', 'uint32_t'),
OFLengthMember('len', 'uint16_t'),
OFPadMember(2),
- OFDataMember('properties', 'list(of_queue_prop_t)')]),
+ OFDataMember('properties', 'list(of_queue_prop_t)')], virtual=False, params={}),
]
self.assertEquals(expected_classes, ofinput.classes)
expected_enums = [
- OFEnum('ofp_port_config', [
- ('OFPPC_PORT_DOWN', 1),
- ('OFPPC_NO_STP', 2),
- ('OFPPC_NO_RECV', 4),
- ('OFPPC_NO_RECV_STP', 8),
- ('OFPPC_NO_FLOOD', 16),
- ('OFPPC_NO_FWD', 32),
- ('OFPPC_NO_PACKET_IN', 64)]),
- OFEnum('ofp_queue_op_failed_code', [
- ('OFPQOFC_BAD_PORT', 0),
- ('OFPQOFC_BAD_QUEUE', 1),
- ('OFPQOFC_EPERM', 2)]),
+ OFEnum(name='ofp_port_config', entries=[
+ OFEnumEntry('OFPPC_PORT_DOWN', 1, {}),
+ OFEnumEntry('OFPPC_NO_STP', 2, {}),
+ OFEnumEntry('OFPPC_NO_RECV', 4, {}),
+ OFEnumEntry('OFPPC_NO_RECV_STP', 8, {}),
+ OFEnumEntry('OFPPC_NO_FLOOD', 16, {}),
+ OFEnumEntry('OFPPC_NO_FWD', 32, {}),
+ OFEnumEntry('OFPPC_NO_PACKET_IN', 64, {})], params={}),
+ OFEnum(name='ofp_queue_op_failed_code', entries=[
+ OFEnumEntry('OFPQOFC_BAD_PORT', 0, {}),
+ OFEnumEntry('OFPQOFC_BAD_QUEUE', 1, {}),
+ OFEnumEntry('OFPQOFC_EPERM', 2, {})], params={}),
]
self.assertEquals(expected_enums, ofinput.enums)
@@ -145,7 +145,7 @@
#version 1
struct of_queue_prop {
- uint16_t type;
+ uint16_t type == ?;
uint16_t len;
pad(4);
};
@@ -163,12 +163,12 @@
expected_ast = [
['metadata', 'version', '1'],
- ['struct', 'of_queue_prop', None, [
- ['data', 'uint16_t', 'type'],
+ ['struct', 'of_queue_prop', [], None, [
+ ['discriminator', 'uint16_t', 'type'],
['data', 'uint16_t', 'len'],
['pad', 4]]],
- ['struct', 'of_queue_prop_min_rate', 'of_queue_prop', [
+ ['struct', 'of_queue_prop_min_rate', [], 'of_queue_prop', [
['type', 'uint16_t', 'type', 1],
['data', 'uint16_t', 'len'],
['pad', 4],
@@ -179,16 +179,16 @@
ofinput = frontend.create_ofinput(ast)
expected_classes = [
- OFClass('of_queue_prop', None, [
- OFDataMember('type', 'uint16_t'),
+ OFClass(name='of_queue_prop', superclass=None, members=[
+ OFDiscriminatorMember('type', 'uint16_t'),
OFLengthMember('len', 'uint16_t'),
- OFPadMember(4)]),
- OFClass('of_queue_prop_min_rate', 'of_queue_prop', [
+ OFPadMember(4)], virtual=True, params={}),
+ OFClass(name='of_queue_prop_min_rate', superclass='of_queue_prop', members= [
OFTypeMember('type', 'uint16_t', 1),
OFLengthMember('len', 'uint16_t'),
OFPadMember(4),
OFDataMember('rate', 'uint16_t'),
- OFPadMember(6)]),
+ OFPadMember(6)], virtual=False, params= {}),
]
self.assertEquals(expected_classes, ofinput.classes)
diff --git a/utest/test_parser.py b/utest/test_parser.py
index c24665c..8199096 100755
--- a/utest/test_parser.py
+++ b/utest/test_parser.py
@@ -42,7 +42,7 @@
struct foo { };
"""
ast = parser.parse(src)
- self.assertEquals(ast, [['struct', 'foo', None, []]])
+ self.assertEquals(ast, [['struct', 'foo', [], None, []]])
def test_one_field(self):
src = """\
@@ -52,7 +52,7 @@
"""
ast = parser.parse(src)
self.assertEquals(ast,
- [['struct', 'foo', None, [['data', 'uint32_t', 'bar']]]])
+ [['struct', 'foo', [], None, [['data', 'uint32_t', 'bar']]]])
def test_multiple_fields(self):
src = """\
@@ -64,7 +64,7 @@
"""
ast = parser.parse(src)
self.assertEquals(ast,
- [['struct', 'foo', None,
+ [['struct', 'foo', [], None,
[['data', 'uint32_t', 'bar'],
['data', 'uint8_t', 'baz'],
['data', 'uint64_t', 'abc']]]])
@@ -77,7 +77,7 @@
"""
ast = parser.parse(src)
self.assertEquals(ast,
- [['struct', 'foo', None, [['data', 'uint32_t[4]', 'bar']]]])
+ [['struct', 'foo', [], None, [['data', 'uint32_t[4]', 'bar']]]])
def test_list_type(self):
src = """\
@@ -87,7 +87,7 @@
"""
ast = parser.parse(src)
self.assertEquals(ast,
- [['struct', 'foo', None, [['data', 'list(of_action_t)', 'bar']]]])
+ [['struct', 'foo', [], None, [['data', 'list(of_action_t)', 'bar']]]])
def test_pad_member(self):
src = """\
@@ -97,7 +97,7 @@
"""
ast = parser.parse(src)
self.assertEquals(ast,
- [['struct', 'foo', None, [['pad', 1]]]])
+ [['struct', 'foo', [], None, [['pad', 1]]]])
def test_type_member(self):
src = """\
@@ -107,7 +107,7 @@
"""
ast = parser.parse(src)
self.assertEquals(ast,
- [['struct', 'foo', None, [['type', 'uint16_t', 'foo', 0x10]]]])
+ [['struct', 'foo', [], None, [['type', 'uint16_t', 'foo', 0x10]]]])
def test_inheritance(self):
src = """\
@@ -117,7 +117,7 @@
"""
ast = parser.parse(src)
self.assertEquals(ast,
- [['struct', 'foo', 'bar', [['type', 'uint16_t', 'foo', 0x10]]]])
+ [['struct', 'foo', [], 'bar', [['type', 'uint16_t', 'foo', 0x10]]]])
class EnumTests(unittest.TestCase):
def test_empty(self):
@@ -126,7 +126,7 @@
};
"""
ast = parser.parse(src)
- self.assertEquals(ast, [['enum', 'foo', []]])
+ self.assertEquals(ast, [['enum', 'foo', [], []]])
def test_one(self):
src = """\
@@ -135,7 +135,7 @@
};
"""
ast = parser.parse(src)
- self.assertEquals(ast, [['enum', 'foo', [['BAR', 1]]]])
+ self.assertEquals(ast, [['enum', 'foo', [], [['BAR', [], 1]]]])
def test_multiple(self):
src = """\
@@ -146,7 +146,7 @@
};
"""
ast = parser.parse(src)
- self.assertEquals(ast, [['enum', 'foo', [['OFP_A', 1], ['OFP_B', 2], ['OFP_C', 3]]]])
+ self.assertEquals(ast, [['enum', 'foo', [], [['OFP_A', [], 1], ['OFP_B', [], 2], ['OFP_C', [], 3]]]])
def test_trailing_comma(self):
src = """\
@@ -157,7 +157,7 @@
};
"""
ast = parser.parse(src)
- self.assertEquals(ast, [['enum', 'foo', [['OFP_A', 1], ['OFP_B', 2], ['OFP_C', 3]]]])
+ self.assertEquals(ast, [['enum', 'foo', [], [['OFP_A', [], 1], ['OFP_B', [], 2], ['OFP_C', [], 3]]]])
class TestMetadata(unittest.TestCase):
def test_version(self):
@@ -175,7 +175,7 @@
"""
ast = parser.parse(src)
self.assertEquals(ast,
- [['struct', 'foo', None, []], ['struct', 'bar', None, []]])
+ [['struct', 'foo', [], None, []], ['struct', 'bar', [], None, []]])
def test_comments(self):
src = """\
@@ -189,7 +189,7 @@
"""
ast = parser.parse(src)
self.assertEquals(ast,
- [['struct', 'foo', None, [['data', 'uint32_t', 'a']]]])
+ [['struct', 'foo', [], None, [['data', 'uint32_t', 'a']]]])
def test_mixed(self):
src = """\
@@ -201,9 +201,9 @@
ast = parser.parse(src)
self.assertEquals(ast,
[['metadata', 'version', '1'],
- ['struct', 'foo', None, []],
+ ['struct', 'foo', [], None, []],
['metadata', 'version', '2'],
- ['struct', 'bar', None, []]])
+ ['struct', 'bar', [], None, []]])
class TestErrors(unittest.TestCase):
def syntax_error(self, src, regex):