From 9953b245a1cccb0bcf0efe519a8fc7a7b579969d Mon Sep 17 00:00:00 2001 From: Alex Mykyta Date: Thu, 9 May 2019 21:47:53 -0700 Subject: [PATCH] Add node util tests. Version release --- systemrdl/__about__.py | 2 +- test/test_node_utils.py | 61 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 test/test_node_utils.py diff --git a/systemrdl/__about__.py b/systemrdl/__about__.py index ed34683..14d9d2f 100644 --- a/systemrdl/__about__.py +++ b/systemrdl/__about__.py @@ -1 +1 @@ -__version__ = "1.7.0-dev" +__version__ = "1.7.0" diff --git a/test/test_node_utils.py b/test/test_node_utils.py new file mode 100644 index 0000000..837da5d --- /dev/null +++ b/test/test_node_utils.py @@ -0,0 +1,61 @@ + +from .unittest_utils import RDLSourceTestCase + +#=============================================================================== +# Validate inferred field bit placement/packing +#=============================================================================== +class TestNodeUtils(RDLSourceTestCase): + + def test_index_tools(self): + top = self.compile( + ["rdl_testcases/address_packing.rdl"], + "hier" + ) + + with self.subTest("hier.x"): + node = top.find_by_path("hier.x") + self.assertEqual(node.get_path(), "hier.x") + node.clear_lineage_index() + self.assertEqual(node.get_path(), "hier.x") + node.zero_lineage_index() + self.assertEqual(node.get_path(), "hier.x") + + with self.subTest("hier.y.a"): + node = top.find_by_path("hier.y[2].a") + self.assertEqual(node.get_path(), "hier.y[2].a[][]") + node.zero_lineage_index() + self.assertEqual(node.get_path(), "hier.y[0].a[0][0]") + node.clear_lineage_index() + self.assertEqual(node.get_path(), "hier.y[].a[][]") + + def test_address_tools(self): + top = self.compile( + ["rdl_testcases/address_packing.rdl"], + "hier" + ) + + with self.subTest("hier.y[2].a"): + node = top.find_by_path("hier.y[2].a") + with self.assertRaises(ValueError): + node.address_offset + with self.assertRaises(ValueError): + node.absolute_address + self.assertEqual(node.raw_address_offset, 0) + self.assertEqual(node.raw_absolute_address, 0x100) + + with self.subTest("hier.y.c[1][1]"): + node = top.find_by_path("hier.y.c[1][1]") + self.assertEqual(node.address_offset, 0x64 + 4*4+4) + with self.assertRaises(ValueError): + node.absolute_address + self.assertEqual(node.raw_address_offset, 0x64) + self.assertEqual(node.raw_absolute_address, 0x100 + 0x64) + + def test_repr(self): + top = self.compile( + ["rdl_testcases/address_packing.rdl"], + "hier" + ) + + node = top.find_by_path("hier.x.b.a") + self.assertRegex(str(node), "")