HardenedBSD/tests/examples/test_ktest_example.py
Alexander V. Chernikov 3e5d0784b9 Testing: add framework for the kernel unit tests.
This changes intends to reduce the bar to the kernel unit-testing by
 introducing a new kernel-testing framework ("ktest") based on Netlink,
 loadable test modules and python test suite integration.

This framework provides the following features:
* Integration to the FreeBSD test suite
* Automatic test discovery
* Automatic test module loading
* Minimal boiler-plate code in both kernel and userland
* Passing any metadata to the test
* Convenient environment pre-setup using python testing framework
* Streaming messages from the kernel to the userland
* Running tests in the dedicated taskqueues
* Skipping or parametrizing tests

Differential Revision: https://reviews.freebsd.org/D39385
MFC after:	2 weeks
2023-04-14 15:47:55 +00:00

36 lines
918 B
Python

import pytest
from atf_python.ktest import BaseKernelTest
from atf_python.sys.netlink.attrs import NlAttrStr
from atf_python.sys.netlink.attrs import NlAttrU32
class TestExample(BaseKernelTest):
KTEST_MODULE_NAME = "ktest_example"
@pytest.mark.parametrize(
"numbers",
[
pytest.param([1, 2], id="1_2_Sum"),
pytest.param([3, 4], id="3_4_Sum"),
],
)
def test_with_params(self, numbers):
"""override to parametrize"""
test_meta = [
NlAttrU32(1, numbers[0]),
NlAttrU32(2, numbers[1]),
NlAttrStr(3, "test string"),
]
self.runtest(test_meta)
@pytest.mark.skip(reason="comment me ( or delete the func) to run the test")
def test_failed(self):
pass
@pytest.mark.skip(reason="comment me ( or delete the func) to run the test")
def test_failed2(self):
pass