diff options
| author | Alexander V. Chernikov <melifaro@FreeBSD.org> | 2022-12-16 12:02:17 +0000 |
|---|---|---|
| committer | Alexander V. Chernikov <melifaro@FreeBSD.org> | 2022-12-16 12:02:50 +0000 |
| commit | 3873bdc2f28f6aab6b426ccb6c85ab2a41483264 (patch) | |
| tree | fcbb252c9e05b56c4f0fa2237d8c3fde7876fd6e /tests/atf_python/utils.py | |
| parent | 69542f26820b7edb8351398b36edda5299c1db56 (diff) | |
Diffstat (limited to 'tests/atf_python/utils.py')
| -rw-r--r-- | tests/atf_python/utils.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/atf_python/utils.py b/tests/atf_python/utils.py new file mode 100644 index 000000000000..12cd56c10149 --- /dev/null +++ b/tests/atf_python/utils.py @@ -0,0 +1,46 @@ +#!/usr/bin/env 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 + + +class LibCWrapper(object): + def __init__(self): + path: Optional[str] = find_library("c") + if path is None: + raise RuntimeError("libc not found") + self._libc = CDLL(path, use_errno=True) + + def modfind(self, mod_name: str) -> int: + if self._libc.modfind(bytes(mod_name, encoding="ascii")) == -1: + return get_errno() + return 0 + + def jail_attach(self, jid: int) -> int: + if self._libc.jail_attach(jid) != 0: + return get_errno() + return 0 + + +libc = LibCWrapper() + + +class BaseTest(object): + REQUIRED_MODULES: List[str] = [] + + def _check_modules(self): + for mod_name in self.REQUIRED_MODULES: + error_code = libc.modfind(mod_name) + if error_code != 0: + err_str = os.strerror(error_code) + pytest.skip( + "kernel module '{}' not available: {}".format(mod_name, err_str) + ) + + def check_constraints(self): + self._check_modules() |
