qemu-gpiodev/libgpiod.git
5 years agotests: mockup: validate the chip index where applicable
Bartosz Golaszewski [Sat, 3 Aug 2019 16:14:32 +0000 (18:14 +0200)]
tests: mockup: validate the chip index where applicable

In functions that take the chip index as argument: let's verify that
its value is valid i.e. it refers to an existing chip to avoid potential
segfaults.

While we're at it: delegate the validation of arguments in mockup getter
helpers to a separate routine.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
5 years agotests: drop manual test case links and use GList
Bartosz Golaszewski [Fri, 2 Aug 2019 18:40:12 +0000 (20:40 +0200)]
tests: drop manual test case links and use GList

Let's not handcode a linked list if GLib already provides us with
a robust implementation. Use GList to link the tests at registration.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
5 years agotests: mockup: add extern "C" to the header
Bartosz Golaszewski [Fri, 2 Aug 2019 12:22:29 +0000 (14:22 +0200)]
tests: mockup: add extern "C" to the header

The gpio-mockup support library should be usable from C++ code too.
Add extern "C" to the header.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
5 years agotests: use GLib for library test cases and bats for gpio-tools
Bartosz Golaszewski [Fri, 7 Jun 2019 12:30:57 +0000 (14:30 +0200)]
tests: use GLib for library test cases and bats for gpio-tools

This replaces the custom hand-crafted testing suite with well-known
open-source tools while keeping the same coverage. The core library
is now tested using the GLib unit testing framework. The gpio-tools
are now tested in bash using the bats testing system instead of being
invoked from a C program.

This simplifies and shrinks the testing code and makes it less prone
to bugs.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
5 years agogpioinfo: mark kernel claimed lines as used
Ramon Fried [Wed, 31 Jul 2019 17:38:14 +0000 (20:38 +0300)]
gpioinfo: mark kernel claimed lines as used

In case where the GPIOLINE_FLAG_KERNEL flag was set and no consumer
string is provided by the kernel, the used column was still showing
the pin as "unused" Fix that by writing "kernel".

Signed-off-by: Ramon Fried <rfried.dev@gmail.com>
[Bartosz:
  - fixed indentation and alignment
  - tweaked the commit message formatting]
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
5 years agotests: setup libgpiomockup before checking the kernel version
Bartosz Golaszewski [Tue, 30 Jul 2019 11:53:13 +0000 (13:53 +0200)]
tests: setup libgpiomockup before checking the kernel version

The gpio-mockup helper library checks the kernel version itself when
creating the context object. We then check the version again (as the
minimum versions for libgpiomockup and the test-suite may differ) in
the test-suite's main function. Make sure the library runs the check
first as we don't want to tell the user the version is OK and then
fail because it isn't...

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
5 years agotests: fix a segfault in error path
Bartosz Golaszewski [Tue, 30 Jul 2019 11:49:49 +0000 (13:49 +0200)]
tests: fix a segfault in error path

We may all the atexit() cleanup func before the gpio_mockup context
is setup. This will result in a segfault so add an appropriate check.

Fixes: b8659e044d50 ("tests: use libgpiomockup")
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
5 years agoTODO: new task for gpiomon
Bartosz Golaszewski [Sat, 27 Jul 2019 19:50:29 +0000 (21:50 +0200)]
TODO: new task for gpiomon

Making gpiomon be able to run external processes is a common request
from users. Add it to the TODO list.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
5 years agotests: mockup: use KERNEL_VERSION()
Bartosz Golaszewski [Mon, 22 Jul 2019 09:46:59 +0000 (11:46 +0200)]
tests: mockup: use KERNEL_VERSION()

There's no need to reimplement checking the kernel version. An
appropriate macro - KERNEL_VERSION() - is already provided in
linux/version.h. Use it in libgpiomockup.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
5 years agotests: iter: free non-mockup GPIO chips
Bartosz Golaszewski [Thu, 11 Jul 2019 15:24:28 +0000 (17:24 +0200)]
tests: iter: free non-mockup GPIO chips

When using gpiod_foreach_chip_noclose() we need to close any non-mockup
GPIO chip that may be present in the system. Otherwise we'll be leaking
memory.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
5 years agobindings: python: fix GCC8 warnings due to function pointer casting
Bartosz Golaszewski [Thu, 11 Jul 2019 09:41:21 +0000 (11:41 +0200)]
bindings: python: fix GCC8 warnings due to function pointer casting

GCC8 has added a new warning heuristic to detect invalid function
casts. This causes a lot of warnings when building libgpiod python
bindings.

Let's use Py_UNUSED where applicable to make function prototypes match
that of PyCFunction. For keyword functions, let's cast them to a
function pointer taking no arguments before casting them again to
PyCFunction. This may not be the best solution but it has to do for
the moment.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
5 years agotests: build: fix the name of the test executable displayed by Makefile
Bartosz Golaszewski [Thu, 11 Jul 2019 08:39:03 +0000 (10:39 +0200)]
tests: build: fix the name of the test executable displayed by Makefile

The test suite Makefile prints a help message after building the test
executable but the name of the program is wrong. Fix it.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
5 years agotests: gpio-mockup: constify num_lines
Bartosz Golaszewski [Tue, 9 Jul 2019 11:02:24 +0000 (13:02 +0200)]
tests: gpio-mockup: constify num_lines

The array pointed to by num_lines is never modified so make it really
constant.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
5 years agotests: fix a memory leak in exit path
Bartosz Golaszewski [Sat, 6 Jul 2019 17:31:36 +0000 (19:31 +0200)]
tests: fix a memory leak in exit path

When exiting normally we free all allocated resources (mostly to keep
valgrind quiet). The toolpath string is not being freed and pops up in
valgrind's "still reachable" category of leaks. Free this memory too
in the atexit() cleanup callback.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
5 years agotests: gpio-mockup: store the number of chips in gpio_mockup_probe()
Bartosz Golaszewski [Fri, 5 Jul 2019 14:57:40 +0000 (16:57 +0200)]
tests: gpio-mockup: store the number of chips in gpio_mockup_probe()

We're currently not storing the number of chips in the gpio-mockup
context structure after probing the module. The value is left
initialized to 0. This leads to both a memory leak and to chip ordering
errors when running the tests at high CPU loads. This patch fixes both
issues.

Fixes: e43e46d4f79c ("tests: mockup: add a library for controlling the gpio-mockup module")
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
5 years agotests: gpio-mockup: don't allocate the chip structure twice
Bartosz Golaszewski [Fri, 5 Jul 2019 14:47:39 +0000 (16:47 +0200)]
tests: gpio-mockup: don't allocate the chip structure twice

We incorrectly allocate the chip structure twice: once in
gpio_mockup_probe() and then again in make_chip() which leads to a
memory leak. Remove the first instance as it's the one that's
unnecessary.

Fixes: e43e46d4f79c ("tests: mockup: add a library for controlling the gpio-mockup module")
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
5 years agoTODO: remove the task for factoring out of common testing code
Bartosz Golaszewski [Sun, 9 Jun 2019 09:21:57 +0000 (11:21 +0200)]
TODO: remove the task for factoring out of common testing code

We now have libgpiomockup and it's used by the core library testing
executable. Remove the task from TODO.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
5 years agolibgpiod: start v1.5 development cycle
Bartosz Golaszewski [Fri, 7 Jun 2019 09:13:17 +0000 (11:13 +0200)]
libgpiod: start v1.5 development cycle

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
5 years agolibgpiod v1.4
Bartosz Golaszewski [Thu, 6 Jun 2019 13:18:00 +0000 (15:18 +0200)]
libgpiod v1.4

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
5 years agoNEWS: updates for v1.4
Bartosz Golaszewski [Thu, 6 Jun 2019 13:14:22 +0000 (15:14 +0200)]
NEWS: updates for v1.4

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
5 years agotests: gpiomon: use test_trigger_event() to fix timing errors
Bartosz Golaszewski [Mon, 3 Jun 2019 16:18:53 +0000 (18:18 +0200)]
tests: gpiomon: use test_trigger_event() to fix timing errors

Since we don't need to trigger events from a separate thread when
testing tools and we've experienced timing issues with these two
test cases, let's use the new helper for triggering of single events.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
5 years agotests: provide test_trigger_event()
Bartosz Golaszewski [Mon, 3 Jun 2019 16:18:38 +0000 (18:18 +0200)]
tests: provide test_trigger_event()

We use a separate thread to trigger line events for library test cases
but if we're testing tools which are separate processes, we can generate
the events from the main thread. Add a simple helper for that.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
5 years agotests: gpiomon: tweak the timing for single event type tests
Bartosz Golaszewski [Mon, 3 Jun 2019 16:17:57 +0000 (18:17 +0200)]
tests: gpiomon: tweak the timing for single event type tests

Since switching to using libgpiomockup there are some timing problems
with two gpiomon test cases. I'm not sure what the reason is and we'll
be switching to glib unit tests soon, so let's not waste time on that
and just increase the sleep time.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
5 years agotests: use libgpiomockup
Bartosz Golaszewski [Mon, 13 May 2019 15:24:37 +0000 (17:24 +0200)]
tests: use libgpiomockup

Now that all the gpio-mockup support lives in a separate library we
can drop a lot of code from the testing framework.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
5 years agotests: mockup: add a library for controlling the gpio-mockup module
Bartosz Golaszewski [Fri, 10 May 2019 09:43:22 +0000 (11:43 +0200)]
tests: mockup: add a library for controlling the gpio-mockup module

In order to both switch to glib unit testing framework for core
libgpiod tests as well as to cover the bindings in other languages
with proper testing while avoiding unnecessary code duplication, let's
factor out the code responsible for interaction with the gpio-mockup
module into a separate shared library.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
5 years agotests: remove make check target
Bartosz Golaszewski [Thu, 23 May 2019 16:25:35 +0000 (18:25 +0200)]
tests: remove make check target

Having both --enable-tests configure option and the check make target
seems redundant and confusing. Especially since the tests won't even
run without appropriate permissions for /dev/gpiochipX anyway.

Remove the check target and the --enable-install-tests option. From now
on the tests - if enabled - are built as a regular program installed to
${prefix}/bin.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
5 years agotests: fix mapping of chip numbers
Bartosz Golaszewski [Wed, 29 May 2019 15:30:53 +0000 (17:30 +0200)]
tests: fix mapping of chip numbers

After recent changes the tests stopped working when other (non mockup)
GPIO chips are present in the system. The reason for that is broken
mapping of chip numbers to chip indexes. This patch fixes it.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
5 years agoTODO: remove the task for converting the tests for linux v5.1
Bartosz Golaszewski [Wed, 17 Apr 2019 07:15:29 +0000 (09:15 +0200)]
TODO: remove the task for converting the tests for linux v5.1

The conversion of the testing framework for linux v5.1 is now done.
Remove the task from the list.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
5 years agotests: make linux v5.1 the minimum version to run tests
Bartosz Golaszewski [Tue, 16 Apr 2019 07:37:37 +0000 (09:37 +0200)]
tests: make linux v5.1 the minimum version to run tests

The testing framework has been adjusted for linux v5.1. It will no
longer work with older versions.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
5 years agotests: line: use debugfs to verify set values
Bartosz Golaszewski [Mon, 15 Apr 2019 08:58:41 +0000 (10:58 +0200)]
tests: line: use debugfs to verify set values

Use new debugfs helpers when verifying if line values were correctly
set.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
5 years agotests: gpioset: make test cases work with linux v5.1
Bartosz Golaszewski [Fri, 12 Apr 2019 15:16:47 +0000 (17:16 +0200)]
tests: gpioset: make test cases work with linux v5.1

Make all gpioset test cases work with the recent changes to gpio-mockup
introduced in linux v5.1.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
5 years agotests: gpiomon: increase the time waiting for events
Bartosz Golaszewski [Fri, 12 Apr 2019 14:45:53 +0000 (16:45 +0200)]
tests: gpiomon: increase the time waiting for events

We no longer have influence over the type of generated events. We
always start with a rising edge-event and then get alternating edges.
We need to wait slightly longer to collect the events we're expecting
in one of the test cases.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
5 years agotests: gpioget: make test cases work with linux v5.1
Bartosz Golaszewski [Fri, 12 Apr 2019 14:37:52 +0000 (16:37 +0200)]
tests: gpioget: make test cases work with linux v5.1

Make all gpioget test cases work with the recent changes to gpio-mockup
introduced in linux v5.1.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
5 years agotests: event: make test cases work with linux v5.1
Bartosz Golaszewski [Fri, 12 Apr 2019 08:05:30 +0000 (10:05 +0200)]
tests: event: make test cases work with linux v5.1

Make all event test cases work with the recent changes to gpio-mockup
introduced in linux v5.1.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
5 years agotests: ctxless: make test cases work with linux v5.1
Bartosz Golaszewski [Thu, 28 Mar 2019 13:21:45 +0000 (14:21 +0100)]
tests: ctxless: make test cases work with linux v5.1

Make all ctxless test cases work with the recent changes to gpio-mockup
introduced in linux v5.1.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
5 years agotests: provide test_debugfs_get/set_value() helpers
Bartosz Golaszewski [Thu, 28 Mar 2019 13:14:51 +0000 (14:14 +0100)]
tests: provide test_debugfs_get/set_value() helpers

Since linux v5.1 gpio-mockup simulates pull-up/down resistors for dummy
lines. The current pull can be set using debugfs. Since we can no longer
verify if the character device interface properly sets line values, the
debugfs interface now also allows to read line values. This way we can
verify if the ABI works correctly using different code paths.

Provide functions for reading and setting values of mockup GPIO lines.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
5 years agotests: document the freq argument in test_set_event()
Bartosz Golaszewski [Wed, 27 Mar 2019 13:47:21 +0000 (14:47 +0100)]
tests: document the freq argument in test_set_event()

The freq argument is not documented and it's not clear what it means.
Add a brief comment.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
5 years agotests: fix debugfs path
Bartosz Golaszewski [Wed, 10 Apr 2019 14:47:19 +0000 (16:47 +0200)]
tests: fix debugfs path

Since linux v5.1 the debugfs path for gpio-mockup changed. Use the new
path both for the main directory as well as for the chip subdirectories
which no longer use the chip's label.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
5 years agotests: don't allow to generate events of the same type subsequently
Bartosz Golaszewski [Wed, 27 Mar 2019 13:44:40 +0000 (14:44 +0100)]
tests: don't allow to generate events of the same type subsequently

Since linux v5.1 the state of simulated lines is tracked by the kernel
and it's no longer possible to generate two subsequent events of the
same type (e.g. two rising edge events one after another). Drop the
event_type parameter from test_set_event() and adjust all users.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
5 years agoman: fix out of source build
Alexander Stein [Fri, 12 Apr 2019 19:18:21 +0000 (21:18 +0200)]
man: fix out of source build

Use build and source directory variables for correct paths. This
distinction is important for out of source builds.

Signed-off-by: Alexander Stein <alexander.stein@mailbox.org>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
6 years agoTODO: add a list of things to implement for feature-complete
Bartosz Golaszewski [Mon, 1 Apr 2019 08:50:47 +0000 (10:50 +0200)]
TODO: add a list of things to implement for feature-complete

Add a document listing major features I'd like to see in libgpiod to
make it more or less complete (not including of course the support for
any potential new features that the kernel may expose in the future).

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
6 years agogitignore: add .swp to the list of ignored extensions
Bartosz Golaszewski [Mon, 1 Apr 2019 13:01:53 +0000 (15:01 +0200)]
gitignore: add .swp to the list of ignored extensions

We want to ignore vim swap files. Add .swp to .gitignore.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
6 years agobindings: cxx: make operator bool() explicit
David Kozub [Thu, 28 Mar 2019 22:49:23 +0000 (23:49 +0100)]
bindings: cxx: make operator bool() explicit

A non-explicit operator bool() is dangerous: It allows unwanted
conversion to integral types:

gpiod::chip c;
int i = c;

This is a trivial example, but more insidious effects are possible,
e.g. with std::set<gpiod::chip>, which would use the operator bool()
to implement element comparison, thus turning such set into a set that
has at most 2 elements: An invalid (false) element and just 1 valid
element:

std::set<gpiod::chip> s;
s.emplace();
s.emplace("/dev/gpiochip0");
s.emplace("/dev/gpiochip1");
// s.size() is still 2 even if both chips were opened!

Making the operator explicit disables this.

See e.g.
https://en.cppreference.com/w/cpp/language/implicit_conversion#The_safe_bool_problem
for more info on this.

Signed-off-by: David Kozub <zub@linux.fjfi.cvut.cz>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
6 years agobindings: cxx: remove superfluous std::move
David Kozub [Thu, 28 Mar 2019 23:27:28 +0000 (00:27 +0100)]
bindings: cxx: remove superfluous std::move

There is no need to use std::move on an r-value (e.g.
std::move(gpiod::chip())). Similarly, there is no need to use std::move
for returning a local variable as in:

T foo()
{
    U local;
    return std::move(local);
}

Not only it doesn't help, it actually inhibits named return value
optimization.

See e.g. https://isocpp.org/blog/2013/02/no-really-moving-a-return-value-is-easy-stackoverflow

Signed-off-by: David Kozub <zub@linux.fjfi.cvut.cz>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
6 years agolibgpiod: start v1.4 development cycle
Bartosz Golaszewski [Mon, 25 Mar 2019 13:06:48 +0000 (14:06 +0100)]
libgpiod: start v1.4 development cycle

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
6 years agolibgpiod v1.3
Bartosz Golaszewski [Mon, 25 Mar 2019 09:30:26 +0000 (10:30 +0100)]
libgpiod v1.3

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
6 years agoNEWS: updates for v1.3
Bartosz Golaszewski [Mon, 25 Mar 2019 09:25:32 +0000 (10:25 +0100)]
NEWS: updates for v1.3

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
6 years agobuild: fix cross-compilation after adding manpages
Bartosz Golaszewski [Mon, 25 Mar 2019 08:57:09 +0000 (09:57 +0100)]
build: fix cross-compilation after adding manpages

Cross-compilation is currently broken because WITH_MANPAGES is defined
conditionally. Move it out of the if/then.

Fixes: 6cbc2e57555a ("doc: add automatically generated man pages for gpio-tools")
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
6 years agotests: look for gpio-tools in more places
Bartosz Golaszewski [Fri, 15 Mar 2019 14:16:53 +0000 (15:16 +0100)]
tests: look for gpio-tools in more places

Currently we only support running the test cases for gpio-tools from
the top-level source directory. Some users want to install the test
executable and run the tests from other locations (/bin, /usr/bin or
custom path).

This patch makes the test suite look in the source tree path first,
then check the directory in which the program resides and last iterate
over all directories in $PATH.

We only do that once at the beginning and then reuse the path later.

Cc: Anders Roxell <anders.roxell@linaro.org>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Reviewed-by: Anders Roxell <anders.roxell@linaro.org>
Tested-by: Anders Roxell <anders.roxell@linaro.org>
6 years agotests: enable installing tests to bindir
Anders Roxell [Fri, 15 Mar 2019 10:01:44 +0000 (11:01 +0100)]
tests: enable installing tests to bindir

Add an enable option to configure that allows to install the testing
binary to <prefix>/bindir.

Signed-off-by: Anders Roxell <anders.roxell@linaro.org>
[Bartosz: trimmed the patch to fit the new approach]
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
6 years agogitignore: ignore patches
Bartosz Golaszewski [Mon, 18 Mar 2019 16:20:55 +0000 (17:20 +0100)]
gitignore: ignore patches

Add all files with the .patch extension to the list of ignored files.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
6 years agotreewide: rearrange source directories
Bartosz Golaszewski [Thu, 7 Mar 2019 10:15:23 +0000 (11:15 +0100)]
treewide: rearrange source directories

The src directory containing lib and tools is not necessary and will
actually cause problems if we tried to add a new component to src/
which would depend on libraries from the bindings directory because it
(bindings) already depends on src/lib.

Simplify the directory structure. Move lib and tools to the root source
directory and update all relevant files. That way we can specify the
exact build order of components from the top source Makefile.am.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
6 years agotools: coding style fix
Bartosz Golaszewski [Thu, 7 Mar 2019 11:10:05 +0000 (12:10 +0100)]
tools: coding style fix

Drop a stray space between '*' and get_progname().

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
6 years agoman: add template to EXTRA_DIST
Bartosz Golaszewski [Thu, 7 Mar 2019 10:45:47 +0000 (11:45 +0100)]
man: add template to EXTRA_DIST

Currently the man page template used by help2man is not included in the
distribution tarball. This causes build failures on systems that
actually do have help2man in which case we rebuild the man pages
locally. Add template to EXTRA_DIST.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
6 years agocore: ctxless: arrange local variables in reverse christmas tree order
Bartosz Golaszewski [Wed, 6 Mar 2019 16:57:32 +0000 (17:57 +0100)]
core: ctxless: arrange local variables in reverse christmas tree order

This is a cosmetic change: let's be consistent treewide and have all
local variables arranged in reverse christmas tree order.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
6 years agocore: ctxless: bail-out if num_lines == 0
Bartosz Golaszewski [Wed, 6 Mar 2019 15:03:34 +0000 (16:03 +0100)]
core: ctxless: bail-out if num_lines == 0

Return -1 and set errno to EINVAL if the number of lines specified in
any context-less helper is 0. This is done in addition to bailing out
when the number is higher than the maximum supported number of GPIO
lines. This fixes the segfaults that currently ocurr for num_lines == 0.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
6 years agoREADME: fix the kernel version required to run tests
Bartosz Golaszewski [Fri, 1 Mar 2019 10:03:48 +0000 (11:03 +0100)]
README: fix the kernel version required to run tests

The kernel version required to run tests is v4.16 while README says
it's v4.11. Fix it.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
6 years agobuild: use top_builddir instead of relative paths
Anders Roxell [Thu, 28 Feb 2019 15:35:34 +0000 (16:35 +0100)]
build: use top_builddir instead of relative paths

The only instance of using a relative path for an internal library is
in tests/Makefile.am. Use top_builddir instead.

Signed-off-by: Anders Roxell <anders.roxell@linaro.org>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
6 years agocore: drop an unnecessary pointer assignment
Bartosz Golaszewski [Thu, 28 Feb 2019 14:28:50 +0000 (15:28 +0100)]
core: drop an unnecessary pointer assignment

The whole line structure is zeroed in the line above, so there's no
need to set the fd_handle pointer to NULL.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
6 years agoconfigure: check for setlinebuf() when building tools
Bartosz Golaszewski [Mon, 25 Feb 2019 09:47:08 +0000 (10:47 +0100)]
configure: check for setlinebuf() when building tools

Add setlinebuf() to the list of functions checked for when building
gpio-tools. This is now required to build gpiomon.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
6 years agogpiomon: add option to set line buffered output
Martin Hundebøll [Mon, 25 Feb 2019 09:43:07 +0000 (10:43 +0100)]
gpiomon: add option to set line buffered output

Some applications call gpiomon in a sub process, in which case glibc
defaults to block buffered output on stdout. This makes the output
arrive to the calling process only when the (4kB) buffer is filled (or
when gpiomon exists), making the information obsolete and pretty much
useless.

Support such scenarios by adding a switch to configure line buffered
output on stdout. Similar switches are available in other applications
(e.g. `rsync`s --output argument).

Signed-off-by: Martin Hundebøll <martin@geanix.com>
[Bartosz:
  - use setlinebuf() instead of setvbuf(),
  - tweak the help string,
  - move the setlinebuf() call directly into the optarg switch statement]
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
6 years agoconfigure: code shrink
Bartosz Golaszewski [Mon, 25 Feb 2019 09:28:46 +0000 (10:28 +0100)]
configure: code shrink

When defining enable arguments, we don't need a full if-else spanning
multiple lines. We only care about the 'true' value, so pull the
relevant code into a single line.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
6 years agotreewide: order includes alphabetically
Bartosz Golaszewski [Wed, 20 Feb 2019 10:30:42 +0000 (11:30 +0100)]
treewide: order includes alphabetically

Unify the header includes by ordering them alphabetically and always
having local headers in a second group below the global ones (separated
by a newline).

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
6 years agoREADME: add a section about API documentation
Bartosz Golaszewski [Tue, 19 Feb 2019 16:34:39 +0000 (17:34 +0100)]
README: add a section about API documentation

Doxygen and python documentation are briefly mentioned in the BINDINGS
section but there's no word about the core C API and automatically
generated man pages.

Add a separate section to the README file describing the process of
generating html doxygen output, python help strings and man pages for
gpio-tools.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
6 years agodoc: add automatically generated man pages for gpio-tools
Bartosz Golaszewski [Mon, 18 Feb 2019 12:44:38 +0000 (13:44 +0100)]
doc: add automatically generated man pages for gpio-tools

Extend the build files to automatically generate man pages for
gpio-tools using help2man if it's present in the system and we're not
cross-compiling (as the built programs must be executable for help2man
to work).

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
6 years agodoc: delete generated files on make clean
Bartosz Golaszewski [Mon, 18 Feb 2019 13:19:51 +0000 (14:19 +0100)]
doc: delete generated files on make clean

Delete the entire doc directory when running make clean.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
6 years agogitignore: add distribution tarballs to ignored files
Bartosz Golaszewski [Fri, 15 Feb 2019 15:36:00 +0000 (16:36 +0100)]
gitignore: add distribution tarballs to ignored files

Add .tar.gz files to .gitignore.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
6 years agobindings: python: add support for 'default_val' in Line.request()
Bartosz Golaszewski [Fri, 15 Feb 2019 12:37:18 +0000 (13:37 +0100)]
bindings: python: add support for 'default_val' in Line.request()

Until now Line.request() only took 'default_vals' argument which was
passed down directly to LineBulk.request() internally. This meant that
even when requesting a single line in output mode, the default value
had to be passed in a sequence.

Add support for the 'default_val' argument which makes it possible to
specify the default value as an integer. The previous 'default_vals'
argument is still supported, but the two cannot be passed at the same
time.

Documentation for default_vals is removed, as it's now deprecated for
Line.request().

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
6 years agobindings: python: fix argument alignment in a function call
Bartosz Golaszewski [Fri, 15 Feb 2019 12:16:57 +0000 (13:16 +0100)]
bindings: python: fix argument alignment in a function call

When breaking a line, the arguments should be aligned with the opening
bracket of the function call.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
6 years agotests: gpiomon: remove failing test case
Bartosz Golaszewski [Thu, 14 Feb 2019 16:07:15 +0000 (17:07 +0100)]
tests: gpiomon: remove failing test case

Since commit fa38869b0161 ("gpiolib: Don't support irq sharing for
userspace") in the kernel, the test case veryfing correct ignoring
of edge events is failing. It will take a while until it will be
fixed upstream so remove this test for now.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
6 years agobindings: cxx: make bitset_cmp::operator() const
Michael Beach [Sat, 9 Feb 2019 15:06:18 +0000 (00:06 +0900)]
bindings: cxx: make bitset_cmp::operator() const

This fixes build problems with clang and libc++ and such constness is
now required by C++17 (see https://cplusplus.github.io/LWG/issue2542).

Signed-off-by: Michael Beach <michaelb@ieee.org>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
6 years agobindings: cxx: do not initialize a chip's shared_ptr with nullptr
Patrick Boettcher [Sun, 3 Feb 2019 12:29:14 +0000 (13:29 +0100)]
bindings: cxx: do not initialize a chip's shared_ptr with nullptr

A shared_ptr initialized with nullptr will still call the deleter which
causes a NULL-pointer dereference if we create a chip_iter when there
are no GPIO chips in the system.

Only initialize the current chip object in chip_iter if
gpiod_chip_iter_next_noclose() returned a valid pointer.

Signed-off-by: Patrick Boettcher <p@yai.se>
[Bartosz:
  - tweaked the commit message
  - use std::move when assigning the chip object]
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
6 years agogpioset: extend help text
Bartosz Golaszewski [Thu, 3 Jan 2019 10:46:25 +0000 (11:46 +0100)]
gpioset: extend help text

There's a common misconception about the way the character device
works. Some users expect line states to be driven as desired even
after gpioset exits. Add a note about that to the help text to avoid
further confusion.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agotreewide: unify naming of local variables representing return values
Bartosz Golaszewski [Wed, 14 Nov 2018 10:15:30 +0000 (11:15 +0100)]
treewide: unify naming of local variables representing return values

For integers representing simple return values of various functions
use the name 'rv' everywhere.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agodoc: C API documentation fixes
Gasper Zejn [Fri, 23 Feb 2018 13:51:19 +0000 (14:51 +0100)]
doc: C API documentation fixes

Fix a couple problems in doxygen documentation of the C API.

(Unfortunately no Signed-off-by tag from the submitter...)
[Bartosz: added a proper commit message]
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agotests: ignore 'remove' events from udev
Bartosz Golaszewski [Mon, 12 Nov 2018 15:43:03 +0000 (16:43 +0100)]
tests: ignore 'remove' events from udev

So far the tests have been executed on a Debian 9 machine with libudev
provided by systemd 232 - everything always worked fine. However
running them on a system with systemd 237 uncovered a bug in the
testing framework.

It turned out that on newer versions the ignored 'remove' events linger
somewhere in the pipeline and get read by subsequent test cases causing
erroneous chip naming and breaking tests.

Check the action string for udev device objects and only care about
those being added.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agolibgpiod: start v1.3 development cycle
Bartosz Golaszewski [Fri, 9 Nov 2018 09:08:18 +0000 (10:08 +0100)]
libgpiod: start v1.3 development cycle

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agolibgpiod v1.2
Bartosz Golaszewski [Thu, 8 Nov 2018 18:36:02 +0000 (19:36 +0100)]
libgpiod v1.2

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agoNEWS: updates for v1.2
Bartosz Golaszewski [Thu, 8 Nov 2018 18:26:31 +0000 (19:26 +0100)]
NEWS: updates for v1.2

Add release notes for libgpiod v1.2.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobuild: check for sys/sysmacros.h in configure
Bartosz Golaszewski [Wed, 7 Nov 2018 20:29:02 +0000 (21:29 +0100)]
build: check for sys/sysmacros.h in configure

We now need this header to build the core library.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agocore: add missing include
Bartosz Golaszewski [Wed, 7 Nov 2018 15:55:52 +0000 (16:55 +0100)]
core: add missing include

Not including <sys/sysmacros.h> causes the following error on ARM:

core.c: In function ‘is_gpiochip_cdev’:
core.c:116:4: warning: implicit declaration of function ‘major’ [-Wimplicit-function-declaration]
    major(statbuf.st_rdev), minor(statbuf.st_rdev));
    ^~~~~
core.c:116:28: warning: implicit declaration of function ‘minor’; did you mean ‘mknod’? [-Wimplicit-function-declaration]
    major(statbuf.st_rdev), minor(statbuf.st_rdev));
                            ^~~~~
                            mknod

It wasn't spotted earlier since it builds fine on x86-64. Add the
missing include.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agocore: harden gpiod_chip_open()
Bartosz Golaszewski [Mon, 5 Nov 2018 02:57:17 +0000 (03:57 +0100)]
core: harden gpiod_chip_open()

Verify that the file we were asked to use is really a GPIO character
device.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agotools: tweak the formatting of help text strings
Bartosz Golaszewski [Sat, 3 Nov 2018 11:56:48 +0000 (12:56 +0100)]
tools: tweak the formatting of help text strings

Add an additional newline between the summary and the options list
for better readability.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agoMerge branch 'next'
Bartosz Golaszewski [Sun, 7 Oct 2018 13:49:50 +0000 (15:49 +0200)]
Merge branch 'next'

This introduces the new context-less event monitor with specifiable
event types and a small tweak in configure.ac.

6 years agoAPI: mark context-less event loop functions as deprecated
Bartosz Golaszewski [Tue, 2 Oct 2018 14:30:37 +0000 (16:30 +0200)]
API: mark context-less event loop functions as deprecated

Mark gpiod_ctxless_event_loop() and gpiod_ctxless_event_loop_multiple()
as deprecated. Those functions suffer from an issue where HW may not
allow setting up both rising and falling egde interrupts. All users
have been converted to using the new event monitor helpers.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agoAPI: add a macro for marking deprecated functions
Bartosz Golaszewski [Tue, 2 Oct 2018 12:49:17 +0000 (14:49 +0200)]
API: add a macro for marking deprecated functions

We want to deprecate the badly designed event loop functions. Introduce
a macro that allows marking API routines as deprecated.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agotests: ctxless: add a test case for the event monitor
Bartosz Golaszewski [Sun, 7 Oct 2018 08:56:38 +0000 (10:56 +0200)]
tests: ctxless: add a test case for the event monitor

Add a test case verifying that the event callback is not called for
events we're not monitoring.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agotests: ctxless: switch to using the event monitor routines
Bartosz Golaszewski [Tue, 2 Oct 2018 15:23:30 +0000 (17:23 +0200)]
tests: ctxless: switch to using the event monitor routines

Use gpiod_ctxless_event_monitor() and
gpiod_ctxless_event_monitor_multiple() instead of
gpiod_ctxless_event_loop() and gpiod_ctxless_event_loop_multiple()
respectively.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agogpiomon: switch to using gpiod_ctxless_event_monitor_multiple()
Bartosz Golaszewski [Tue, 2 Oct 2018 15:05:38 +0000 (17:05 +0200)]
gpiomon: switch to using gpiod_ctxless_event_monitor_multiple()

Switch to using the new context-less routine for event monitoring. We
can now simplify the event callback as there's no need anymore to
check the event type in the handler.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agoctxless: provide new event monitor
Bartosz Golaszewski [Thu, 27 Sep 2018 08:47:14 +0000 (10:47 +0200)]
ctxless: provide new event monitor

Current implementation of gpiod_ctxless_event_loop() (and its variant
for multiple lines) always requests GPIO lines for listening for both
rising and falling edge events. This causes a problem when the
underlying hardware doesn't allow this.

It can e.g. result in the following error raised by the interrupt
controller:

  genirq: Setting trigger mode 3 for irq 107 failed (kempld_irq_set_type+0x0/0x130 [gpio_kempld])

For the sake of backward compatibility we're leaving the old
implementation in place and provide two new routines that that take an
additional parameter allowing users to specify the events libgpiod
should listen for.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobindings: cxx: examples: add missing include
SZ Lin (林上智) [Wed, 26 Sep 2018 09:47:10 +0000 (17:47 +0800)]
bindings: cxx: examples: add missing include

This patch adds proper include file to fix FTBFS issue in
gpiod_cxx_tests.cpp, please see below error.

gpiod_cxx_tests.cpp:29:19: note: 'std::function' is defined in header '<functional>'; did you forget to '#include <functional>'?
gpiod_cxx_tests.cpp:26:1:
+#include <functional>

Signed-off-by: SZ Lin (林上智) <sz.lin@moxa.com>
[Bartosz: tweaked the commit message]
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobuild: don't use unicode characters in configure.ac
Bartosz Golaszewski [Tue, 2 Oct 2018 15:53:27 +0000 (17:53 +0200)]
build: don't use unicode characters in configure.ac

Replace unicode apostrophes with their ASCII counterparts.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobuild: tools: remove unnecessary line breaks
Bartosz Golaszewski [Fri, 24 Aug 2018 15:25:10 +0000 (17:25 +0200)]
build: tools: remove unnecessary line breaks

There are only two source files in the list so don't break the line
too eagerly.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobindings: python: pydoc improvements
Bartosz Golaszewski [Thu, 26 Jul 2018 13:59:19 +0000 (15:59 +0200)]
bindings: python: pydoc improvements

Current documentation of python bindings is quite limited. Extend it
with more elaborate descriptions of types and methods.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobindings: python: bail-out if the line was not found in gpiofind.py
Bartosz Golaszewski [Tue, 31 Jul 2018 12:33:40 +0000 (14:33 +0200)]
bindings: python: bail-out if the line was not found in gpiofind.py

Currently we're not checking if the object returned from
gpiod.fine_line() is None which results in an attribute error being
raised when we try to call line methods on a non-line object.

Add an if and bail-out with an error code if the line with given name
was not found.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobindings: python: fix gpiod_Chip_find_lines() for nonexistent lines
Bartosz Golaszewski [Mon, 30 Jul 2018 13:05:53 +0000 (15:05 +0200)]
bindings: python: fix gpiod_Chip_find_lines() for nonexistent lines

Currently if we call gpiod_Chip_find_lines() with some names that
cannot be looked up, we end up getting an exception from the LineBulk
object's constructor (because None is not a Line and LineBulk can only
hold Line objects).

Fix the behavior of gpiod_Chip_find_lines() for nonexistent lines by
raising an explicit exception if the underlying gpiod_Chip_find_line()
call returns None. Also: add a relevant test case.

Fixes: 96c524c4951c ("bindings: implement python bindings")
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobindings: python: remove a redundant if
Bartosz Golaszewski [Mon, 30 Jul 2018 12:49:17 +0000 (14:49 +0200)]
bindings: python: remove a redundant if

We don't need to check if bulk is NULL in gpiod_Chip_find_lines()
before returning it.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobindings: python: examples: close chip objects where needed
Bartosz Golaszewski [Fri, 27 Jul 2018 11:52:18 +0000 (13:52 +0200)]
bindings: python: examples: close chip objects where needed

Unlike the C++ bindings: we can't expect the python runtime to call
the Chip object's destructor when all references are dropped. We need
to close each chip explicitly. Either call the close() method directly
or use controlled execution in all examples.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobuild: add a comment about libtool version to configure.ac
Bartosz Golaszewski [Thu, 26 Jul 2018 11:09:34 +0000 (13:09 +0200)]
build: add a comment about libtool version to configure.ac

The libtool version only applies to the core C library, not to tools
or python bindings. C++ bindings have a separate libtool version.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agotools: tweak the displayed version format
Bartosz Golaszewski [Tue, 24 Jul 2018 13:09:35 +0000 (15:09 +0200)]
tools: tweak the displayed version format

Prepend the version string with a 'v' to stay consistent with git
tags we're using.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>