From: Luca Weiss <luca-IfPCFPJWly+lVyrhU4qvOw@public.gmane.org>
To: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: Luca Weiss <luca-IfPCFPJWly+lVyrhU4qvOw@public.gmane.org>
Subject: [PATCH v3] pylibfdt: add FdtRo.get_path()
Date: Wed, 26 Jan 2022 16:59:33 +0100 [thread overview]
Message-ID: <20220126155933.865297-1-luca@z3ntu.xyz> (raw)
Add a new Python method wrapping fdt_get_path() from the C API.
Also add a test for the new method.
Signed-off-by: Luca Weiss <luca-IfPCFPJWly+lVyrhU4qvOw@public.gmane.org>
---
Changes since v2:
* Remove arbitrary size limit
* Change size calculation to increase exponentially
* Add test to verify we still get exceptions with bad parameters
pylibfdt/libfdt.i | 26 ++++++++++++++++++++++++++
tests/pylibfdt_tests.py | 11 +++++++++++
2 files changed, 37 insertions(+)
diff --git a/pylibfdt/libfdt.i b/pylibfdt/libfdt.i
index ac70762..2f085c8 100644
--- a/pylibfdt/libfdt.i
+++ b/pylibfdt/libfdt.i
@@ -443,6 +443,27 @@ class FdtRo(object):
"""
return fdt_get_alias(self._fdt, name)
+ def get_path(self, nodeoffset):
+ """Get the full path of a node
+
+ Args:
+ nodeoffset: Node offset to check
+
+ Returns:
+ Full path to the node
+
+ Raises:
+ FdtException if an error occurs
+ """
+ size = 1024
+ while True:
+ ret, path = fdt_get_path(self._fdt, nodeoffset, size)
+ if ret == -NOSPACE:
+ size = size * 2
+ continue
+ check_err(ret)
+ return path
+
def parent_offset(self, nodeoffset, quiet=()):
"""Get the offset of a node's parent
@@ -1115,6 +1136,11 @@ typedef uint32_t fdt32_t;
}
}
+%include "cstring.i"
+
+%cstring_output_maxsize(char *buf, int buflen);
+int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen);
+
/* We have both struct fdt_property and a function fdt_property() */
%warnfilter(302) fdt_property;
diff --git a/tests/pylibfdt_tests.py b/tests/pylibfdt_tests.py
index 5479363..5435881 100644
--- a/tests/pylibfdt_tests.py
+++ b/tests/pylibfdt_tests.py
@@ -348,6 +348,17 @@ class PyLibfdtBasicTests(unittest.TestCase):
self.assertEqual("/subnode@1/subsubnode", self.fdt3.get_alias('ss1'))
self.assertEqual("/subnode@1/subsubnode/subsubsubnode", self.fdt3.get_alias('sss1'))
+ def testGetPath(self):
+ """Test for the get_path() method"""
+ node = self.fdt.path_offset('/subnode@1')
+ node2 = self.fdt.path_offset('/subnode@1/subsubnode')
+ self.assertEqual("/subnode@1", self.fdt.get_path(node))
+ self.assertEqual("/subnode@1/subsubnode", self.fdt.get_path(node2))
+
+ with self.assertRaises(FdtException) as e:
+ self.fdt.get_path(-1)
+ self.assertEqual(e.exception.err, -libfdt.BADOFFSET)
+
def testParentOffset(self):
"""Test for the parent_offset() method"""
self.assertEqual(-libfdt.NOTFOUND,
--
2.34.1
next reply other threads:[~2022-01-26 15:59 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-26 15:59 Luca Weiss [this message]
[not found] ` <20220126155933.865297-1-luca-IfPCFPJWly+lVyrhU4qvOw@public.gmane.org>
2022-01-26 19:29 ` [PATCH v3] pylibfdt: add FdtRo.get_path() Simon Glass
[not found] ` <CAPnjgZ2joJOwVN8D46ehZAmO0EH26fiYgz2zPdq19nW4iFzgow-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2022-01-26 19:50 ` Luca Weiss
2022-01-26 21:16 ` Simon Glass
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220126155933.865297-1-luca@z3ntu.xyz \
--to=luca-ifpcfpjwly+lvyrhu4qvow@public.gmane.org \
--cc=devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).