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>
Erik Schilling [Tue, 21 Nov 2023 08:43:03 +0000 (09:43 +0100)]
bindings: rust: libgpiod-sys: new release
During 86860fb ("bindings: rust: libgpiod: release 0.2.2"), I forgot that
we also need a libgpiod-sys release in order to expose the new feature
flag to raise the minimum libgpiod version.
Changelog:
7552e5d (bindings: rust: expose v2.1 features as flag, 2023-11-06) bc91656 (bindings: rust: add wrapper.h to EXTRA_DIST, 2023-11-03) 2e6ee87 (bindings: rust: mention the libgpiod crate from libgpiod-sys, 2023-07-03) d04639d (bindings: rust: bump MSRV to 1.60, 2023-06-16) ebfed6c (bindings: rust: document build without install, 2023-06-12) bce8623 (bindings: rust: exclude Makefile.am from package, 2023-06-12) caabf53 (bindings: rust: add missing license and copyright boilerplate, 2023-06-13)
Most changes only touch the build scripts or modify packaging details.
Bumping the MSRV and introducing a new feature does not require a major
bump.
Phil Howard [Wed, 8 Nov 2023 15:52:00 +0000 (15:52 +0000)]
bindings: python: standalone build tooling for tests
Move extension definitions and tooling for building tests into
`build_tests.py` and update Makefile.am to call it with appropriate path
prefixes.
`build_tests.py` will perform a standalone build of the text extensions,
keeping any build noise in a temporary directory and copying the final
built modules automatically out to `tests/gpiosim` and `tests/procname`.
Add "python-tests-run" to Makefile.am so it's clear how to run the tests.
Add .so object files generated by build_test.py to Makefile.am's
clean-local.
Signed-off-by: Phil Howard <phil@gadgetoid.com> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Phil Howard [Wed, 25 Oct 2023 08:27:07 +0000 (09:27 +0100)]
bindings: python: optionally include module in sdist
Optionally vendor libgpiod source into sdist so that the Python module can
be built from source, even with a missing or mismatched system libgpiod.
Add two new environment variables "LINK_SYSTEM_LIBGPIOD" and
"LIBGPIOD_VERSION" to control what kind of package setup.py will build.
In order to build an sdist or wheel package with a vendored libgpiod a
version must be specified via the "LIBGPIOD_VERSION" environment variable.
This will instruct setup.py to verify the given version against the list
in sha256sums.asc and ensure it meets or exceeds a LIBGPIOD_MINIMUM_VERSION
required for compatibility with the bindings.
It will then fetch the tarball matching the requested version from
mirrors.edge.kernel.org, verify the sha256 signature, unpack it, and copy
the lib and include directories into the package root so they can be
included in sdist or used to build a binary wheel.
eg: LIBGPIOD_VERSION=2.1.0 python3 setup.py sdist
Will build a source distribution with gpiod version 2.1.0 source included.
It will also save the gpiod version into "libgpiod-version.txt" so that it
can be passed to the build when the sdist is built by pip.
Requiring an explicit version ensures that the Python bindings - which
can be changed and versions independent of libgpiod - are built against a
stable libgpiod release.
In order to force a package with vendored gpiod source to link the system
libgpiod, the "LINK_SYSTEM_LIBGPIOD" environment variable can be used:
eg: LINK_SYSTEM_LIBGPIOD=1 pip install libgpiod
Signed-off-by: Phil Howard <phil@gadgetoid.com> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>