# 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 or

    make test-plugin-NAME

executes only tests for given plugin and similarly

    make fast-test-plugin-NAME

executes only fast tests for given plugin.

It is also possible to run only subset of available tests or only one test using the `run_tests.py` script:

    # python3 tests/run_tests.py fs_test.GenericResize

executes all tests from the GenericResize test class from filesystem plugin test cases and

    # python3 tests/run_tests.py fs_test.GenericResize.test_ext2_generic_resize

executes only test_ext2_generic_resize from this class. This script also allows skipping slow tests or running potentially dangerous tests. Use:

    $ python3 tests/run_tests.py --help

to see all available options.

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'.