]> git.sur5r.net Git - u-boot/commitdiff
fdt: dtoc: Add a full set of property tests
authorSimon Glass <sjg@chromium.org>
Sat, 27 May 2017 13:38:21 +0000 (07:38 -0600)
committerSimon Glass <sjg@chromium.org>
Fri, 2 Jun 2017 16:16:47 +0000 (10:16 -0600)
The tests don't currently cover all the different property types. Add a
new test which checks each property type in turn, to make sure each has
the correct type and value.

Signed-off-by: Simon Glass <sjg@chromium.org>
tools/binman/fdt_test.py
tools/binman/test/45_prop_test.dts [new file with mode: 0644]

index 12edeaba6c3584ec0eb0bea2985de8dc758d7330..65fb94738658f81e13c8ec9e15f0af23a795824f 100644 (file)
@@ -11,6 +11,7 @@ import sys
 import tempfile
 import unittest
 
+import fdt
 from fdt_select import FdtScan
 import fdt_util
 import tools
@@ -37,6 +38,51 @@ class TestFdt(unittest.TestCase):
         dt = FdtScan(fname)
         self._DeleteProp(dt)
 
+    def testFdtNormalProp(self):
+        fname = self.GetCompiled('45_prop_test.dts')
+        dt = FdtScan(fname)
+        node = dt.GetNode('/binman/intel-me')
+        self.assertEquals('intel-me', node.name)
+        val = fdt_util.GetString(node, 'filename')
+        self.assertEquals(str, type(val))
+        self.assertEquals('me.bin', val)
+
+        prop = node.props['intval']
+        self.assertEquals(fdt.TYPE_INT, prop.type)
+        self.assertEquals(3, fdt_util.GetInt(node, 'intval'))
+
+        prop = node.props['intarray']
+        self.assertEquals(fdt.TYPE_INT, prop.type)
+        self.assertEquals(list, type(prop.value))
+        self.assertEquals(2, len(prop.value))
+        self.assertEquals([5, 6],
+                          [fdt_util.fdt32_to_cpu(val) for val in prop.value])
+
+        prop = node.props['byteval']
+        self.assertEquals(fdt.TYPE_BYTE, prop.type)
+        self.assertEquals(chr(8), prop.value)
+
+        prop = node.props['bytearray']
+        self.assertEquals(fdt.TYPE_BYTE, prop.type)
+        self.assertEquals(list, type(prop.value))
+        self.assertEquals(str, type(prop.value[0]))
+        self.assertEquals(3, len(prop.value))
+        self.assertEquals([chr(1), '#', '4'], prop.value)
+
+        prop = node.props['longbytearray']
+        self.assertEquals(fdt.TYPE_INT, prop.type)
+        self.assertEquals(0x090a0b0c, fdt_util.GetInt(node, 'longbytearray'))
+
+        prop = node.props['stringval']
+        self.assertEquals(fdt.TYPE_STRING, prop.type)
+        self.assertEquals('message2', fdt_util.GetString(node, 'stringval'))
+
+        prop = node.props['stringarray']
+        self.assertEquals(fdt.TYPE_STRING, prop.type)
+        self.assertEquals(list, type(prop.value))
+        self.assertEquals(3, len(prop.value))
+        self.assertEquals(['another', 'multi-word', 'message'], prop.value)
+
     def testFdtFallback(self):
         fname = self.GetCompiled('34_x86_ucode.dts')
         dt = FdtScan(fname, True)
diff --git a/tools/binman/test/45_prop_test.dts b/tools/binman/test/45_prop_test.dts
new file mode 100644 (file)
index 0000000..d22e460
--- /dev/null
@@ -0,0 +1,23 @@
+/dts-v1/;
+
+/ {
+       #address-cells = <1>;
+       #size-cells = <1>;
+
+       binman {
+               sort-by-pos;
+               end-at-4gb;
+               size = <16>;
+               intel-me {
+                       filename = "me.bin";
+                       pos-unset;
+                       intval = <3>;
+                       intarray = <5 6>;
+                       byteval = [08];
+                       bytearray = [01 23 34];
+                       longbytearray = [09 0a 0b 0c];
+                       stringval = "message2";
+                       stringarray = "another", "multi-word", "message";
+               };
+       };
+};