diff options
author | Simon Glass <sjg@chromium.org> | 2018-09-14 04:57:16 -0600 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2018-09-28 11:09:01 -0600 |
commit | 6434961b2b2099b458e7dc9dcced5d450b45cbb4 (patch) | |
tree | 27018b698249bbc4b82d0a922384f11bdad0f3ae /tools/dtoc/test_fdt.py | |
parent | e21c27af47183619c7ec7097abb1dec34410e775 (diff) |
dtoc: Add methods for adding and updating properties
Add a few more functions which allow creating and modifying property
values. If only we could do this so easily in the real world.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'tools/dtoc/test_fdt.py')
-rwxr-xr-x | tools/dtoc/test_fdt.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/tools/dtoc/test_fdt.py b/tools/dtoc/test_fdt.py index c94e455d12..22a075d6c5 100755 --- a/tools/dtoc/test_fdt.py +++ b/tools/dtoc/test_fdt.py @@ -352,6 +352,7 @@ class TestProp(unittest.TestCase): 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) def testAddNode(self): self.fdt.pack() @@ -364,6 +365,48 @@ class TestProp(unittest.TestCase): 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) + class TestFdtUtil(unittest.TestCase): """Tests for the fdt_util module |