Vincent Fazio [Tue, 8 Oct 2024 17:51:39 +0000 (12:51 -0500)]
bindings: python: import gpiod attributes in external module
Previously, the external module relied on gpiod attributes being present
within `globals()` to construct return values back to the caller.
This assumption required callers of the external module to have imported
the attributes to populate `globals()` for the interface to work.
Having this implicit contract is opaque and prone to causing issues if
imports within gpiod modules ever get reworked.
Now, the external module explicitly imports attributes from gpiod in
order to return values back to the caller.
There should be no concern about circular imports as the external module
should be completely imported by the time callers call into it.
Since Py_gpiod_GetGlobalType is no longer used, it has been replaced
with Py_gpiod_GetModuleAttrString which returns a new PyObject*
reference for the named module and attribute that must be decremented
when no longer in use.
dbus: display D-Bus API versions implemented by the manager and gpiocli
When passing -v/--version to gpiocli or gpio-manager, it's useful to
also know the version of the GPIO D-Bus API the program implements.
Define the version in the gpiodbus.h header and print it together with
the library version.
There's a reference overflow when adding chips to the global list and an
underflow when fetching existing chips from that list in connect_line().
Fix both issues.
Some distros split glib-mkenums and other GLib build utilities into a
separate package but the glib-2.0 pkgconfig file pointing to it is
typically shipped as part of the -dev package. This can lead to a
situation where configure thinks it knows where glib-mkenums is but make
then fails because it's not really installed on the system. Check the
existence of the actual executable in addition to querying pkgconfig.
AC_HEADER_STDC is deprecated and should be replaced with
AC_CHECK_INCLUDES_DEFAULT. We haven't done this until now because the
latter is only available since autoconf v2.71. We kept supporting v2.69
for the sake of Debian stable but it has since upgraded to autoconf v2.71
so we update configure.ac as well and fix an autoconf warning.
bindings: python: add misc build files to EXTRA_DIST
Several files are not being included in distro tarballs so the
functionality of the python build is limited compared to the repo. Add
them to EXTRA_DIST.
Fixes: d588a6a5928a ("bindings: python: standalone build tooling for tests") Fixes: 72d2fa01a2c1 ("bindings: python: add script to generate sdist and wheels") Fixes: 85089d0e40ac ("bindings: python: add pyproject.toml, pep 518") Fixes: 389a966d4e61 ("bindings: python: move long_description into README.md") Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
On 32-bit architectures the size of a gulong will typically be 4 bytes
while we try to package an 8-byte integer when creating the edge event
variant. The client also expects wrong types and crashes. Use strict
type sizes for sending the events.
Currently, for the output of LineSettings.__repr__() to be eval()able,
the user must have pulled all the relevant definitions from gpiod.line
within the scope where it is used. Modify the output so that all the user
needs is `import gpiod`.
Kent Gibson [Tue, 17 Sep 2024 12:54:55 +0000 (20:54 +0800)]
bindings: python: examples: add graceful exit to async_watch_line_value
The purpose of the example is demonstrate using a request with poll().
It provides a hint as to how the poll can be combined with other fds but,
as Python comes with batteries included, the Python version of the example
can be readily extended to actually demonstrate this, as well as how it
can be used in multi-threaded environments.
Extend the example to use an eventfd to allow the poll() to be run in
a background thread and be gracefully terminated by the main thread.
Kent Gibson [Wed, 4 Sep 2024 12:50:14 +0000 (20:50 +0800)]
dbus: update glib dependency to 2.80
The gpio-manager makes use of g_log_writer_default_set_debug_domains()
which was added in glib 2.80, but the dependency in configure.ac is only
glib 2.54. This results in compile errors when built with glib between 2.54
and 2.80.
Update the glib dependency, and related dependencies, to 2.80.
Kent Gibson [Sat, 31 Aug 2024 07:52:12 +0000 (15:52 +0800)]
build: fix HAS_GI_DOCGEN never defined error
When building without --enable-bindings-glib configure reports this error:
...
checking for help2man... true
checking that generated files are newer than configure... done
configure: error: conditional "HAS_GI_DOCGEN" was never defined.
Usually this means the macro was only invoked conditionally.
make: *** [Makefile:440: config.status] Error 1
Move the initialization of HAS_GI_DOCGEN outside the conditional
with_bindings_glib section so it is always initialized.
tests: don't use g_value_set_static_string() for non-static strings
As pointed out by Philip Withnall, g_value_set_static_string() must only
be used with actual static strings and not with ones whose life-time is
tied to that of their owner. Use g_value_set_string() to get the gpiosim
properties and rework the existing getter functions returning const
gchar * to return the address provided by libgpiosim directly instead of
passing through the GObject property path.
dbus: add the D-Bus daemon, command-line client and tests
Add the D-Bus API definition and its implementation in the form of a GPIO
manager daemon and a companion command-line client as well as some
additional configuration and data files (systemd service, example udev
configuration, etc.) and test suites.
tests: split out the common test code for bash scripts
In order to allow the upcoming DBus command-line client tests to reuse the
existing bash test harness, let's put the common code into an importable
file and rename run_tool to run_prog to reflect that it now can run any
program.
tests: split out reusable test code into a local static library
In order to allow the upcoming GLib and DBus bindings to reuse the test
code, let's put all common elements into reusable libtool objects and
export the relevant symbols in internal headers.
bindings: python: tests: check that event clock is property set in request
We currently only have a test-case that checks if the event clock
property is correctly set in the LineSettings object but not whether it
is actually passed to the line request. Extend the existing test-case for
line requests to account for event clocks as well.
strncpy() truncates the destination buffer if it isn't large enough to
hold the copy. Thus, let's increase the size of the destination strings
to add the NULL character at the end.
strncpy() truncates the destination buffer if it isn't large enough to
hold the copy. Thus, let's increase the size of the destination strings
to add the NULL character at the end.
Add a test-case for line request by name with multiple entries.
Signed-off-by: Chuang Zhu <git@chuang.cz>
[Bartosz:
- tweak the commit message
- improve the test class name
- extend the test assertion to test the 'baz' line too] Co-developed-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> Reviewed-by: Kent Gibson <warthog618@gmail.com> Link: https://lore.kernel.org/r/20240710125719.33655-3-brgl@bgdev.pl Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
bindings: python: fix line request by name with multiple entries
When multiple entries are requested using line names in
Chip.request_lines(), only the the last entry is added to
LineRequest._name_map, causing a ValueError when trying to use functions
like LineRequest.set_value() on any former entries.
bindings: rust: tests: set direction when reconfiguring lines
Linux kernel commit b44039638741 ("gpiolib: cdev: Ignore reconfiguration
without direction") made the direction setting mandatory for line config
passed to the kernel when reconfiguring requested lines. Fix the Rust
test cases which don't do it and now fail due to the rest of the
settings being ignored.
bindings: cxx: tests: set direction when reconfiguring lines
Linux kernel commit b44039638741 ("gpiolib: cdev: Ignore reconfiguration
without direction") made the direction setting mandatory for line config
passed to the kernel when reconfiguring requested lines. Fix the C++ test
case which doesn't do it and now fails due to the rest of the settings
being ignored.
Kent Gibson [Wed, 26 Jun 2024 05:38:08 +0000 (13:38 +0800)]
bindings: python: tests: add coverage of kernel reconfigure as-is behaviour
The kernel's handling of reconfigure with default values, as is the
case for providing a None value as the settings to the Python bindings'
reconfigure_lines(), resets any flags set to non-default values when the
line is requested to their default values. While the flags are cleared,
the kernel makes no corresponding change to the electrical settings -
though subsequent calls to get and set values will apply the updated
flags.
The tests for missing or None settings are extended to demonstrate the
issue for active_low and drive flags, though the issue applies to all
flags.
The tests fail unless the kernel is patched to ignore reconfiguration
of lines without direction set.
Kent Gibson [Wed, 26 Jun 2024 05:38:07 +0000 (13:38 +0800)]
bindings: python: more flexible reconfigure_lines()
The C API requires the configuration passed to reconfigure_lines()
to contain the lines in the same order as they were requested. This is
problematic for the Python bindings which accepts the configuration in
the form of a dict. For versions prior to Python 3.6, dicts do not
maintain insertion order, so iterating over the dict emits lines in
unreliable order.
Even with later Python versions, the ordering requirement makes
reconfigure_lines() awkward to use as subsequent configurations may
group line settings quite differently to the request, yet the user must
go out of their way to reproduce the original ordering.
This is a task better performed by the bindings.
Further, while the documentation for reconfigure_lines() states that
None settings values are treated as default values, the current
implementation raises an error when it tries to dereference the None,
thinking it is an actual object.
Similarly, providing default values for lines for which no settings
are provided would allow support for reconfiguring a subset of
requested lines.
Rework reconfigure_lines() to remove the ordering requirement and
construct the configuration provided to the C API in request order.
Populate missing or None line settings with default values to satisfy
the requirements of the C API that all requested lines must be
reconfigured.
A number of the corner cases for reconfiguration are untested, including
- using None for default settings
- missing settings for some lines
- jumbled line ordering relative to the request
- extra settings for non-requested lines
README: list the development packages required to build the library
The error messages emitted by configure when either libtool, pkg-config
or autoconf-archive packages are missing on the host are not very clear
and seem to cause confusion among users building the project from
sources. List the required packages in the README.
Kent Gibson [Fri, 5 Jul 2024 02:17:50 +0000 (10:17 +0800)]
doc: fix sphinx config for rtd
Generating the latest documentation on readthedocs is broken as the
index.html generated by Doxygen is now being overwritten by one
generated by Sphinx.
Make Sphinx generate a differently named root page that does not
conflict with the index.html generated by Doxygen.
Changelog:
- add a script for generating sdist and wheels
- fix make build
- support casting of line.Value to bool
- test fixes
- fix __repr__() implementations
Extend the "Contributing" section of the README to include mentions of
shell scripts having to pass the `shellcheck` test and the entire tree
having to conform to `reuse lint` requirements.
Vincent Fazio [Tue, 11 Jun 2024 20:50:41 +0000 (15:50 -0500)]
bindings: python: add script to generate sdist and wheels
Introduce a shell script that generates an sdist tarball and PEP 600/656
conformant wheels.
The wheels are generated via cibuildwheel, a tool provided by the Python
Packaging Authority (PyPA) [0]. The tool leverages toolchains within
containers maintained by PyPA [1] to generate wheels that are runnable
on hosts that meet the platform compatibility tag [2] requirements.
By default, the script creates X86_64 and AArch64 CPython 3.9-3.12
wheels for glibc and musl libc based systems.
These defaults can be overridden via CIBW_* environment variables [3].
$@ does not break up quoted arguments which is what we want in all cases
in the bash test-suite. Use it instead of $*. While at it: prevent
globbing with double quotes but allow variable expansion.
Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Reviewed-by: Kent Gibson <warthog618@gmail.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Link: https://lore.kernel.org/r/20240528-fix-bash-tests-v3-2-e9b5be2ba8bf@linaro.org Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Kent Gibson [Wed, 22 May 2024 00:46:42 +0000 (08:46 +0800)]
bindings: python: tests: add test for casting line.Value to bool
The line.Value represents the logical line state, so intuitively you
would expect it to be able to be cast to bool, with ACTIVE
corresponding to True, and INACTIVE to False.
TODO: add a task for migrating C++ tests to Catch2 v3
Current Catch2 release is v3.6. C++ tests in libgpiod still use v2.x.
Catch2 v2 and v3 are not compatible and the tests must be migrated to
the most recent major release. Add a task for it to TODO.
Kent Gibson [Mon, 13 May 2024 16:00:31 +0000 (00:00 +0800)]
tests: add enable_debounce_then_edge_detection
A bug was recently discovered in the kernel that can result in the edge
event fifo not being correctly initialised and stack contents being
returned in edge events. The trigger for the bug is requesting a line with
debounce, but not edge detection, and then reconfiguring the line to
enable edge detection.
Add a test case that triggers the bug. This will fail on kernels that
do not contain the fix for the bug. The test is located in a new test
file, tests-kernel-uapi.c, intended to contain tests specifically
testing some aspect of the kernel uAPI, not libgpiod itself.
tools: tests: accept the new gpio-sim label format in test cases
Since kernel commit 840a97e2fbaf ("gpio: sim: delimit the fwnode name
with a ":" when generating labels") the gpio-sim automatic labels are
generated by delimiting the device name and the fwnode name with ':'
instead of '-' for better readability. This will break the tests once
linux v6.9 is out. Act in advance and accept both forms.
We currently store time as microseconds in 32-bit integers and allow
seconds as the longest time unit when parsing command-line arguments
limiting the time period possible to specify when passing arguments such
as --hold-period to 35 minutes. Let's use 64-bit integers to vastly
increase that.
Use nanosleep() instead of usleep() to extend the possible sleep time
range.
tools: use ppoll() where higher timeout resolution makes sense
We allow timeout units to be specified in microseconds but for poll() we
need to round them up to milliseconds. Switch to ppoll() to avoid losing
precision.
licensing: relicense C++ bindings under LGPL-2.1-or-later
Commit ea84f882d5d3 ("licensing: relicense C++ library code under
LGPL-3.0-or-later") changed the license of C++ bindings in order to
solve potential issues with code generated from templates[1], default
implementations, etc. However this change makes the bindings less
attractive to projects that have strict licensing restrictions and avoid
GPL-3.0 code[2].
After talking to Grant Likely I decided that the best approach is to
make the bindings available under LGPL-v2.1-or-later and simply let the
end user decide which version's text to apply.
While at it: tweak the README to also mention that examples are provided
under GPL-2.0-or-later.
Link: [1] https://www.spinics.net/lists/linux-gpio/msg46605.html
Link: [2] https://github.com/brgl/libgpiod/issues/72 Suggested-by: Walter Lozano <walter.lozano@collabora.com> Suggested-by: Grant Likely <grant.likely@linaro.org> Acked-by: Kent Gibson <warthog618@gmail.com> Acked-by: Kevin Hilman <khilman@baylibre.com> Acked-by: Grant Likely <grant.likely@linaro.org> Link: https://lore.kernel.org/r/20240416212141.6683-2-brgl@bgdev.pl Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
build: fix configure error messages on missing functions
Fix three incorrect messages that report missing library functions as
required to build the core library when they are actually needed to build
the gpio-tools.
Fixes: 9e69d7552cf2 ("configure: improve the header and library function checks") Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
README: remove out-of-date information on python bindings
The way Python bindings are built has changed and the information in the
README file is now outdated. Remove the no longer valid bits and - while
at it - point the readers to sub-READMEs for Python and Rust bindings.
orbea [Wed, 20 Mar 2024 13:49:57 +0000 (06:49 -0700)]
bindings: cxx: link using the libtool archives
When linking with internal dependencies that were built with libtool the
most reliable method is to use the libtool archive (.la) files.
When building with slibtool it fails when it doesn't find the -lgpiod
linker flag, but if libgpiod is already installed to the system it will
be built using the system version instead of the newly built libraries.
Link: https://bugs.gentoo.org/913899 Signed-off-by: orbea <orbea@riseup.net>
[Bartosz: fix a typo in tests Makefile] Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
The __repr__() function should - if possible - return a valid Python
expression that can be used to instantiate a new object when evaluated.
LineSettings.__repr__() is missing comas between arguments. Both Chip and
LineSettings also don't prefix the returned string with 'gpiod.'. Fix
both functions and add more test cases - including actually using the
strings returned by __repr__() to create new objects and compare their
contents.
Reported-by: Robert Thomas <rob.thomas@raspberrypi.com> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
core: check for positive values returned by calls to ioctl()
If the kernel GPIO driver (erroneously) returns a positive value from one
of its callbacks, it may end up being propagated to user space as
a positive value returned by the call to ioctl(). Let's treat all
non-zero values as errors as GPIO uAPI ioctl()s are not expected to ever
return positive values.
To that end let's create a wrapper around the libc's ioctl() that checks
the return value and sets errno to EBADE (Invalid exchange) if it's
greater than 0.
This should be addressed in the kernel but will remain a problem on older
or unpatched versions so we need to sanitize it in user-space too.
Reported-by: José Guilherme de Castro Rodrigues <joseguilhermebh@hotmail.com> Fixes: b7ba732e6a93 ("treewide: libgpiod v2 implementation") Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> Reviewed-by: Kent Gibson <warthog618@gmail.com>
The github page over at https://github.com/brgl/libgpiod has been reopened
for bug reports and discussions. Add a link and a mention to the README
file.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> Reviewed-by: Erik Schilling <erik.schilling@linaro.org>
bindings: python: fix package installation with Makefile build
The modules are installed in the .egg directory, and therefore cannot be
imported after that. Additionally PIP tries to remove the global gpiod
module if it's not invoked with the --ignore-installed option.
Specify correct --root and fix the --prefix switch.
core: remove buggy flags sanitization from line-config
We try to drop potentially set output flags from line config if edge
detection is enabled but we use the library enum instead of the one from
the uAPI. In any case, we should actually loudly complain if user tries
to use the output mode with edge-detection (like we do currently) so just
remove offending lines entirely.
Reported-by: Anne Bezemer <j.a.bezemer@opensourcepartners.nl> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> Reviewed-by: Kent Gibson <warthog618@gmail.com> Reviewed-by: Anne Bezemer <j.a.bezemer@opensourcepartners.nl>
Kent Gibson [Fri, 29 Dec 2023 09:33:27 +0000 (17:33 +0800)]
gpioset: reword note on post-exit behaviour
The note regarding the state of a line after gpioset exits is confusing
and unhelpful to the average reader, if not outright incorrect.
A common mis-interpretation is that this behaviour is arbitrarily chosen
by spiteful implementors. The note also specifies that the line reverts
to default, but that is not always the case, or is at least out of the
control of gpioset or libgpiod.
Reword the note to constrain the scope to that relevant to the likely
reader, and to emphasize that the behaviour is inherent in the kernel
GPIO interface, not in the gpioset implementation.
Signed-off-by: Kent Gibson <warthog618@gmail.com> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>