xref: /freebsd/tests/sys/netlink/test_netlink_message_writer.py (revision 17083b94a91563aba15ba03d1c74796a35bb1c26)
1import mmap
2import pytest
3
4from atf_python.ktest import BaseKernelTest
5from atf_python.sys.netlink.attrs import NlAttrU32
6
7M_NOWAIT = 1
8M_WAITOK = 2
9
10NLMSG_SMALL = 128
11NLMSG_LARGE = 2048
12
13class TestNetlinkMessageWriter(BaseKernelTest):
14    KTEST_MODULE_NAME = "ktest_netlink_message_writer"
15
16    @pytest.mark.parametrize(
17        "malloc_flags",
18        [
19            pytest.param(M_NOWAIT, id="NOWAIT"),
20            pytest.param(M_WAITOK, id="WAITOK"),
21        ],
22    )
23    @pytest.mark.parametrize(
24        "sz",
25        [
26            pytest.param([NLMSG_SMALL, NLMSG_SMALL], id="NLMSG_SMALL"),
27            pytest.param([NLMSG_LARGE, NLMSG_LARGE], id="NLMSG_LARGE"),
28            pytest.param([NLMSG_LARGE + 256, NLMSG_LARGE + 256], id="NLMSG_LARGE+256"),
29        ],
30    )
31    def test_nlbuf_writer_allocation(self, sz, malloc_flags):
32        """override to parametrize"""
33
34        test_meta = [
35            NlAttrU32(1, sz[0]),  # size
36            NlAttrU32(2, sz[1]),  # expected_avail
37            NlAttrU32(3, malloc_flags),
38        ]
39        self.runtest(test_meta)
40