qemu-gpiodev/libgpiod.git
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>
7 years agotests: request 0 chips for the error handling test case
Bartosz Golaszewski [Thu, 8 Jun 2017 11:26:42 +0000 (13:26 +0200)]
tests: request 0 chips for the error handling test case

We now support having no gpio-mockup chips for test cases. Update the
error handling test.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: allow having zero gpio-mockup chips for tests
Bartosz Golaszewski [Thu, 8 Jun 2017 11:24:36 +0000 (13:24 +0200)]
tests: allow having zero gpio-mockup chips for tests

We may have tests which don't require any gpio-mockup chips to be
present. When an empty array is given as the list of chip line counts,
the gpio-mockup module will not be loaded.

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

Use the newly added API for subprocesses to test a simple use case
of the gpiodetect tool.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: add infrastructure for testing the tools
Bartosz Golaszewski [Thu, 8 Jun 2017 10:50:02 +0000 (12:50 +0200)]
tests: add infrastructure for testing the tools

Implement new routines allowing to start an external process and
retrieve its output.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: new assertion
Bartosz Golaszewski [Thu, 25 May 2017 14:32:50 +0000 (16:32 +0200)]
tests: new assertion

Add a new test macro which checks if given string contains a specific
substring using strstr().

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agoREADME: explain what gpiod stands for
Bartosz Golaszewski [Wed, 7 Jun 2017 16:08:47 +0000 (18:08 +0200)]
README: explain what gpiod stands for

In case someone incorrectly thinks it stands for 'GPIO daemon'.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: tweak test output
Bartosz Golaszewski [Tue, 16 May 2017 20:45:21 +0000 (22:45 +0200)]
tests: tweak test output

Say PASS instead of OK when a test is passed.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: tweak the event worker
Bartosz Golaszewski [Tue, 16 May 2017 11:30:05 +0000 (13:30 +0200)]
tests: tweak the event worker

The event worker thread should only inject another line event if
pthread_cond_timedwait() returned -ETIMEDOUT. If it returned 0, then
the main thread called pthread_cond_broadcast() and either requested
the worker thread to terminate or to change the event configuration.

In both cases we should not inject an event.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: only cleanup the gpio-mockup module from the main process
Bartosz Golaszewski [Tue, 16 May 2017 09:14:45 +0000 (11:14 +0200)]
tests: only cleanup the gpio-mockup module from the main process

In preparation for adding support for subprocesses: store the pid of
the main process and use it such that we don't try to unload the
mockup module twice leading to a splat from libkmod.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: convert named_lines into a general 'flags' field
Bartosz Golaszewski [Sun, 14 May 2017 14:49:47 +0000 (16:49 +0200)]
tests: convert named_lines into a general 'flags' field

We currently have the boolean 'named_lines' field in the test
description structure. Convert it to an integer in order to allow
passing multiple test switches in the future.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: rename a couple static functions
Bartosz Golaszewski [Sun, 14 May 2017 14:38:57 +0000 (16:38 +0200)]
tests: rename a couple static functions

We use the 'test_' prefix to mark the testing framework API
definitions. Don't use it for static functions in gpiod-test.c.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: put the printf attribute in the header for _test_print_failed()
Bartosz Golaszewski [Sun, 14 May 2017 11:37:51 +0000 (13:37 +0200)]
tests: put the printf attribute in the header for _test_print_failed()

If the printf attribute is only present next to the function's
definition, the compiler only checks the calls in the same compilation
unit.

In order to verify all the calls, annotate the declaration of
_test_print_failed() in gpiod-test.h.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: make test_func private
Bartosz Golaszewski [Sun, 14 May 2017 11:06:40 +0000 (13:06 +0200)]
tests: make test_func private

The test callback prototype should not be used by the test code, so
prefix it with an underscore to indicate that.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: change the test API prefix
Bartosz Golaszewski [Sun, 14 May 2017 09:56:19 +0000 (11:56 +0200)]
tests: change the test API prefix

The gu_ prefix stood for gpiod unit, but it's no longer valid. These
definitions are not visible outside of the tests subdirectory, so
there's no need for a unique prefix. Just start all symbols with test_
or TEST_.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: use a default consumer name
Bartosz Golaszewski [Sun, 14 May 2017 09:47:06 +0000 (11:47 +0200)]
tests: use a default consumer name

We're using the same consumer name everywhere in the tests. Hide it
behind a define.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: rename gpiod-unit to gpiod-test
Bartosz Golaszewski [Sun, 14 May 2017 09:13:42 +0000 (11:13 +0200)]
tests: rename gpiod-unit to gpiod-test

The testing framework will be reused for all kinds of tests. Also: the
tests we have are not really separated, but use external components so
calling them unit tests is wrong anyway.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: remove the unit subdirectory
Bartosz Golaszewski [Thu, 11 May 2017 10:59:08 +0000 (12:59 +0200)]
tests: remove the unit subdirectory

Initially we planned to have different subdirectories for different
kinds of tests (unit, tools etc.) but since it was decided that we'll
reuse the already existing framework for all tests (in order to avoid
having to reimplement the same functionality) we can get rid of the
unit subdirectory.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agolibgpiod: start v0.3 development cycle
Bartosz Golaszewski [Tue, 9 May 2017 18:45:49 +0000 (20:45 +0200)]
libgpiod: start v0.3 development cycle

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