qemu-gpiodev/libgpiod.git
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>
7 years agolibgpiod v0.2
Bartosz Golaszewski [Tue, 9 May 2017 17:58:30 +0000 (19:58 +0200)]
libgpiod v0.2

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agoNEWS: updates for v0.2
Bartosz Golaszewski [Mon, 8 May 2017 16:14:42 +0000 (18:14 +0200)]
NEWS: updates for v0.2

Add release notes for libgpiod v0.2.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agoNEWS: wrap lines at 80 characters
Bartosz Golaszewski [Mon, 8 May 2017 16:05:37 +0000 (18:05 +0200)]
NEWS: wrap lines at 80 characters

Stick to the same standards everywhere in the project.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: add test cases for line events
Bartosz Golaszewski [Mon, 8 May 2017 15:01:24 +0000 (17:01 +0200)]
tests: add test cases for line events

Verify that low-level routines for line events work correctly.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: fix a dmesg error message from gpio-mockup
Bartosz Golaszewski [Mon, 8 May 2017 14:36:53 +0000 (16:36 +0200)]
tests: fix a dmesg error message from gpio-mockup

When checking if we can load gpio-mockup, we don't pass the
gpio_mockup_ranges argument to the module. This makes probe() fail
and causes an error message to be emitted.

Pass a correct argument to gpio-mockup so that a dummy GPIO chip gets
created and no errors are displayed.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: add a test case for misc line flags
Bartosz Golaszewski [Mon, 8 May 2017 11:16:29 +0000 (13:16 +0200)]
tests: add a test case for misc line flags

Test the open drain, open source and kernel flags.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: move the test case execution into a separate function
Bartosz Golaszewski [Mon, 8 May 2017 09:28:27 +0000 (11:28 +0200)]
tests: move the test case execution into a separate function

For better readability move the code executing the test case into a
separate function - between the setup and teardown routines.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: add new assertion
Bartosz Golaszewski [Fri, 5 May 2017 17:20:28 +0000 (19:20 +0200)]
tests: add new assertion

GU_ASSERT_FALSE() checks if given statement evaluates to false.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: add a test case for gpiod_line_active_state()
Bartosz Golaszewski [Fri, 5 May 2017 17:07:35 +0000 (19:07 +0200)]
tests: add a test case for gpiod_line_active_state()

Verify that the active state is changed correctly depending on the
parameters of the request.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: add a test case for gpiod_line_direction()
Bartosz Golaszewski [Fri, 5 May 2017 16:57:56 +0000 (18:57 +0200)]
tests: add a test case for gpiod_line_direction()

Verify that the direction is changed properly and that a correct value
is returned from gpiod_line_direction().

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agoREADME: add some info on unit tests
Bartosz Golaszewski [Fri, 5 May 2017 15:43:06 +0000 (17:43 +0200)]
README: add some info on unit tests

Describe how to build and use the testing framework.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agolibgpiod: add the NEWS file
Bartosz Golaszewski [Fri, 5 May 2017 15:04:52 +0000 (17:04 +0200)]
libgpiod: add the NEWS file

It should have been there from the beginning but it was somehow
forgotten. Add it now - before the v0.2 release.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: add a test case for gpiod_simple_event_loop()
Bartosz Golaszewski [Tue, 2 May 2017 21:51:17 +0000 (23:51 +0200)]
tests: add a test case for gpiod_simple_event_loop()

Test a very simple use case: wait for a single event of any type.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: extend the testing framework with support for event injecting
Bartosz Golaszewski [Tue, 2 May 2017 21:50:28 +0000 (23:50 +0200)]
tests: extend the testing framework with support for event injecting

Add a routine allowing tests to specify a single event to be injected
at regular intervals.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: fix the return value of gpiod_simple_event_loop()
Bartosz Golaszewski [Tue, 2 May 2017 21:58:43 +0000 (23:58 +0200)]
core: fix the return value of gpiod_simple_event_loop()

This routine should always return 0 when no errors were encountered.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: add a test case for gpiod_line_find_by_name()
Bartosz Golaszewski [Wed, 15 Mar 2017 13:50:40 +0000 (14:50 +0100)]
tests: add a test case for gpiod_line_find_by_name()

Use the newly added support for named lines and add a test case
verifying that lines can be found by name.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: add support for named lines
Bartosz Golaszewski [Wed, 15 Mar 2017 13:48:59 +0000 (14:48 +0100)]
tests: add support for named lines

If the named_lines field is true in the test description, pass an
additional module parameter to gpio-mockup to have the GPIO lines
named.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: require at least linux v4.11
Bartosz Golaszewski [Wed, 15 Mar 2017 13:40:59 +0000 (14:40 +0100)]
tests: require at least linux v4.11

This is the first linux kernel release that supports GPIO event
injecting over debugfs. Make it a hard requirement for running tests.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agobuild: readability tweak for the unit tests make message
Bartosz Golaszewski [Thu, 16 Mar 2017 13:26:18 +0000 (14:26 +0100)]
build: readability tweak for the unit tests make message

Shift the text one character right for better readability.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: sort mockup chips by number, not by name
Bartosz Golaszewski [Tue, 14 Mar 2017 16:52:24 +0000 (17:52 +0100)]
tests: sort mockup chips by number, not by name

If we request more than 9 chips for a test case, we'll run into
a problem: 'gpiochip10' will come before 'gpiochip2' when sorting by
name.

Sort by chip number instead - it's stored as an unsigned integer and
the above situation will not occur.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: print an info message after building tests
Bartosz Golaszewski [Wed, 8 Mar 2017 14:09:27 +0000 (15:09 +0100)]
tests: print an info message after building tests

We can't automatically run unit tests from 'make check' as the test
executable works together with the gpio-mockup kernel module. Without
any additional udev configuration /dev/gpiochipX files are only
accessible for superuser.

Print a message explaining what to do after the tests are built.

NOTE: the message says that linux kernel >=v4.11 is needed to run the
tests. This is not true currently, as we don't test events yet. Event
injecting over debugfs is a new feature of gpio-mockup and will be
available in the upcoming kernel release.

Once v4.11 is released and appropriate test cases implemented, we'll
make it a hard requirement for tests.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agobuild: use a more standard autogen.sh
Thierry Reding [Tue, 7 Mar 2017 13:52:47 +0000 (14:52 +0100)]
build: use a more standard autogen.sh

This version of the autogen.sh script allows execution from a sub-
directory and will automatically run the configure script that it has
generated. This is useful for out-of-tree and cross builds.

Signed-off-by: Thierry Reding <treding@nvidia.com>
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agobuild: store m4 files in an `m4' subdirectory
Thierry Reding [Tue, 7 Mar 2017 13:49:47 +0000 (14:49 +0100)]
build: store m4 files in an `m4' subdirectory

This is similar to the AUX directory that the autotools use to put
their files into, except that the `m4' directory will contain
autoconf macro files.

Signed-off-by: Thierry Reding <treding@nvidia.com>
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agobuild: check for udev and kmod using pkg-config
Thierry Reding [Tue, 7 Mar 2017 13:40:40 +0000 (14:40 +0100)]
build: check for udev and kmod using pkg-config

Using AC_CHECK_LIB is dangerous because it modifies the global LIBS
variable that will be passed to each linker invocation. If care is not
taken, each binary will end up depending on libraries listed in this
variable.

A typical way to avoid this is to save and restore the LIBS variable
before and after the AC_CHECK_LIB function, respectively. That's quite
tedious, though, and often a better solution is to detect the presence
as well as compile and linker flags with pkg-config. This can be done
using the PKG_CHECK_MODULES autoconf macro.

Both udev and kmod ship pkg-config files, so use PKG_CHECK_MODULES for
them.

Signed-off-by: Thierry Reding <treding@nvidia.com>
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: fix out-of-tree builds
Thierry Reding [Tue, 7 Mar 2017 13:39:03 +0000 (14:39 +0100)]
tests: fix out-of-tree builds

When building out of tree, the config.h header file and the
libgpiod.la file are generated in the build rather than the
source directory.

While at it, link to libgpiod.la directly rather than via the
-L and -l linker options to enable extra libtool magic.

Signed-off-by: Thierry Reding <treding@nvidia.com>
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: make gpiod-unit.h a source for gpiod-unit
Thierry Reding [Tue, 7 Mar 2017 14:01:06 +0000 (15:01 +0100)]
tests: make gpiod-unit.h a source for gpiod-unit

Listing gpiod-unit.h as a source for the gpiod-unit binary ensures that
it is properly tracked as a dependency and that it will be included in
distribution tarballs.

Signed-off-by: Thierry Reding <treding@nvidia.com>
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agogitignore: add libtools-common.la
Bartosz Golaszewski [Tue, 7 Mar 2017 10:07:37 +0000 (11:07 +0100)]
gitignore: add libtools-common.la

Add the new convencience library created for gpio-tools to gitignore.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotools: build convenience library
Thierry Reding [Mon, 6 Mar 2017 22:35:36 +0000 (23:35 +0100)]
tools: build convenience library

Build a convenience library to avoid having to add the tools-common.c
source file for each of the tools.

This also has the side-effect of fixing 'make distcheck' because the
tools-common.h header file is now included in the source tarball.

Signed-off-by: Thierry Reding <treding@nvidia.com>
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotools: fix out-of-tree builds
Thierry Reding [Mon, 6 Mar 2017 22:27:41 +0000 (23:27 +0100)]
tools: fix out-of-tree builds

When building out of tree, the config.h header file and the libgpiod.la
file are generated in the build rather than the source directory.

While at it, link to libgpiod.la directly rather than via the -L and -l
linker options to enable extra libtool magic.

Signed-off-by: Thierry Reding <treding@nvidia.com>
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agocore: fix out-of-tree builds
Thierry Reding [Mon, 6 Mar 2017 22:14:39 +0000 (23:14 +0100)]
core: fix out-of-tree builds

When building out of tree, the config.h header file is generated in the
build directory rather than the source directory.

Signed-off-by: Thierry Reding <treding@nvidia.com>
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: new test case for chip iterators
Bartosz Golaszewski [Thu, 2 Mar 2017 16:25:43 +0000 (17:25 +0100)]
tests: new test case for chip iterators

Verify that we can correctly break a loop in gpiod_foreach_chip().

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: add a test case for gpiod_line_consumer()
Bartosz Golaszewski [Thu, 2 Mar 2017 16:19:33 +0000 (17:19 +0100)]
tests: add a test case for gpiod_line_consumer()

Verify that we get the correct consumer info after requesting a line.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: add a test case for busy lines
Bartosz Golaszewski [Thu, 2 Mar 2017 16:03:56 +0000 (17:03 +0100)]
tests: add a test case for busy lines

Run a scenario in which we try to request a line twice and verify that
the second attempt fails.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agocore: fix checking for busy lines
Bartosz Golaszewski [Thu, 2 Mar 2017 15:59:27 +0000 (16:59 +0100)]
core: fix checking for busy lines

If we have a bulk object containing only a single line passed to
verify_line_bulk(), we end up not checking if the line was previously
requested.

Fix it by starting the iteration at offset 0 instead of 1 and skipping
the line owner check for i == 0.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
8 years agotests: remove gu_release_line()
Bartosz Golaszewski [Thu, 2 Mar 2017 10:30:04 +0000 (11:30 +0100)]
tests: remove gu_release_line()

There cannot be any memory leaks if we don't release a line as long
as we close the gpiochip handle. Remove all code releasing lines on
errors.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
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>