xref: /freebsd/tests/sys/netlink/test_nl_core.py (revision fee65b7e21eeeb625dcaba8cf2b9e0cf5af83498)
10079d177SAlexander V. Chernikovimport errno
20079d177SAlexander V. Chernikovimport socket
30079d177SAlexander V. Chernikov
40079d177SAlexander V. Chernikovimport pytest
50079d177SAlexander V. Chernikovfrom atf_python.sys.net.vnet import SingleVnetTestTemplate
6*fee65b7eSAlexander V. Chernikovfrom atf_python.sys.netlink.netlink import NetlinkTestTemplate
7*fee65b7eSAlexander V. Chernikovfrom atf_python.sys.netlink.utils import NlConst
80079d177SAlexander V. Chernikov
90079d177SAlexander V. Chernikov
100079d177SAlexander V. Chernikovclass TestNlCore(NetlinkTestTemplate, SingleVnetTestTemplate):
110079d177SAlexander V. Chernikov    @pytest.mark.parametrize(
120079d177SAlexander V. Chernikov        "params",
130079d177SAlexander V. Chernikov        [
140079d177SAlexander V. Chernikov            pytest.param({"type": socket.SOCK_RAW}, id="SOCK_RAW"),
150079d177SAlexander V. Chernikov            pytest.param({"type": socket.SOCK_DGRAM}, id="SOCK_DGRAM"),
160079d177SAlexander V. Chernikov        ],
170079d177SAlexander V. Chernikov    )
180079d177SAlexander V. Chernikov    def test_socket_type(self, params):
190079d177SAlexander V. Chernikov        s = socket.socket(NlConst.AF_NETLINK, params["type"], NlConst.NETLINK_ROUTE)
200079d177SAlexander V. Chernikov        s.close()
210079d177SAlexander V. Chernikov
220079d177SAlexander V. Chernikov    @pytest.mark.parametrize(
230079d177SAlexander V. Chernikov        "params",
240079d177SAlexander V. Chernikov        [
250079d177SAlexander V. Chernikov            pytest.param({"type": socket.SOCK_STREAM}, id="SOCK_STREAM"),
260079d177SAlexander V. Chernikov            pytest.param({"type": socket.SOCK_RDM}, id="SOCK_RDM"),
270079d177SAlexander V. Chernikov            pytest.param({"type": socket.SOCK_SEQPACKET}, id="SOCK_SEQPACKET"),
280079d177SAlexander V. Chernikov        ],
290079d177SAlexander V. Chernikov    )
300079d177SAlexander V. Chernikov    def test_socket_type_unsup(self, params):
310079d177SAlexander V. Chernikov        with pytest.raises(OSError) as exc_info:
320079d177SAlexander V. Chernikov            socket.socket(NlConst.AF_NETLINK, params["type"], NlConst.NETLINK_ROUTE)
330079d177SAlexander V. Chernikov        assert exc_info.value.errno == errno.EPROTOTYPE
34