qemu-gpiodev/libgpiod.git
9 months agotools: tests: don't mix string and array
Kent Gibson [Mon, 3 Jun 2024 11:56:21 +0000 (19:56 +0800)]
tools: tests: don't mix string and array

Fix shellcheck SC2145[1] - argument mixes string and array.

Separate the command from the array of arguments to avoid mixing.

[1] https://www.shellcheck.net/wiki/SC2145

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/20240603115628.102616-2-warthog618@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
9 months agobindings: cxx: Migrate C++ tests to use Catch2 v3
Khem Raj [Fri, 31 May 2024 18:42:23 +0000 (11:42 -0700)]
bindings: cxx: Migrate C++ tests to use Catch2 v3

Catch2 v3.x has API changes which needs to be addressed
in the tests themselves, hence this changeset is to fix
those.

Signed-off-by: Khem Raj <raj.khem@gmail.com>
Link: https://lore.kernel.org/r/20240531184223.3949069-1-raj.khem@gmail.com
[Bartosz: added a version requirement (>= 3.0) for catch2 to configure.ac]
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
10 months agotools: tests: remove dependency on grep
Bartosz Golaszewski [Tue, 28 May 2024 08:25:51 +0000 (10:25 +0200)]
tools: tests: remove dependency on grep

We only use grep in one place where we don't really need it as we can use
find directly.

Reported-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Suggested-by: Kent Gibson <warthog618@gmail.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-4-e9b5be2ba8bf@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
10 months agotools: tests: remove unneeded ';' in while loops
Bartosz Golaszewski [Tue, 28 May 2024 08:25:50 +0000 (10:25 +0200)]
tools: tests: remove unneeded ';' in while loops

We're already breaking the line between while and do so there's no need
for the ';' character.

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-3-e9b5be2ba8bf@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
10 months agotools: tests: use "$@" instead of $*
Bartosz Golaszewski [Tue, 28 May 2024 08:25:49 +0000 (10:25 +0200)]
tools: tests: use "$@" instead of $*

$@ 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>
10 months agotools: tests: use tabs for indentation consistently
Bartosz Golaszewski [Tue, 28 May 2024 08:25:48 +0000 (10:25 +0200)]
tools: tests: use tabs for indentation consistently

Replace all spaces used for indentation with tabs.

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-1-e9b5be2ba8bf@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
10 months agobindings: python: fix python-tests-run make target
Kent Gibson [Sun, 26 May 2024 11:32:34 +0000 (19:32 +0800)]
bindings: python: fix python-tests-run make target

The python-tests-run target is broken as it does not correctly split
lines.  It also calls Python directly rather then through the $PYTHON
variable.

Fix the line splitting and call Python using the $PYTHON variable.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/20240526113234.253859-3-warthog618@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
10 months agobindings: python: add Testing section to README
Kent Gibson [Sun, 26 May 2024 11:32:33 +0000 (19:32 +0800)]
bindings: python: add Testing section to README

Add a section describing how to run the test suite.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/20240526113234.253859-2-warthog618@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
10 months agobindings: python: tests: run the Value cast test with the rest of the suite
Bartosz Golaszewski [Thu, 23 May 2024 08:08:31 +0000 (10:08 +0200)]
bindings: python: tests: run the Value cast test with the rest of the suite

Make the new test file for line definitions part of the entire test-suite
for python bindings.

Fixes: c8e3ae0499c8 ("bindings: python: tests: add test for casting line.Value to bool")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
10 months agobindings: python: tests: add test for casting line.Value to bool
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.

Add a test that line.Value can be cast to bool.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/20240522004643.96863-2-warthog618@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
10 months agobindings: python: support casting line.Value to bool
Kent Gibson [Wed, 22 May 2024 00:46:43 +0000 (08:46 +0800)]
bindings: python: support casting line.Value to bool

Python types default to being truthy when cast to bool, so casting
line.Value to bool always returns True.

Add a line.Value.__bool__() operator to map the line value to bool as
one would intuitively expect, so ACTIVE is True and INACTIVE is False.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/20240522004643.96863-3-warthog618@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
10 months agoTODO: add a task for migrating C++ tests to Catch2 v3
Bartosz Golaszewski [Thu, 23 May 2024 07:36:14 +0000 (09:36 +0200)]
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.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
10 months agobindings: python: tests: fix invalid syntax warnings
Bartosz Golaszewski [Wed, 22 May 2024 18:07:34 +0000 (20:07 +0200)]
bindings: python: tests: fix invalid syntax warnings

Use double '/' for escaping regex special characters for patterns in
python strings to silence the following warnings:

bindings/python/tests/tests_edge_event.py:211: SyntaxWarning: invalid escape sequence '\.'
  "<EdgeEvent type=Type\.RISING_EDGE timestamp_ns=[0-9]+ line_offset=0 global_seqno=1 line_seqno=1>",
bindings/python/tests/tests_info_event.py:188: SyntaxWarning: invalid escape sequence '\.'
  '<InfoEvent type=Type\.LINE_REQUESTED timestamp_ns=[0-9]+ line_info=<LineInfo offset=0 name="None" used=True consumer="\?" direction=Direction\.INPUT active_low=False bias=Bias\.UNKNOWN drive=Drive\.PUSH_PULL edge_detection=Edge\.NONE event_clock=Clock\.MONOTONIC debounced=False debounce_period=0:00:00>>',

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
10 months agotests: add enable_debounce_then_edge_detection
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.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/20240513160031.309139-1-warthog618@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
10 months agobuild: drop the LGPL-3.0 license file from EXTRA_DIST
Bartosz Golaszewski [Mon, 13 May 2024 09:25:31 +0000 (11:25 +0200)]
build: drop the LGPL-3.0 license file from EXTRA_DIST

The release tarball building is currently broken because it looks for
a file that no longer exists. Drop the LGPL-3.0 license file from
EXTRA_DIST.

Fixes: 76ecc337c519 ("licensing: relicense C++ bindings under LGPL-2.1-or-later")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
10 months agotools: tests: accept the new gpio-sim label format in test cases
Bartosz Golaszewski [Mon, 6 May 2024 16:25:06 +0000 (18:25 +0200)]
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.

Reviewed-by: Kent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/20240506162506.176935-1-brgl@bgdev.pl
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
11 months agotools: add minutes as a new supported time unit
Bartosz Golaszewski [Tue, 23 Apr 2024 10:04:52 +0000 (12:04 +0200)]
tools: add minutes as a new supported time unit

Make it more convenient to specify longer time periods in gpio-tools by
introducing minutes as the new time unit.

Link: https://lore.kernel.org/r/20240423100452.32958-5-brgl@bgdev.pl
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
11 months agotools: allow longer time periods
Bartosz Golaszewski [Tue, 23 Apr 2024 10:04:51 +0000 (12:04 +0200)]
tools: allow longer time periods

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.

Reported-by: Gunnar Thörnqvist <gunnar@igl.se>
Link: https://lore.kernel.org/r/20240423100452.32958-4-brgl@bgdev.pl
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
11 months agotools: use ppoll() where higher timeout resolution makes sense
Bartosz Golaszewski [Tue, 23 Apr 2024 10:04:50 +0000 (12:04 +0200)]
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.

Reviewed-by: Kent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/20240423100452.32958-3-brgl@bgdev.pl
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
11 months agotools: rename timeout to idle_timeout in gpiomon and gpionotify
Bartosz Golaszewski [Tue, 23 Apr 2024 10:04:49 +0000 (12:04 +0200)]
tools: rename timeout to idle_timeout in gpiomon and gpionotify

Use a more meaningful name for the variable storing the idle timeout
value.

Suggested-by: Kent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/20240423100452.32958-2-brgl@bgdev.pl
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
11 months agodoc: add a file explaining the contribution process in detail
Bartosz Golaszewski [Tue, 16 Apr 2024 21:21:41 +0000 (23:21 +0200)]
doc: add a file explaining the contribution process in detail

Add a separate document explaining the contribution process for libgpiod
with emphasis on the Developer's Certificate of Origin.

I based the text of this document on the one written by Grant Likely[1]
and adjusted it for libgpiod.

[1] https://github.com/glikely/obs-ptz/blob/main/CONTRIBUTING.md

Suggested-by: Grant Likely <grant.likely@linaro.org>
Acked-by: Grant Likely <grant.likely@linaro.org>
Link: https://lore.kernel.org/r/20240416212141.6683-3-brgl@bgdev.pl
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
11 months agolicensing: relicense C++ bindings under LGPL-2.1-or-later
Bartosz Golaszewski [Tue, 16 Apr 2024 21:21:40 +0000 (23:21 +0200)]
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>
11 months agobuild: fix configure error messages on missing functions
Bartosz Golaszewski [Tue, 9 Apr 2024 08:18:18 +0000 (10:18 +0200)]
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>
11 months agoREADME: remove out-of-date information on python bindings
Bartosz Golaszewski [Mon, 8 Apr 2024 12:24:14 +0000 (14:24 +0200)]
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.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
11 months agodoc: fix doc text alignment
Bartosz Golaszewski [Mon, 8 Apr 2024 11:58:02 +0000 (13:58 +0200)]
doc: fix doc text alignment

Align the text in broken lines to the start of the paragraph in places
where this is not consistent.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
11 months agobindings: cxx: fix doxygen description of line_request::release()
Bartosz Golaszewski [Mon, 8 Apr 2024 09:20:30 +0000 (11:20 +0200)]
bindings: cxx: fix doxygen description of line_request::release()

Seems like the description was copy-pasted from chip::close(). Fix it.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
12 months agogitignore: ignore gcov output
Bartosz Golaszewski [Fri, 29 Mar 2024 20:16:05 +0000 (21:16 +0100)]
gitignore: ignore gcov output

Add .gcov files generated by gcov to the list of globally ignored files.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
12 months agobuild: add missing space to one of the Makefiles
Bartosz Golaszewski [Fri, 29 Mar 2024 20:14:39 +0000 (21:14 +0100)]
build: add missing space to one of the Makefiles

The Makefile in lib/ is missing a space in LDFLAGS assignment. Add it.
This is not a functional change, just coding style.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
12 months agotreewide: fix spelling of "immediately".
Kent Gibson [Mon, 25 Mar 2024 11:17:17 +0000 (19:17 +0800)]
treewide: fix spelling of "immediately".

"immediately" is incorrectly spelled "immediatelly" in several places, so
replace with correct spelling.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
12 months agobindings: cxx: link using the libtool archives
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>
12 months agobindings: cxx: examples: fix typo in comment
Kent Gibson [Sat, 9 Mar 2024 10:30:41 +0000 (18:30 +0800)]
bindings: cxx: examples: fix typo in comment

Fix typo in comment in watch_multiple_line_values.cpp.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
13 months agobindings: python: fix __repr__() implementations
Bartosz Golaszewski [Tue, 30 Jan 2024 15:04:48 +0000 (16:04 +0100)]
bindings: python: fix __repr__() implementations

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>
14 months agocore: check for positive values returned by calls to ioctl()
Bartosz Golaszewski [Thu, 25 Jan 2024 08:06:29 +0000 (09:06 +0100)]
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>
14 months agoREADME: mention the Linux 5.10 requirement for libgpiod v2
Bartosz Golaszewski [Tue, 16 Jan 2024 09:40:57 +0000 (10:40 +0100)]
README: mention the Linux 5.10 requirement for libgpiod v2

Major version 2 of libgpiod requires linux kernel uAPI v2 to be available.
This was released in Linux 5.10 so mention it in the README.

Suggested-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
14 months agoREADME: add info about the github page
Bartosz Golaszewski [Mon, 15 Jan 2024 11:19:28 +0000 (12:19 +0100)]
README: add info about the github page

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>
14 months agobindings: python: fix package installation with Makefile build
Bartosz Golaszewski [Tue, 9 Jan 2024 19:09:37 +0000 (20:09 +0100)]
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.

Link: https://github.com/pypa/pip/issues/3063
Suggested-by: Maxim Devaev <mdevaev@gmail.com>
Reported-by: Maxim Devaev <mdevaev@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
14 months agocore: remove buggy flags sanitization from line-config
Bartosz Golaszewski [Thu, 4 Jan 2024 13:50:58 +0000 (14:50 +0100)]
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>
14 months agoREADME: fix typo
Kent Gibson [Sat, 30 Dec 2023 02:34:13 +0000 (10:34 +0800)]
README: fix typo

Fix typo in --enable-gpioset-interactive in TOOLS section.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
14 months agogpioset: improve toggle option help
Kent Gibson [Fri, 29 Dec 2023 09:33:28 +0000 (17:33 +0800)]
gpioset: improve toggle option help

Reword toggle option help to add that a 0 terminated sequence will exit.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
14 months agogpioset: reword note on post-exit behaviour
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>
16 months agobindings: rust: libgpiod-sys: new release
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.

Signed-off-by: Erik Schilling <erik.schilling@linaro.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
16 months agobindings: rust: libgpiod: release 0.2.2
Erik Schilling [Tue, 14 Nov 2023 08:43:40 +0000 (09:43 +0100)]
bindings: rust: libgpiod: release 0.2.2

Minor update the exposes feature flag and bindings for v2.1.

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)
3b40a37 (bindings: rust: fix EXTRA_DIST for examples, 2023-11-03)

Signed-off-by: Erik Schilling <erik.schilling@linaro.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
16 months agobindings: python: gpiod v2.1.3
Bartosz Golaszewski [Thu, 9 Nov 2023 20:26:53 +0000 (21:26 +0100)]
bindings: python: gpiod v2.1.3

Another small bugfix release addressing an issue with building tests.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
16 months agobindings: python: add build_tests.py to the manifest
Bartosz Golaszewski [Thu, 9 Nov 2023 20:21:24 +0000 (21:21 +0100)]
bindings: python: add build_tests.py to the manifest

build_tests.py is not part of the sdist so tests cannot be built from
pypi releases. Add it to MANIFEST.in.

Fixes: d588a6a5928a ("bindings: python: standalone build tooling for tests")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
16 months agobindings: python: gpiod v2.1.2
Bartosz Golaszewski [Thu, 9 Nov 2023 20:13:47 +0000 (21:13 +0100)]
bindings: python: gpiod v2.1.2

This is a small bugfix release improving how the C extensions for python
bindings tests are built.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
16 months agobindings: python: standalone build tooling for tests
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>
16 months agobindings: rust: expose v2.1 features as flag
Erik Schilling [Mon, 6 Nov 2023 12:53:14 +0000 (13:53 +0100)]
bindings: rust: expose v2.1 features as flag

v2.1 provided a getter to read the chip name from a request.

This adds v2_1 as feature in order to raise the minimum requested version
to v2.1 for exposing the new API.

This is identical to the concept patch that was posted [1] when this
feature flag mechanism was proposed. Only the commit message was
reworded.

[1] https://lore.kernel.org/all/20231006-b4-bindings-old-version-fix-v1-2-a65f431afb97@linaro.org/

Signed-off-by: Erik Schilling <erik.schilling@linaro.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
16 months agobindings: python: gpiod v2.1.1
Bartosz Golaszewski [Fri, 3 Nov 2023 19:31:23 +0000 (20:31 +0100)]
bindings: python: gpiod v2.1.1

This is a small bugfix release of the python bindings fixing how the
homepage on pypi is displayed.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
16 months agobindings: python: fix README.md SPDX license tags
Phil Howard [Fri, 3 Nov 2023 19:14:55 +0000 (19:14 +0000)]
bindings: python: fix README.md SPDX license tags

Replace the # (which is a markdown heading) with HTML tags to hide SPDX
identifier tags within the project description on pypi.

Signed-off-by: Phil Howard <phil@gadgetoid.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
16 months agobindings: python: gpiod v2.1.0
Bartosz Golaszewski [Fri, 3 Nov 2023 18:34:25 +0000 (19:34 +0100)]
bindings: python: gpiod v2.1.0

Release libgpiod python bindings v2.1.0.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
16 months agolibgpiod: start v2.2 development cycle
Bartosz Golaszewski [Fri, 3 Nov 2023 16:40:15 +0000 (17:40 +0100)]
libgpiod: start v2.2 development cycle

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
16 months agolibgpiod v2.1
Bartosz Golaszewski [Fri, 3 Nov 2023 13:25:38 +0000 (14:25 +0100)]
libgpiod v2.1

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
16 months agoNEWS: updates for v2.1
Bartosz Golaszewski [Fri, 3 Nov 2023 13:25:14 +0000 (14:25 +0100)]
NEWS: updates for v2.1

Add release notes for libgpiod v2.1.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
16 months agotests: fix version parsing (again)
Bartosz Golaszewski [Fri, 3 Nov 2023 16:17:00 +0000 (17:17 +0100)]
tests: fix version parsing (again)

This time we missed the fact that the last part is optional. Fix it
treewide.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
16 months agotools: tests: include the test script in the release tarball
Bartosz Golaszewski [Fri, 3 Nov 2023 13:06:06 +0000 (14:06 +0100)]
tools: tests: include the test script in the release tarball

Apparently bash scripts need to be listed in the dist_noinst_SCRIPTS in
order to be picked up into the dist package, noinst_SCRIPTS is not
enough.

Fixes: 555f5e4cfe9f ("tools: tests: port tests to shunit2")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
16 months agobindings: rust: add wrapper.h to EXTRA_DIST
Bartosz Golaszewski [Fri, 3 Nov 2023 13:01:27 +0000 (14:01 +0100)]
bindings: rust: add wrapper.h to EXTRA_DIST

We need to package wrapper.h in the release tarball so add it to
EXTRA_DIST.

Fixes: 1f8085953086 ("bindings: rust: build against pkg-config info")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
16 months agobindings: rust: fix EXTRA_DIST for examples
Bartosz Golaszewski [Fri, 3 Nov 2023 11:04:16 +0000 (12:04 +0100)]
bindings: rust: fix EXTRA_DIST for examples

One of the examples listed in EXTRA_DIST is missing the .rs suffix while
another lists a file that doesn't exist. Fix both issues.

Fixes: aaed0f2e6255 ("bindings: rust: examples: replace tools examples with use case examples")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
16 months agobindings: python: fix EXTRA_DIST for examples
Bartosz Golaszewski [Fri, 3 Nov 2023 10:53:11 +0000 (11:53 +0100)]
bindings: python: fix EXTRA_DIST for examples

One of the example scripts is named differently than what the Makefile
lists it as. Change the EXTRA_DIST variable to fix it.

Fixes: 96c52d3e595b ("bindings: python: examples: replace tools examples with use case examples")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
16 months agobindings: python: optionally include module in sdist
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>
17 months agobindings: python: move long_description into README.md
Phil Howard [Tue, 17 Oct 2023 14:55:49 +0000 (15:55 +0100)]
bindings: python: move long_description into README.md

Move the long_description into README.md and include some basic
information about libgpiod, and some simple Python example code.

Signed-off-by: Phil Howard <phil@gadgetoid.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
17 months agobindings: python: change the package name to 'gpiod'
Bartosz Golaszewski [Tue, 17 Oct 2023 11:41:59 +0000 (13:41 +0200)]
bindings: python: change the package name to 'gpiod'

We now control the name 'gpiod' on pypi. Let's change the project name
as the package we import in python code is named 'gpiod' and not
'libgpiod'

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
17 months agobindings: python: fix the distutils import
Bartosz Golaszewski [Tue, 24 Oct 2023 07:55:12 +0000 (09:55 +0200)]
bindings: python: fix the distutils import

The presence of _distutils in setuptools is an implementation detail. If
we want anything from the distutils package, we should import it directly.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
17 months agobindings: python: simplify environ access
Phil Howard [Thu, 12 Oct 2023 19:51:39 +0000 (20:51 +0100)]
bindings: python: simplify environ access

Use environ.get() in lieu of an explicit check for GPIOD_WITH_TESTS in
os.environ.

Returns None and evaluates as False if GPIOD_WITH_TESTS == "1" is
not specified.

Signed-off-by: Phil Howard <phil@gadgetoid.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
17 months agobindings: python: add pyproject.toml, pep 518
Phil Howard [Thu, 12 Oct 2023 21:02:28 +0000 (22:02 +0100)]
bindings: python: add pyproject.toml, pep 518

Add pyproject.toml to prevent spurious deprecation warnings from pip.

Signed-off-by: Phil Howard <phil@gadgetoid.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
17 months agobindings: python: require python 3.9.0
Phil Howard [Wed, 11 Oct 2023 12:12:46 +0000 (13:12 +0100)]
bindings: python: require python 3.9.0

Required minimum version for PyModule_AddType helper.

Signed-off-by: Phil Howard <phil@gadgetoid.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
17 months agobindings: rust: libgpiod: release 0.2.1
Erik Schilling [Tue, 10 Oct 2023 07:13:11 +0000 (09:13 +0200)]
bindings: rust: libgpiod: release 0.2.1

While the release technically removes a function, that function was not
available in any released libgpiod version. Therefore, this only bumps
the minor.

This release fixes building with releases from the 2.x series of the C
lib.

Changelog:
=========

acebcf2 (bindings: rust: feature gate unreleased features, 2023-10-06)

Signed-off-by: Erik Schilling <erik.schilling@linaro.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
17 months agobindings: python: replace PyModule_AddObjectRef() with PyModule_AddObject()
Bartosz Golaszewski [Mon, 9 Oct 2023 19:02:52 +0000 (21:02 +0200)]
bindings: python: replace PyModule_AddObjectRef() with PyModule_AddObject()

PyModule_AddObjectRef() was added in cpython v3.10 while libgpiod claims
to depend on python v3.9. Replace it with an older variant that steals the
reference to the added object on success.

Reported-by: Phil Howard <phil@gadgetoid.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
17 months agobindings: rust: feature gate unreleased features
Erik Schilling [Fri, 6 Oct 2023 07:24:26 +0000 (09:24 +0200)]
bindings: rust: feature gate unreleased features

`gpiod_line_request_get_chip_name()` is not released yet. Still, libgpiod-sys
will just happily generate bindings for it if it sees the definition in the
header file.

This guards the unreleased features behind an optional feature `vnext`.

To sketch the process of what happens once these features get into an
assumed "2.1" release:

libgpiod-sys will get updated with a `v2_1` feature. That feature would
then raise the minimum version that is attempted to query from pkg-
config. An identical feature will then be introduced on the `libgpiod`
crate and `vnext` guards will be changed to `v2_1` guards. The `vnext`
feature will then be updated to require the new `v2_1` feature.

Eventually, we will probably raise the minimum supported version for the
rust bindings and drop all the version gates before that.

Signed-off-by: Erik Schilling <erik.schilling@linaro.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
17 months agobindings: rust: libgpiod: release 0.2.0
Erik Schilling [Thu, 5 Oct 2023 07:42:23 +0000 (09:42 +0200)]
bindings: rust: libgpiod: release 0.2.0

Since we had some (potentially-)breaking changes, we bump the major for
the next release of the crate.

Note:
I am using the term "major" as defined in the Rust SemVer compatibility
guide [1], where the first non-zero digit is considered as "major".

[1] https://doc.rust-lang.org/cargo/reference/semver.html

Changelog:
=========

(potentially-)breaking changes:
  a29f3e6 (bindings: rust: rename {event,settings}_clone to try_clone, 2023-10-04)
  b290348 (bindings: rust: fix soundness of line_info modeling, 2023-10-03)
  d04639d (bindings: rust: bump MSRV to 1.60, 2023-06-16)

new functionality:
  808d15e (bindings: rust: allow cloning line::InfoRef -> line::Info, 2023-10-03)
  64aac85 (bindings: rust: mark all owning types as `Send`, 2023-09-28)
  d12ce74 (bindings: rust: provide LineRequest::chip_name(), 2023-07-20)
  53226d5 (bindings: rust: examples: add dedicated examples, 2023-06-14)

other changes:
  0a570b6 (bindings: rust: drop unneeded Arc within Chip, 2023-09-27)
  a97fe96 (bindings: rust: construct chip infos by reference, 2023-09-27)
  27afa47 (bindings: rust: remove useless clone, 2023-09-28)
  3f6e0bf (bindings: rust: add README.md for libgpiod crate, 2023-07-03)
  4b8357b (bindings: rust: clippy: silence false-positive on iterator, 2023-06-30)
  39189f0 (bindings: rust: clippy: drop unneeded conversions, 2023-06-30)
  46115fd (bindings: rust: clippy: silence false-positives on casts, 2023-06-30)
  901104e (bindings: rust: clippy: drop unnecessary casts, 2023-06-30)
  46ecbe0 (rust: examples: file comment consistency, 2023-06-24)
  aaed0f2 (bindings: rust: examples: replace tools examples with use case examples, 2023-06-23)
  b37bd9e (bindings: rust: examples: consistency cleanup, 2023-06-23)
  06c8ad9 (bindings: rust: package new examples in the distro tarball, 2023-06-15)

Signed-off-by: Erik Schilling <erik.schilling@linaro.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
17 months agobindings: rust: rename {event,settings}_clone to try_clone
Erik Schilling [Wed, 4 Oct 2023 13:00:00 +0000 (15:00 +0200)]
bindings: rust: rename {event,settings}_clone to try_clone

What is getting cloned is already clear from the type. This also aligns
a bit better with similar methods from the `std` crate [1].

[1] https://doc.rust-lang.org/std/index.html?search=try_clone

Link: https://lore.kernel.org/r/CVUKC1HXG1P8.13XIUCCXN95F0@ablu-work
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Erik Schilling <erik.schilling@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
17 months agobindings: rust: allow cloning line::InfoRef -> line::Info
Erik Schilling [Tue, 3 Oct 2023 09:39:59 +0000 (11:39 +0200)]
bindings: rust: allow cloning line::InfoRef -> line::Info

While one would usually use the ToOwned [1] contract in rust, libgpipd's
API only allows copying that may fail.

Thus, we cannot implement the existing trait and roll our own method. I
went with `try_clone` since that seems to be used in similar cases across
the `std` crate [2].

It also closes the gap of not having any way to clone owned instances.
Though - again - not through the Clone trait which may not fail [3].

[1] https://doc.rust-lang.org/std/borrow/trait.ToOwned.html
[2] https://doc.rust-lang.org/std/index.html?search=try_clone
[3] https://doc.rust-lang.org/std/clone/trait.Clone.html

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Erik Schilling <erik.schilling@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
17 months agobindings: rust: fix soundness of line_info modeling
Erik Schilling [Tue, 3 Oct 2023 09:39:57 +0000 (11:39 +0200)]
bindings: rust: fix soundness of line_info modeling

While attention was provided to prevent freeing in non-owned use-cases,
the lifetime of these object was not properly modeled.

The line_info from an event may only be used for as long as the event
exists.

This allowed us to write unsafe-free Rust code that causes a
use-after-free:

  let event = chip.read_info_event().unwrap();
  let line_info = event.line_info().unwrap();
  drop(event);
  dbg!(line_info.name().unwrap());

Which makes the AddressSanitizer scream:

  ==90154==ERROR: AddressSanitizer: heap-use-after-free on address 0x50b000005dc4 at pc 0x55a4f883a009 bp 0x7f60ac8fbbc0 sp 0x7f60ac8fb388
  READ of size 2 at 0x50b000005dc4 thread T2
      [...]
      #3 0x55a4f8c3d5f3 in libgpiod::line_info::Info::name::h5ba0bfd360ecb405 libgpiod/bindings/rust/libgpiod/src/line_info.rs:70:18
     [...]

  0x50b000005dc4 is located 4 bytes inside of 112-byte region [0x50b000005dc0,0x50b000005e30)
  freed by thread T2 here:
      [...]
      #1 0x7f60b07f7e31 in gpiod_info_event_free libgpiod/lib/info-event.c:61:2
      [...]

  previously allocated by thread T2 here:
      #0 0x55a4f88b04be in malloc /rustc/llvm/src/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:69:3
      #1 0x7f60b07f8ff0 in gpiod_line_info_from_uapi libgpiod/lib/line-info.c:144:9

The fix is to distinguish between the owned and non-owned variants and
assigning lifetimes to non-owned variants.

For modeling the non-owned type there are a couple of options. The ideal
solution would be using extern_types [1]. But that is still unstable.
Instead, we are defining a #[repr(transparent)] wrapper around the opaque
gpiod_line_info struct and cast the pointer to a reference.

This was recommended on the Rust Discord server as good practise.
(Thanks to Kyuuhachi, shepmaster, pie_flavor and ilyvion! Also thanks to
@epilys for a brainstorming on this on #linaro-virtualization IRC).

Of course, determining the lifetimes and casting across the types
requires some care. So this adds a couple of SAFETY comments that would
probably also have helped the existing code.

[1] https://github.com/rust-lang/rfcs/blob/master/text/1861-extern-types.md

Fixes: 91f9373c6558 ("bindings: rust: Add libgpiod crate")
Signed-off-by: Erik Schilling <erik.schilling@linaro.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
18 months agobindings: rust: mark all owning types as `Send`
Erik Schilling [Thu, 28 Sep 2023 14:37:30 +0000 (16:37 +0200)]
bindings: rust: mark all owning types as `Send`

The thread-safety rules of libgpiod allow individual object instances to
be used from different threads. So far, this was not actually possible
with the Rust bindings. Not being `Send` disallowed the user to transfer
the ownership to different threads.

Rust also has a `Sync` marker. That one would even allow sending
references of objects to other threads. Since we wrap a lot of C
functions with `fn foo(&self)` signatures, that would not be safe.
libgpiod does not allow concurrent API calls to the same object instance
- which Rust would allow for read-only references. Thus, we do not
define that one.

Chip was already modeled correctly.

line::Info is not marked as Send since it may either be owning or non-
owning. That problem is fixed as part of a separate pull request [1].

[1] https://lore.kernel.org/r/20230927-rust-line-info-soundness-v1-0-990dce6f18ab@linaro.org

Link: https://lore.kernel.org/r/CVHO091CC80Y.3KUOSLSOBVL0T@ablu-work
Signed-off-by: Erik Schilling <erik.schilling@linaro.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
18 months agodoc: document thread safety guarantees
Erik Schilling [Thu, 28 Sep 2023 14:37:29 +0000 (16:37 +0200)]
doc: document thread safety guarantees

This mostly adds the information from the linked thread to the doxygen
documentation.

Summarized:
- libgpiod object's require synchronization
- individual objects may be used concurrently by different threds

Link: https://lore.kernel.org/r/CVHO091CC80Y.3KUOSLSOBVL0T@ablu-work
Signed-off-by: Erik Schilling <erik.schilling@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
18 months agodoc: drop unneeded <p> tags
Erik Schilling [Thu, 28 Sep 2023 14:37:28 +0000 (16:37 +0200)]
doc: drop unneeded <p> tags

Even before Doxygen gained Markdown support, empty lines were considered
as paragraphs. Changelogs indicate that this was the case since at least
the doxygen 1.2 series (where I found a mentiond that something around
this behaviour was fixed). So at least works in Doxygen versions
released after 2001 [1].

[1] https://sourceforge.net/p/doxygen/mailman/message/172899/

Signed-off-by: Erik Schilling <erik.schilling@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
18 months agobindings: rust: drop unneeded Arc within Chip
Erik Schilling [Wed, 27 Sep 2023 09:25:24 +0000 (11:25 +0200)]
bindings: rust: drop unneeded Arc within Chip

Chip was modeled with an Arc that only was used to pass the chip pointer
to the chip::Info constructor. With that refactored to take a reference,
we can just drop the Arc.

This allows to get rid of the `Internal` helper struct that was only
required by the Arc.

As a side-effect, we also get rid of this clippy warning:

  warning: usage of an `Arc` that is not `Send` or `Sync`
    --> libgpiod/src/chip.rs:75:21
     |
  75 |         let ichip = Arc::new(Internal::open(path)?);
     |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |
     = note: the trait `Send` is not implemented for `Internal`
     = note: the trait `Sync` is not implemented for `Internal`
     = note: required for `Arc<Internal>` to implement `Send` and `Sync`
     = help: consider using an `Rc` instead or wrapping the inner type with a `Mutex`

Signed-off-by: Erik Schilling <erik.schilling@linaro.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
18 months agobindings: rust: construct chip infos by reference
Erik Schilling [Wed, 27 Sep 2023 09:25:23 +0000 (11:25 +0200)]
bindings: rust: construct chip infos by reference

No need to clone the Arc for this. A simple reference is enough to get
to the underlying chip pointer.

Signed-off-by: Erik Schilling <erik.schilling@linaro.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
18 months agobindings: rust: remove useless clone
Erik Schilling [Thu, 28 Sep 2023 06:23:19 +0000 (08:23 +0200)]
bindings: rust: remove useless clone

Reported by 1.74.0-nightly:

  warning: call to `.clone()` on a reference in this situation does nothing
    --> libgpiod/tests/line_request.rs:71:44
     |
  71 |             let chip_name = sim.chip_name().clone();
     |                                            ^^^^^^^^ help: remove this redundant call
     |
     = note: the type `str` does not implement `Clone`, so calling `clone` on `&str` copies the reference, which does not do anything and can be removed
     = note: `#[warn(noop_method_call)]` on by default

Signed-off-by: Erik Schilling <erik.schilling@linaro.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
18 months agobindings: python: tests: don't use the same chip from different threads
Bartosz Golaszewski [Tue, 19 Sep 2023 09:31:42 +0000 (11:31 +0200)]
bindings: python: tests: don't use the same chip from different threads

There are no thread-safety guarantees in libgpiod. Let's not reuse the
chip object created in one thread to generate info events in another but
use a global request function instead.

Reported-by: Erik Schilling <erik.schilling@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Erik Schilling <erik.schilling@linaro.org>
18 months agobindings: cxx: tests: don't use the same chip from different threads
Bartosz Golaszewski [Tue, 19 Sep 2023 09:31:41 +0000 (11:31 +0200)]
bindings: cxx: tests: don't use the same chip from different threads

There are no thread-safety guarantees in libgpiod. Let's not reuse the
chip object created in one thread to generate info events in another but
create a second chip for that purpose instead.

Reported-by: Erik Schilling <erik.schilling@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Erik Schilling <erik.schilling@linaro.org>
18 months agotests: don't use the same chip object from different threads
Bartosz Golaszewski [Tue, 19 Sep 2023 09:31:40 +0000 (11:31 +0200)]
tests: don't use the same chip object from different threads

There are no thread-safety guarantees in libgpiod. Let's not reuse the
chip object created in one thread to generate info events in another but
create a second chip for that purpose instead.

Reported-by: Erik Schilling <erik.schilling@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Erik Schilling <erik.schilling@linaro.org>
19 months agotests: add missing return value check
Bartosz Golaszewski [Sun, 6 Aug 2023 20:16:15 +0000 (22:16 +0200)]
tests: add missing return value check

One of the line-request test cases is missing the return value check
after the call to gpiod_line_request_set_values_subset(). Add it.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
20 months agoexamples: simplify find_line_by_name
Kent Gibson [Thu, 27 Jul 2023 21:10:56 +0000 (05:10 +0800)]
examples: simplify find_line_by_name

Simplify the find_line_by_name example by using
gpiod_chip_get_line_offset_from_name() rather than iterating over each
line in a chip.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
20 months agobindings: rust: provide LineRequest::chip_name()
Bartosz Golaszewski [Thu, 20 Jul 2023 14:47:47 +0000 (16:47 +0200)]
bindings: rust: provide LineRequest::chip_name()

Provide a wrapper around gpiod_line_request_get_chip_name() for Rust
bindings and add a test-case.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Erik Schilling <erik.schilling@linaro.org>
Reviewed-by: Kent Gibson <warthog618@gmail.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
20 months agobindings: python: provide the chip_name property in line_request
Bartosz Golaszewski [Thu, 20 Jul 2023 14:47:46 +0000 (16:47 +0200)]
bindings: python: provide the chip_name property in line_request

Provide a wrapper around gpiod_line_request_get_chip_name() for Python
bindings and update the tests.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
20 months agobindings: cxx: provide line_request::chip_name()
Bartosz Golaszewski [Thu, 20 Jul 2023 14:47:45 +0000 (16:47 +0200)]
bindings: cxx: provide line_request::chip_name()

Provide a wrapper around gpiod_line_request_get_chip_name() for C++
bindings and update the tests.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
20 months agotests: add a test-case for gpiod_line_request_get_chip_name()
Bartosz Golaszewski [Thu, 20 Jul 2023 14:47:44 +0000 (16:47 +0200)]
tests: add a test-case for gpiod_line_request_get_chip_name()

Add a test case for the chip name getter on line-request objects.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
20 months agocore: provide gpiod_line_request_get_chip_name()
Bartosz Golaszewski [Thu, 20 Jul 2023 14:47:43 +0000 (16:47 +0200)]
core: provide gpiod_line_request_get_chip_name()

While we can get the list of requested offsets from a line-request object,
this information lacks context if we don't provide any data about the GPIO
chip the request was made on. Add a helper allowing users to get the name
of the parent chip.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
21 months agobindings: rust: mention the libgpiod crate from libgpiod-sys
Erik Schilling [Mon, 3 Jul 2023 07:20:00 +0000 (09:20 +0200)]
bindings: rust: mention the libgpiod crate from libgpiod-sys

If people view this README.md on crates.io [1], they likely want to
use the safe wrapper instead. So this hints the existence of that other
crate.

[1] https://crates.io/crates/libgpiod-sys

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Erik Schilling <erik.schilling@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
21 months agobindings: rust: add README.md for libgpiod crate
Erik Schilling [Mon, 3 Jul 2023 07:19:59 +0000 (09:19 +0200)]
bindings: rust: add README.md for libgpiod crate

crates.io treats the README as landing page for a crate [1]. Since
we have none, it currently displays a blank page. Lets add at least a
little bit of info here so people can figure out what they are dealing
with.

[1] https://crates.io/crates/libgpiod

Signed-off-by: Erik Schilling <erik.schilling@linaro.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
21 months agotools: tests: print additional info when regex matching fails
Bartosz Golaszewski [Mon, 3 Jul 2023 10:39:06 +0000 (12:39 +0200)]
tools: tests: print additional info when regex matching fails

Add shunit assert messages when testing the result of regex matches,
otherwise we're left with a not very useful: "expected:<0> but was:<1>".

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
21 months agobuild: remove redundant SOURCES assignments
Bartosz Golaszewski [Fri, 30 Jun 2023 12:28:25 +0000 (14:28 +0200)]
build: remove redundant SOURCES assignments

For any given target (let's say foobar), automake defaults to looking for
foobar.c if foobar_SOURCES are not specified. Remove redundant assignments
as we've seen multiple hidden typos in makefiles already.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Kent Gibson <warthog618@gmail.com>
21 months agocore: examples: fix warning for u64 formatting on 32bit
Kent Gibson [Fri, 30 Jun 2023 09:08:57 +0000 (17:08 +0800)]
core: examples: fix warning for u64 formatting on 32bit

The watch_line_info example prints the u64 timestamps using "%ld" which
produces a warning for 32bit.  Replace it with PRIu64.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
21 months agobindings: rust: clippy: silence false-positive on iterator
Erik Schilling [Fri, 30 Jun 2023 11:18:47 +0000 (13:18 +0200)]
bindings: rust: clippy: silence false-positive on iterator

This was fixed on clippy master [1], but it is still broken on 0.1.70. So
lets silence it until the clippy fix is widely available.

clippy version: clippy 0.1.70 (90c5418 2023-05-31).

[1] https://github.com/rust-lang/rust-clippy/commit/9fa40894103e32364fdbade539d4ecb3d40f3d7f

Reported-by: Kent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/20230612154055.56556-1-warthog618@gmail.com
Signed-off-by: Erik Schilling <erik.schilling@linaro.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
21 months agobindings: rust: clippy: drop unneeded conversions
Erik Schilling [Fri, 30 Jun 2023 11:18:46 +0000 (13:18 +0200)]
bindings: rust: clippy: drop unneeded conversions

Fixes clippy warnings on these lines.

Applied the suggested fix using:

    cargo clippy --fix

clippy version: clippy 0.1.70 (90c5418 2023-05-31).

Reported-by: Kent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/20230612154055.56556-1-warthog618@gmail.com
Signed-off-by: Erik Schilling <erik.schilling@linaro.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
21 months agobindings: rust: clippy: silence false-positives on casts
Erik Schilling [Fri, 30 Jun 2023 11:18:45 +0000 (13:18 +0200)]
bindings: rust: clippy: silence false-positives on casts

clippy falsely complains about these lines. The problem is known, but
unfixed [1]. So lets silence the warning until a fix is widely available.

clippy version: clippy 0.1.70 (90c5418 2023-05-31).

[1] https://github.com/rust-lang/rust-clippy/issues/10555

Reported-by: Kent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/20230612154055.56556-1-warthog618@gmail.com
Signed-off-by: Erik Schilling <erik.schilling@linaro.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
21 months agobindings: rust: clippy: drop unnecessary casts
Erik Schilling [Fri, 30 Jun 2023 11:18:44 +0000 (13:18 +0200)]
bindings: rust: clippy: drop unnecessary casts

Fixes clippy warnings on these lines.

Applied the suggested fix using:

    cargo clippy --fix

clippy version: clippy 0.1.70 (90c5418 2023-05-31).

Reported-by: Kent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/20230612154055.56556-1-warthog618@gmail.com
Signed-off-by: Erik Schilling <erik.schilling@linaro.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
21 months agobindings: rust: fix unclear resolver warning
Kent Gibson [Thu, 29 Jun 2023 10:14:55 +0000 (18:14 +0800)]
bindings: rust: fix unclear resolver warning

Fix the following warning:

"some crates are on edition 2021 which defaults to `resolver = "2"`,
 but virtual workspaces default to `resolver = "1"`"

Clarify the resolver selection as the 2021 edition by setting the
workspace.resolver to "2".

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Reviewed-by: Erik Schilling <erik.schilling@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
21 months agobindings: cxx: use () instead of (void) in line_settings::reset()
Bartosz Golaszewski [Mon, 26 Jun 2023 10:44:57 +0000 (12:44 +0200)]
bindings: cxx: use () instead of (void) in line_settings::reset()

While () and (void) are synonymous in C++, we use () everywhere else so
fix the only exception. This DOES NOT change the ABI as the generated
symbol is the same (at least as verified on gcc and clang).

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
21 months agobindings: cxx: examples: consistently use () for functions taking no args
Bartosz Golaszewski [Mon, 26 Jun 2023 10:36:03 +0000 (12:36 +0200)]
bindings: cxx: examples: consistently use () for functions taking no args

While () and (void) are synonymous in C++, we use () everywhere else so
stick to that pattern in examples.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>