3 from ctypes import CDLL
4 from ctypes import get_errno
5 from ctypes.util import find_library
6 from typing import List
7 from typing import Optional
12 class LibCWrapper(object):
14 path: Optional[str] = find_library("c")
16 raise RuntimeError("libc not found")
17 self._libc = CDLL(path, use_errno=True)
19 def modfind(self, mod_name: str) -> int:
20 if self._libc.modfind(bytes(mod_name, encoding="ascii")) == -1:
24 def jail_attach(self, jid: int) -> int:
25 if self._libc.jail_attach(jid) != 0:
33 class BaseTest(object):
34 REQUIRED_MODULES: List[str] = []
36 def _check_modules(self):
37 for mod_name in self.REQUIRED_MODULES:
38 error_code = libc.modfind(mod_name)
40 err_str = os.strerror(error_code)
42 "kernel module '{}' not available: {}".format(mod_name, err_str)
47 # 'test_ip6_output.py::TestIP6Output::test_output6_pktinfo[ipandif] (setup)'
48 return os.environ.get("PYTEST_CURRENT_TEST").split(" ")[0]
50 def setup_method(self, method):
51 """Run all pre-requisits for the test execution"""