Kent Gibson [Mon, 12 Jun 2023 02:56:42 +0000 (10:56 +0800)]
tools: tests: remove implicit run-time dependency on ncurses
bats has an implicit depencency on ncurses, as I found when trying to
run the tests on a minimal install that lacked ncurses. Rather than make
the dependency explicit, force the output formatting to use the TAP
format which does not require ncurses.
Signed-off-by: Kent Gibson <warthog618@gmail.com> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Kent Gibson [Mon, 12 Jun 2023 02:56:41 +0000 (10:56 +0800)]
tools: tests: speed up continuous toggle test
The continuous toggle test was recently changed to poll the line to
check for toggles, and so increase test reliability. Tighten up the
test timings so the test can now also run in a significantly shorter
time.
And, as it is now faster, add an extra edge just to be sure.
Note that the test does not need to catch every edge, it only has to
check that the line is in fact toggling.
Signed-off-by: Kent Gibson <warthog618@gmail.com> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Kent Gibson [Mon, 12 Jun 2023 02:56:40 +0000 (10:56 +0800)]
tools: tests: add tests for idle-timeout and debounce period.
There are no tests for the --debounce-period for gpiomon, or the new
idle-timeout option for gpiomon and gpionotify, so add some.
In both cases the focus of the test is not the period itself, which is
problematic to test reliably, but that the options are supported and
have the otherwise anticipated effects.
Signed-off-by: Kent Gibson <warthog618@gmail.com> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Add an idle timeout option to gpiomon and gpionotify to exit gracefully
when no event has been detected for a given period.
Signed-off-by: Gabriel Matni <gabriel.matni@exfo.com> Reviewed-by: Kent Gibson <warthog618@gmail.com> Tested-by: Kent Gibson <warthog618@gmail.com> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Kent Gibson [Fri, 9 Jun 2023 15:36:06 +0000 (23:36 +0800)]
bindings: python: examples: fix potential glitch in gpioset.py
gpioset.py requests lines without setting their output value, and so
sets them all inactive, and subsequently sets them to their requested
value. This can result in glitches on lines which were active and
are set active.
As this is example code, it is also important to demonstrate that the
output value can be set by the request itself.
Request the lines with the correct output values set in the request
itself.
Signed-off-by: Kent Gibson <warthog618@gmail.com> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Joe Slater [Tue, 6 Jun 2023 15:04:27 +0000 (08:04 -0700)]
tools: tests: modify delays in toggle test
The test "gpioset: toggle (continuous)" uses fixed delays to test
toggling values. This is not reliable, so we switch to looking
for transitions from one value to another.
We wait for a transition up to 1.5 seconds.
Signed-off-by: Joe Slater <joe.slater@windriver.com> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Erik Schilling [Fri, 26 May 2023 15:27:33 +0000 (17:27 +0200)]
bindings: rust: build against pkg-config info
This change replaces building against "bundled" headers by always
building agains system headers (while following standard conventions to
allow users to specify the version to build against).
Reasoning:
Previously, the code generated the bindings based on the headers, but
then links against `-lgpiod` without further specifying where that is
coming from.
This results in some challenges and problems:
1. Packaging a Rust crate with `cargo package` requires the folder
containing the Cargo.toml to be self-contained. Essentially, a tar
ball with all the sources of that folder is created. Building against
that tar ball fails, since the headers files passed to bindgen are
a relative path pointing outside of that folder.
2. While, for example, the cxx bindings are built AND linked against
the build results, the packaging situation for C++ libraries is a
bit different compared to Rust libs. The C++ libs will likely get
built as part of the larger libgpiod build and published together
with the C variant.
In Rust, the vast majority of people will want to build the glue-code
during the compilation of the applications that consume this lib.
This may lead to inconsistencies between the bundled headers and the
libraries shipped by the user's distro. While ABI should hopefully
be forward-compatible within the same MAJOR number of the .so,
using too new headers will likely quickly lead to mismatches with
symbols defined in the lib.
3. Trying to build the core lib as part of the Rust build quickly runs
into similar packaging issues as the existing solution. The source
code of the C lib would need to become part of some package
(often people opt to pull it in as a submodule under their -sys crate
or even create a separate -src package [1]). This clearly does not
work well with the current setup...
Since building against system libs is probably? what 90%+ of the people
want, this change hopefully addresses the problems above. The
system-deps dependency honors pkg-config conventions, but also allows
users flexible ways to override the defaults [2]. Overall, this keeps
things simple while still allowing maximum flexibility.
Since the pkg-config interface is just telling us which include paths to
use, we switch back to a wrapper.h file that includes the real gpiod.h.
Once Rust bindings require a lower version floor, the version metadata
can also be updated to help telling users that their system library is
too old.
In order to support people hacking on the Rust bindings, building with
make will automatically set the right set of environment variables.
In case people want to customize it when building without `make`, a
reference to the system_deps documentation is given in the README.md.
bindings: python: specify the symbols to export explicitly
We're currently unintentionally exporting a bunch of symbols that should
remain local to sub-modules. Use __all__ where appropriate so that we
don't re-export standard library functions such as select() etc. in the
gpiod module.
bindings: python: change the interpretation of None in event wait
The docs don't mention it but currently passing None as the timeout to
one of the event wait methods works like passing 0 to select() - the wait
method returns immediately. Change it to a more standard behavior - None
makes the method block indefinitely until an event becomes available for
reading.
This is a slight change in the behavior but let's hope nobody complains
as libgpiod v2 is still pretty recent and its adoption is (hopegully)
not wide-spread yet.
Reported-by: Nicolas Frattaroli <frattaroli.nicolas@gmail.com> Suggested-by: Kent Gibson <warthog618@gmail.com> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> Reviewed-by: Kent Gibson <warthog618@gmail.com>
bindings: cxx: clarify the meaning of negative timeouts in event wait
chip::wait_info_event() and line_request::wait_edge_events() behave the
same as their C counterparts in that they block indefinitely when passed
a negative timeout value. State it explicitly in the docs.
tests: move the test case for duplicate configured offsets
This test case lives in tests-line-request.c but it doesn't really test
request functionality but rather only the behavior of line-config. Limit
it to only testing struct gpiod_line_config and move it to
tests-line-config.c.
The GLib wrapper for libgpiosim tries to create the gpiosim context and
bank objects in the class's init() function but the constructed()
callback doesn't check if that operation succeeded, leading to a crash
when it dereferences the bank pointer.
As init() should only perform operations that cannot fail, let's move all
the gpiosim initialization code to constructed() and bail-out of it if
any of the steps fails.
bindings: python: don't install test-specific C extension binaries
We want to ship the source code for C extensions used by the test suite
but not install the built shared objects or put them into the bdist.
Extend the build_ext command to delete the tests from the build directory
right after the extensions have been built and - possibly - installed
into the source tree (if --inplace is set).
setup() arguments must *always* be /-separated paths relative to the
setup.py directory, *never* absolute paths.
As the Makefile build should only be used for development purposes, I
think we can safely drop support for out-of-tree build. Python bindings
have now been spun out into their own tarball and are available to
install from pip.
I'm not sure what historical reasons there were to install test programs
if they are built but now I can't see any anymore. Tests can be run from
the build directory and users such as meta-openembedded can install them
and the relevant libraries (libgpiosim) manually into the filesystem as
they don't usually live in ${bindir} anyway. Installing test binaries just
pollutes the filesystem now so stop doing it.
tests: check the return value of gpiod_line_config_add_line_settings()
The call to gpiod_line_config_add_line_settings() can fail in the thread
function used by info-event test cases so check its return value and act
accordingly.
Update the version of python bindings to v2.0.1. I treat it as a bug-fix
release as the changes only apply to packaging and building (in
preparation for making the package available on pypi) and there are no
functional changes in the bindings.
We currently "include" the gpiod package in find_packages() which does
nothing as it would be discovered anyway. We want to package the test
sources but exclude it from the binary wheel so use the "exclude"
argument.
bindings: python: change the project name to libgpiod
The name 'gpiod' is already taken on pypi. Switch to using 'libgpiod'
as the name of the project. Keep 'gpiod' as the package name which
maintains code compatibility.
tests: simplify and reduce the strictness of version string regex patterns
It seems like every release there's some new problem with parsing the
version strings in tests. Let's reduce the strictness of the patterns
to avoid future test failures and accept the following version schemes:
The square bracket is in the wrong place which makes the regex not match
version strings of the form: x.y.z. Fix the pattern in core and bindings
tests.
tests: provide and use gpiod_test_chip_watch_line_info_or_fail()
We can shrink the code a bit by wrapping the call to
gpiod_chip_watch_line_info() and the subsequent checks in a helper macro.
This also fixes a potential null-pointer dereference in one of the info
event test cases.
Some of the helpers' names don't refer to the objects they're acting
upon. Make the naming consistent. While at it: fix line breaking in the
helpers header.
Sorting chip names with alphasort() results in gpiochip2 coming after
gpiochip19 as it only find the lexicographic order of strings. Switching
to using versionsort() makes it look better and the order is more logical
with the numbering being taken into account.
Reviewed-by: Kent Gibson <warthog618@gmail.com> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
tools: tests: update the kernel version required to run tests
The v5.16 kernel requirement is a leftover from when the tests were
developed to work with gpio-sim before the module was actually released
in v5.17. Update the kernel requirement to v5.17.4 which includes fixes
to set/get_multiple() callbacks in gpio-sim.
build: use AM_V_GEN when calling external programs
In order to output a status line in silent mode and the whole command in
default mode, use the AM_V_GEN predefined automake variable when executing
external programs like doxygen and help2man.
bindings: cxx: tests: fix the test case for chip::unwatch_line_info()
We need to actually trigger a line-info event before making sure the watch
has been disabled.
Fixes: f2245fa32c1b ("bindings: cxx: tests: add a test case for chip::unwatch_line_info()") Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
tests: fix the test case for gpiod_line_request_reconfigure_lines()
We need to actually pass the line config with different offsets to
gpiod_line_request_reconfigure_lines() for the test to make sense.
Fixes: 8ef0ca0fae8f ("tests: add more test cases for gpiod_line_request_reconfigure_lines()") Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
tests: add more test cases for gpiod_line_request_reconfigure_lines()
Add two new test cases for gpiod_line_request_reconfigure_lines(). One
verifies that NULL line config is handled correctly, the other checks
that reconfigured offsets must be the same as the ones requested.
After discussing this a while back we removed the call to fcntl() that
would make the request file descriptor non-blocking so that a call to
gpiod_line_request_read_edge_events() would block if no events are
pending. We agreed that the same behavior should apply to info events and
made the docs state that. Unfortunately we still pass the O_NONBLOCK flag
to open() making read() called on the chip file descriptor return
immediately if no info events are pending. Fix it by removing this flag.
Benjamin Li [Mon, 6 Mar 2023 18:45:45 +0000 (10:45 -0800)]
contrib: add sample Android.bp to build within an Android tree
Add an Android.bp file for Soong, the Android build system, to build
the library including C++ bindings along with all the CLI tools.
This reference Android build file will live in a contrib/ folder to
indiciate it is a less-maintained part of libgpiod. It will need to
be moved to the root directory in order to use it, though, as Soong
doesn't let Blueprint files reference sources in a parent directory.
Signed-off-by: Benjamin Li <benl@squareup.com>
[Bartosz: add the build file to the release tarball generated by 'make dist'] Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Benjamin Li [Mon, 6 Mar 2023 18:45:44 +0000 (10:45 -0800)]
tools: remove dependency on glibc program_invocation_[short_]name
Platforms like Bionic libc don't have program_invocation_[short_]name,
which is a GNU extension. It does have getprogname(), a BSD extension,
but rather than supporting multiple extensions let's just introduce
our own local helpers.
We derive the short name ourselves rather than calling basename(),
as the POSIX version takes char *, not const char *, and is thus
not guaranteed to avoid modifying its input. (The GNU version does
take const char * but we are avoiding extensions here.)
Signed-off-by: Benjamin Li <benl@squareup.com> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
core: sanitize the output values in gpiod_line_config_set_output_values()
We check the output values for invalid ones in
gpiod_line_settings_set_output_value() but in
gpiod_line_config_set_output_values() we just accept all indiscriminately.
Factor out the common checking code into a helper function, use it in both
functions and add a relevant test case.
bindings: cxx: make edge_event's impl struct implementations final
The implementations of the abstract edge_event's base impl private struct
can be made final and their destructors non-virtual. As these types are
entirely private, it does not affect the ABI.
tests: add a test-case for looking up non-standard GPIO line names
Make sure line names with whitespaces or some less common characters (that
can be found in real-life names in mainline .dts files) can be correctly
mapped to offsets.
GPIOD_VERSION_STRING environment variable is no longer used by setup.py.
It's been replaced by reading the version from the variable defined in
version.py.
libgpiod C++ types are not meant to be inherited from. They already don't
even provide virtual destructors so mark them explicitly as final. With
that the destructors of throwable types can also be made non-virtual.
If info is NULL in one of the line-info test cases, we'll still try to
read its property leading to an abort() triggered from assert(info). Just
bail out of the test function if gpiod_chip_get_line_info() fails.
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.
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.
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.
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.