From: Kent Gibson <warthog618@gmail.com>
To: Bartosz Golaszewski <brgl@bgdev.pl>
Cc: Linus Walleij <linus.walleij@linaro.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Darrien <darrien@freenet.de>,
Viresh Kumar <viresh.kumar@linaro.org>, Jiri Benc <jbenc@upir.cz>,
Joel Savitz <joelsavitz@gmail.com>,
"open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>
Subject: Re: [libgpiod v2][PATCH v2 4/5] bindings: python: add tests for v2 API
Date: Thu, 7 Jul 2022 20:22:42 +0800 [thread overview]
Message-ID: <20220707122242.GA66970@sol> (raw)
In-Reply-To: <CAMRc=MegkfLxQr5tEWdn0jOoC=PzpZPHTtqUtk6QEr8ZZU4o0g@mail.gmail.com>
On Thu, Jul 07, 2022 at 12:17:17PM +0200, Bartosz Golaszewski wrote:
> On Tue, Jul 5, 2022 at 4:08 AM Kent Gibson <warthog618@gmail.com> wrote:
> >
> > On Tue, Jun 28, 2022 at 10:42:25AM +0200, Bartosz Golaszewski wrote:
> > > This adds a python wrapper around libgpiosim and a set of test cases
> > > for the v2 API using python's standard unittest module.
> > >
> > > Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
> > > ---
> > > bindings/python/tests/Makefile.am | 14 +
> > > bindings/python/tests/cases/__init__.py | 12 +
> > > bindings/python/tests/cases/tests_chip.py | 157 +++++++
> > > .../python/tests/cases/tests_chip_info.py | 59 +++
> > > .../python/tests/cases/tests_edge_event.py | 279 +++++++++++
> > > .../python/tests/cases/tests_info_event.py | 135 ++++++
> > > .../python/tests/cases/tests_line_config.py | 254 ++++++++++
> > > .../python/tests/cases/tests_line_info.py | 90 ++++
> > > .../python/tests/cases/tests_line_request.py | 345 ++++++++++++++
> > > bindings/python/tests/cases/tests_misc.py | 53 +++
> > > .../tests/cases/tests_request_config.py | 77 ++++
> > > bindings/python/tests/gpiod_py_test.py | 25 +
> > > bindings/python/tests/gpiosimmodule.c | 434 ++++++++++++++++++
> > > 13 files changed, 1934 insertions(+)
> > > create mode 100644 bindings/python/tests/Makefile.am
> > > create mode 100644 bindings/python/tests/cases/__init__.py
> > > create mode 100644 bindings/python/tests/cases/tests_chip.py
> > > create mode 100644 bindings/python/tests/cases/tests_chip_info.py
> > > create mode 100644 bindings/python/tests/cases/tests_edge_event.py
> > > create mode 100644 bindings/python/tests/cases/tests_info_event.py
> > > create mode 100644 bindings/python/tests/cases/tests_line_config.py
> > > create mode 100644 bindings/python/tests/cases/tests_line_info.py
> > > create mode 100644 bindings/python/tests/cases/tests_line_request.py
> > > create mode 100644 bindings/python/tests/cases/tests_misc.py
> > > create mode 100644 bindings/python/tests/cases/tests_request_config.py
> > > create mode 100755 bindings/python/tests/gpiod_py_test.py
> > > create mode 100644 bindings/python/tests/gpiosimmodule.c
> > >
> > > diff --git a/bindings/python/tests/Makefile.am b/bindings/python/tests/Makefile.am
> > > new file mode 100644
> > > index 0000000..099574f
> > > --- /dev/null
> > > +++ b/bindings/python/tests/Makefile.am
> > > @@ -0,0 +1,14 @@
> > > +# SPDX-License-Identifier: GPL-2.0-or-later
> > > +# SPDX-FileCopyrightText: 2017-2021 Bartosz Golaszewski <bartekgola@gmail.com>
> > > +
> >
> > It is 2022?
> >
> > Which email address are you going with? gmail here and bgdev below.
> >
>
> These patches will be squashed together anyway. When I wrote this part
> I used this email and then switched to brgl@bgdev.pl. It's just
> copyright anyway. I can fix it up later.
>
> [snip!]
>
> > > +
> > > + def test_falling_edge_event(self):
> > > + with gpiod.request_lines(
> > > + self.sim.dev_path,
> > > + gpiod.RequestConfig(offsets=[6]),
> > > + gpiod.LineConfig(edge_detection=Edge.FALLING),
> > > + ) as req:
> > > + buf = gpiod.EdgeEventBuffer()
> > > + self.thread = threading.Thread(
> > > + target=partial(self.trigger_falling_and_rising_edge, 6)
> > > + )
> > > + self.thread.start()
> > > +
> >
> > Benefit of the thread? (and elsewhere a background thread is used)
> > The sleeps therein are only necessary because it is run in the
> > background.
> >
>
> Just to make it similar to real-life applications. I did the same for
> C++ and C. And no: if I triggered multiple events without any sleeps
> in between, then some of them would risk not being registered. You can
> try it for yourself with gpiosim. It happens because when the kernel
> irq_work is busy adding an interrupt, new ones get ignored.
>
I know, and I still don't think that this is the place for that.
I'd rather see some example code do that.
If you want to add some threaded tests in then sure, do that, but the
tests do not really need it - it just makes them more complicated than
you require.
Sure, you can't issue multiple events on a single gpio-sim line without
waiting for the result, but you never need to. You toggle a line
and check the result. Toggle a line, check a result.
All from the main thread.
And yeah, it is a bit disconcerting that userspace can toggle the
gpio-sim line faster than the interrupt handling in the kernel can
manage. But I can live with that.
> [nsip]
>
> >
> > These tests should be in tests_chip.py, as they are testing the
> > Chip.request_lines() method.
> >
>
> I would argue that there's some overlap in where the test cases should
> live. For instance - if we moved the line watching out of
> tests_info_event into tests_chip then not much would be left. I would
> leave these here as they test the general idea of requesting lines
> rather than the functionality of class LineRequest. Same for the
> module level line requests.
>
And I would argue the reverse - that overlap is imaginary.
This is just basic discoverability.
I looked in the tests_chip.py for the tests for Chip.request_lines(), so a
method on a Chip and implemented in chip.c, and found nothing.
Putting them in tests_line_request.py because that is what they
construct is a wee bit unintuitive.
The tests in test_line_request.py will certainly need to call
Chip.request_lines(), as that is effectively the constructor, but I
would only epxect to see successful Chip.request_lines() there as part
of the test setup, not the test proper. All the failure cases should be
in tests_chip.py, and of course some success cases as well.
But that isn't overlap.
In general the tests in tests_<blah>.py should be for the methods
implemented in <blah>.c. In the case of InfoEvent, that might not be
much, but you get that - it is a tiny module. Those tests being
lonely is not a good reason to move tests in from tests_chip.c.
Cheers,
Kent.
next prev parent reply other threads:[~2022-07-07 12:22 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-28 8:42 [libgpiod v2][PATCH v2 0/5] bindings: implement python bindings for libgpiod v2 Bartosz Golaszewski
2022-06-28 8:42 ` [libgpiod v2][PATCH v2 1/5] bindings: python: remove old version Bartosz Golaszewski
2022-06-28 8:42 ` [libgpiod v2][PATCH v2 2/5] bindings: python: enum: add a piece of common code for using python's enums from C Bartosz Golaszewski
2022-06-28 8:42 ` [libgpiod v2][PATCH v2 3/5] bindings: python: add examples for v2 API Bartosz Golaszewski
2022-06-28 8:42 ` [libgpiod v2][PATCH v2 4/5] bindings: python: add tests " Bartosz Golaszewski
2022-07-05 2:08 ` Kent Gibson
2022-07-07 10:17 ` Bartosz Golaszewski
2022-07-07 12:22 ` Kent Gibson [this message]
2022-06-28 8:42 ` [libgpiod v2][PATCH v2 5/5] bindings: python: add the implementation " Bartosz Golaszewski
2022-06-30 2:25 ` Kent Gibson
2022-06-30 6:54 ` Bartosz Golaszewski
2022-06-30 8:14 ` Kent Gibson
2022-06-30 8:38 ` Kent Gibson
2022-07-01 6:07 ` Kent Gibson
2022-07-01 7:21 ` Bartosz Golaszewski
2022-07-01 7:26 ` Kent Gibson
2022-07-01 7:29 ` Bartosz Golaszewski
2022-07-01 7:33 ` Kent Gibson
2022-07-01 8:02 ` Kent Gibson
2022-07-01 8:18 ` Bartosz Golaszewski
2022-07-01 8:32 ` Bartosz Golaszewski
2022-07-01 8:52 ` Kent Gibson
2022-07-01 9:28 ` Bartosz Golaszewski
2022-07-01 8:32 ` Kent Gibson
2022-07-05 2:09 ` Kent Gibson
2022-07-07 12:19 ` Bartosz Golaszewski
2022-07-07 13:09 ` Kent Gibson
2022-07-07 20:09 ` Bartosz Golaszewski
2022-07-08 1:38 ` Kent Gibson
2022-07-08 9:49 ` Bartosz Golaszewski
2022-07-08 10:56 ` Kent Gibson
2022-07-08 11:28 ` Bartosz Golaszewski
2022-07-08 15:26 ` Bartosz Golaszewski
2022-07-08 15:58 ` Kent Gibson
2022-06-28 8:47 ` [libgpiod v2][PATCH v2 0/5] bindings: implement python bindings for libgpiod v2 Bartosz Golaszewski
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=20220707122242.GA66970@sol \
--to=warthog618@gmail.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=brgl@bgdev.pl \
--cc=darrien@freenet.de \
--cc=jbenc@upir.cz \
--cc=joelsavitz@gmail.com \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=viresh.kumar@linaro.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).