Bartosz Golaszewski [Wed, 15 Feb 2023 13:46:16 +0000 (14:46 +0100)]
bindings: python: tests: release the request before removing GPIO sim
One of the test cases doesn't release the request object leading to the
following warning in the kernel log:
REMOVING GPIOCHIP WITH GPIOS STILL REQUESTED
Fix it.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Wed, 15 Feb 2023 12:46:30 +0000 (13:46 +0100)]
tests: fix the enum type in line-request tests
Use the correct enumeration type for GPIO simulator line values.
Fixes: 67ffa262e393 ("tests: add line value enums for gpiosim GLib wrapper")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Mon, 13 Feb 2023 10:53:42 +0000 (11:53 +0100)]
tests: add line value enums for gpiosim GLib wrapper
libgpiosim has a dedicated enum type for line values but the GLib wrapper
still uses magic numbers (0 and 1). Add an enum type for the wrapper and
use it across all test cases.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Mon, 13 Feb 2023 10:03:47 +0000 (11:03 +0100)]
tests: use GLib typedef conventions for line names and hogs
The GVariant packaging works in the context of GLib unit testing so use
GLib conventions for declaring data types.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Tue, 14 Feb 2023 10:10:56 +0000 (11:10 +0100)]
bindings: cxx: drop the re-export guard of visible symbols
The ifdef guard that changes the definition of GPIOD_CXX_API between
"default" and "hidden" is there to prevent libraries that would include
gpiod.hpp from re-exporting libgpiodcxx symbols.
Unfortunately the hidden linkage only works for translation units within
the same ELF object. At static linking time we must always mark the
throwable types as visible or we'll get the following errors:
/usr/bin/ld: tests-chip.o:(.data+0x0): undefined reference to `typeinfo for gpiod::chip_closed'
/usr/bin/ld: tests-line-request.o:(.data+0x0): undefined reference to `typeinfo for gpiod::request_released'
/usr/bin/ld: .libs/gpiod-cxx-test: hidden symbol `_ZTIN5gpiod11chip_closedE' isn't defined
/usr/bin/ld: final link failed: bad value
On top of that we actually WANT to re-export typeinfo for throwable types
as they can be propagated to external callers when an exception is thrown.
The above error can only be triggered on clang. GCC seems to be
incorrectly omitting the "hidden" attribute in this case.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Viresh Kumar [Tue, 14 Feb 2023 06:45:35 +0000 (12:15 +0530)]
bindings: rust: update bindgen's version
The currently selected version of bindgen has a unmaintained dependency
and generates the following build warning while building vhost-device
crate:
Crate: ansi_term
Version: 0.12.1
Warning: unmaintained
Title: ansi_term is Unmaintained
Date: 2021-08-18
ID: RUSTSEC-2021-0139
URL: https://rustsec.org/advisories/RUSTSEC-2021-0139
Dependency tree:
ansi_term 0.12.1
└── clap 2.34.0
└── bindgen 0.59.2
└── libgpiod-sys 0.1.0
└── libgpiod 0.1.0
└── vhost-device-gpio 0.1.0
error: 1 denied warning found!
Fix it by moving to a later version of bindgen, which updates the types
of few of the arguments to the FFI helpers and so required changes to
few of explicit type conversions.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Viresh Kumar [Tue, 14 Feb 2023 06:45:34 +0000 (12:15 +0530)]
bindings: rust: align formatting to what's suggested by 'cargo fmt'
Align code to follow what 'cargo fmt' suggests.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Fri, 10 Feb 2023 21:11:11 +0000 (22:11 +0100)]
gpiosim: use twalk() instead of twalk_r()
twalk_r() is a GNU extension for the binary search tree API. Musl libc
doesn't provide it and after inquiring with the maintainer it turned out
it won't provide it anytime soon as musl strives to only implement well
standardized functions.
In order to not limit building libgpiosim and tests to glibc only, let's
replace twalk_r() with twalk() and use global variables for the state.
It's not a big deal as we're already using a global root node and a mutex
to protect it.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Mon, 13 Feb 2023 17:10:32 +0000 (18:10 +0100)]
bindings: python: don't pass GPIOD_WITH_TESTS to 'setup.py install'
The GPIOD_WITH_TESTS environment variable is not used by setup.py install
command. Drop it.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Mon, 13 Feb 2023 16:54:31 +0000 (17:54 +0100)]
bindings: python: pass DESTDIR to setup.py
As per automake docs:
The DESTDIR variable can be used to perform a staged installation. The
package should be configured as if it was going to be installed in its
final location (e.g., --prefix /usr), but when running make install, the
DESTDIR should be set to the absolute name of a directory into which the
installation will be diverted. From this directory it is easy to review
which files are being installed where, and finally copy them to their
final location by some means.
Prefix $(prefix) with $(DESTDIR) when calling setup.py.
Reported-by: Peter Robinson <pbrobinson@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Peter Robinson <pbrobinson@gmail.com>
Tested-by: Peter Robinson <pbrobinson@gmail.com>
Bartosz Golaszewski [Fri, 10 Feb 2023 20:20:14 +0000 (21:20 +0100)]
configure: add more tests for less commonly used functions
Don't take chances - I've seen enough strange setups recently. Add more
checks for atexit() and functions from search.h.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Fri, 10 Feb 2023 12:54:18 +0000 (13:54 +0100)]
bindings: cxx: fix building gpiod::timestamp with clang
Clang's system_clock implementation uses microseconds resolution by
default and we fail to construct a time_point out of chrono::nanoseconds
as the library prohibits us from accidentally losing information when
casting the latter to the former. Use nanoseconds explicitly as the
resolution of the realtime timestamp.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Thu, 9 Feb 2023 20:03:56 +0000 (21:03 +0100)]
configure: verify the availability of twalk_r() for tests
Some C libraries (notably musl) don't have twalk_r() as of yet. Add a
check for it in configure so that we fail sooner rather than at
build-time.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Thu, 9 Feb 2023 18:49:38 +0000 (19:49 +0100)]
tools: use 'unsigned int' instead of 'uint'
uint is an old compatibility name that GCC still provides but clang
doesn't. Use unsigned int instead.
Fixes: 8ffb6489286f ("tools: line name focussed rework")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Kent Gibson <warthog618@gmail.com>
Bartosz Golaszewski [Thu, 9 Feb 2023 18:29:07 +0000 (19:29 +0100)]
tests: remove unused variables
Clang (unlike GCC) reported certain GLib autopointers as unused. Remove
them.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Tue, 7 Feb 2023 20:23:41 +0000 (21:23 +0100)]
libgpiod v2.0-rc1
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Tue, 7 Feb 2023 13:56:49 +0000 (14:56 +0100)]
NEWS: updates for v2.0
Add release notes for libgpiod v2.0.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Tue, 7 Feb 2023 21:13:57 +0000 (22:13 +0100)]
tests: extend the regex matching string versions
We need to match release candidate versions too.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Tue, 7 Feb 2023 20:22:30 +0000 (21:22 +0100)]
tools: update the copyright date in the output of --version
Update the displayed years in the output of --version for all gpio-tools.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Wed, 8 Feb 2023 12:34:26 +0000 (13:34 +0100)]
bindings: python: don't store build system paths in output files
Using the __FILE__ macro contaminates the build artifacts with global
build host file system paths. Don't use it.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Tue, 7 Feb 2023 13:17:04 +0000 (14:17 +0100)]
tests: use predefined exit codes when returning from main()
Use EXIT_FAILURE to indicate an error in main() instead of returning 1.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Mon, 6 Feb 2023 09:58:02 +0000 (10:58 +0100)]
configure: don't look for qsort()
We no longer need qsort for the test suite after switching to gpio-sim.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Mon, 6 Feb 2023 10:18:34 +0000 (11:18 +0100)]
tests: use native types for main() arguments
Follow the GLib recommendation and use native C types for the main()
function's arguments and return values.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Wed, 1 Feb 2023 09:24:45 +0000 (10:24 +0100)]
tests: rework error handling and stop overusing g_error()
GLib recommends using g_error() only for programming errors and
unrecoverable situations. It calls abort() and triggers a core dump. This
means that if we encounter an error when running a test case, we'll
exit immediately and leave a "leaked" GPIO simulator in configfs.
Rework the error handling: use g_error() only when a programming bug is
encountered (e.g. invalid enum value) while everywhere else use the
regular GError-based error handling. This way, in case of an error in
libgpiosim, we'll simply fail the current test case and release all
resources as usual.
In order not to pollute the test cases with error handling, let's hide the
actual error checking behind macros for g_gpiosim_chip_new() and
g_gpiosim_chip_get_value(). For g_gpiosim_chip_set_pull() let's just emit
a log and do nothing as the test case in question will inevitably fail if
the expected value is not correctly read back.
In order for the chip to get a failing constructor, we need to link the
test-suite against the entire libgio, not only libgobject (for the
GInitable interface).
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Wed, 1 Feb 2023 09:18:57 +0000 (10:18 +0100)]
Revert "tests: consistently use GLib types in tests"
GLib recommends to use standard library's int as the return type for
main() and g_test_run() also returns int, not gint. Revert the commit
that made main() return gint.
This reverts commit
c0176f58f98e837f1b9eb40514ac58c51f24e644.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Wed, 1 Feb 2023 08:34:30 +0000 (09:34 +0100)]
tests: drop the .dispose() method from gpiosim-glib's chip class
The .dispose() method should be used to drop references to any other
GObjects while .finalize() should free any remaining memory. While we are
dropping references in .dispose(), these are references to the libgpiosim
objects that are also guaranteed to always be at most equal 1. Move the
reference drops to .finalize() and remove .dispose() entirely.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Wed, 1 Feb 2023 08:29:12 +0000 (09:29 +0100)]
tests: add a missing call to parent's implementation of .constructed()
In GObject inheriting classes must call the parent's implementation of
"virtual" methods manually. Add a missing call to parent's .constructed()
method in the GLib wrapper of libgpiosim.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Tue, 31 Jan 2023 18:29:16 +0000 (19:29 +0100)]
tests: shrink helper code
Use g_autoptr() for GVariantBuilder objects and shrink the code by a few
lines.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Tue, 31 Jan 2023 17:45:29 +0000 (18:45 +0100)]
configure: drop mention of a removed build option from comments
The make install-tests configure switch has been removed in commit
0dd2125c8ca9 ("tests: remove make check target") so don't mention it
in comments.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Tue, 31 Jan 2023 15:08:48 +0000 (16:08 +0100)]
gpioset: use #ifdef instead of #if with GPIOSET_INTERACTIVE
We're not setting GPIOSET_INTERACTIVE to any specific value that we'd
want to check so be consistent and use #ifdef everywhere to simply check
if it's defined or not.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Tue, 31 Jan 2023 14:53:27 +0000 (15:53 +0100)]
tests: fix a GVariant referencing bug
g_variant_new() returns a floating reference that must be converted to
a full reference before returning or else we may get weird reference
counting errors.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Mon, 30 Jan 2023 10:58:55 +0000 (11:58 +0100)]
doc: various tweaks and improvements treewide
Improve inline docs across the codebase. Fix formatting, unify the usage
of whitespaces inside comments, annotate argument names with '\p', etc.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Thu, 26 Jan 2023 12:24:39 +0000 (13:24 +0100)]
bindings: cxx: remove duplicate mapping helper
We have two helpers that do the same thing: given a key and a map, they
return the associated value or throw an exception if the map doesn't
contain it. The difference is just in the type of the exception. Remove
one and reuse the other. While at it: modify the names a bit for better
readability - especially the mapping function which is not limited to
just mapping enum types.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Thu, 26 Jan 2023 12:39:49 +0000 (13:39 +0100)]
bindings: cxx: don't shift raw pointers around
There are two leftover instances where we return raw C pointers from
local functions. For safety and consistency with the rest of the code
convert those functions to return unique_ptr.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Thu, 26 Jan 2023 12:36:16 +0000 (13:36 +0100)]
bindings: cxx: remove unused code
The malloc_deleter struct is a leftover from earlier implementation.
Drop it.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Fri, 13 Jan 2023 10:52:33 +0000 (11:52 +0100)]
bindings: rust: provide line_config.set_output_values()
Add a new function to line config allowing to set a list of output values
for requested lines. This works very similarily to the C++ version of the
new C interface.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Bartosz Golaszewski [Fri, 13 Jan 2023 14:12:46 +0000 (15:12 +0100)]
bindings: rust: make mutators return &mut self
In C++ bindings we can chain the mutators as they all return a reference
to the object they modify. It's a common practice to allow that in Rust
too so make all mutators that don't already do it return a mutable
reference to self.
It's also logically incorrect to make mutators borrow an immutable
reference to self. Even if that builds - as we're fiddling with C
pointers - it could change in the future. It's fine for getters but
setters should all use mutable references.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Bartosz Golaszewski [Fri, 13 Jan 2023 09:41:44 +0000 (10:41 +0100)]
bindings: python: add the output_values argument to Chip.request_lines()
Add a new optional argument to Chip.request_lines() called output_values.
It accepts a dictionary of mappings between line names or offsets to the
output values the requested lines should be set to at request-time.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Thu, 12 Jan 2023 18:30:25 +0000 (19:30 +0100)]
bindings: cxx: add line_config.set_output_values()
Extend line_config to expose a new method - set_output_values() - which
wraps the new C function for setting multiple output values at once.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Thu, 12 Jan 2023 18:13:12 +0000 (19:13 +0100)]
gpioset: use gpiod_line_config_set_output_values()
Use the new line config function to shrink the gpioset code and drop one
for loop.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Thu, 12 Jan 2023 18:12:51 +0000 (19:12 +0100)]
core: provide gpiod_line_config_set_output_values()
Currently if user wants to use the same settings for a set of requested
lines with the exception of the output value - they need to go through
hoops by updating the line settings object and adding it one by one to
the line config. Provide a helper function that allows to set a global
list of output values that override the settings. For details on the
interface: see documentation in this commit.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Tue, 24 Jan 2023 09:58:11 +0000 (10:58 +0100)]
treewide: unify gpiod_line_config/request_get_offsets() functions
We have two functions in the C API that allow users to retrieve a list
of offsets from objects: gpiod_line_request_get_offsets() and
gpiod_line_config_get_offsets(). Even though they serve pretty much the
same purpose, they have different signatures and one of them also
requires the user to free the memory allocated within the libgpiod
library with a non-libgpiod free() function.
Unify them: make them take the array in which to store offsets and the
size of this array. Make them return the number of offsets actually
stored in the array and make them impossible to fail. Change their names
to be more descriptive and in the case of line_config: add a new function
that allows users to get the number of configured offsets.
Update the entire tree to use the new interfaces.
For rust bindings: also unify the line config interface to return a map
of line settings like C++ bindings do instead of having a function to
get settings by offset. A map returned from a single call is easier to
iterate over with a for loop than using an integer and calling the
previous line_settings() method.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Viresh Kumar [Tue, 24 Jan 2023 08:23:43 +0000 (13:53 +0530)]
bindings: rust: Allow reusing locally installed gpio library
The rust crates builds fine when built with the 'make' command, as
static linking works fine. But when referenced from a remote rust crate,
it gives following error:
error: could not find native static library `gpiod`, perhaps an -L flag is missing?
This happens since we only support 'static' LIB-KIND currently. Remove
the same to allow others to work too.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Viresh Kumar [Tue, 24 Jan 2023 08:23:46 +0000 (13:53 +0530)]
bindings: rust: Align formatting to what's suggested by 'cargo fmt'
Align code to follow what 'cargo fmt' suggests.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Wed, 11 Jan 2023 12:30:24 +0000 (13:30 +0100)]
README: update for libgpiod v2
Certain parts of the README file still refer to concepts removed from
libgpiod v2. Update whatever needs updating.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Fri, 13 Jan 2023 13:51:09 +0000 (14:51 +0100)]
bindings: rust: make request_config optional in Chip.request_lines()
Request config is not necessary to request lines. In C API we accept
a NULL pointer, in C++ it's not necessary to assign a request_config
to the request builder, in Python the consumer and event buffer size
arguments are optional. Let's make rust bindings consistent and not
require the request config to be always present. Convert the argument
in request_lines to Option and update the rest of the code.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Bartosz Golaszewski [Thu, 12 Jan 2023 18:16:38 +0000 (19:16 +0100)]
tests: add a helper for reading back line settings from line config
Add a helper for getting line settings from line config that allows to
shrink the test code a bit.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Thu, 12 Jan 2023 18:15:12 +0000 (19:15 +0100)]
tests: fix the line config reset test case
We're using testing wrong variables in the reset_config test case. We
should be checking the retrieved0 settings which are read back from
the line config object.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Fri, 13 Jan 2023 08:52:24 +0000 (09:52 +0100)]
bindings: cxx: allow to copy line_settings
Implement the copy operator for line_settings. We have a copy() method
for line settings in C API while in C++ it's useful to copy line_settings
returned in an std::map from line_config.get_line_settings().
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Thu, 12 Jan 2023 18:36:32 +0000 (19:36 +0100)]
bindings: cxx: prepend all C symbols with the scope resolution operator
We explicitly resolve all global C symbols from libgpiod to the top-level
namespace. Fix it wherever its missing (mostly for C enum types).
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Wed, 11 Jan 2023 16:24:44 +0000 (17:24 +0100)]
doc: update docs for libgpiod v2
Update docs in gpiod.h wherever they're outdated or make incorrect
statements. While at it: fix formatting in some places.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Wed, 11 Jan 2023 13:13:21 +0000 (14:13 +0100)]
build: unify the coding style of source files lists in Makefiles
Use the most common and readable convention for listing source files
in Makefiles wherever it's not consistent yet.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Wed, 11 Jan 2023 13:08:40 +0000 (14:08 +0100)]
tests: avoid shadowing local variables with common names in macros
The name 'ret' if very common for local variables so change it to _ret
in test helper macros to avoid potential shadowing.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Bartosz Golaszewski [Mon, 16 Jan 2023 15:15:25 +0000 (16:15 +0100)]
build: update the required python version
We don't guarantee libgpiod python bindings to work with anything older
than python 3.9. Let's fix the required version in configure.ac.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Mon, 16 Jan 2023 15:08:21 +0000 (16:08 +0100)]
build: drop unused python-related bits from configure.ac
We no longer use autotools to build python bindings. We should still
check the interpreter but let's not set any automake variables.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Joerg Faschingbauer [Wed, 18 Jan 2023 09:11:45 +0000 (10:11 +0100)]
bindings: python: fix out-of-tree build
Makefile.am delegates the build of the python extension to its
setup.py file, which references the extension .c files relative to the
source dir. This makes it impossible to build in a directory that is
different from the source directory (for example, for PC and ARM but
from the same source).
* Invoke setup.py from $(srcdir)
* Modify setup.py to pick up .c files relative from setup.py's own
directory.
Signed-off-by: Joerg Faschingbauer <jf@faschingbauer.co.at>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Tue, 17 Jan 2023 08:24:44 +0000 (09:24 +0100)]
Revert "configure: replace deprecated macro"
This reverts commit
b353e7b1b65450d04bcbc72e42efc13b04d98a00.
AC_CHECK_INCLUDES_DEFAULT is only available in autoconf v2.70 while we
want to keep supporting v2.69.
Reported-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Kent Gibson [Mon, 16 Jan 2023 12:51:44 +0000 (20:51 +0800)]
bindings: rust: fix documentation of line_request set_values
Replace "Get" with "Set".
Signed-off-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Sun, 18 Dec 2022 09:06:18 +0000 (10:06 +0100)]
core: make the library NULL-aware
Currently we almost never check the validity of pointers passed to the
core C API routines. While we cannot know if a non-NULL pointer points
to an actual object, we can at least verify that it is not NULL before
dereferencing it.
Conceptually we can think of two categories of pointers in libgpiod:
First, there are the objects we manipulate using the API. These are
normally the first arguments in any given method and they are only
instantiated inside the library and never dereferenced by the user.
They should always be valid, so passing a NULL pointer here should
always lead to a crash. Currently it will take the form of a segfault
at the moment of dereference but with this change, we make the user
program abort() with the stack trace pointing right at the offender.
The second category would be pointers to objects that are logically
parameters of methods i.e. not their first argument. Example is:
gpiod_chip_request_lines(chip, req_cfg, line_cfg) (whose logical OOP
version would be: chip->request_lines(req_cfg, line_cfg)). Here we
accept a NULL req_cfg but we'll segfault on a NULL line_cfg. For
consistency: don't crash here but instead return -1 and set errno
to EINVAL. Same everywhere else.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Mon, 2 Jan 2023 14:31:58 +0000 (15:31 +0100)]
gpiosim: fix error reporting in gpiosim_bank_hog_line()
We don't return errno numbers from public functions - we set errno and
indicate an error by returning -1 or NULL depending on the function
signature. Make gpiosim_bank_hog_line() consistent with that behavior.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Fri, 16 Dec 2022 14:06:54 +0000 (15:06 +0100)]
core: don't check if the pointer about to be freed is NULL
Unless we dereference it before passing it to free(), we don't need to
care whether the pointer is NULL - free() can handle it.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Fri, 16 Dec 2022 09:02:09 +0000 (10:02 +0100)]
core: chip: drop the unneeded prefix from a static function
Rename the static function that uses the word 'chip' twice in its name.
Just remove the prefix as we don't export this symbol.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Fri, 16 Dec 2022 13:44:43 +0000 (14:44 +0100)]
configure: replace deprecated macro
AC_HEADER_STDC is deprecated. Replace it with AC_CHECK_INCLUDES_DEFAULT.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Fri, 16 Dec 2022 11:16:46 +0000 (12:16 +0100)]
tools: tests: check for egrep presence in the system
egrep is not a standard shell tool so don't expect it to be present by
default on every system. Check its presence before proceeding.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Fri, 16 Dec 2022 08:32:24 +0000 (09:32 +0100)]
tests: improve coding style for macros
Using parentheses around macro arguments makes sense if lack thereof can
affect operator precedence. Remove them wherever that cannot happen.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Thu, 15 Dec 2022 18:50:12 +0000 (19:50 +0100)]
tests: consistently use GLib types in tests
We use GLib in tests so instead of int use gint everywhere.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Tue, 13 Dec 2022 10:55:33 +0000 (11:55 +0100)]
tests: don't link against pthread explicitly
We use GLib threads now, so there's no need to link againt pthread.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Tue, 13 Dec 2022 09:57:26 +0000 (10:57 +0100)]
tests: drop unneeded typedef
G_DECLARE_FINAL_TYPE() already takes care of correctly declaring the type
so we don't need the explicit typedef.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Mon, 12 Dec 2022 20:16:36 +0000 (21:16 +0100)]
configure: restore AS_IF() when using PKG_CHECK_MODULES()
pkg-config fails if we only try to build the tests without building the
tools. I'm not sure why that happens and can't find any other fix than
restore the AS_IF() for the 'with_tools' block.
Surprisingly: PKG_CHECK_MODULES() works fine elsewhere. Add a FIXME in
the configure.ac and investigate later.
Fixes: 68dd8c6e5edb ("configure: drop AS_IF() macros")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Mon, 12 Dec 2022 18:22:19 +0000 (19:22 +0100)]
tests: add the missing newline to tests' Makefile.am
Git complains about the missing newline in tests/Makefile.am so make
it happy and add one.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Mon, 12 Dec 2022 09:35:10 +0000 (10:35 +0100)]
tools: tests: remove leftover echo
This looks like some unneeded leftover from the development that was
missed because bats intercepts all echo output.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Kent Gibson <warthog618@gmail.com>
Bartosz Golaszewski [Sun, 11 Dec 2022 22:25:05 +0000 (23:25 +0100)]
core: rename gpiod_version_string() to gpiod_api_version()
Instead of telling the user what type this function returns (they can
check it by looking at the prototype), tell them what the return value
actually represents.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Fri, 9 Dec 2022 09:40:32 +0000 (10:40 +0100)]
configure: improve the header and library function checks
The project is often cross-compiled for embedded systems with all kinds
of wonky toolchains so update configure.ac with checks for less standard
functions and headers. While at it: rearrange the existing checks a bit
so that we only check for headers and symbols when we need them for
current build configuration.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Fri, 9 Dec 2022 10:46:37 +0000 (11:46 +0100)]
configure: use C++17 as the only standard
The entire C++ code base has switched to using the gnu++17 standard so
update the check in configure.ac.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Fri, 9 Dec 2022 10:19:52 +0000 (11:19 +0100)]
build: use LIBEDIT_CFLAGS when building gpioset with interactive mode
The Makefile doesn't include the libedit CLFLAGS when building gpioset
with interactive mode enabled. This can lead to a build failure if the
header is not in the standard location (/usr/include/editline/readline.h).
Add LIBEDIT_CFLAGS to AM_CFLAGS.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Fri, 9 Dec 2022 09:53:18 +0000 (10:53 +0100)]
configure: drop AS_IF() macros
AS_IF() is much less readable than a regular if/else and it's only called
for by docs if the code inside the expansion uses AC_REQUIRE(). Convert
AS_IF() occurrences to standard if/else syntax.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Fri, 9 Dec 2022 10:07:03 +0000 (11:07 +0100)]
gpiosim: add missing fcntl.h include
The fcntl.h header is needed for openat() and mkdirat() that the gpiosim
code uses. It seems to be pulled in indirectly on most toolchains but for
the sake of correctness, include it explicitly.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Fri, 9 Dec 2022 09:26:08 +0000 (10:26 +0100)]
gpioset: put local variables of the same type on a single line
Unless it hurts readability, try to keep the variables of the same type
on the same line.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Wed, 7 Dec 2022 09:35:53 +0000 (10:35 +0100)]
treewide: add missing commas to enums and struct definitions
The code is not consistent with regard to following the last element in
enums and struct definitions with a comma. Unless the last element is
guaranteed not to change (e.g. '{ }', or NULL), follow it with a comma
treewide to avoid churn in git when adding new values.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Tue, 6 Dec 2022 09:56:21 +0000 (10:56 +0100)]
bindings: python: tests: set the process name
When we run the test suite by calling the __main__ function of the module,
the name of the process as visible in the system becomes "python". Let's
set it to "python-gpiod" before running the tests. This way gpiosim will
name its configfs attributes appropriately.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Tue, 6 Dec 2022 13:23:54 +0000 (14:23 +0100)]
gpiosim: get the process name using prctl()
program_invocation_short_name is set once at the program's start. If we
change the process name using prctl(), we need to retrieve it using the
same system call as program_invocation_short_name will not be updated.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Esben Haabendal [Tue, 6 Dec 2022 08:46:37 +0000 (09:46 +0100)]
gpioset: fix memory leak in interactive mode
Even when readline() returns an empty buffer, we still need to free() it to
avoid leaking memory.
Signed-off-by: Esben Haabendal <esben@geanix.com>
[Kent: suggested a shorter version]
Co-developed-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Wed, 7 Dec 2022 09:24:29 +0000 (10:24 +0100)]
bindings: python: add version.py to EXTRA_DIST
The version file is missing from the distro tarball, so add it.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Mon, 5 Dec 2022 13:08:04 +0000 (14:08 +0100)]
gpiosim: fix a resource leak
If we set the number of lines to x, set line names or hogs for lines
from 0 through x, then set the number of lines to (x - y), we will not
unlink all the line directories as we only iterate up to num_lines in
bank_release().
Allocate a small structure for every line we create a lineX directory
for and iterate over it in bank_release() to know exactly which ones
need freeing.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Mon, 5 Dec 2022 10:12:13 +0000 (11:12 +0100)]
gpiosim: use wrappers around container_of()
Simplify the code a bit by providing helpers that extract the underlying
structure from struct refcount using container_of().
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Wed, 30 Nov 2022 12:42:31 +0000 (13:42 +0100)]
bindings: python: extend setup.py
Add additional information to setup.py. This will be visible in the EGG
file.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Wed, 30 Nov 2022 12:42:30 +0000 (13:42 +0100)]
bindings: python: fix the GPIOD_WITH_TESTS build flag
Currently in order to disable test the variable needs to be explicitly
set to GPIOD_WITH_TESTS= in the environment or setup.py will crash.
Assume tests should not be built if the variable is not set at all.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Wed, 30 Nov 2022 12:42:29 +0000 (13:42 +0100)]
bindings: python: decouple the version of the bindings from libgpiod API version
Python bindings now have their own setup.py script and can be built
separately from the rest of the code-base. Let's decouple the python
package version from libgpiod API (but let's keep a module attribute
containing the API version) by introducing a version.py submodule that
can be executed by the setup.py script. This way we have a single
canonical place defining the version number.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Wed, 30 Nov 2022 12:42:28 +0000 (13:42 +0100)]
bindings: rust: include rust sources in the release tarballs
Rust sources and Cargo files are not added to EXTRA_DIST. Add them so that
they end up in the release tarballs generated by autotools.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Bartosz Golaszewski [Wed, 30 Nov 2022 12:42:27 +0000 (13:42 +0100)]
bindings: rust: make reuse happy
Add missing license text files and use the CC0-1.0 license for the
rust-specific .gitignore file.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Bartosz Golaszewski [Wed, 30 Nov 2022 12:42:26 +0000 (13:42 +0100)]
tools: display the correct license with --version
The tools are licensed under GPL-2.0-or-later so fix the output
of --version.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Wed, 7 Dec 2022 08:53:28 +0000 (09:53 +0100)]
gpiosim: rename HOG_DIR to DIRECTION
The enum itself should just define direction settings, it's the functions
that use it that should refer to hogging.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Bartosz Golaszewski [Wed, 30 Nov 2022 12:42:24 +0000 (13:42 +0100)]
treewide: rename EVENT_CLOCK to CLOCK
While we use it for edge event timestamps exclusively at the moment,
the actual enum names shouldn't limit its application and simply just
refer to existing clock types known by the GPIO uAPI. The relevant
functions are still called set/get_event_clock() as it's in line with
their functionality.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Bartosz Golaszewski [Wed, 30 Nov 2022 12:42:23 +0000 (13:42 +0100)]
treewide: use plural 'events' in read_edge_event() functions
The read_edge_event() family of functions should actually be called
read_edge_events() as they universally allow to read more than one
event. We're converting wait_edge_event() too for consistency.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Bartosz Golaszewski [Wed, 7 Dec 2022 08:45:06 +0000 (09:45 +0100)]
treewide: apply formatting changes with clang-format
Use linux kernel's .clang-format file to automatically improve the coding
style of libgpiod's C code base. We don't import the file into the
repository as it's not perfect and certain converted fragments were
rolled back because they looked better before the conversion.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Wed, 30 Nov 2022 12:42:21 +0000 (13:42 +0100)]
treewide: use C enum types explicitly
Use enum types explicitly across the entire C API. Modern compilers can
catch some bugs with enums and it also helps IDEs and general readability.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
[Viresh: make rust bindings work with negative enum values]
Co-authored-by: Viresh Kumar <viresh.kumar@linaro.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Bartosz Golaszewski [Tue, 6 Dec 2022 09:23:44 +0000 (10:23 +0100)]
bindings: python: tests: use the version parser from setuptools
We currently require the third-party packaging module to be installed in
order to run tests. Let's instead use the version parser that's already
available in setuptools.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Mon, 5 Dec 2022 13:56:45 +0000 (14:56 +0100)]
tests: join the thread at the end of the seqno test case
The call to g_thread_join() is missing at the end of the test case for
event sequence numbers so add it and fix a resource leak.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Bartosz Golaszewski [Mon, 5 Dec 2022 13:22:38 +0000 (14:22 +0100)]
tests: unref GVariant objects
We need to drop the reference count of the GVariants we create when
packing hogs and line names. This fixes all memory leaks in tests that
are caused by this bug.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Kent Gibson [Mon, 21 Nov 2022 10:22:53 +0000 (18:22 +0800)]
README: update Tools section for v2 tools
Update the Tools section to reflect the changes to the tools for v2.
Signed-off-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>