qemu-gpiodev/libgpiod.git
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>
8 years agocore: remove doxygen hack
Bartosz Golaszewski [Wed, 1 Mar 2017 21:16:56 +0000 (22:16 +0100)]
core: remove doxygen hack

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

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

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

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

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

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

Break the line that's longer than 80 characters.

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

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

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

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

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

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

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

Add terminal colors for improved readability of the test output.

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

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

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

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

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

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

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

This function is static so drop the prefix.

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

This function is static so drop the prefix.

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

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

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

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

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

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

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

Remove a double space in check_chip_index().

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

This macro is never used directly.

Just make it a part of GU_DEFINE_TEST().

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

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

Test cases should use provided helper macros when registering tests.

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

Add some comments to the test header file.

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

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

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

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

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

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

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

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

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

We forgot to test this one before.

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

Rename line_bulk to bulk for brevity.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Make gpiod_chip_open_lookup() also check the chip label.

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

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

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

Add first test cases for GPIO lines.

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

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

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

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

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

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

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

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

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

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

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

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

Make struct definitions consistent.

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