Jiri Benc [Tue, 6 Oct 2020 17:17:08 +0000 (19:17 +0200)]
bindings: python: fix Line.request() crashing
On an attempt to call the 'request' method of a Line object, the program
crashes with this exception:
> SystemError: ../Objects/dictobject.c:2606: bad argument to internal function
>
> The above exception was the direct cause of the following exception:
>
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> SystemError: <class 'gpiod.LineBulk'> returned a result with an error set
The problem is that keyword args are NULL (rather than an empty dict) if
they are not present. However, PyDict_Size sets an exception if it gets
NULL.
bindings: python: tests: add a test-case exposing a bug in Line.request()
Calling Line.request() with no keyword arguments leads to an exception
being raised by PyDict_Size(). Add a test-case exposing this bug. It
will be fixed in the subsequent commit.
The current comments for functions related to line lookups state that
"lines are not unique" but they're really supposed to say "line names
are not unqiue".
Kent Gibson [Sat, 12 Sep 2020 08:11:05 +0000 (16:11 +0800)]
core: fix reading subset of available events
Only read the requested number of events from the kernel rather than
reading up to 16 and quietly discarding any surplus.
The previous behavour is particularly bad for reading single events as
userspace must read the events as quickly as they arrive, effectively
negating the presence of the kernel event kfifo.
Fixes: 44921ecc9a00 ("core: provide functions for reading multiple line events at once") Signed-off-by: Kent Gibson <warthog618@gmail.com> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Kent Gibson [Sat, 12 Sep 2020 08:11:04 +0000 (16:11 +0800)]
tests: event: extend testing to cover reading a subset of available events
Add tests for gpiod_line_event_read(), including reading multiple
entries from the kernel event kfifo, and extend the existing
read_multiple_event tests to read a subset of the available events as
well as all the available events.
Signed-off-by: Kent Gibson <warthog618@gmail.com> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Kent Gibson [Wed, 9 Sep 2020 01:40:03 +0000 (09:40 +0800)]
bindings: cxx: fix event timestamp calculation for 32bit
Use appropriate C++ chrono library functions to convert the event
timestamp from a struct timespec to ::std::chrono::nanoseconds to
ensure correct conversion independent of platform.
Fixes: 8078a4a2ad90 ("bindings: implement C++ bindings") Reported-by: Florian Evers <florian-evers@gmx.de> Signed-off-by: Kent Gibson <warthog618@gmail.com> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Alexander Stein [Sat, 8 Aug 2020 09:59:41 +0000 (11:59 +0200)]
doc: use autotoolized Doxyfile
This has several advantages:
* More simplified Makefile.am
* Actually used doxygen config is available as a file
* Building doc out-of-tree is possible
Signed-off-by: Alexander Stein <alexander.stein@mailbox.org>
[Bartosz: add a dependency on Doxygen to the doc target in Makefile] Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Alexander Stein [Sat, 8 Aug 2020 09:59:40 +0000 (11:59 +0200)]
doc: fix doxygen warnings
Apparently __<name>__ is not supported for @defgroup commands anymore in
doxygen v1.8.19 (and possibly earlier versions). This results in the
following warning (printed multiple times):
gpiod.h:79: warning: group strong: ignoring title ">high_level</strong> High-level
API" that does not match old title ">common</strong> Common helper macros"
Also the module list is broken.
Fix this my removing the underscores.
Signed-off-by: Alexander Stein <alexander.stein@mailbox.org> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
GPIO line names in the kernel aren't unique - neither globally nor
within a single chip. The current API doesn't take this into
consideration and simply returns the first matching line in
gpiod_line_find() and co.
This will be addressed in v2.0 but we can't fix it in v1.x without
introducing new interfaces and deprecating the ones that already exist.
Let's document this behavior in doxygen comments for all affected
routines.
TODO: add a task for improving the interface for line lookups
The functions allowing to find GPIO lines by name don't take into
account the fact that line names are not unique in the linux kernel
(neither globally nor per chip). Add a task to address that in v2.0.
Bumping the major version number is now planned to coincide with the
release of the v2 kernel uAPI for the GPIO character device. Update
the appropriate paragraph in the TODO file.
doc: improve the description of gpiod_line_event_read()
The description of gpiod_line_event_read() states that it reads the last
event that occurred for this line. This is not true: the kernel stores
the events in a FIFO and this function reads the next event from it.
At some point in the future we'll make non-compatible changes to the
API and increase the major version number. Add a list of changes planned
for v2.0 to the TODO file.
tools: tests: fix regex patterns for timestamps in gpiomon test cases
Commit f8850206e160 ("gpio: Switch timestamps to ktime_get_ns()") in the
linux kernel (released in v5.7-rc1) changed the clock used to generate
line events from real-time to monotonic. This has the effect of making
the timestamp values much smaller and it uncovered a bug in regex
patterns used to verify gpiomon output: they don't expect there to be
any whitespace characters in the timestamp part of the line.
Fix it by accepting any number of whitespace chars between the opening
'[' and the first digit of the timestamp.
Fixes: 9c5a6f31ebff ("tests: use GLib for library test cases and bats for gpio-tools") Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
bindings: python: add the __version__ module attribute
The python module provides the version_string() function that returns
the API version but the standard way to do this according to PEP 396
is by providing the __version__ attribute at the module level.
Add __version__ constant to gpiod module and mark version_string() as
deprecated in the doc.
Andy Shevchenko [Thu, 6 Feb 2020 18:13:58 +0000 (20:13 +0200)]
core: relax gpiod_chip_open() for symbolic links
User may ask device helper tool, for example, udev, to create a specific
symbolic link to a device node. GPIO chip character device node is not
exceptional. However, libgpiod in the commit d9b1c1f14c6b
("core: harden gpiod_chip_open()") went way too far in the hardening device
node check.
Relax that hardening for symbolic link to fix the regression.
We try to always resolve symbols from std starting from the global
namespace by using the '::' prefix but there are a couple places where
this was missed. This patch makes the resolution consistent treewide.
The current development version is v1.6-devel. The '-' character is
there to differentiate between the "main" version part and the extra
suffix.
The existing test case for the version string is now failing because
we used '.' previously for the extra version suffix. Fix it by extending
the regex pattern.
README: remove the reference to v4.8 kernel headers
The project now depends on v5.5 kernel headers to build. Drop the
reference to v4.8 headers and instead refer readers to the contents
of configure.ac for the exact required version.
configure: move the ABI version definition for libgpiomockup
Having it separated from the other ABI versions already led to it almost
being forgotten when incrementing versions before release. Group all
versions together.
build: increment the revision in libgpiomockup's ABI version
This helper library too has a separate ABI version, but we missed it
when incrementing other ABI numbers for v1.5-rc1. Increment the revision
only as no new interfaces were added or old ones removed.
bindings: python: tests: package the python test-suite in the dist tarball
The test-suite python scripts is added to bin_SCRIPTS in Makefile.am.
This means it's not distributed by default. Add it to dist_bin_SCRIPTS
and make it part of the distribution tarball.
Fixes: 452696601ae5 ("bindings: python: use unittest to implement a proper test-suite") Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Cleanup the main .gitignore: remove explicit filenames which are already
implicitly ignored with pattern entries and move all the specific
entries into appropriate sub-directories.
core: provide functions for reading multiple line events at once
The kernel allows us to read multiple (up to 16) line events with
a single read() call, but up to this point libgpiod only supported
reading one event at a time. Add two new functions that allow users
to read more events at the same time.
core: use gpiod_line_event_get_fd() in gpiod_line_event_read()
We can drop the redundant line state check if we directly call
gpiod_line_event_get_fd() from gpiod_line_event_read(). As opposed
to line_get_fd() it checks if the line was requested for events.
gitignore: ignore libtool scripts created when cross-compiling
When '--host' option is passed to configure, the name of the generated
libtool script will be prefixed with the value used as argument for
'--host'. Add a pattern for prefixed 'libtool' scripts to .gitignore.
Original libgpiod relied on linux headers v4.8 to build but it was only
documented in README and not enforced at build-time. We now support
features first available in linux v5.5. Add a check to configure.ac that
verifies if recent enough kernel headers are available - otherwise we'd
fail only when trying to build the library.
Joel Savitz [Tue, 3 Dec 2019 19:23:05 +0000 (14:23 -0500)]
bindings: python: fix segfault when calling Line.request()
When Line.request() is called without the required 'consumer=value'
argument, the module attempts access an empty dictionary object
resulting in a segfault. This patch avoids such access when the
dictionary is empty and maintains the current design where the
LineBulk object is responsible for validation of arguments.
Signed-off-by: Joel Savitz <jsavitz@redhat.com> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Kent Gibson [Sun, 1 Dec 2019 03:24:07 +0000 (11:24 +0800)]
bindings: python: make vals in gpiod_Line_set_value consistent with other functions
Change the vals in gpiod_Line_set_value from a tuple of tuples to just a
tuple. This brings it into line with other vals in the module such as
gpiod_Line_set_config and gpiod_Line_set_direction_output.
The previous usage made the vals equivalent to an args (a tuple of
arguments equivalent to argc,argv in C), as per gpiod_Line_set_flags.
Renaming vals to args in gpiod_Line_set_value was not an option as there
is already an args parameter.
Signed-off-by: Kent Gibson <warthog618@gmail.com> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
The handling of NULL values by gpiod_line_set_value_bulk has been changed
to interpret NULL as low values for all lines. This patch updates the
documentation of the function to describe that.
Signed-off-by: Kent Gibson <warthog618@gmail.com> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Kent Gibson [Sun, 1 Dec 2019 03:23:58 +0000 (11:23 +0800)]
bindings: python: move tuple to int array conversion into helper function
Restructured gpiod_LineBulk_set_values to move the conversion of values
from Python tuple to int array into a helper function as it is useful for
similar functions.
Signed-off-by: Kent Gibson <warthog618@gmail.com> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Kent Gibson [Sun, 1 Dec 2019 03:23:54 +0000 (11:23 +0800)]
core: add support for SET_CONFIG
Extend the libgpiod API to support the setting line configuration using the
GPIO GPIOHANDLE_SET_CONFIG_IOCTL uAPI ioctl.
The core change is the addition of gpiod_line_set_config, which provides a
low level wrapper around the ioctl.
Additionally, higher level helper functions, gpiod_line_set_flags,
gpiod_line_set_direction_input, and gpiod_line_set_direction_output provide
slightly simplified APIs for common use cases.
Bulk forms of all functions are also provided.
Documented the fields of gpiod_line to better identify the purpose of
each where the field name alone is not sufficiently clear, and to
indicate which flags are applicable to each field.
Implementation includes a few helper functions that serve to keep the
code tidier and are consistent with similar helper functions already
present.
Signed-off-by: Kent Gibson <warthog618@gmail.com> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Kent Gibson [Sun, 1 Dec 2019 03:23:48 +0000 (11:23 +0800)]
core: add support for bias flags
Extend the libgpiod API to support the bias flags recently added to the
kernel GPIO uAPI. The core change is the addition of
GPIOD_LINE_REQUEST_FLAG_BIAS_DISABLE, GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_UP
and GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_DOWN flags to be passed into
line_request functions, and the addition of gpiod_line_bias to return the
bias state of lines.
Variants of the ctxless functions that accept an active_low flag
are added to also accept other flags. The variant names add a "_ext"
suffix to the name of the original function.
Based on initial work by Drew Fustini <drew@pdp7.com>.
Signed-off-by: Kent Gibson <warthog618@gmail.com> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
build: use AC_CHECK_PROG() instead of AC_CHECK_FILE() for python3-config
Commit 9ed02fc793b3 ("build: check for python-config in configure")
breaks cross-compilation because AC_CHECK_FILE() only checks the host
machine. Use AC_CHECK_PROG() instead.
Cc: Joel Savitz <joelsavitz@gmail.com> Fixes: 9ed02fc793b3 ("build: check for python-config in configure") Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
This function and the logic behind have been introduced in an early
version of libgpiod for reasons that have been long forgotten.
When updating the line info after a line request fails, just propagate
the error out of the request function instead of setting the internal
needs_update variable. Drop the entire logic behind gpiod_needs_update(),
make this routine always return false and mark it as deprecated in the
header.
Suggested-by: Kent Gibson <warthog618@gmail.com> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Kent Gibson [Mon, 18 Nov 2019 14:46:12 +0000 (15:46 +0100)]
treewide: change "correspond with" to "correspond to"
Trivial grammar fix. "correspond with" can mean either being in agreement
with, happening at the same time, or communication between parties.
"correspond to" is used to mean equivalance, which is the intended use
throughout the documentation.
Signed-off-by: Kent Gibson <warthog618@gmail.com> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Kent Gibson [Mon, 18 Nov 2019 14:41:04 +0000 (15:41 +0100)]
core: allow gpiod_line_set_value_bulk() to accept null values
Change gpiod_line_set_value_bulk to interpret a NULL values pointer as an
array of zero, as per gpiod_line_request_bulk, gpiod_line_set_config_bulk,
and gpiod_line_set_direction_bulk_output.
The old behaviour was to segfault.
Add a corresponding test case for gpiod_line_set_value_bulk().
Signed-off-by: Kent Gibson <warthog618@gmail.com> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Joel Savitz [Fri, 4 Oct 2019 16:11:26 +0000 (12:11 -0400)]
build: check for python-config in configure
Currently, configure succeeds when python is installed without its
development components, i.e. python-config and headers. The subsequent
make will fail when gcc cannot locate Python.h.
This patch fixes that behavior by throwing an error at configure-time if
python-config cannot be found.
Signed-off-by: Joel Savitz <joelsavitz@gmail.com> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
bindings: python: directly return the value from PyErr_SetFromErrno()
PyErr_SetFromErrno() always returns NULL. We can return from functions
on failure directly instead of calling it and then returning NULL in
the next line.
Add information about the tests included in Python and C++ bindings.
Move the BINDINGS section above TESTING so that the user first knows
that bindings exist before learning they also provide their own
test-suites.
Python bindings are missing the functionality provided by the core C
library's gpiod_line_update(). Extend the Line class with the update()
method that allows to re-read the line information from the kernel.