aboutsummaryrefslogtreecommitdiff
path: root/tools/dtoc/test_fdt.py
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2021-12-05 22:42:07 -0500
committerTom Rini <trini@konsulko.com>2021-12-05 22:42:07 -0500
commit6c56bd31b7c11c1f4e97bf6bd1db9f48e35ec10b (patch)
treed1d2b1c7bc2e31a33e65b769e464cb23e8aac22e /tools/dtoc/test_fdt.py
parentf89615088fba1b1f33713ad26dbe3a3c82b692ec (diff)
parentc229cd2b6e443a1365ff5089c4c4a6440f218dce (diff)
Merge tag 'dm-pull-5dec21a' of https://source.denx.de/u-boot/custodians/u-boot-dm into next
binman refactoring to improve section handling bloblist - allow it to be allocated sandbox config-header cleanup # gpg: Signature made Sun 05 Dec 2021 10:14:24 PM EST # gpg: using RSA key B25C0022AF86A7CC1655B6277F173A3E9008ADE6 # gpg: issuer "sjg@chromium.org" # gpg: Good signature from "Simon Glass <sjg@chromium.org>" [unknown] # gpg: WARNING: This key is not certified with a trusted signature! # gpg: There is no indication that the signature belongs to the owner. # Primary key fingerprint: B25C 0022 AF86 A7CC 1655 B627 7F17 3A3E 9008 ADE6
Diffstat (limited to 'tools/dtoc/test_fdt.py')
-rwxr-xr-xtools/dtoc/test_fdt.py53
1 files changed, 50 insertions, 3 deletions
diff --git a/tools/dtoc/test_fdt.py b/tools/dtoc/test_fdt.py
index d104f3c774..55b70e9876 100755
--- a/tools/dtoc/test_fdt.py
+++ b/tools/dtoc/test_fdt.py
@@ -16,9 +16,15 @@ import unittest
our_path = os.path.dirname(os.path.realpath(__file__))
sys.path.insert(1, os.path.join(our_path, '..'))
+# Bring in the libfdt module
+sys.path.insert(2, 'scripts/dtc/pylibfdt')
+sys.path.insert(2, os.path.join(our_path, '../../scripts/dtc/pylibfdt'))
+sys.path.insert(2, os.path.join(our_path,
+ '../../build-sandbox_spl/scripts/dtc/pylibfdt'))
+
from dtoc import fdt
from dtoc import fdt_util
-from dtoc.fdt_util import fdt32_to_cpu
+from dtoc.fdt_util import fdt32_to_cpu, fdt64_to_cpu
from fdt import Type, BytesToValue
import libfdt
from patman import command
@@ -122,7 +128,7 @@ class TestFdt(unittest.TestCase):
node = self.dtb.GetNode('/spl-test')
props = self.dtb.GetProps(node)
self.assertEqual(['boolval', 'bytearray', 'byteval', 'compatible',
- 'intarray', 'intval', 'longbytearray',
+ 'int64val', 'intarray', 'intval', 'longbytearray',
'maybe-empty-int', 'notstring', 'stringarray',
'stringval', 'u-boot,dm-pre-reloc'],
sorted(props.keys()))
@@ -329,6 +335,10 @@ class TestProp(unittest.TestCase):
self.assertEqual(Type.INT, prop.type)
self.assertEqual(1, fdt32_to_cpu(prop.value))
+ prop = self._ConvertProp('int64val')
+ self.assertEqual(Type.INT, prop.type)
+ self.assertEqual(0x123456789abcdef0, fdt64_to_cpu(prop.value))
+
prop = self._ConvertProp('intarray')
self.assertEqual(Type.INT, prop.type)
val = [fdt32_to_cpu(val) for val in prop.value]
@@ -580,10 +590,21 @@ class TestFdtUtil(unittest.TestCase):
self.assertEqual(3, fdt_util.GetInt(self.node, 'missing', 3))
with self.assertRaises(ValueError) as e:
- self.assertEqual(3, fdt_util.GetInt(self.node, 'intarray'))
+ fdt_util.GetInt(self.node, 'intarray')
self.assertIn("property 'intarray' has list value: expecting a single "
'integer', str(e.exception))
+ def testGetInt64(self):
+ self.assertEqual(0x123456789abcdef0,
+ fdt_util.GetInt64(self.node, 'int64val'))
+ self.assertEqual(3, fdt_util.GetInt64(self.node, 'missing', 3))
+
+ with self.assertRaises(ValueError) as e:
+ fdt_util.GetInt64(self.node, 'intarray')
+ self.assertIn(
+ "property 'intarray' should be a list with 2 items for 64-bit values",
+ str(e.exception))
+
def testGetString(self):
self.assertEqual('message', fdt_util.GetString(self.node, 'stringval'))
self.assertEqual('test', fdt_util.GetString(self.node, 'missing',
@@ -594,6 +615,15 @@ class TestFdtUtil(unittest.TestCase):
self.assertIn("property 'stringarray' has list value: expecting a "
'single string', str(e.exception))
+ def testGetStringList(self):
+ self.assertEqual(['message'],
+ fdt_util.GetStringList(self.node, 'stringval'))
+ self.assertEqual(
+ ['multi-word', 'message'],
+ fdt_util.GetStringList(self.node, 'stringarray'))
+ self.assertEqual(['test'],
+ fdt_util.GetStringList(self.node, 'missing', ['test']))
+
def testGetBool(self):
self.assertEqual(True, fdt_util.GetBool(self.node, 'boolval'))
self.assertEqual(False, fdt_util.GetBool(self.node, 'missing'))
@@ -614,6 +644,23 @@ class TestFdtUtil(unittest.TestCase):
self.assertIn("property 'intval' has length 4, expecting 1",
str(e.exception))
+ def testGetBytes(self):
+ self.assertEqual(bytes([5]), fdt_util.GetBytes(self.node, 'byteval', 1))
+ self.assertEqual(None, fdt_util.GetBytes(self.node, 'missing', 3))
+ self.assertEqual(
+ bytes([3]), fdt_util.GetBytes(self.node, 'missing', 3, bytes([3])))
+
+ with self.assertRaises(ValueError) as e:
+ fdt_util.GetBytes(self.node, 'longbytearray', 7)
+ self.assertIn(
+ "Node 'spl-test' property 'longbytearray' has length 9, expecting 7",
+ str(e.exception))
+
+ self.assertEqual(
+ bytes([0, 0, 0, 1]), fdt_util.GetBytes(self.node, 'intval', 4))
+ self.assertEqual(
+ bytes([3]), fdt_util.GetBytes(self.node, 'missing', 3, bytes([3])))
+
def testGetPhandleList(self):
dtb = fdt.FdtScan(find_dtb_file('dtoc_test_phandle.dts'))
node = dtb.GetNode('/phandle-source2')