qemu-gpiodev/libgpiod.git
7 years agoevent: rename event requests routines
Bartosz Golaszewski [Mon, 10 Jul 2017 08:15:05 +0000 (10:15 +0200)]
event: rename event requests routines

The event request functionality is now merged with the regular
requests. Change the naming pattern for event requests and move the
prototypes under the input and output requests.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: merge event requests with regular line requests
Bartosz Golaszewski [Sat, 1 Jul 2017 17:50:11 +0000 (19:50 +0200)]
core: merge event requests with regular line requests

Requesting the lines both for reading/setting values as well as for
watching events will now be done using the gpiod_line_request_*()
family of functions.

This is the first part of changes required to fully convert the API.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agochip: lazily allocate lines
Bartosz Golaszewski [Sat, 1 Jul 2017 12:11:40 +0000 (14:11 +0200)]
chip: lazily allocate lines

Only allocate the array of line pointers is they're actually needed.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: don't duplicate chip-related data structures
Bartosz Golaszewski [Sat, 1 Jul 2017 11:54:33 +0000 (13:54 +0200)]
core: don't duplicate chip-related data structures

Introduce an internal structure - line_chip_ctx - used to store the
chip-related information. This structure is shared among all line
objects exposed by a single chip.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agosimple-api: reposition the prototypes in the public header
Bartosz Golaszewski [Sat, 1 Jul 2017 09:14:52 +0000 (11:14 +0200)]
simple-api: reposition the prototypes in the public header

Move the 'multiple' variants below the single value ones.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: line: new test case
Bartosz Golaszewski [Sat, 1 Jul 2017 09:07:13 +0000 (11:07 +0200)]
tests: line: new test case

Verify that a consumer string over 31 characters long is correctly
cropped.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agoline: remove an unnecessary check
Bartosz Golaszewski [Sat, 1 Jul 2017 08:56:06 +0000 (10:56 +0200)]
line: remove an unnecessary check

We have changed the way line objects are allocated. This check is no
longer needed.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agochip: use a temporary variable in gpiod_chip_close()
Bartosz Golaszewski [Fri, 30 Jun 2017 14:28:30 +0000 (16:28 +0200)]
chip: use a temporary variable in gpiod_chip_close()

The code looks better if we use a temporary pointer to gpiod_line.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: separate the chip and line logic
Bartosz Golaszewski [Fri, 30 Jun 2017 10:55:36 +0000 (12:55 +0200)]
core: separate the chip and line logic

Lazily allocate memory for line objects in chip.c. This eliminates the
need for chip routines to know the size of a line object.

Line objects now contain the chip file descriptor as well, so that we
don't need to access the chip object in any way from line.c.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agochip: release lines in bulk on close()
Bartosz Golaszewski [Thu, 29 Jun 2017 15:10:57 +0000 (17:10 +0200)]
chip: release lines in bulk on close()

When closing the chip use a bulk operation to release all lines.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agoline: remove stray semicolons
Bartosz Golaszewski [Thu, 29 Jun 2017 15:05:27 +0000 (17:05 +0200)]
line: remove stray semicolons

These got introduced accidentally when adding chip_get_fd().

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agochip: rename is_unsigned_int()
Bartosz Golaszewski [Thu, 29 Jun 2017 13:36:01 +0000 (15:36 +0200)]
chip: rename is_unsigned_int()

Use a shorter name for this simple routine.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agoline: coding style fix
Bartosz Golaszewski [Thu, 29 Jun 2017 13:27:27 +0000 (15:27 +0200)]
line: coding style fix

Correctly align a broken line.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: tweak some comments
Bartosz Golaszewski [Thu, 29 Jun 2017 13:23:55 +0000 (15:23 +0200)]
core: tweak some comments

Minor changes to the file header comments in the core library.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: move all line-related code to line.c and remove core.c
Bartosz Golaszewski [Thu, 29 Jun 2017 13:12:22 +0000 (15:12 +0200)]
core: move all line-related code to line.c and remove core.c

This is the final stage of splitting the core library code into
separate files.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: move chip definitions to a separate file
Bartosz Golaszewski [Wed, 28 Jun 2017 15:33:51 +0000 (17:33 +0200)]
core: move chip definitions to a separate file

Move all chip-related code to chip.c and create temporary glue-code
header for chip.c and core.c.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: kill gpiod_line_event_release()
Bartosz Golaszewski [Wed, 28 Jun 2017 14:39:36 +0000 (16:39 +0200)]
core: kill gpiod_line_event_release()

We can (and already do in gpiod_chip_close()) easily figure out if
a GPIO line was configured for events or values, so there's no need
to have a separate release function for events.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: move gpiod_version_string() to misc.c
Bartosz Golaszewski [Wed, 28 Jun 2017 14:15:04 +0000 (16:15 +0200)]
core: move gpiod_version_string() to misc.c

Create a separate .c file for misc definitions.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: move iterator definitions to a separate file
Bartosz Golaszewski [Sat, 24 Jun 2017 11:05:34 +0000 (13:05 +0200)]
core: move iterator definitions to a separate file

Move all iterator-related code to iter.c.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agosimple API: un-inline simple API routines
Bartosz Golaszewski [Sat, 24 Jun 2017 10:54:20 +0000 (12:54 +0200)]
simple API: un-inline simple API routines

Try to avoid inline functions in the public header wherever possible.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: move the simple API definitions into a separate file
Bartosz Golaszewski [Sat, 24 Jun 2017 10:48:54 +0000 (12:48 +0200)]
core: move the simple API definitions into a separate file

This is the first step in splitting up the core library code.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: kill nsec_to_timespec()
Bartosz Golaszewski [Sat, 24 Jun 2017 10:43:00 +0000 (12:43 +0200)]
core: kill nsec_to_timespec()

This function is tiny and only used in one place.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: kill zalloc() and use calloc() where applicable
Bartosz Golaszewski [Sat, 24 Jun 2017 10:37:50 +0000 (12:37 +0200)]
core: kill zalloc() and use calloc() where applicable

Remove zalloc() and use malloc() + memset() in the code. When
allocating an array of elements, use calloc(). This is done in
preparation for splitting up the core library code into separate
files.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: kill gpio_ioctl()
Bartosz Golaszewski [Sat, 24 Jun 2017 10:32:01 +0000 (12:32 +0200)]
core: kill gpio_ioctl()

We used this wrapper around ioctl() to set the libgpiod-specific error
number if the ioctl() call failed.

We no longer use custom error numbers, so remove this function.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: kill custom error handling
Bartosz Golaszewski [Sat, 24 Jun 2017 10:21:57 +0000 (12:21 +0200)]
core: kill custom error handling

The libgpiod-specific error codes are not really necessary and can be
easily replaced with regular libc error numbers defined in errno.h.

Remove all routines and definitions dealing with error numbers and
switch to using errnos in the library code.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: fix checking the kernel version
Bartosz Golaszewski [Thu, 6 Jul 2017 08:41:15 +0000 (10:41 +0200)]
tests: fix checking the kernel version

Previous check was incorrect and would break at major version change.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agolibgpiod: start 1.0 development cycle
Bartosz Golaszewski [Sat, 24 Jun 2017 09:41:19 +0000 (11:41 +0200)]
libgpiod: start 1.0 development cycle

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agolibgpiod v0.3
Bartosz Golaszewski [Fri, 23 Jun 2017 14:56:09 +0000 (16:56 +0200)]
libgpiod v0.3

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agoNEWS: updates for v0.3
Bartosz Golaszewski [Fri, 23 Jun 2017 14:52:07 +0000 (16:52 +0200)]
NEWS: updates for v0.3

Add release notes for libgpiod v0.3.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: gpiomon: new test case
Bartosz Golaszewski [Fri, 23 Jun 2017 14:42:07 +0000 (16:42 +0200)]
tests: gpiomon: new test case

Verify that gpiomon bails out if the same line offset is given more
than once.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: gpiomon: new test case for watching multiple lines
Bartosz Golaszewski [Fri, 23 Jun 2017 14:38:56 +0000 (16:38 +0200)]
tests: gpiomon: new test case for watching multiple lines

Make sure gpiomon behaves correctly when the requested line offsets
are not in order.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agogpiomon: implement monitoring multiple lines at the same time
Bartosz Golaszewski [Fri, 23 Jun 2017 09:25:13 +0000 (11:25 +0200)]
gpiomon: implement monitoring multiple lines at the same time

Switch from the simple API to low-level libgpiod routines and
implement watching multiple lines at the same time.

Update tests and README.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: event: use correct flags when requesting events
Bartosz Golaszewski [Fri, 23 Jun 2017 10:37:21 +0000 (12:37 +0200)]
core: event: use correct flags when requesting events

We must use the GPIOEVENT_REQUEST_* flags, not GPIOEVENT_EVENT_* since
the latter are only meaningful when receiving event info.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agogpioset: improve error messages
Bartosz Golaszewski [Fri, 23 Jun 2017 09:04:18 +0000 (11:04 +0200)]
gpioset: improve error messages

Say more than just the name of the failed function.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agoREADME: improve readability of examples
Bartosz Golaszewski [Thu, 22 Jun 2017 19:16:40 +0000 (21:16 +0200)]
README: improve readability of examples

We're using the same character for comments and the command prompt.
That's not very readable. Use '$' as prompt.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agoREADME: add an example of gpiomon custom output formats
Bartosz Golaszewski [Thu, 22 Jun 2017 19:11:18 +0000 (21:11 +0200)]
README: add an example of gpiomon custom output formats

In the examples section: show how to specify a custom, easily parsable
output in gpiomon.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: gpiomon: new test case
Bartosz Golaszewski [Thu, 22 Jun 2017 18:56:36 +0000 (20:56 +0200)]
tests: gpiomon: new test case

Verify that we actually ignore events we're not watching.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agoREADME: update the building section
Bartosz Golaszewski [Thu, 22 Jun 2017 18:42:11 +0000 (20:42 +0200)]
README: update the building section

Commit 6876721f7407 ("build: use a more standard autogen.sh") made
the supplied autogen execute ./configure unless the NOCONFIGURE
environment variable is set. Reflect that in the README file.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agogpiomon: simplify custom formats
Bartosz Golaszewski [Wed, 21 Jun 2017 11:47:30 +0000 (13:47 +0200)]
gpiomon: simplify custom formats

Instead of replacing the format specifiers in a separate buffer, just
make use of the output stream buffering.

Also: update the gpiomon tests with some corner cases.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: don't allocate the subprocess output buffer everytime
Bartosz Golaszewski [Wed, 21 Jun 2017 09:46:42 +0000 (11:46 +0200)]
tests: don't allocate the subprocess output buffer everytime

It's more efficient to just allocate it at testing suite's startup and
reuse it for all child processes.

While we're at it: verify that the output of subprocesses consists
of ASCII characters only.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: gpiomon: use a different unknown custom format specifier
Bartosz Golaszewski [Wed, 21 Jun 2017 08:21:44 +0000 (10:21 +0200)]
tests: gpiomon: use a different unknown custom format specifier

We previously used a character that is not interpreted by
printf()-like functions due to a bug in the testing framework.

This is now fixed, so just use %x so that we self-test the test suite
at the same time.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: fix reading the output of subprocesses
Bartosz Golaszewski [Wed, 21 Jun 2017 08:16:36 +0000 (10:16 +0200)]
tests: fix reading the output of subprocesses

We're currently using vasprintf() internally when reading the output
streams of terminated subprocesses. This routine interprets the buffer
as a printf() format string, so substrings like '%x' get converted
unintentionally.

Instead allocate a big enough buffer and just read the output without
any modifications.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agogpiomon: fix parsing of custom output formats
Bartosz Golaszewski [Tue, 20 Jun 2017 18:03:33 +0000 (20:03 +0200)]
gpiomon: fix parsing of custom output formats

The '%%e' string should be printed as '%e' - the same as for printf()
format specifiers - but gpiomon prints '%%e' in this case. Fix it.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agoconfigure: tests: require versions of libkmod & libudev known to work
Bartosz Golaszewski [Tue, 20 Jun 2017 13:00:03 +0000 (15:00 +0200)]
configure: tests: require versions of libkmod & libudev known to work

When building tests: require libkmod and libudev versions to be at
least 18 & 215 respectively. These versions are shipped with debian
jessie and are known to work.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agoconfigure: check for regex functions when building tests
Bartosz Golaszewski [Tue, 20 Jun 2017 08:36:16 +0000 (10:36 +0200)]
configure: check for regex functions when building tests

Check if regexec() is available if we need to build the test suite.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: add a FIXME comment
Bartosz Golaszewski [Mon, 19 Jun 2017 19:26:29 +0000 (21:26 +0200)]
tests: add a FIXME comment

Reading output from child processes should be fixed at some point to
ignore printf() format specifiers.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agogpiomon: implement custom output formats
Bartosz Golaszewski [Thu, 15 Jun 2017 07:23:13 +0000 (09:23 +0200)]
gpiomon: implement custom output formats

Add a new argument allowing the user to specify the format of the
output string printed on GPIO line events.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: fix subprocess cleanup when dying
Bartosz Golaszewski [Thu, 15 Jun 2017 06:31:49 +0000 (08:31 +0200)]
tests: fix subprocess cleanup when dying

We need to kill the tool subprocess when bailing out during tests
everytime, not only when an error during test_tool_wait() occurs.

Also: we need to wait() for killed processes too as otherwise we may
end up calling delete_module() before the process actually stops using
gpio-mockup giving us a nasty error message from libkmod and leaving
the module in memory.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: fix the error message when dying during test's execution
Bartosz Golaszewski [Thu, 15 Jun 2017 05:52:42 +0000 (07:52 +0200)]
tests: fix the error message when dying during test's execution

If die() or die_perr() is called during a test case, print an
additional newline character so that the error message is displayed
below the test description.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agoNEWS: updates for v0.2.1
Bartosz Golaszewski [Wed, 14 Jun 2017 11:52:13 +0000 (13:52 +0200)]
NEWS: updates for v0.2.1

Add release notes for libgpiod v0.2.1.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: gpiomon: more test cases
Bartosz Golaszewski [Wed, 14 Jun 2017 11:07:35 +0000 (13:07 +0200)]
tests: gpiomon: more test cases

Add various test cases for gpiomon. Testing invalid input, active-low
mode, termination on signals etc.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agogpiomon: don't ignore superfluous arguments
Bartosz Golaszewski [Wed, 14 Jun 2017 10:53:19 +0000 (12:53 +0200)]
gpiomon: don't ignore superfluous arguments

We don't currently support watching more than one line at a time. Bail
out if the user gives us more than two non-option arguments.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agogpiomon: capitalize 'GPIO' in error message
Bartosz Golaszewski [Wed, 14 Jun 2017 10:44:31 +0000 (12:44 +0200)]
gpiomon: capitalize 'GPIO' in error message

Stay consistent with other error strings.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: gpiomon: check the whole output string
Bartosz Golaszewski [Wed, 14 Jun 2017 10:22:02 +0000 (12:22 +0200)]
tests: gpiomon: check the whole output string

Add the 'event:' prefix to the regex pattern when checking the output
of gpiomon.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: gpiomon: new test cases
Bartosz Golaszewski [Wed, 14 Jun 2017 08:37:56 +0000 (10:37 +0200)]
tests: gpiomon: new test cases

Add test cases verifying the --silent mode and receiving
multiple events.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agogpiomon: fix the displayed name for falling edge events
Bartosz Golaszewski [Wed, 14 Jun 2017 08:28:57 +0000 (10:28 +0200)]
gpiomon: fix the displayed name for falling edge events

Remove the unnecessary underscore.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: don't hardcode the chip names
Bartosz Golaszewski [Wed, 14 Jun 2017 08:11:27 +0000 (10:11 +0200)]
tests: don't hardcode the chip names

Use test_chip_name() to get the name of a chip. Don't hardcode it as
it will make the tests not work if any gpiochips other than the ones
created by gpio-mockup already exist in the system.

This also fixes a couple hidden bugs, where we requested inexistent
chips in tools' command-line arguments.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: gpiomon: test a single rising edge event
Bartosz Golaszewski [Wed, 14 Jun 2017 07:55:58 +0000 (09:55 +0200)]
tests: gpiomon: test a single rising edge event

Add a simple test case checking if gpiomon can receive a single rising
edge event.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: gpioget: fix potential crash
Bartosz Golaszewski [Wed, 14 Jun 2017 07:00:53 +0000 (09:00 +0200)]
tests: gpioget: fix potential crash

We're writing outside the values array. Fix the index.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: chip: fix potential segfault
Bartosz Golaszewski [Wed, 14 Jun 2017 05:48:00 +0000 (07:48 +0200)]
tests: chip: fix potential segfault

The automatically cleaned up string is not initialized, but if
asprintf() failed, its contents would be undefined which could lead
to a segmentation fault.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: iter: fix potential segfault
Bartosz Golaszewski [Tue, 13 Jun 2017 20:04:13 +0000 (22:04 +0200)]
tests: iter: fix potential segfault

All automatically cleaned up variables must be initialized. Otherwise
we risk calling free() on an uninitialized pointer if an assertion
fails before we assign it a value.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: gpioinfo: improve test descriptions
Bartosz Golaszewski [Tue, 13 Jun 2017 19:52:05 +0000 (21:52 +0200)]
tests: gpioinfo: improve test descriptions

Explain more precisely what we're actually testing.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: gpioinfo: test incorrect input
Bartosz Golaszewski [Tue, 13 Jun 2017 19:44:27 +0000 (21:44 +0200)]
tests: gpioinfo: test incorrect input

Check if gpioinfo behaves correctly if the chip for which we want the
info dumped doesn't exist.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: gpioinfo: test cases for printing info about specific chips
Bartosz Golaszewski [Tue, 13 Jun 2017 19:32:59 +0000 (21:32 +0200)]
tests: gpioinfo: test cases for printing info about specific chips

Add test cases checking if gpioinfo correctly dumps info if we specify
only certain chips over command-line and omits the ones we don't
request.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: new assertions
Bartosz Golaszewski [Tue, 13 Jun 2017 19:29:16 +0000 (21:29 +0200)]
tests: new assertions

Add two new string-related assertions for tests.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotools: capitalize 'GPIO' in error messages
Bartosz Golaszewski [Tue, 13 Jun 2017 14:51:48 +0000 (16:51 +0200)]
tools: capitalize 'GPIO' in error messages

Be consistent in all error messages in gpioget & gpioset.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: gpioset: test cases for invalid arguments
Bartosz Golaszewski [Tue, 13 Jun 2017 14:41:29 +0000 (16:41 +0200)]
tests: gpioset: test cases for invalid arguments

Add various test cases checking the behavior of gpioset when given
invalid arguments.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: gpioset: test the --sec argument
Bartosz Golaszewski [Tue, 13 Jun 2017 14:32:40 +0000 (16:32 +0200)]
tests: gpioset: test the --sec argument

Make sure gpioset understands the --sec argument together
with --mode=time.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: gpioset: test the --active-low flag
Bartosz Golaszewski [Tue, 13 Jun 2017 14:29:41 +0000 (16:29 +0200)]
tests: gpioset: test the --active-low flag

Duplicate the basic exit mode test but use the --active-low flag and
verify that the values are inverted.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: gpioset: test the 'time' mode
Bartosz Golaszewski [Tue, 13 Jun 2017 14:25:00 +0000 (16:25 +0200)]
tests: gpioset: test the 'time' mode

Order gpioset to wait for 100 milliseconds before exiting, then sleep
for 200 milliseconds before checking if it exited correctly.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: gpioset: test case for the 'signal' mode
Bartosz Golaszewski [Tue, 13 Jun 2017 13:15:45 +0000 (15:15 +0200)]
tests: gpioset: test case for the 'signal' mode

Run gpioset on a set of lines, give it a couple milliseconds to
execute, then send it SIGTERM and check that it exits correctly.

Repeat for SIGINT.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: improve sigprocmask()-related error messages
Bartosz Golaszewski [Tue, 13 Jun 2017 13:00:29 +0000 (15:00 +0200)]
tests: improve sigprocmask()-related error messages

When sigprocmask() fails for how=SIG_BLOCK|SIG_UNBLOCK, say explicitly
we were unable to block/unblock SIGCHLD.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: unblock SIGCHLD after closing the signalfd
Bartosz Golaszewski [Tue, 13 Jun 2017 12:58:20 +0000 (14:58 +0200)]
tests: unblock SIGCHLD after closing the signalfd

Restore the state from before running the subprocess.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: gpioset: check the 'exit' mode explicitly
Bartosz Golaszewski [Mon, 12 Jun 2017 20:28:08 +0000 (22:28 +0200)]
tests: gpioset: check the 'exit' mode explicitly

Duplicate the previous 'exit' mode test but pass the mode argument
explicitly to gpioset.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: read siginfo after receiving SIGCHLD
Bartosz Golaszewski [Mon, 12 Jun 2017 20:25:09 +0000 (22:25 +0200)]
tests: read siginfo after receiving SIGCHLD

If we don't actually read the signal info, the signals pile up after
every child process exits even if we close the sigfd.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: gpioset: test the 'wait' mode
Bartosz Golaszewski [Mon, 12 Jun 2017 20:04:04 +0000 (22:04 +0200)]
tests: gpioset: test the 'wait' mode

Verify the behavior of gpioset in the 'wait' mode. Send a newline
to gpioset's standard input and check if it correctly exits.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: provide test_tool_stdin_write()
Bartosz Golaszewski [Mon, 12 Jun 2017 20:02:37 +0000 (22:02 +0200)]
tests: provide test_tool_stdin_write()

Implement a routine allowing the test code to write a formatted string
to the child process' standard input.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: gpioget: test the --active-low flag
Bartosz Golaszewski [Mon, 12 Jun 2017 19:44:13 +0000 (21:44 +0200)]
tests: gpioget: test the --active-low flag

Read all lines, change their values and re-read but this time pass
the --active-low flag to gpioget.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: add a simple test case for gpioset
Bartosz Golaszewski [Mon, 12 Jun 2017 19:38:04 +0000 (21:38 +0200)]
tests: add a simple test case for gpioset

Verify the 'exit' mode of gpioset.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: check reading specific lines with gpioget
Bartosz Golaszewski [Mon, 12 Jun 2017 19:11:02 +0000 (21:11 +0200)]
tests: check reading specific lines with gpioget

Add a test case where we only read a couple GPIO line values at
specified offsets.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: new test case for gpioget
Bartosz Golaszewski [Mon, 12 Jun 2017 19:01:10 +0000 (21:01 +0200)]
tests: new test case for gpioget

Verify that gpioget correctly bails out if the user requested to read
more GPIO lines than the number exposed by the chip.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: use calloc() where applicable
Bartosz Golaszewski [Mon, 12 Jun 2017 18:44:03 +0000 (20:44 +0200)]
tests: use calloc() where applicable

Introduce xcalloc() and use it whenever we're allocating an array
of elements.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: new test cases for gpioget
Bartosz Golaszewski [Mon, 12 Jun 2017 18:34:33 +0000 (20:34 +0200)]
tests: new test cases for gpioget

Verify the correct behavior of gpioget on invalid arguments.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: add a test case for gpioget
Bartosz Golaszewski [Mon, 12 Jun 2017 17:58:21 +0000 (19:58 +0200)]
tests: add a test case for gpioget

Add a simple test case for gpioget: read all lines at their initial
state, change the values of some of them and re-read.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: rename test_gpiotool_run()
Bartosz Golaszewski [Mon, 12 Jun 2017 10:52:53 +0000 (12:52 +0200)]
tests: rename test_gpiotool_run()

Use the same prefix for all functions for tools testing.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: new test case for gpiodetect
Bartosz Golaszewski [Mon, 12 Jun 2017 10:51:30 +0000 (12:51 +0200)]
tests: new test case for gpiodetect

Verify that we bail out if the user passes any non-option argument
to gpiodetect.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: verify the behavior of gpiofind in case of invalid arguments
Bartosz Golaszewski [Mon, 12 Jun 2017 10:46:04 +0000 (12:46 +0200)]
tests: verify the behavior of gpiofind in case of invalid arguments

Make sure we bail out with the correct error message when the user
doesn't give us exactly one GPIO line name.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agogpiofind: tweak the error message on invalid arguments
Bartosz Golaszewski [Mon, 12 Jun 2017 10:41:48 +0000 (12:41 +0200)]
gpiofind: tweak the error message on invalid arguments

We print the same error message in case of too many or not enough
arguments. Make the message appropriate for both cases.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: fix a potential segfault
Bartosz Golaszewski [Mon, 12 Jun 2017 09:01:52 +0000 (11:01 +0200)]
tests: fix a potential segfault

A string passed to test_free_str() must be allocated by malloc() or
NULL, so we need to initialize ptrn.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: fix a memory leak
Bartosz Golaszewski [Sun, 11 Jun 2017 18:15:50 +0000 (20:15 +0200)]
tests: fix a memory leak

We don't free the string allocated by asprintf() in a test case for
gpioinfo. Fix it.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: fix a test case for gpiofind
Bartosz Golaszewski [Sun, 11 Jun 2017 18:13:04 +0000 (20:13 +0200)]
tests: fix a test case for gpiofind

We must not hardcode the chip names. Use test_chip_name() instead.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: add a missing assertion
Bartosz Golaszewski [Fri, 9 Jun 2017 15:34:05 +0000 (17:34 +0200)]
tests: add a missing assertion

asprintf() can fail. Check its return value.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: improve the test names
Bartosz Golaszewski [Fri, 9 Jun 2017 15:29:54 +0000 (17:29 +0200)]
tests: improve the test names

Make the names of the gpiotools test cases more informative.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: new test case for gpioinfo
Bartosz Golaszewski [Fri, 9 Jun 2017 15:27:58 +0000 (17:27 +0200)]
tests: new test case for gpioinfo

Check if we correctly report exported lines.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: tweak test output
Bartosz Golaszewski [Fri, 9 Jun 2017 08:55:53 +0000 (10:55 +0200)]
tests: tweak test output

Tweak the log message header a bit: instead of having a fixed width
of the contents between the brackets in the header, fix the length of
the whole header to 8 characters.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: add test cases for gpiofind
Bartosz Golaszewski [Fri, 9 Jun 2017 07:42:04 +0000 (09:42 +0200)]
tests: add test cases for gpiofind

Verify the correct behavior of gpiofind in two cases: when it can find
a GPIO line by name and when the requested line doesn't exist.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: improve the version string test
Bartosz Golaszewski [Thu, 8 Jun 2017 13:26:24 +0000 (15:26 +0200)]
tests: improve the version string test

Use the recently introduced regex matching function to verify that
the version string has a correct format.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: don't request gpio-mockup chips for the version string test
Bartosz Golaszewski [Thu, 8 Jun 2017 13:20:00 +0000 (15:20 +0200)]
tests: don't request gpio-mockup chips for the version string test

Change the line sizes list into an empty array.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: add a test case for gpioinfo
Bartosz Golaszewski [Thu, 8 Jun 2017 13:19:01 +0000 (15:19 +0200)]
tests: add a test case for gpioinfo

Add a simple test for gpioinfo.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: add regex handling
Bartosz Golaszewski [Thu, 8 Jun 2017 13:11:45 +0000 (15:11 +0200)]
tests: add regex handling

Add a routine allowing to check if a string contains a substring
matching against given regex pattern.

Also: add a corresponding assertion.

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