diff --git a/tests/atf_python/Makefile b/tests/atf_python/Makefile --- a/tests/atf_python/Makefile +++ b/tests/atf_python/Makefile @@ -2,7 +2,7 @@ .PATH: ${.CURDIR} -FILES= __init__.py atf_pytest.py +FILES= __init__.py atf_pytest.py utils.py SUBDIR= sys .include diff --git a/tests/atf_python/sys/net/vnet.py b/tests/atf_python/sys/net/vnet.py --- a/tests/atf_python/sys/net/vnet.py +++ b/tests/atf_python/sys/net/vnet.py @@ -5,17 +5,15 @@ import socket import sys import time -from ctypes import cdll from ctypes import get_errno -from ctypes.util import find_library from multiprocessing import Pipe from multiprocessing import Process from typing import Dict from typing import List from typing import NamedTuple -from typing import Optional from atf_python.sys.net.tools import ToolsHelper +from atf_python.utils import libc, BaseTest def run_cmd(cmd: str, verbose=True) -> str: @@ -145,7 +143,7 @@ def __init__(self, test_name: str): self.test_name = test_name - test_id = convert_test_name(test_name) + self.test_id = convert_test_name(test_name) self.file_name = self.INTERFACES_FNAME def _register_iface(self, iface_name: str): @@ -204,11 +202,6 @@ @staticmethod def attach_jid(jid: int): - _path: Optional[str] = find_library("c") - if _path is None: - raise Exception("libc not found") - path: str = _path - libc = cdll.LoadLibrary(path) if libc.jail_attach(jid) != 0: raise Exception("jail_attach() failed: errno {}".format(get_errno())) @@ -290,7 +283,7 @@ vnet_aliases: List[str] -class VnetTestTemplate(object): +class VnetTestTemplate(BaseTest): TOPOLOGY = {} def _get_vnet_handler(self, vnet_alias: str): @@ -395,6 +388,7 @@ # 'test_ip6_output.py::TestIP6Output::test_output6_pktinfo[ipandif] (setup)' test_id = os.environ.get("PYTEST_CURRENT_TEST").split(" ")[0] test_name = test_id.split("::")[-1] + self.check_constraints() topology = self.TOPOLOGY # First, setup kernel objects - interfaces & vnets obj_map = self.setup_topology(topology, test_name) diff --git a/tests/atf_python/utils.py b/tests/atf_python/utils.py new file mode 100644 --- /dev/null +++ b/tests/atf_python/utils.py @@ -0,0 +1,35 @@ +#!/usr/local/bin/python3 +import os +from ctypes import CDLL +from ctypes import get_errno +from ctypes.util import find_library +from typing import List +from typing import Optional + +import pytest + + +def get_libc(): + _path: Optional[str] = find_library("c") + if _path is None: + raise RuntimeError("libc not found") + path: str = _path + return CDLL(path, use_errno=True) + + +libc = get_libc() + + +class BaseTest(object): + REQUIRED_MODULES: List[str] = [] + + def _check_modules(self): + for mod_name in self.REQUIRED_MODULES: + if libc.modfind(bytes(mod_name, encoding="utf-8")) == -1: + err_str = os.strerror(get_errno()) + pytest.skip( + "kernel module '{}' not available: {}".format(mod_name, err_str) + ) + + def check_constraints(self): + self._check_modules() diff --git a/tests/sys/Makefile b/tests/sys/Makefile --- a/tests/sys/Makefile +++ b/tests/sys/Makefile @@ -24,6 +24,7 @@ TESTS_SUBDIRS+= netinet TESTS_SUBDIRS+= netinet6 TESTS_SUBDIRS+= netipsec +TESTS_SUBDIRS+= netlink TESTS_SUBDIRS+= netmap TESTS_SUBDIRS+= netpfil TESTS_SUBDIRS+= opencrypto diff --git a/tests/sys/netlink/test_rtnl_iface.py b/tests/sys/netlink/test_rtnl_iface.py --- a/tests/sys/netlink/test_rtnl_iface.py +++ b/tests/sys/netlink/test_rtnl_iface.py @@ -22,6 +22,8 @@ class TestRtNlIface(SingleVnetTestTemplate): + REQUIRED_MODULES = ["netlink"] + def setup_method(self, method): super().setup_method(method) self.helper = NlHelper()