All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Gibson <david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org>
To: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
Cc: Devicetree Compiler
	<devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	Benjamin Bimmermann <b.bimmermann-LWAfsSFWpa4@public.gmane.org>,
	Ulrich Langenbach
	<ulrich.langenbach-srmvecZYGfHobmly5n/iKBvVK+yQ3ZXh@public.gmane.org>
Subject: Re: [PATCH v5 2/5] Add tests for pylibfdt
Date: Mon, 20 Feb 2017 14:42:29 +1100	[thread overview]
Message-ID: <20170220034229.GA27524@umbus> (raw)
In-Reply-To: <CAPnjgZ3wEUUEx6-XiKJ5kns-tA9HdKonXULdBYcXAkyEbHaztg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>

[-- Attachment #1: Type: text/plain, Size: 6959 bytes --]

On Thu, Feb 16, 2017 at 09:48:28PM -0700, Simon Glass wrote:
> Hi David,
> 
> On 14 February 2017 at 22:44, David Gibson <david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org> wrote:
> > On Tue, Feb 14, 2017 at 08:51:57PM -0700, Simon Glass wrote:
> >> Add a set of tests to cover the functionality in pylibfdt.
> >>
> >> Signed-off-by: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
> >> ---
> >>
> >> Changes in v5:
> >> - Adjust tests to match new swig bindings
> >>
> >> Changes in v4:
> >> - Drop tests that are no-longer applicable
> >> - Add a get for getprop()
> >>
> >> Changes in v3:
> >> - Add some more tests
> >>
> >> Changes in v2:
> >> - Update tests for new pylibfdt
> >> - Add a few more tests to increase coverage
> >>
> >>  tests/pylibfdt_tests.py | 267 ++++++++++++++++++++++++++++++++++++++++++++++++
> >>  tests/run_tests.sh      |  19 +++-
> >>  2 files changed, 285 insertions(+), 1 deletion(-)
> >>  create mode 100644 tests/pylibfdt_tests.py
> >>
> 
> [..]
> 
> >> +    def testPathOffset(self):
> >> +        """Check that we can find the offset of a node"""
> >> +        self.assertEquals(self.fdt.path_offset('/'), 0)
> >> +        self.assertEquals(self.fdt.path_offset('/subnode@1'), 124)
> >
> > This test is potentially fragile.  Eventually it would be nice to be
> > able to run the Python tests expecting test_tree1 on any of the copies
> > of test_tree1 we generate.  Those are required to be semantically
> > identicaly (including node/property order) to test_tree1.dtb.
> > However, some versions won't preserve exact offsets - for example
> > there's a sequence of tests where we insert additional nops in the
> > encoding to test handling of that.  That's why tests/path_offset.c,
> > for example, checks the behaviour of path_offset() against
> > subnode_offset() and knowing what property and node names are supposed
> > to be present, rather than against explicit known offsets.I'm
> 
> Yes it is fragile, will check it's >0 which should be safe.

Ok.

> Re the tests, I feel we should try to avoid testing all the same
> things as the C code, when we could just test the interface. But it
> might be easier just to duplicate the tests you as say.

I think so.  The set of tree1 tests is a good model, because it's
already a reasonably thorough test model of the basic libfdt
interfaces.

> >
> >> +        with self.assertRaisesRegexp(FdtException, get_err(libfdt.NOTFOUND)):
> >> +            self.fdt.path_offset('/wibble')
> >> +        self.assertEquals(self.fdt.path_offset('/wibble', QUIET_NOTFOUND),
> >> +                          -libfdt.NOTFOUND)
> >> +
> >> +    def testPropertyOffset(self):
> >> +        """Walk through all the properties in the root node"""
> >> +        self.assertEquals(self.fdt.first_property_offset(0), ROOT_PROPS[0])
> >> +        for pos in range(len(ROOT_PROPS) - 1):
> >> +            self.assertEquals(self.fdt.next_property_offset(ROOT_PROPS[pos]),
> >> +                              ROOT_PROPS[pos + 1])
> >> +        self.assertEquals(self.fdt.next_property_offset(ROOT_PROPS[-1],
> >> +                                                        QUIET_NOTFOUND),
> >> +                          -libfdt.NOTFOUND)
> >> +
> >> +    def testPropertyOffsetExceptions(self):
> >> +        """Check that exceptions are raised as expected"""
> >> +        with self.assertRaisesRegexp(FdtException, get_err(libfdt.NOTFOUND)):
> >> +            self.fdt.next_property_offset(108)
> >
> > Same issue here.
> 
> OK, I can just drop this one.
> 
> >
> >> +        with self.assertRaisesRegexp(FdtException, get_err(libfdt.BADOFFSET)):
> >> +            self.fdt.next_property_offset(107)
> >> +        with self.assertRaisesRegexp(FdtException, get_err(libfdt.BADOFFSET)):
> >> +            self.fdt.first_property_offset(107, QUIET_NOTFOUND)
> >> +        with self.assertRaisesRegexp(FdtException, get_err(libfdt.BADOFFSET)):
> >> +            self.fdt.next_property_offset(107, QUIET_NOTFOUND)
> >> +
> >> +        node = self.fdt.path_offset('/subnode@1/ss1')
> >> +        self.assertEquals(self.fdt.first_property_offset(node, QUIET_NOTFOUND),
> >> +                          -libfdt.NOTFOUND)
> >> +        with self.assertRaisesRegexp(FdtException, get_err(libfdt.NOTFOUND)):
> >> +            self.fdt.first_property_offset(node)
> >> +
> >> +    def testGetName(self):
> >> +        """Check that we can get the name of a node"""
> >> +        self.assertEquals(self.fdt.get_name(0), '')
> >> +        node = self.fdt.path_offset('/subnode@1/subsubnode')
> >> +        self.assertEquals(self.fdt.get_name(node), 'subsubnode')
> >> +
> >> +        with self.assertRaisesRegexp(FdtException, get_err(libfdt.BADOFFSET)):
> >> +            self.fdt.get_name(-2)
> >> +
> >> +    def testGetPropertyByOffset(self):
> >> +        """Check that we can read the name and contents of a property"""
> >> +        root = self.fdt.path_offset('/')
> >
> > No point to this - offset of / is always 0.  If you want to test that
> > happens, make it a separate testcase.
> 
> I already have it above so will drop this.
> 
> >
> >> +        poffset = self.fdt.first_property_offset(root)
> >> +        prop = self.fdt.get_property_by_offset(poffset)
> >> +        self.assertEquals(prop.name, 'compatible')
> >> +        self.assertEquals(prop.value, 'test_tree1\0')
> >> +
> >> +        with self.assertRaisesRegexp(FdtException, get_err(libfdt.BADOFFSET)):
> >> +            self.fdt.get_property_by_offset(-2)
> >> +        self.assertEquals(
> >> +                -libfdt.BADOFFSET,
> >> +                self.fdt.get_property_by_offset(-2, [libfdt.BADOFFSET]))
> >> +
> >> +    def testGetProp(self):
> >> +        """Check that we can read the contents of a property by name"""
> >> +        root = self.fdt.path_offset('/')
> >> +        value = self.fdt.getprop(root, "compatible")
> >> +        self.assertEquals(value, 'test_tree1\0')
> >> +        self.assertEquals(-libfdt.NOTFOUND, self.fdt.getprop(root, 'missing',
> >> +                                                             QUIET_NOTFOUND))
> >
> > For testing, it might be useful to add a special value you can set the
> > quiet parameter to to make all errors quiet.
> 
> Isn't that what I did?

Sorry, I wasn't very clear.  What I mean is that if you want to treat
*all* errors as quiet, at the moment you have to do
	self.whatever(..., quiet=[NOTFOUND, EXISTS, NOSPACE,...])

I was suggesting an extension to check_err() so you can instead say
'quiet=SOMETHING' where SOMETHING is a special value, and it will
interpret that as making all errors quiet.

-- 
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: 819 bytes --]

  parent reply	other threads:[~2017-02-20  3:42 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-15  3:51 [PATCH v5 0/5] Introduce Python bindings for libfdt Simon Glass
     [not found] ` <20170215035200.29934-1-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2017-02-15  3:51   ` [PATCH v5 1/5] Add an initial Python library " Simon Glass
     [not found]     ` <20170215035200.29934-2-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2017-02-15  5:29       ` David Gibson
     [not found]         ` <20170215052942.GI12369-K0bRW+63XPQe6aEkudXLsA@public.gmane.org>
2017-02-17  4:48           ` Simon Glass
     [not found]             ` <CAPnjgZ2SK-WRkeZwzjh+gA_zB0GiNFyVyer4zA_k9LUdXRV94Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-02-20  3:37               ` David Gibson
     [not found]                 ` <20170220033726.GN12644-K0bRW+63XPQe6aEkudXLsA@public.gmane.org>
2017-02-21 18:07                   ` Simon Glass
     [not found]                     ` <CAPnjgZ2hWsfm7PoNReLt7cAk=OiZBzwERFQnb-utF4fWMuUXgw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-02-22  1:15                       ` David Gibson
2017-02-15  5:47       ` David Gibson
2017-02-15  3:51   ` [PATCH v5 2/5] Add tests for pylibfdt Simon Glass
     [not found]     ` <20170215035200.29934-3-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2017-02-15  5:44       ` David Gibson
     [not found]         ` <20170215054423.GJ12369-K0bRW+63XPQe6aEkudXLsA@public.gmane.org>
2017-02-17  4:48           ` Simon Glass
     [not found]             ` <CAPnjgZ3wEUUEx6-XiKJ5kns-tA9HdKonXULdBYcXAkyEbHaztg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-02-20  3:42               ` David Gibson [this message]
2017-02-21 18:08                 ` Simon Glass
     [not found]                   ` <CAPnjgZ3CSwq7mG+fVdOjx2BSKZF1hK2UY4t6OCy_qYYAC-p42A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-02-22  2:11                     ` David Gibson
     [not found]                       ` <20170222021142.GF12577-K0bRW+63XPQe6aEkudXLsA@public.gmane.org>
2017-02-22  4:33                         ` Simon Glass
     [not found]                           ` <CAPnjgZ2v=oQTnYFEwucuCsUN1tQGx3zQfpHBZ1gRzpyZW8_g-g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-02-22  6:19                             ` David Gibson
2017-02-15  5:51       ` David Gibson
2017-02-15  3:51   ` [PATCH v5 3/5] Mention pylibfdt in the documentation Simon Glass
     [not found]     ` <20170215035200.29934-4-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2017-02-15  5:53       ` David Gibson
2017-02-15  3:51   ` [PATCH v5 4/5] Adjust libfdt.h to work with swig Simon Glass
2017-02-15  3:52   ` [PATCH v5 5/5] Build pylibfdt as part of the normal build process 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=20170220034229.GA27524@umbus \
    --to=david-xt8fgy+axnrb3ne2bgzf6laj5h9x9tb+@public.gmane.org \
    --cc=b.bimmermann-LWAfsSFWpa4@public.gmane.org \
    --cc=devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org \
    --cc=ulrich.langenbach-srmvecZYGfHobmly5n/iKBvVK+yQ3ZXh@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.