Testing libblockdev

libblockdev's test suite is written using the standard unittest.TestCase framework in Python. Tests are separated in modules, usually one per libblockdev plugin - e.g. BTRFS, LVM, Crypto. There are one or more base classes in each module used to setup the environment and perform some testing. More specific test scenarios inherit from these base classes.

Before running the tests you have to prepare your system so that libblockdev can be built from source.

Install all build requirements. On Fedora this can be done with


cat dist/libblockdev.spec.in | grep BuildRequires: | cut -f2 -d: | cut -f2 -d' ' | xargs dnf -y install
      

Configure the build scripts

./autogen.sh
./configure

To execute the Pylint code analysis tool run:

make check

The check target is a dependency of all test targets and you don't have to execute it explicitly when testing.

To execute the test suite from inside the source directory run one of these commands:

make test

executes all safe tests or

make fast-test

executes all fast tests or

make test-all

executes all tests, including ones which may result in kernel panic or take more time to complete.

It is also possible to generate test coverage reports using the Python coverage tool:

make coverage

is equivalent to `make test'.

make coverage-all

is equivalent to `make test-all'.

libblockdev also supports running the test and coverage targets using Python3. To do this define the PYTHON or COVERAGE variables respectively. For example:

make PYTHON=python3 test

make COVERAGE=coverage3 coverage