[Crosstoolchain-logs] [device-tree-compiler] 48/57: pylibfdt: Add support for fdt_subnode_offset()

Vagrant Cascadian vagrant at moszumanska.debian.org
Thu Sep 28 22:04:00 UTC 2017


This is an automated email from the git hooks/post-receive script.

vagrant pushed a commit to branch upstream/latest
in repository device-tree-compiler.

commit 5bed86aee9e82cd8467560a9a39358943aaa4ad9
Author: Simon Glass <sjg at chromium.org>
Date:   Sat Aug 19 11:18:01 2017 -0600

    pylibfdt: Add support for fdt_subnode_offset()
    
    Add this into the class to simplify use of this function.
    
    Signed-off-by: Simon Glass <sjg at chromium.org>
    Signed-off-by: David Gibson <david at gibson.dropbear.id.au>
---
 pylibfdt/libfdt.i       | 17 +++++++++++++++++
 tests/pylibfdt_tests.py | 12 ++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/pylibfdt/libfdt.i b/pylibfdt/libfdt.i
index d492d58..415820d 100644
--- a/pylibfdt/libfdt.i
+++ b/pylibfdt/libfdt.i
@@ -174,6 +174,23 @@ class Fdt:
         self._fdt = bytearray(data)
         check_err(fdt_check_header(self._fdt));
 
+    def subnode_offset(self, parentoffset, name, quiet=()):
+        """Get the offset of a named subnode
+
+        Args:
+            parentoffset: Offset of the parent node to check
+            name: Name of the required subnode, e.g. 'subnode at 1'
+            quiet: Errors to ignore (empty to raise on all errors)
+
+        Returns:
+            The node offset of the found node, if any
+
+        Raises
+            FdtException if there is no node with that name, or other error
+        """
+        return check_err(fdt_subnode_offset(self._fdt, parentoffset, name),
+                         quiet)
+
     def path_offset(self, path, quiet=()):
         """Get the offset for a given path
 
diff --git a/tests/pylibfdt_tests.py b/tests/pylibfdt_tests.py
index 8028c1a..95d911a 100644
--- a/tests/pylibfdt_tests.py
+++ b/tests/pylibfdt_tests.py
@@ -118,6 +118,18 @@ class PyLibfdtTests(unittest.TestCase):
             fdt = libfdt.Fdt('a string')
         self.assertEquals(e.exception.err, -libfdt.BADMAGIC)
 
+    def testSubnodeOffset(self):
+        """check that we can locate a subnode by name"""
+        node1 = self.fdt.path_offset('/subnode at 1')
+        self.assertEquals(self.fdt.subnode_offset(0, 'subnode at 1'), node1)
+
+        with self.assertRaises(FdtException) as e:
+            self.fdt.subnode_offset(0, 'missing')
+        self.assertEquals(e.exception.err, -libfdt.NOTFOUND)
+
+        node2 = self.fdt.path_offset('/subnode at 1/subsubnode')
+        self.assertEquals(self.fdt.subnode_offset(node1, 'subsubnode'), node2)
+
     def testPathOffset(self):
         """Check that we can find the offset of a node"""
         self.assertEquals(self.fdt.path_offset('/'), 0)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/crosstoolchain/device-tree-compiler.git



More information about the Crosstoolchain-logs mailing list