1
0
mirror of https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git synced 2026-10-24 00:48:53 +03:00
Commit Graph

46 Commits

Author SHA1 Message Date
Bartosz Golaszewski
ad325c0b65 tests: split out the common test code for bash scripts
In order to allow the upcoming DBus command-line client tests to reuse the
existing bash test harness, let's put the common code into an importable
file and rename run_tool to run_prog to reflect that it now can run any
program.

Tested-by: Alexander Sverdlin <alexander.sverdlin@siemens.com>
Link: https://lore.kernel.org/r/20240812-dbus-v5-2-ead288509217@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-08-13 10:38:40 +02:00
Bartosz Golaszewski
e60e38375c tests: split out reusable test code into a local static library
In order to allow the upcoming GLib and DBus bindings to reuse the test
code, let's put all common elements into reusable libtool objects and
export the relevant symbols in internal headers.

Tested-by: Alexander Sverdlin <alexander.sverdlin@siemens.com>
Link: https://lore.kernel.org/r/20240812-dbus-v5-1-ead288509217@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-08-13 10:38:40 +02:00
Kent Gibson
0a552e7908 tests: add enable_debounce_then_edge_detection
A bug was recently discovered in the kernel that can result in the edge
event fifo not being correctly initialised and stack contents being
returned in edge events. The trigger for the bug is requesting a line with
debounce, but not edge detection, and then reconfiguring the line to
enable edge detection.

Add a test case that triggers the bug.  This will fail on kernels that
do not contain the fix for the bug.  The test is located in a new test
file, tests-kernel-uapi.c, intended to contain tests specifically
testing some aspect of the kernel uAPI, not libgpiod itself.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/20240513160031.309139-1-warthog618@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-05-15 10:59:52 +02:00
Bartosz Golaszewski
e622ed2327 tests: don't install test executables
I'm not sure what historical reasons there were to install test programs
if they are built but now I can't see any anymore. Tests can be run from
the build directory and users such as meta-openembedded can install them
and the relevant libraries (libgpiosim) manually into the filesystem as
they don't usually live in ${bindir} anyway. Installing test binaries just
pollutes the filesystem now so stop doing it.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-04-17 11:16:42 +02:00
Bartosz Golaszewski
dc746daef2 tests: drop the profiling CFLAGS from tests' Makefile
We only need the profiling flags on the library, we don't need to
generate gcov data for the test objects.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-03-16 09:24:47 +01:00
Bartosz Golaszewski
daaa6964c9 tests: rework error handling and stop overusing g_error()
GLib recommends using g_error() only for programming errors and
unrecoverable situations. It calls abort() and triggers a core dump. This
means that if we encounter an error when running a test case, we'll
exit immediately and leave a "leaked" GPIO simulator in configfs.

Rework the error handling: use g_error() only when a programming bug is
encountered (e.g. invalid enum value) while everywhere else use the
regular GError-based error handling. This way, in case of an error in
libgpiosim, we'll simply fail the current test case and release all
resources as usual.

In order not to pollute the test cases with error handling, let's hide the
actual error checking behind macros for g_gpiosim_chip_new() and
g_gpiosim_chip_get_value(). For g_gpiosim_chip_set_pull() let's just emit
a log and do nothing as the test case in question will inevitably fail if
the expected value is not correctly read back.

In order for the chip to get a failing constructor, we need to link the
test-suite against the entire libgio, not only libgobject (for the
GInitable interface).

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-02-01 17:22:12 +01:00
Bartosz Golaszewski
40fb86ed6b build: unify the coding style of source files lists in Makefiles
Use the most common and readable convention for listing source files
in Makefiles wherever it's not consistent yet.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-01-18 16:17:18 +01:00
Bartosz Golaszewski
662d8b5781 tests: don't link against pthread explicitly
We use GLib threads now, so there's no need to link againt pthread.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2022-12-13 11:57:30 +01:00
Bartosz Golaszewski
50c3c06b82 tests: add the missing newline to tests' Makefile.am
Git complains about the missing newline in tests/Makefile.am so make
it happy and add one.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2022-12-12 19:22:19 +01:00
Bartosz Golaszewski
b7ba732e6a treewide: libgpiod v2 implementation
This commit is the result of a squash of all the commits created during
the development of libgpiod v2. This is done to preserve bisectability
of the git tree. It contains significant re-writes of the core C library
as well as C++ and python bindings. The tools have been adjusted to work
with the new API but have not undergone significant changes yet.

This commit contains the bulk of the work on libgpiod v2 but the
development continues with more changes planned.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
[Ben: fix format specifier for uint64_t]
Signed-off-by: Ben Hutchings <ben.hutchings@mind.be>
[Viresh: Fix ioctl number for gpiod_line_request_reconfigure_lines()]
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
[Kent: bug fixes, improvements, better pointer contracts, type strictness]
Signed-off-by: Kent Gibson <warthog618@gmail.com>
2022-10-31 11:15:14 +01:00
Bartosz Golaszewski
d2327948c6 tests: port C tests to libgpiosim
This converts the core library tests to using libgpiosim instead of
libgpiod-mockup while keeping the same interface for tests.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
2022-02-10 14:42:50 +01:00
Bartosz Golaszewski
a2f6e8cd35 libgpiosim: new library for controlling the gpio-sim module
Add a C library for controlling the gpio-sim kernel module from various
libgpiod test suites. This aims at replacing the old gpio-mockup module
and its user-space library - libgpio-mockup - in the project's tree.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
2022-02-10 14:42:44 +01:00
Bartosz Golaszewski
0949b0cd95 tests: remove line bulk test cases
Together with the removal of line objects, we'll entirely drop the
line bulk concept. In order to avoid having to update tests that will
soon be unneeded when introducing further changes, let's remove line
bulk test cases already.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2021-03-18 09:34:15 +01:00
Bartosz Golaszewski
154e7c5a82 licensing: relicense non-library code under GPL-2.0-or-later
LGPL-2.1 is a license meant for shared libraries. Because I didn't know
any better I used it for all files in the repository, including programs
linking against libgpiod. The standard approach for many similar projects
is to use LGPL for library code and GPL for programs (and also Makefiles
and other files containing code or configuration).

Relicense all programs, tests, makefiles and autotools files under
GPL-2.0 or later.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Acked-by: Kent Gibson <warthog618@gmail.com>
2021-02-18 17:42:12 +01:00
Bartosz Golaszewski
dfb707c255 licensing: make the project REUSE-compliant
In order to make the licensing situation of libgpiod clear and enable
easy reusing of the code, let's make all the files in the repository
compliant with the REUSE v3.0 specification.

In order to achieve that:
  - put all used licenses into a separate LICENSES/ directory
  - add SPDX license identifiers to all files that were missing them with
    regular text files being licensed under CC-BY-SA-4.0, while files
    containing code and configuration are licensed under GPL-2.0-or-later
  - replace custom copyright texts with SPDX-FileCopyrightText
  - update the gpio.h kernel uAPI header with the upstream version where
    the SDPX license identifier was fixed to use 'GPL-2.0-only' variant
    instead of the deprecated 'GPL-2.0'

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Acked-by: Kent Gibson <warthog618@gmail.com>
2021-02-18 17:42:08 +01:00
Bartosz Golaszewski
d0a9ddcb9c core: kill chip iterators
Chip iterators require the user to have permission to access all GPIO
chips. They also don't take into account symbolic links. In general
they're badly designed so remove them treewide in favor of scanning /dev
manually using the provided gpiod_is_gpiochip_device() helper.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-12-14 15:57:15 +01:00
Bartosz Golaszewski
5489e2b7ea build: drop the message about tests having been built successfully
This is a leftover from early times. We now have multiple different
test suites and none prints such a message. Drop it.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2020-12-14 15:56:34 +01:00
Bartosz Golaszewski
9b6e6d2686 ctxless: drop all context-less interfaces
The context-less family of functions seems to be largely unused.
Drop this part of the codebase and convert tools to using the regular
low-level API.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2020-11-18 09:25:49 +01:00
Bartosz Golaszewski
2b02d7ae1a treewide: rework struct gpiod_line_bulk
Current implementation of struct gpiod_line_bulk uses stack memory
excessively. The structure is big: it's an array 64 pointers + 4 bytes
size. That amounts to 260 bytes on 32-bit and 516 bytes on 64-bit
architectures respectively. It's also used everywhere as all functions
dealing with single lines eventually end up calling bulk counterparts.

The rework addresses it by making the bulk structure opaque and
providing appropriate interfaces for library users while retaining a way
for internal users to allocate single line bulks on the stack.

The macro-based loop has been removed. In its place we provide a function
iterating over all lines held by a bulk and calling the provided callback
function for each line.

Since bulk operations can now fail, a bunch of test-cases has been added
to cover the relevant code.

While at it: using the word offset both when referring to line's HW
offset in a chip as well as the offset in a bulk leads to confusion.
This patch renames the bulk offset to index.

Some additional improvements to the patch by:
  Kent Gibson <warthog618@gmail.com>

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2020-11-04 16:39:09 +01:00
Bartosz Golaszewski
c89e9565cf build: use the gnu89 C standard explicitly
We're already using it implicitly but GCC may change the default
standard to gnu99 at some point, so use gnu89 explicitly whenever
building C files.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2020-03-17 18:08:36 +01:00
Bartosz Golaszewski
1f0d078c83 build: tweak formatting of multi-line variables in Makefiles
Don't put a tab between the asignment and the first string - just move
the whole list one line below.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2019-09-10 10:43:24 +02:00
Bartosz Golaszewski
ab5b56bb25 tests: specify G_LOG_DOMAIN
We're using GLib for tests so let's specify a log domain for the
test-suit code.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2019-08-21 09:47:41 +02:00
Bartosz Golaszewski
9c5a6f31eb tests: use GLib for library test cases and bats for gpio-tools
This replaces the custom hand-crafted testing suite with well-known
open-source tools while keeping the same coverage. The core library
is now tested using the GLib unit testing framework. The gpio-tools
are now tested in bash using the bats testing system instead of being
invoked from a C program.

This simplifies and shrinks the testing code and makes it less prone
to bugs.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2019-08-01 17:31:31 +02:00
Bartosz Golaszewski
dbc056eac0 tests: build: fix the name of the test executable displayed by Makefile
The test suite Makefile prints a help message after building the test
executable but the name of the program is wrong. Fix it.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2019-07-11 10:39:03 +02:00
Bartosz Golaszewski
b8659e044d tests: use libgpiomockup
Now that all the gpio-mockup support lives in a separate library we
can drop a lot of code from the testing framework.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2019-06-05 12:06:32 +02:00
Bartosz Golaszewski
e43e46d4f7 tests: mockup: add a library for controlling the gpio-mockup module
In order to both switch to glib unit testing framework for core
libgpiod tests as well as to cover the bindings in other languages
with proper testing while avoiding unnecessary code duplication, let's
factor out the code responsible for interaction with the gpio-mockup
module into a separate shared library.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2019-06-05 11:39:53 +02:00
Bartosz Golaszewski
0dd2125c8c tests: remove make check target
Having both --enable-tests configure option and the check make target
seems redundant and confusing. Especially since the tests won't even
run without appropriate permissions for /dev/gpiochipX anyway.

Remove the check target and the --enable-install-tests option. From now
on the tests - if enabled - are built as a regular program installed to
${prefix}/bin.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2019-06-05 11:37:38 +02:00
Anders Roxell
6cf91dd02d tests: enable installing tests to bindir
Add an enable option to configure that allows to install the testing
binary to <prefix>/bindir.

Signed-off-by: Anders Roxell <anders.roxell@linaro.org>
[Bartosz: trimmed the patch to fit the new approach]
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2019-03-20 10:49:44 +01:00
Bartosz Golaszewski
8159d9b540 treewide: rearrange source directories
The src directory containing lib and tools is not necessary and will
actually cause problems if we tried to add a new component to src/
which would depend on libraries from the bindings directory because it
(bindings) already depends on src/lib.

Simplify the directory structure. Move lib and tools to the root source
directory and update all relevant files. That way we can specify the
exact build order of components from the top source Makefile.am.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2019-03-07 13:49:00 +01:00
Anders Roxell
98a7203d86 build: use top_builddir instead of relative paths
The only instance of using a relative path for an internal library is
in tests/Makefile.am. Use top_builddir instead.

Signed-off-by: Anders Roxell <anders.roxell@linaro.org>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2019-03-01 10:13:19 +01:00
Bartosz Golaszewski
d1561302b0 build: tweak the message emitted after building tests
The kernel version displayed in the message has not been updated the
last time we bumped the kernel version required for running tests.

We don't need to print this version here - the test suite will bail-out
anyway if the kernel is too old. Drop it from the message.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-04-12 14:51:09 +02:00
Bartosz Golaszewski
b59666510f tests: use SPDX license identifier
Use the SPDX license identifier for LGPLv2.1 or later in source files
of the testing framework.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-03-04 10:38:50 +01:00
Bartosz Golaszewski
7bddc61ae5 API: use gpiod_ctxless_ as prefix for the high-level API
As suggested by Linus Walleij: the word 'simple' is generally
subjective and the high-level routines provided by libgpiod are not
necessarily simple, but rather contextless, as they don't require any
resource managemend. Use 'gpiod_ctxless_' as prefix for all high-level
symbols.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-01-26 10:36:04 +01:00
Bartosz Golaszewski
0704bcdbbf all: update the copyright notice
All these files have been updated in 2018.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-01-13 23:16:31 +01:00
Bartosz Golaszewski
7df216bf4d all: modify the license preamble in files
This project contains both a library and executables so it's better to
use an umbrella term "This program ..." than "This library ..." in all
the source files.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-01-10 01:50:36 +01:00
SZ Lin
7d61309458 all: make license type consistent between source files and COPYING file
The license type of COPYING file is "LGPL-2.1+", but it is declared
as "LGPL-2.1" in the preamble of source files.

This patch fixes license type inconsistency issue in each source file.

Signed-off-by: SZ Lin <sz.lin@moxa.com>
[Bartosz: tweaked the commit message]
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2017-12-01 18:43:54 +01:00
Bartosz Golaszewski
f0455aa13e build: fix the kernel version in the 'make check' message
The minimum kernel version for running tests is now 4.12.6. Reflect
that in the message displayed after building the test suite.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2017-09-24 10:52:55 +02:00
Bartosz Golaszewski
66dc083969 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>
2017-06-14 09:55:58 +02:00
Bartosz Golaszewski
8bba443fbc tests: add a simple test case for gpioset
Verify the 'exit' mode of gpioset.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2017-06-12 21:38:04 +02:00
Bartosz Golaszewski
6e8c4247b0 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>
2017-06-12 20:28:19 +02:00
Bartosz Golaszewski
5c70c6e184 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>
2017-06-09 10:50:43 +02:00
Bartosz Golaszewski
694e789e11 tests: add a test case for gpioinfo
Add a simple test for gpioinfo.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2017-06-08 15:19:01 +02:00
Bartosz Golaszewski
fbc58c4682 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>
2017-06-08 13:06:13 +02:00
Bartosz Golaszewski
2f5d950907 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>
2017-05-14 13:18:39 +02:00
Bartosz Golaszewski
715791a3a3 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>
2017-05-14 13:09:36 +02:00
Bartosz Golaszewski
8ff90454fc 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>
2017-02-17 14:40:43 +01:00