Skip to content

Commit

Permalink
Skip tests for plugins disabled during compile time
Browse files Browse the repository at this point in the history
Fixes: #943
  • Loading branch information
vojtechtrefny committed Oct 1, 2024
1 parent 3bcac3a commit e6b280e
Show file tree
Hide file tree
Showing 25 changed files with 146 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,4 @@ dist/libblockdev.spec
tools/lvm-cache-stats
tools/vfat-resize
misc/.vagrant
tests/config_h.py
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ DISTCHECK_CONFIGURE_FLAGS += --without-s390
endif


SUBDIRS = include src dist scripts data tools
SUBDIRS = include src dist scripts data tools tests
if WITH_GTK_DOC
SUBDIRS += docs
endif
Expand Down
3 changes: 2 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ AC_CONFIG_FILES([Makefile src/Makefile \
scripts/Makefile \
tools/Makefile \
data/Makefile \
data/conf.d/Makefile])
data/conf.d/Makefile \
tests/Makefile])

m4_ifdef([GOBJECT_INTROSPECTION_CHECK],
[GOBJECT_INTROSPECTION_CHECK([1.3.0])],
Expand Down
82 changes: 82 additions & 0 deletions tests/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Generate config.h.py with translated defines for easy use within Python

CONFIG_H_PY = config_h.py
PLUGINS =

if WITH_BTRFS
PLUGINS += btrfs
endif

if WITH_CRYPTO
PLUGINS += crypto
endif

if WITH_DM
PLUGINS += dm
endif

if WITH_LOOP
PLUGINS += loop
endif

if WITH_LVM
PLUGINS += lvm
endif

if WITH_LVM_DBUS
PLUGINS += lvm-dbus
endif

if WITH_MDRAID
PLUGINS += mdraid
endif

if WITH_MPATH
PLUGINS += mpath
endif

if WITH_SWAP
PLUGINS += swap
endif

if WITH_PART
PLUGINS += part
endif

if WITH_FS
PLUGINS += fs
endif

if WITH_NVDIMM
PLUGINS += nvdimm
endif

if WITH_NVME
PLUGINS += nvme
endif

if WITH_SMART
PLUGINS += smart
endif

if WITH_SMARTMONTOOLS
PLUGINS += smartmontools
endif

if WITH_TOOLS
PLUGINS += tools
endif

$(CONFIG_H_PY):
echo -n 'ENABLED_PLUGINS = [ ' > $(CONFIG_H_PY)
for i in $(PLUGINS); do \
echo -n "'$$i', " >> $(CONFIG_H_PY); \
done
echo ']' >> $(CONFIG_H_PY)

all: $(CONFIG_H_PY)

EXTRA_DIST =

clean-local:
rm -f *~ $(CONFIG_H_PY)
4 changes: 3 additions & 1 deletion tests/btrfs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from packaging.version import Version

import overrides_hack
from utils import create_sparse_tempfile, create_lio_device, delete_lio_device, fake_utils, fake_path, mount, umount, run_command, TestTags, tag_test
from utils import create_sparse_tempfile, create_lio_device, delete_lio_device, fake_utils, fake_path, mount, umount, run_command, TestTags, tag_test, required_plugins

import gi
gi.require_version('GLib', '2.0')
Expand All @@ -21,6 +21,8 @@
def wipefs(device):
os.system("wipefs -a %s > /dev/null" % device)


@required_plugins(("btrfs",))
class BtrfsTest(unittest.TestCase):
requested_plugins = BlockDev.plugin_specs_from_names(("btrfs",))

Expand Down
3 changes: 2 additions & 1 deletion tests/crypto_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import re
import tarfile

from utils import create_sparse_tempfile, create_lio_device, delete_lio_device, get_avail_locales, requires_locales, run_command, read_file, TestTags, tag_test
from utils import create_sparse_tempfile, create_lio_device, delete_lio_device, get_avail_locales, requires_locales, run_command, read_file, TestTags, tag_test, required_plugins

import gi
gi.require_version('GLib', '2.0')
Expand All @@ -35,6 +35,7 @@ def check_cryptsetup_version(version):
HAVE_OPAL = check_cryptsetup_version("2.7.0")


@required_plugins(("crypto", "loop"))
class CryptoTestCase(unittest.TestCase):

requested_plugins = BlockDev.plugin_specs_from_names(("crypto", "loop"))
Expand Down
3 changes: 2 additions & 1 deletion tests/dm_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
import os
import overrides_hack

from utils import run, create_sparse_tempfile, create_lio_device, delete_lio_device, fake_utils, fake_path, TestTags, tag_test
from utils import run, create_sparse_tempfile, create_lio_device, delete_lio_device, fake_utils, fake_path, TestTags, tag_test, required_plugins

import gi
gi.require_version('GLib', '2.0')
gi.require_version('BlockDev', '3.0')
from gi.repository import GLib, BlockDev


@required_plugins(("dm",))
class DevMapperTest(unittest.TestCase):

requested_plugins = BlockDev.plugin_specs_from_names(("dm",))
Expand Down
2 changes: 1 addition & 1 deletion tests/fs_tests/fs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def check_output(args, ignore_retcode=True):
else:
raise


@utils.required_plugins(("fs", "loop"))
class FSNoDevTestCase(unittest.TestCase):

requested_plugins = BlockDev.plugin_specs_from_names(("fs", "loop"))
Expand Down
1 change: 1 addition & 0 deletions tests/fs_tests/generic_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,7 @@ def ntfs_size(drive):
self.assertEqual(new_size, size)

@tag_test(TestTags.UNSTABLE)
@utils.required_plugins(("tools",))
def test_vfat_generic_resize(self):
"""Test generic resize function with a vfat file system"""
def mkfs_vfat(device, options=None):
Expand Down
2 changes: 2 additions & 0 deletions tests/fs_tests/vfat_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def setUp(self):

class VfatTestAvailability(VfatNoDevTestCase):

@utils.required_plugins(("tools",))
def test_vfat_available(self):
"""Verify that it is possible to check vfat tech availability"""
available = BlockDev.fs_is_tech_avail(BlockDev.FSTech.VFAT,
Expand Down Expand Up @@ -281,6 +282,7 @@ def test_vfat_set_uuid(self):
BlockDev.fs_vfat_check_uuid(10 * "f")


@utils.required_plugins(("tools",))
class VfatResize(VfatTestCase):
def test_vfat_resize(self):
"""Verify that it is possible to resize an vfat file system"""
Expand Down
3 changes: 2 additions & 1 deletion tests/library_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
import unittest
import re
import overrides_hack
from utils import fake_path, TestTags, tag_test
from utils import fake_path, TestTags, tag_test, required_plugins

import gi
gi.require_version('GLib', '2.0')
gi.require_version('BlockDev', '3.0')
from gi.repository import GLib, BlockDev


@required_plugins(("crypto","dm", "loop", "mdraid", "part", "swap"))
class LibraryOpsTestCase(unittest.TestCase):
log = ""

Expand Down
4 changes: 3 additions & 1 deletion tests/loop_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import time
import overrides_hack

from utils import create_sparse_tempfile, TestTags, tag_test
from utils import create_sparse_tempfile, TestTags, tag_test, required_plugins

import gi
gi.require_version('GLib', '2.0')
gi.require_version('BlockDev', '3.0')
from gi.repository import GLib, BlockDev


@required_plugins(("loop",))
class LoopTestCase(unittest.TestCase):

requested_plugins = BlockDev.plugin_specs_from_names(("loop",))
Expand Down
3 changes: 2 additions & 1 deletion tests/lvm_dbus_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from itertools import chain
import sys

from utils import create_sparse_tempfile, create_lio_device, delete_lio_device, run_command, TestTags, tag_test, read_file
from utils import create_sparse_tempfile, create_lio_device, delete_lio_device, run_command, TestTags, tag_test, read_file, required_plugins

import gi
gi.require_version('GLib', '2.0')
Expand All @@ -38,6 +38,7 @@ def wait_for_sync(vg_name, lv_name):
time.sleep(1)


@required_plugins(("lvm-dbus",))
class LVMTestCase(unittest.TestCase):
@classmethod
def setUpClass(cls):
Expand Down
3 changes: 2 additions & 1 deletion tests/lvm_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from contextlib import contextmanager
from packaging.version import Version

from utils import create_sparse_tempfile, create_lio_device, delete_lio_device, fake_utils, fake_path, TestTags, tag_test, run_command, read_file
from utils import create_sparse_tempfile, create_lio_device, delete_lio_device, fake_utils, fake_path, TestTags, tag_test, run_command, read_file, required_plugins

import gi
gi.require_version('GLib', '2.0')
Expand All @@ -32,6 +32,7 @@ def wait_for_sync(vg_name, lv_name):
time.sleep(1)


@required_plugins(("lvm",))
class LVMTestCase(unittest.TestCase):

@classmethod
Expand Down
4 changes: 3 additions & 1 deletion tests/mdraid_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from contextlib import contextmanager
import overrides_hack

from utils import create_sparse_tempfile, create_lio_device, delete_lio_device, fake_utils, fake_path, TestTags, tag_test, run_command
from utils import create_sparse_tempfile, create_lio_device, delete_lio_device, fake_utils, fake_path, TestTags, tag_test, run_command, required_plugins

import gi
gi.require_version('GLib', '2.0')
Expand All @@ -27,6 +27,8 @@ def wait_for_action(action_name):
print("Sleeping")
time.sleep(1)


@required_plugins(("mdraid",))
class MDTest(unittest.TestCase):

requested_plugins = BlockDev.plugin_specs_from_names(("mdraid",))
Expand Down
4 changes: 3 additions & 1 deletion tests/mpath_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import overrides_hack
import shutil

from utils import create_sparse_tempfile, create_lio_device, delete_lio_device, fake_utils, fake_path, get_version, TestTags, tag_test
from utils import create_sparse_tempfile, create_lio_device, delete_lio_device, fake_utils, fake_path, get_version, TestTags, tag_test, required_plugins

import gi
gi.require_version('GLib', '2.0')
gi.require_version('BlockDev', '3.0')
from gi.repository import GLib, BlockDev


@required_plugins(("mpath",))
class MpathTest(unittest.TestCase):

requested_plugins = BlockDev.plugin_specs_from_names(("mpath",))
Expand Down
3 changes: 2 additions & 1 deletion tests/nvdimm_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@

from packaging.version import Version

from utils import run_command, read_file, fake_path, TestTags, tag_test
from utils import run_command, read_file, fake_path, TestTags, tag_test, required_plugins

import gi
gi.require_version('GLib', '2.0')
gi.require_version('BlockDev', '3.0')
from gi.repository import GLib, BlockDev


@required_plugins(("nvdimm",))
class NVDIMMTestCase(unittest.TestCase):

requested_plugins = BlockDev.plugin_specs_from_names(("nvdimm",))
Expand Down
4 changes: 3 additions & 1 deletion tests/nvme_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
import shutil
import overrides_hack

from utils import create_sparse_tempfile, create_nvmet_device, delete_nvmet_device, setup_nvme_target, teardown_nvme_target, find_nvme_ctrl_devs_for_subnqn, find_nvme_ns_devs_for_subnqn, get_nvme_hostnqn, run_command, TestTags, tag_test, read_file, write_file
from utils import create_sparse_tempfile, create_nvmet_device, delete_nvmet_device, setup_nvme_target, teardown_nvme_target, find_nvme_ctrl_devs_for_subnqn, find_nvme_ns_devs_for_subnqn, get_nvme_hostnqn, run_command, TestTags, tag_test, read_file, write_file, required_plugins

import gi
gi.require_version('GLib', '2.0')
gi.require_version('BlockDev', '3.0')
from gi.repository import GLib, BlockDev


@required_plugins(("nvme", "loop"))
class NVMeTest(unittest.TestCase):
requested_plugins = BlockDev.plugin_specs_from_names(("nvme", "loop"))

Expand Down
3 changes: 2 additions & 1 deletion tests/overrides_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
gi.require_version('BlockDev', '3.0')
from gi.repository import BlockDev

from utils import TestTags, tag_test
from utils import TestTags, tag_test, required_plugins


@required_plugins(("crypto", "dm", "loop", "lvm", "mdraid", "part", "swap"))
class OverridesTest(unittest.TestCase):
# all plugins except for 'btrfs', 'fs' and 'mpath' -- these don't have all
# the dependencies on CentOS/Debian and we don't need them for this test
Expand Down
4 changes: 3 additions & 1 deletion tests/part_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest
import os
import re
from utils import create_sparse_tempfile, create_lio_device, delete_lio_device, TestTags, tag_test, run_command
from utils import create_sparse_tempfile, create_lio_device, delete_lio_device, TestTags, tag_test, run_command, required_plugins
import overrides_hack

from bytesize.bytesize import Size, ROUND_UP
Expand All @@ -12,6 +12,8 @@
gi.require_version('BlockDev', '3.0')
from gi.repository import GLib, BlockDev


@required_plugins(("part",))
class PartTestCase(unittest.TestCase):

requested_plugins = BlockDev.plugin_specs_from_names(("part",))
Expand Down
3 changes: 2 additions & 1 deletion tests/s390_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
import os
import overrides_hack

from utils import fake_path, TestTags, tag_test
from utils import fake_path, TestTags, tag_test, required_plugins

import gi
gi.require_version('GLib', '2.0')
gi.require_version('BlockDev', '3.0')
from gi.repository import GLib, BlockDev

@unittest.skipUnless(os.uname()[4].startswith('s390'), "s390x architecture required")
@required_plugins(("s390",))
class S390TestCase(unittest.TestCase):

requested_plugins = BlockDev.plugin_specs_from_names(("s390",))
Expand Down
3 changes: 2 additions & 1 deletion tests/smart_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
import shutil
import overrides_hack

from utils import run, create_sparse_tempfile, create_lio_device, delete_lio_device, fake_utils, fake_path, TestTags, tag_test, write_file, run_command
from utils import run, create_sparse_tempfile, create_lio_device, delete_lio_device, fake_utils, fake_path, TestTags, tag_test, write_file, run_command, required_plugins

import gi
gi.require_version('GLib', '2.0')
gi.require_version('BlockDev', '3.0')
from gi.repository import BlockDev, GLib


@required_plugins(("smart",))
class SMARTTest(unittest.TestCase):

# dumps from real drives, both HDD and SSD
Expand Down
Loading

0 comments on commit e6b280e

Please sign in to comment.