From nobody Mon Jan 23 22:12:08 2023 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4P148S4Mvlz2t0c0; Mon, 23 Jan 2023 22:12:08 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4P148S3B1Rz3Lty; Mon, 23 Jan 2023 22:12:08 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674511928; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=/bD711XJCOZMvqQocgkAm6wZZRNgdgxrxP0I1oegFiE=; b=gatTtRFD+yHwRpZKztXj1RIauKDIaoLCIABrDF1DSv6Bl+oNM62km8MJE7PW8lFCeMXnIN UOWAJHFio6yzZilbYF06gSSijKj1rEuk+6y4+bk/+WE0QCfSBBjo0PLqrKVdwlXSr2IwCJ orjegyVrkFxrdcZZd+aOsbaxsQEQkzq+UsWU01gWqqXZxOuWx1TAfUSpYLTCF/d/VcfsLM lW4EF0VAb/hIsntFM3lVAS/PmBMS1LLJhARR4ndppThD3Xr5iNpa3ffWPyHA7Ra+okR+OC sf4XxibCPJ2t/pXTUaBkKbZlO0ZGix8JH8fLRfKNlPZDK6/WwrhJyyDedaGhqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674511928; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=/bD711XJCOZMvqQocgkAm6wZZRNgdgxrxP0I1oegFiE=; b=wSRsGVI17JvB9JoHvoY/QRaJWwro0uSN0/P5xLc6fGugC+JZtCne2b4qTf3UpoNJp/Yl4E env8ccX6jzS3I6Taenajxhi3n9iYtoHZzE9YXQhp/K9dUsAz/q7fU5pdWkoUl9MqJmXmD8 O5Om3Vm5imdMkxtjFf+DxROQQv9YzQTmyu8xeQByYZHVgBC1LavhIVqlmBKJzJ6IfDGQBW HSuGOZQ50FjH+i3BExEo8p1Qxbn6n7hLo/AZXb80EiW1kpymrpel/D14al/scdAsbepl9i CJ502KWSPUS3tpox6kMaE/2I+Ht/iQygwxKG1VayTkblXR0PMVhp690b9Ue2Ww== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1674511928; a=rsa-sha256; cv=none; b=ItcZUXPXp/ipVTu2Bdnpu4bd0SlIWxOGH3nLV7ObSnnpnekcAUEZkNt7UbrtwZ81B5psfL 7sx/fkSV9hjmJqXxt0I85afLXqock6J4J9rBe78OoNR8+L2Rw1Qc5SML12V8X0/GadxTvS lQe4CWOjzT0GEoMzJZ3ISZ90xt3I8Fs6pB7AoLkthX3ILz4eXnW8q8amvbzWtV3KJgeMj9 fc5tvEjSRqwLdnSKGIzySttEK/M9l3teNXRXr3jX8TCerZADVtwh+ozCvS2meDT9zQN5c4 mEenH3Jykb8a85eC0aAn44lASQcrfXNKsWv7X/1liTilhu3HK44iEJfoLrPezw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4P148S2Gyvzlly; Mon, 23 Jan 2023 22:12:08 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 30NMC8IZ013971; Mon, 23 Jan 2023 22:12:08 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30NMC8kh013970; Mon, 23 Jan 2023 22:12:08 GMT (envelope-from git) Date: Mon, 23 Jan 2023 22:12:08 GMT Message-Id: <202301232212.30NMC8kh013970@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: "Alexander V. Chernikov" Subject: git: 65f065ec7131 - stable/13 - netlink: connect netlink tests to the build List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: melifaro X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 65f065ec7131db4028ed37d951d94d905298bc31 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=65f065ec7131db4028ed37d951d94d905298bc31 commit 65f065ec7131db4028ed37d951d94d905298bc31 Author: Alexander V. Chernikov AuthorDate: 2022-12-16 12:02:17 +0000 Commit: Alexander V. Chernikov CommitDate: 2023-01-23 22:04:03 +0000 netlink: connect netlink tests to the build Reviewed By: ngie Differential Revision: https://reviews.freebsd.org/D37708 (cherry picked from commit 3873bdc2f28f6aab6b426ccb6c85ab2a41483264) --- tests/atf_python/Makefile | 2 +- tests/atf_python/sys/net/tools.py | 7 ------ tests/atf_python/sys/net/vnet.py | 20 ++++++---------- tests/atf_python/utils.py | 46 ++++++++++++++++++++++++++++++++++++ tests/sys/Makefile | 1 + tests/sys/netlink/test_rtnl_iface.py | 2 ++ 6 files changed, 57 insertions(+), 21 deletions(-) diff --git a/tests/atf_python/Makefile b/tests/atf_python/Makefile index 26d419743257..1a2fec387eda 100644 --- 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/tools.py b/tests/atf_python/sys/net/tools.py index 23bb5f4b4128..567d9d4b21ac 100644 --- a/tests/atf_python/sys/net/tools.py +++ b/tests/atf_python/sys/net/tools.py @@ -1,13 +1,6 @@ #!/usr/local/bin/python3 import json import os -import socket -import time -from ctypes import cdll -from ctypes import get_errno -from ctypes.util import find_library -from typing import List -from typing import Optional class ToolsHelper(object): diff --git a/tests/atf_python/sys/net/vnet.py b/tests/atf_python/sys/net/vnet.py index 0d9f969b28d9..faae58e95b6f 100644 --- a/tests/atf_python/sys/net/vnet.py +++ b/tests/atf_python/sys/net/vnet.py @@ -5,17 +5,14 @@ import os 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 +142,7 @@ class IfaceFactory(object): 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,13 +201,9 @@ class VnetInstance(object): @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())) + error_code = libc.jail_attach(jid) + if error_code != 0: + raise Exception("jail_attach() failed: errno {}".format(error_code)) def attach(self): self.attach_jid(self.jid) @@ -290,7 +283,7 @@ class SingleInterfaceMap(NamedTuple): vnet_aliases: List[str] -class VnetTestTemplate(object): +class VnetTestTemplate(BaseTest): TOPOLOGY = {} def _get_vnet_handler(self, vnet_alias: str): @@ -395,6 +388,7 @@ class VnetTestTemplate(object): # '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 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() diff --git a/tests/sys/Makefile b/tests/sys/Makefile index 2ba60f41b76c..14d96e053b64 100644 --- a/tests/sys/Makefile +++ b/tests/sys/Makefile @@ -24,6 +24,7 @@ TESTS_SUBDIRS+= ${_netgraph} 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 index 38a3075f09c9..3340eaa4d16d 100644 --- a/tests/sys/netlink/test_rtnl_iface.py +++ b/tests/sys/netlink/test_rtnl_iface.py @@ -22,6 +22,8 @@ from atf_python.sys.net.vnet import SingleVnetTestTemplate class TestRtNlIface(SingleVnetTestTemplate): + REQUIRED_MODULES = ["netlink"] + def setup_method(self, method): super().setup_method(method) self.helper = NlHelper()