qemu-gpiodev/libgpiod.git
8 years agotests: fix a memory leak
Bartosz Golaszewski [Thu, 2 Mar 2017 10:28:24 +0000 (11:28 +0100)]
tests: fix a memory leak

We must free the error string from a failed test after displaying it.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: improve test descriptions
Bartosz Golaszewski [Thu, 2 Mar 2017 10:20:36 +0000 (11:20 +0100)]
tests: improve test descriptions

Use the test descriptions to tell the user exactly what
each test is validating.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: add a test case for a bad line request
Bartosz Golaszewski [Thu, 2 Mar 2017 10:08:58 +0000 (11:08 +0100)]
tests: add a test case for a bad line request

Implement a test case in which we try to request lines from different
GPIO chips in a single bulk object.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: add a test case for gpiod_line_request_bulk_output()
Bartosz Golaszewski [Thu, 2 Mar 2017 09:53:41 +0000 (10:53 +0100)]
tests: add a test case for gpiod_line_request_bulk_output()

Simple test case validating bulk output requests.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: add misc test cases
Bartosz Golaszewski [Thu, 2 Mar 2017 09:37:38 +0000 (10:37 +0100)]
tests: add misc test cases

Add test cases for err handling and gpiod_version_string().

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agocore: remove doxygen hack
Bartosz Golaszewski [Wed, 1 Mar 2017 21:16:56 +0000 (22:16 +0100)]
core: remove doxygen hack

Keep gpiod.h clean - pull _gpiod_line_event_request_type() into
core.c and un-inline the gpiod_line_event_request_*() routines.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: add simple test cases for line iterators
Bartosz Golaszewski [Wed, 1 Mar 2017 17:14:10 +0000 (18:14 +0100)]
tests: add simple test cases for line iterators

We'll test them some more though after new functionalities in
gpio-mockup are released in kernel 4.11.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agocore: don't expose designated initializers in the library header
Bartosz Golaszewski [Wed, 1 Mar 2017 16:51:26 +0000 (17:51 +0100)]
core: don't expose designated initializers in the library header

We don't know who might want to include gpiod.h, so let's try to avoid
any C99 extensions in the header.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: coding style fix
Bartosz Golaszewski [Wed, 1 Mar 2017 11:56:05 +0000 (12:56 +0100)]
tests: coding style fix

Break the line that's longer than 80 characters.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: tweak a log message
Bartosz Golaszewski [Wed, 1 Mar 2017 11:49:43 +0000 (12:49 +0100)]
tests: tweak a log message

Drop the 'test' prefix from the message displayed when running
a test. We're already stating that in the message header.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: use the 'malloc' attribute
Bartosz Golaszewski [Wed, 1 Mar 2017 11:46:36 +0000 (12:46 +0100)]
tests: use the 'malloc' attribute

Use the gcc 'malloc' attribute for all malloc-like routines in the
unit testing framework.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: rename an argument
Bartosz Golaszewski [Wed, 1 Mar 2017 11:17:00 +0000 (12:17 +0100)]
tests: rename an argument

Rename the 'color' argument in vmsg()/vmsgn() to 'hdr_clr' to better
reflect its purpose - it affects the color of the message header, not
the message itself.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: add colors to output
Bartosz Golaszewski [Wed, 1 Mar 2017 11:12:18 +0000 (12:12 +0100)]
tests: add colors to output

Add terminal colors for improved readability of the test output.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: rework logging
Bartosz Golaszewski [Wed, 1 Mar 2017 10:50:08 +0000 (11:50 +0100)]
tests: rework logging

Major rework of the way logging works: always print to stderr, add
new routines for raw printing, store the message from a failed test
in the test context and print it after the test, general code
reorganization.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: use function attribute consistently
Bartosz Golaszewski [Wed, 1 Mar 2017 10:22:11 +0000 (11:22 +0100)]
tests: use function attribute consistently

Move all function attributes to the function definitions and put them
before the return type.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agocore: use the 'malloc' attribute
Bartosz Golaszewski [Wed, 1 Mar 2017 10:19:12 +0000 (11:19 +0100)]
core: use the 'malloc' attribute

Use the 'malloc' gcc attribute in the zalloc() definition.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: drop the external prefix in gu_err()
Bartosz Golaszewski [Wed, 1 Mar 2017 10:15:38 +0000 (11:15 +0100)]
tests: drop the external prefix in gu_err()

This function is static so drop the prefix.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: drop the external prefix in gu_msg()
Bartosz Golaszewski [Wed, 1 Mar 2017 10:14:55 +0000 (11:14 +0100)]
tests: drop the external prefix in gu_msg()

This function is static so drop the prefix.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: explain the need for qsort()
Bartosz Golaszewski [Wed, 1 Mar 2017 10:12:03 +0000 (11:12 +0100)]
tests: explain the need for qsort()

Add a comment explaining why we need to sort the mockup gpiochip
structures after detecting them with udev.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agobuild: fix a test in configure.ac
Bartosz Golaszewski [Tue, 28 Feb 2017 17:17:17 +0000 (18:17 +0100)]
build: fix a test in configure.ac

We were checking the 'with_tools' variable instead of 'with_tests'.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: simplify test_load_module()
Bartosz Golaszewski [Tue, 28 Feb 2017 10:24:33 +0000 (11:24 +0100)]
tests: simplify test_load_module()

Add a new function that simplifies the string building when preparing
the module params for gpio-mockup.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: remove a stray space
Bartosz Golaszewski [Tue, 28 Feb 2017 10:02:05 +0000 (11:02 +0100)]
tests: remove a stray space

Remove a double space in check_chip_index().

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: remove GU_REGISTER_TEST()
Bartosz Golaszewski [Mon, 27 Feb 2017 12:30:34 +0000 (13:30 +0100)]
tests: remove GU_REGISTER_TEST()

This macro is never used directly.

Just make it a part of GU_DEFINE_TEST().

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: make struct gu_chip_descr & gu_test private
Bartosz Golaszewski [Mon, 27 Feb 2017 12:21:31 +0000 (13:21 +0100)]
tests: make struct gu_chip_descr & gu_test private

Add an underscore to struct gu_chip_descr & struct gu_test. This
indicates that these structures are for internal use only.

Test cases should use provided helper macros when registering tests.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: document test API
Bartosz Golaszewski [Mon, 27 Feb 2017 12:18:25 +0000 (13:18 +0100)]
tests: document test API

Add some comments to the test header file.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: make gu_msg() and gu_err() static
Bartosz Golaszewski [Mon, 27 Feb 2017 11:53:44 +0000 (12:53 +0100)]
tests: make gu_msg() and gu_err() static

Tests should only ever print anything when an assertion fails. Make
gu_msg() and gu_err() static and instead allow passing an error
message to _gu_test_failed().

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: remove unnecessary goto
Bartosz Golaszewski [Mon, 27 Feb 2017 11:46:52 +0000 (12:46 +0100)]
tests: remove unnecessary goto

Check all loop conditions in a single if in test_prepare() and remove
the 'cont' label.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: test case for gpiod_foreach_chip_noclose()
Bartosz Golaszewski [Fri, 24 Feb 2017 11:20:07 +0000 (12:20 +0100)]
tests: test case for gpiod_foreach_chip_noclose()

Add a test for the noclose variants of the chip iterator routines.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: add new cleanup helper
Bartosz Golaszewski [Fri, 24 Feb 2017 11:18:54 +0000 (12:18 +0100)]
tests: add new cleanup helper

Add gu_free_chip_iter_noclose() which calls
gpiod_chip_iter_free_noclose() internally to free the chip iterator
without closing the most recent chip handle.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: add a test for gpiod_chip_open_by_name()
Bartosz Golaszewski [Fri, 24 Feb 2017 11:05:02 +0000 (12:05 +0100)]
tests: add a test for gpiod_chip_open_by_name()

We forgot to test this one before.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agocore: tweak argument names
Bartosz Golaszewski [Fri, 24 Feb 2017 11:02:07 +0000 (12:02 +0100)]
core: tweak argument names

Rename line_bulk to bulk for brevity.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agogpiod.h: documentation updates
Bartosz Golaszewski [Fri, 24 Feb 2017 10:56:22 +0000 (11:56 +0100)]
gpiod.h: documentation updates

Clarify that all functions dealing with sets of lines expect at least
a single line in order to work correctly and that the behavior is
undefined for zero lines. This applies both to bulk objects as well
as the high-level API.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: add test cases for the high-level API
Bartosz Golaszewski [Fri, 24 Feb 2017 10:40:37 +0000 (11:40 +0100)]
tests: add test cases for the high-level API

For now we only test the get and set operations. We'll add event tests
once the support for that is merged in the kernel.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: add new assertion helper
Bartosz Golaszewski [Fri, 24 Feb 2017 10:39:39 +0000 (11:39 +0100)]
tests: add new assertion helper

Add GU_ASSERT_NOTEQ() for testing if two numbers are not equal.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agocore: don't use double underscores
Bartosz Golaszewski [Thu, 23 Feb 2017 16:00:54 +0000 (17:00 +0100)]
core: don't use double underscores

Symbols starting with a double underscore are reserved for the
compiler. Private symbols in libgpiod should start with a single
underscore.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agocore: use uint8_t instead of __u8
Bartosz Golaszewski [Thu, 23 Feb 2017 15:54:59 +0000 (16:54 +0100)]
core: use uint8_t instead of __u8

User space should use types defined in <stdint.h>, not the
linux-specific ones.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: fix potential memory corruption
Bartosz Golaszewski [Thu, 23 Feb 2017 15:03:12 +0000 (16:03 +0100)]
tests: fix potential memory corruption

Valgrind is complaining about invalid reads and writes from the two
line test cases. The culprit is the order in which the cleanup
functions are called.

Declare the chip pointers above the line handles so that we don't
free the resources associated with the chip before releasing the
lines.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: move exported functions below main()
Bartosz Golaszewski [Thu, 23 Feb 2017 14:27:21 +0000 (15:27 +0100)]
tests: move exported functions below main()

Group all functions that are used exclusively by tests together and
below main() for better readability.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: remove xcasprintf()
Bartosz Golaszewski [Thu, 23 Feb 2017 14:25:15 +0000 (15:25 +0100)]
tests: remove xcasprintf()

There's only one user and we already removed xasprintf() which was no
longer used after introducing udev polling. Remove it for simplicity.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: wait for gpiochips before running tests
Bartosz Golaszewski [Thu, 23 Feb 2017 14:17:29 +0000 (15:17 +0100)]
tests: wait for gpiochips before running tests

We're currently using an ugly hack to check if gpiochip files are
actually mockup chips. Remove it and use libudev instead to poll for
uevents until all mockup GPIO devices appear in /dev.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: move the closedir() call
Bartosz Golaszewski [Thu, 23 Feb 2017 10:51:00 +0000 (11:51 +0100)]
tests: move the closedir() call

Close the directory immediately after the loop iterating over
its entries ends.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: fix a potential segfault
Bartosz Golaszewski [Thu, 23 Feb 2017 10:47:57 +0000 (11:47 +0100)]
tests: fix a potential segfault

We should only sort the mockup chip pointers after determining that
all gpiochip device files have actually been created. Otherwise we
might sort invalid memory since we don't create the mockup_chip
structures for nonexistent devices.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: implement xcasprintf()
Bartosz Golaszewski [Wed, 22 Feb 2017 15:18:30 +0000 (16:18 +0100)]
tests: implement xcasprintf()

Add another flavor of xasprintf() which can also return the number of
bytes written to the created string.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: introduce x-funcs
Bartosz Golaszewski [Wed, 22 Feb 2017 15:10:43 +0000 (16:10 +0100)]
tests: introduce x-funcs

Add a couple helper functions that check for unrecoverable errors
internally and die() if they occur.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: don't sort entire structures
Bartosz Golaszewski [Wed, 22 Feb 2017 14:57:09 +0000 (15:57 +0100)]
tests: don't sort entire structures

Instead of moving around whole mockup_chip structures, keep an array
of pointers in the test context structure and pass it to qsort().

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agocore: extend gpiod_chip_open_lookup()
Bartosz Golaszewski [Wed, 22 Feb 2017 11:01:41 +0000 (12:01 +0100)]
core: extend gpiod_chip_open_lookup()

Make gpiod_chip_open_lookup() also check the chip label.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agocore: new gpiod_chip_open() flavor
Bartosz Golaszewski [Wed, 22 Feb 2017 10:47:52 +0000 (11:47 +0100)]
core: new gpiod_chip_open() flavor

Implement gpiod_chip_open_by_label() which allows to find and open
a GPIO chip by its in-kernel label.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: add a couple line test cases
Bartosz Golaszewski [Wed, 22 Feb 2017 09:57:23 +0000 (10:57 +0100)]
tests: add a couple line test cases

Add first test cases for GPIO lines.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: new cleanup helper
Bartosz Golaszewski [Wed, 22 Feb 2017 09:55:24 +0000 (10:55 +0100)]
tests: new cleanup helper

Add a new cleanup helper which releases a previously requested GPIO
line when a gpiod_line pointer used with GU_CLEANUP() goes out of
scope.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: new assertion helper
Bartosz Golaszewski [Wed, 22 Feb 2017 09:44:33 +0000 (10:44 +0100)]
tests: new assertion helper

Add the GU_ASSERT_RET_OK() macro which checks if an integer (normally
returned from a function call) equals 0 - indicating a correct result.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: fix a comment
Bartosz Golaszewski [Mon, 20 Feb 2017 15:16:17 +0000 (16:16 +0100)]
tests: fix a comment

This file contains iterator test cases, not GPIO chip tests.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: add a chip iterator test case
Bartosz Golaszewski [Mon, 20 Feb 2017 14:57:24 +0000 (15:57 +0100)]
tests: add a chip iterator test case

Add a test case checking the chip iterators and the accompanying
gpiod_foreach_chip() macro.

Since we're adding a new file: make the cleanup helpers reusable from
all test files.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: add a simple unit testing framework and a couple tests
Bartosz Golaszewski [Thu, 9 Feb 2017 10:02:13 +0000 (11:02 +0100)]
tests: add a simple unit testing framework and a couple tests

Implement a simple unit testing framework working together with the
gpio-mockup module present in the mainline linux kernel.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agocore: coding style fixes
Bartosz Golaszewski [Wed, 15 Feb 2017 11:43:49 +0000 (12:43 +0100)]
core: coding style fixes

Make struct definitions consistent.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agomake: simplify Makefile.am in src/
Bartosz Golaszewski [Thu, 9 Feb 2017 13:51:53 +0000 (14:51 +0100)]
make: simplify Makefile.am in src/

Drop the redundant variable and use SUBDIRS directly.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agomake: use LDADD instead of AM_LDFLAGS when linking against libgpiod
Bartosz Golaszewski [Wed, 8 Feb 2017 13:35:04 +0000 (14:35 +0100)]
make: use LDADD instead of AM_LDFLAGS when linking against libgpiod

Libtool tends to have problems (especially with C++) when the
variables are used incorrectly. When building tools, specify the
library we want to link against using LDADD.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agoconfigure: use quotation marks consistently
Bartosz Golaszewski [Wed, 8 Feb 2017 11:11:54 +0000 (12:11 +0100)]
configure: use quotation marks consistently

Always use quotation marks when testing variables.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agoconfigure: fix variable assignment
Bartosz Golaszewski [Wed, 8 Feb 2017 11:02:11 +0000 (12:02 +0100)]
configure: fix variable assignment

We must not use spaces in assignment.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agocore: code shrink
Bartosz Golaszewski [Wed, 8 Feb 2017 10:21:41 +0000 (11:21 +0100)]
core: code shrink

Use the ternary operator instead of an if-else.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agocore: drop a redundant call to gpiod_line_name()
Bartosz Golaszewski [Tue, 7 Feb 2017 10:03:57 +0000 (11:03 +0100)]
core: drop a redundant call to gpiod_line_name()

We're storing the name in line_name, so reuse it.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agocore: really fix event requests
Bartosz Golaszewski [Mon, 6 Feb 2017 11:34:34 +0000 (12:34 +0100)]
core: really fix event requests

The previous commit addressing the issue when requesting both types
of line events was braindead. Actually fix the bug this time: check
the event_type, not the eventflags.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agocore: close GPIO chip device files on exec
Bartosz Golaszewski [Mon, 6 Feb 2017 09:59:00 +0000 (10:59 +0100)]
core: close GPIO chip device files on exec

Pass the O_CLOEXEC flag to open() so that we don't leak open GPIO
chip descriptors to any processes spawned by users of the library.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agogpioset: fix helptext
Bartosz Golaszewski [Sun, 5 Feb 2017 16:25:30 +0000 (17:25 +0100)]
gpioset: fix helptext

Add 'signal' to the list of available modes.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agocore: add non-closing gpiochip iterator function and foreach macro
Clemens Gruber [Tue, 31 Jan 2017 21:08:02 +0000 (22:08 +0100)]
core: add non-closing gpiochip iterator function and foreach macro

Allows users to iterate over the gpiochips without closing them
automatically. The lines can then be used during the runtime of the
program. The user is responsible for closing the chips after they are
no longer needed.

Signed-off-by: Clemens Gruber <clemens.gruber@pqgruber.com>
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agocore: fix requesting events
Bartosz Golaszewski [Mon, 30 Jan 2017 11:02:07 +0000 (12:02 +0100)]
core: fix requesting events

There was a bitwise OR and assignment operator in an 'if else' instead
of an equality operator when requesting 'both edges' events.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agolibgpiod: relicense under LGPLv2.1
Bartosz Golaszewski [Sun, 29 Jan 2017 12:06:15 +0000 (13:06 +0100)]
libgpiod: relicense under LGPLv2.1

The library is much less useful under GPLv3 - change the license
to the more permissive LGPLv2.1 for the entire project.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Acked-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
8 years agocore: simplify verify_line_bulk()
Bartosz Golaszewski [Sat, 28 Jan 2017 16:49:10 +0000 (17:49 +0100)]
core: simplify verify_line_bulk()

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agocore: rename line_update() to line_maybe_update()
Bartosz Golaszewski [Sat, 28 Jan 2017 16:36:35 +0000 (17:36 +0100)]
core: rename line_update() to line_maybe_update()

This routine can silently fail, so reflect that in the name.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agocore: simplify gpiod_chip_close()
Bartosz Golaszewski [Sat, 28 Jan 2017 16:32:23 +0000 (17:32 +0100)]
core: simplify gpiod_chip_close()

Use a temporary pointer for GPIO lines and helpers for reading the
line state.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agogpioinfo: increase the width of the line offset
Bartosz Golaszewski [Sat, 28 Jan 2017 16:00:46 +0000 (17:00 +0100)]
gpioinfo: increase the width of the line offset

Increase the width of the line offset to 3 - that way we can display
999 lines before the formatting will be shifted.

This should be generally enough, but we should still implement
a correct, generic solution for gpioinfo display.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agogpioset: include <poll.h> instead of <sys/poll.h>
Bartosz Golaszewski [Wed, 25 Jan 2017 10:55:31 +0000 (11:55 +0100)]
gpioset: include <poll.h> instead of <sys/poll.h>

Just like we did in core.c: don't include <sys/poll.h> directly.

Follow the manual and include <poll.h>.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agobuild: use AC_FUNC_STRERROR_R to check the version of strerror_r()
Bartosz Golaszewski [Tue, 24 Jan 2017 10:45:36 +0000 (11:45 +0100)]
build: use AC_FUNC_STRERROR_R to check the version of strerror_r()

Define _GNU_SOURCE globally in configure.ac and use the
AC_FUNC_STRERROR_R macro to figure out what version of strerror_r() is
provided. Some libraries (e.g. musl) only provide the POSIX version
even if we explicitly request GNU extensions.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agodoc: documentation updates
Bartosz Golaszewski [Tue, 24 Jan 2017 09:53:35 +0000 (10:53 +0100)]
doc: documentation updates

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agocore: allow to read values of lines configured for events
Bartosz Golaszewski [Mon, 23 Jan 2017 15:01:28 +0000 (16:01 +0100)]
core: allow to read values of lines configured for events

The kernel allows us to read values of lines on which we're listening
for events, but libgpiod bails out if the user tries to do it.

Modify gpiod_line_get_value_bulk() to select the correct file
descriptor, depending on how the line object is configured and
allow reading values for both normally exported and monitored lines.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agocore: include <poll.h> instead of <sys/poll.h>
Thomas Petazzoni [Mon, 23 Jan 2017 08:18:32 +0000 (21:18 +1300)]
core: include <poll.h> instead of <sys/poll.h>

<sys/poll.h> is an internal C library header, which shouldn't be
included directly. <poll.h> should be included instead, as advertised
in poll(2).

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
[Bartosz: tweaked the commit message]
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agogpiod.h: include missing <time.h> include
Thomas Petazzoni [Mon, 23 Jan 2017 08:17:15 +0000 (21:17 +1300)]
gpiod.h: include missing <time.h> include

gpiod.h uses "struct timespec", but forgets to include the <time.h>
header which defines "struct timespec". This causes a build error with
the musl C library:

In file included from core.c:11:0:
../../include/gpiod.h:232:49: warning: â€˜struct timespec’ declared inside parameter list
 typedef int (*gpiod_event_cb)(int, const struct timespec *, void *);

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
[Bartosz: tweaked the commit message]
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agoconfigure: add helpers for printing common errors
Bartosz Golaszewski [Fri, 20 Jan 2017 17:11:20 +0000 (18:11 +0100)]
configure: add helpers for printing common errors

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agoconfigure: tweak error messages
Bartosz Golaszewski [Fri, 20 Jan 2017 16:29:42 +0000 (17:29 +0100)]
configure: tweak error messages

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agoconfigure: don't check stdint.h
Bartosz Golaszewski [Fri, 20 Jan 2017 16:23:40 +0000 (17:23 +0100)]
configure: don't check stdint.h

We probably have it if AC_HEADER_STDC succeeded.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agoconfigure: don't check headers/functions unnecessarily
Bartosz Golaszewski [Fri, 20 Jan 2017 16:22:20 +0000 (17:22 +0100)]
configure: don't check headers/functions unnecessarily

Only check functions & headers required by tools if we're actually
building them.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agoconfigure: check sys/poll.h availability
Bartosz Golaszewski [Fri, 20 Jan 2017 14:57:54 +0000 (15:57 +0100)]
configure: check sys/poll.h availability

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agoconfigure: check ppoll() availability
Bartosz Golaszewski [Fri, 20 Jan 2017 14:41:46 +0000 (15:41 +0100)]
configure: check ppoll() availability

We're using ppoll() for events - not poll(). Check the right syscall.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agoREADME: fix the required version of kernel headers
Bartosz Golaszewski [Thu, 19 Jan 2017 14:53:25 +0000 (15:53 +0100)]
README: fix the required version of kernel headers

The project actually needs kernel headers >= v4.8 to compile.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agogpiomon: fix shortops
Bartosz Golaszewski [Thu, 19 Jan 2017 14:10:10 +0000 (15:10 +0100)]
gpiomon: fix shortops

The short option for --silent is missing in gpiomon. Add it.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agobuild: don't try to process docs if doxygen is not installed
Bartosz Golaszewski [Wed, 18 Jan 2017 14:14:36 +0000 (15:14 +0100)]
build: don't try to process docs if doxygen is not installed

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agolibgpiod: start 0.2 development cycle
Bartosz Golaszewski [Wed, 18 Jan 2017 13:59:37 +0000 (14:59 +0100)]
libgpiod: start 0.2 development cycle

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agolibgpiod v0.1
Bartosz Golaszewski [Wed, 18 Jan 2017 13:30:28 +0000 (14:30 +0100)]
libgpiod v0.1

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agoREADME: add examples
Bartosz Golaszewski [Wed, 18 Jan 2017 10:57:35 +0000 (11:57 +0100)]
README: add examples

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agoREADME: add the autoconf version needed to compile the project
Bartosz Golaszewski [Wed, 18 Jan 2017 10:30:25 +0000 (11:30 +0100)]
README: add the autoconf version needed to compile the project

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agoREADME: add bullet points to the tool list
Bartosz Golaszewski [Wed, 18 Jan 2017 10:26:49 +0000 (11:26 +0100)]
README: add bullet points to the tool list

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agoREADME: the introduction is not a code block
Bartosz Golaszewski [Wed, 18 Jan 2017 10:10:36 +0000 (11:10 +0100)]
README: the introduction is not a code block

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agoREADME: rename to README.md for nice github cover
Bartosz Golaszewski [Wed, 18 Jan 2017 10:09:42 +0000 (11:09 +0100)]
README: rename to README.md for nice github cover

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agoREADME: update
Bartosz Golaszewski [Tue, 17 Jan 2017 18:53:37 +0000 (19:53 +0100)]
README: update

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agocore: constify function arguments that will not be modified
Bartosz Golaszewski [Tue, 17 Jan 2017 16:34:03 +0000 (17:34 +0100)]
core: constify function arguments that will not be modified

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agogpiomon: modify the output format
Bartosz Golaszewski [Tue, 17 Jan 2017 16:25:00 +0000 (17:25 +0100)]
gpiomon: modify the output format

Drop unnecessary strings. Add offset info (if we ever wanted to allow
monitoring multiple lines at once while staying backwards compatible).

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agogpiomon: check if offset is not negative
Bartosz Golaszewski [Tue, 17 Jan 2017 16:21:28 +0000 (17:21 +0100)]
gpiomon: check if offset is not negative

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agocore: name the iterator functions consistently
Bartosz Golaszewski [Tue, 17 Jan 2017 16:06:53 +0000 (17:06 +0100)]
core: name the iterator functions consistently

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agocore: skip chips and lines on error in gpiod_line_find_by_name()
Bartosz Golaszewski [Tue, 17 Jan 2017 16:04:46 +0000 (17:04 +0100)]
core: skip chips and lines on error in gpiod_line_find_by_name()

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agogpiomon: new options
Bartosz Golaszewski [Tue, 17 Jan 2017 15:51:11 +0000 (16:51 +0100)]
gpiomon: new options

Add new options to gpiomon:
  - allow to specify the number of events after which the program
    should exit
  - allow to silence the output
  - allow to only monitor certain types of events

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agogpioset: arrange local arguments for better readability
Bartosz Golaszewski [Tue, 17 Jan 2017 15:21:28 +0000 (16:21 +0100)]
gpioset: arrange local arguments for better readability

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