From: David Gibson <david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org>
To: Luca Weiss <luca-IfPCFPJWly+lVyrhU4qvOw@public.gmane.org>
Cc: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH 2/4] pylibfdt: add Property.as_*int*_array()
Date: Tue, 28 Dec 2021 15:30:51 +1100 [thread overview]
Message-ID: <YcqS++UZtf+tSumt@yekko> (raw)
In-Reply-To: <20211225132558.167123-3-luca-IfPCFPJWly+lVyrhU4qvOw@public.gmane.org>
[-- Attachment #1: Type: text/plain, Size: 3244 bytes --]
On Sat, Dec 25, 2021 at 02:25:56PM +0100, Luca Weiss wrote:
> Add new methods to handle decoding of int32, uint32, int64 and uint64
> arrays.
>
> Also add tests for the new methods.
>
> Signed-off-by: Luca Weiss <luca-IfPCFPJWly+lVyrhU4qvOw@public.gmane.org>
Applied, thanks.
> ---
> pylibfdt/libfdt.i | 15 +++++++++++++++
> tests/pylibfdt_tests.py | 11 +++++++++++
> tests/test_props.dts | 4 ++++
> 3 files changed, 30 insertions(+)
>
> diff --git a/pylibfdt/libfdt.i b/pylibfdt/libfdt.i
> index c81b504..ac70762 100644
> --- a/pylibfdt/libfdt.i
> +++ b/pylibfdt/libfdt.i
> @@ -716,6 +716,21 @@ class Property(bytearray):
> def as_int64(self):
> return self.as_cell('q')
>
> + def as_list(self, fmt):
> + return list(map(lambda x: x[0], struct.iter_unpack('>' + fmt, self)))
> +
> + def as_uint32_list(self):
> + return self.as_list('L')
> +
> + def as_int32_list(self):
> + return self.as_list('l')
> +
> + def as_uint64_list(self):
> + return self.as_list('Q')
> +
> + def as_int64_list(self):
> + return self.as_list('q')
> +
> def as_str(self):
> """Unicode is supported by decoding from UTF-8"""
> if self[-1] != 0:
> diff --git a/tests/pylibfdt_tests.py b/tests/pylibfdt_tests.py
> index 7e3cc4c..5479363 100644
> --- a/tests/pylibfdt_tests.py
> +++ b/tests/pylibfdt_tests.py
> @@ -382,6 +382,17 @@ class PyLibfdtBasicTests(unittest.TestCase):
> self.get_prop("prop-uint64").as_uint64())
> self.assertEqual(-2, self.get_prop("prop-int64").as_int64())
>
> + def testGetIntListProperties(self):
> + """Test that we can access properties as integer lists"""
> + self.assertEqual([128, -16, -2],
> + self.get_prop("prop-int32-array").as_int32_list())
> + self.assertEqual([0x1, 0x98765432, 0xdeadbeef],
> + self.get_prop("prop-uint32-array").as_uint32_list())
> + self.assertEqual([0x100000000, -2],
> + self.get_prop("prop-int64-array").as_int64_list())
> + self.assertEqual([0x100000000, 0x1],
> + self.get_prop("prop-uint64-array").as_uint64_list())
> +
> def testGetStringlistProperties(self):
> """Test that we can access properties as string list"""
> node = self.fdt.path_offset('/subnode@1/subsubnode')
> diff --git a/tests/test_props.dts b/tests/test_props.dts
> index 7e59bd1..5089023 100644
> --- a/tests/test_props.dts
> +++ b/tests/test_props.dts
> @@ -8,4 +8,8 @@
> prop-hex64 = /bits/ 64 <0xdeadbeef01abcdef>;
> prop-uint64 = /bits/ 64 <9223372036854775807>;
> prop-int64 = /bits/ 64 <0xfffffffffffffffe>;
> + prop-int32-array = <128>, <(-16)>, <0xfffffffe>;
> + prop-uint32-array = <0x1>, <0x98765432>, <0xdeadbeef>;
> + prop-int64-array = /bits/ 64 <0x100000000 0xfffffffffffffffe>;
> + prop-uint64-array = /bits/ 64 <0x100000000 0x1>;
> };
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2021-12-28 4:30 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-25 13:25 [PATCH 0/4] Add new helpers to pylibfdt Luca Weiss
[not found] ` <20211225132558.167123-1-luca-IfPCFPJWly+lVyrhU4qvOw@public.gmane.org>
2021-12-25 13:25 ` [PATCH 1/4] pylibfdt: add Property.as_stringlist() Luca Weiss
[not found] ` <20211225132558.167123-2-luca-IfPCFPJWly+lVyrhU4qvOw@public.gmane.org>
2021-12-28 4:29 ` David Gibson
2022-01-05 22:48 ` Rob Herring
[not found] ` <CAL_JsqLvQdm1kqMED8G03LEsm+xgyY2A+F+FD8DYeAy5o+eiGg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2022-01-18 10:08 ` David Gibson
2022-01-20 19:24 ` Luca Weiss
2022-01-21 0:12 ` David Gibson
2021-12-25 13:25 ` [PATCH 2/4] pylibfdt: add Property.as_*int*_array() Luca Weiss
[not found] ` <20211225132558.167123-3-luca-IfPCFPJWly+lVyrhU4qvOw@public.gmane.org>
2021-12-28 4:30 ` David Gibson [this message]
2021-12-25 13:25 ` [PATCH 3/4] pylibfdt: add FdtRo.get_path() Luca Weiss
[not found] ` <20211225132558.167123-4-luca-IfPCFPJWly+lVyrhU4qvOw@public.gmane.org>
2021-12-28 4:33 ` David Gibson
2021-12-25 13:25 ` [PATCH 4/4] pylibfdt: add FdtRo.getprop_or_none() Luca Weiss
[not found] ` <20211225132558.167123-5-luca-IfPCFPJWly+lVyrhU4qvOw@public.gmane.org>
2021-12-28 5:20 ` David Gibson
2021-12-28 8:34 ` Simon Glass
[not found] ` <CAPnjgZ3wun92Q1vMSEem9CH6A8MWNbKZNaepf4j4Ttmf-GNPtQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2022-01-22 10:36 ` Luca Weiss
2022-01-24 17:57 ` Simon Glass
[not found] ` <CAPnjgZ1NX2Q884T_LNUOLJT8=RKZXEj2z7uxzQF4MrHiKObZvA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2022-01-24 20:50 ` Luca Weiss
2022-01-24 21:28 ` Simon Glass
2022-01-25 4:50 ` David Gibson
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=YcqS++UZtf+tSumt@yekko \
--to=david-xt8fgy+axnrb3ne2bgzf6laj5h9x9tb+@public.gmane.org \
--cc=devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=luca-IfPCFPJWly+lVyrhU4qvOw@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 NNTP newsgroup(s).