aboutsummaryrefslogtreecommitdiff
path: root/tools/dtoc/test_fdt.py
diff options
context:
space:
mode:
authorSimon Glass2020-10-03 11:31:27 -0600
committerSimon Glass2020-10-29 14:42:17 -0600
commite144cafe43c8298bd41c044329857c3068cd845b (patch)
tree0c671dc9826b0ca6569294c438597fcc89f78039 /tools/dtoc/test_fdt.py
parentabb9cd30b23858125ce015c1dffdae4d7895bae8 (diff)
dtoc: Fix widening of int to bytes
At present an integer is converted to bytes incorrectly. The whole 32-bit integer is inserted as the first element of the byte array, and the other three bytes are skipped. This was not noticed because the unit test did not check it, and the functional test was checking for wrong values. Update the code to handle this as a special case. Add one more test to cover all code paths. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'tools/dtoc/test_fdt.py')
-rwxr-xr-xtools/dtoc/test_fdt.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/tools/dtoc/test_fdt.py b/tools/dtoc/test_fdt.py
index b4f9b7f498f..cfe3e04c7ad 100755
--- a/tools/dtoc/test_fdt.py
+++ b/tools/dtoc/test_fdt.py
@@ -298,6 +298,7 @@ class TestProp(unittest.TestCase):
def testWiden(self):
"""Test widening of values"""
node2 = self.dtb.GetNode('/spl-test2')
+ node3 = self.dtb.GetNode('/spl-test3')
prop = self.node.props['intval']
# No action
@@ -316,11 +317,20 @@ class TestProp(unittest.TestCase):
# byte array, it should turn into an array.
prop = self.node.props['longbytearray']
prop2 = node2.props['longbytearray']
+ prop3 = node3.props['longbytearray']
self.assertFalse(isinstance(prop2.value, list))
self.assertEqual(4, len(prop2.value))
+ self.assertEqual(b'\x09\x0a\x0b\x0c', prop2.value)
prop2.Widen(prop)
self.assertTrue(isinstance(prop2.value, list))
self.assertEqual(9, len(prop2.value))
+ self.assertEqual(['\x09', '\x0a', '\x0b', '\x0c', '\0',
+ '\0', '\0', '\0', '\0'], prop2.value)
+ prop3.Widen(prop)
+ self.assertTrue(isinstance(prop3.value, list))
+ self.assertEqual(9, len(prop3.value))
+ self.assertEqual(['\x09', '\x0a', '\x0b', '\x0c', '\x0d',
+ '\x0e', '\x0f', '\x10', '\0'], prop3.value)
# Similarly for a string array
prop = self.node.props['stringval']