summaryrefslogtreecommitdiff
path: root/tools/dtoc/test_fdt.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/dtoc/test_fdt.py')
-rwxr-xr-xtools/dtoc/test_fdt.py67
1 files changed, 66 insertions, 1 deletions
diff --git a/tools/dtoc/test_fdt.py b/tools/dtoc/test_fdt.py
index e88d19f80e..d259702050 100755
--- a/tools/dtoc/test_fdt.py
+++ b/tools/dtoc/test_fdt.py
@@ -337,6 +337,7 @@ class TestProp(unittest.TestCase):
self.node.AddZeroProp('one')
self.node.AddZeroProp('two')
self.node.AddZeroProp('three')
+ self.dtb.Sync(auto_resize=True)
# Updating existing properties should be OK, since the device-tree size
# does not change
@@ -344,11 +345,75 @@ class TestProp(unittest.TestCase):
self.node.SetInt('one', 1)
self.node.SetInt('two', 2)
self.node.SetInt('three', 3)
+ self.dtb.Sync(auto_resize=False)
# This should fail since it would need to increase the device-tree size
+ self.node.AddZeroProp('four')
with self.assertRaises(libfdt.FdtException) as e:
- self.node.SetInt('four', 4)
+ self.dtb.Sync(auto_resize=False)
self.assertIn('FDT_ERR_NOSPACE', str(e.exception))
+ self.dtb.Sync(auto_resize=True)
+
+ def testAddNode(self):
+ self.fdt.pack()
+ self.node.AddSubnode('subnode')
+ with self.assertRaises(libfdt.FdtException) as e:
+ self.dtb.Sync(auto_resize=False)
+ self.assertIn('FDT_ERR_NOSPACE', str(e.exception))
+
+ self.dtb.Sync(auto_resize=True)
+ offset = self.fdt.path_offset('/spl-test/subnode')
+ self.assertTrue(offset > 0)
+
+ def testAddMore(self):
+ """Test various other methods for adding and setting properties"""
+ self.node.AddZeroProp('one')
+ self.dtb.Sync(auto_resize=True)
+ data = self.fdt.getprop(self.node.Offset(), 'one')
+ self.assertEqual(0, fdt32_to_cpu(data))
+
+ self.node.SetInt('one', 1)
+ self.dtb.Sync(auto_resize=False)
+ data = self.fdt.getprop(self.node.Offset(), 'one')
+ self.assertEqual(1, fdt32_to_cpu(data))
+
+ val = '123' + chr(0) + '456'
+ self.node.AddString('string', val)
+ self.dtb.Sync(auto_resize=True)
+ data = self.fdt.getprop(self.node.Offset(), 'string')
+ self.assertEqual(val + '\0', data)
+
+ self.fdt.pack()
+ self.node.SetString('string', val + 'x')
+ with self.assertRaises(libfdt.FdtException) as e:
+ self.dtb.Sync(auto_resize=False)
+ self.assertIn('FDT_ERR_NOSPACE', str(e.exception))
+ self.node.SetString('string', val[:-1])
+
+ prop = self.node.props['string']
+ prop.SetData(val)
+ self.dtb.Sync(auto_resize=False)
+ data = self.fdt.getprop(self.node.Offset(), 'string')
+ self.assertEqual(val, data)
+
+ self.node.AddEmptyProp('empty', 5)
+ self.dtb.Sync(auto_resize=True)
+ prop = self.node.props['empty']
+ prop.SetData(val)
+ self.dtb.Sync(auto_resize=False)
+ data = self.fdt.getprop(self.node.Offset(), 'empty')
+ self.assertEqual(val, data)
+
+ self.node.SetData('empty', '123')
+ self.assertEqual('123', prop.bytes)
+
+ def testFromData(self):
+ dtb2 = fdt.Fdt.FromData(self.dtb.GetContents())
+ self.assertEqual(dtb2.GetContents(), self.dtb.GetContents())
+
+ self.node.AddEmptyProp('empty', 5)
+ self.dtb.Sync(auto_resize=True)
+ self.assertTrue(dtb2.GetContents() != self.dtb.GetContents())
class TestFdtUtil(unittest.TestCase):