| 1 |
.. |
| 2 |
SPDX-License-Identifier: CC-BY-SA-4.0 |
| 3 |
SPDX-FileCopyrightText: 2025 Bartosz Golaszewski <[email protected]> |
| 4 |
|
| 5 |
.. |
| 6 |
This file is part of libgpiod. |
| 7 |
|
| 8 |
Contribution guide. |
| 9 |
|
| 10 |
Testing |
| 11 |
======= |
| 12 |
|
| 13 |
A comprehensive testing framework is included with the library and can be used |
| 14 |
to test both the core library code as well as the kernel-to-user-space |
| 15 |
interface. |
| 16 |
|
| 17 |
The minimum kernel version required to run the tests can be checked in the |
| 18 |
``tests/gpiod-test.c`` source file (it's subject to change if new features are |
| 19 |
added to the kernel). The tests work together with the **gpio-sim** kernel |
| 20 |
module which must either be built-in or available for loading using kmod. |
| 21 |
A helper library - **libgpiosim** - is included to enable straightforward |
| 22 |
interaction with the module. |
| 23 |
|
| 24 |
To build the testing executable add the ``--enable-tests`` option when running |
| 25 |
the configure script. If enabled, the tests will be installed next to |
| 26 |
**gpio-tools**. |
| 27 |
|
| 28 |
As opposed to standard autotools projects, libgpiod doesn't execute any tests |
| 29 |
when invoking ``make check``. Instead the user must run them manually with |
| 30 |
superuser privileges. |
| 31 |
|
| 32 |
The testing framework uses the **GLib unit testing** library so development |
| 33 |
package for GLib must be installed. |
| 34 |
|
| 35 |
The **gpio-tools** programs can be tested separately using the |
| 36 |
``gpio-tools-test.bash`` script. It requires `shunit2 |
| 37 |
<https://github.com/kward/shunit2>`_ to run and assumes that the tested |
| 38 |
executables are in the same directory as the script. |
| 39 |
|
| 40 |
C++, Rust and Python bindings also include their own test-suites. All three |
| 41 |
reuse the **libgpiosim** library to avoid code duplication when interacting |
| 42 |
with **gpio-sim**. |
| 43 |
|
| 44 |
Python test-suite uses the standard unittest package. C++ tests use an external |
| 45 |
testing framework - **Catch2** - which must be installed in the system. Rust |
| 46 |
bindings use the standard tests module layout and the ``#[test]`` attribute. |