[PATCH 0/3] kunit: add attribute API tests and fix two filtering bugs

From: Miao Tianzhong

Date: Thu Dec 03 2026 - 21:57:13 EST


This series fixes two bugs in the test attribute API found while adding
unit tests for it, and then adds those tests.

Patch 1 fixes parsing of the kunit.filter_attr= list when the list ends
with a comma (e.g. "kunit.filter_attr=speed=slow,"). The empty trailing
segment was counted as an extra filter by kunit_get_filter_count(), and
kunit_next_attr_filter() then left the cursor pointing at the beginning of
the string instead of terminating the list, so the same filter was parsed
and applied twice.

Patch 2 fixes a NULL pointer dereference when filtering on the module
attribute. kunit_filter_attr_tests() evaluates the filter for the test,
suite and default attribute values; a test case without a module_name
yields a NULL value, which attr_string_filter() passed to strcmp().

Patch 3 adds lib/kunit/attributes_test.c with parameterized unit tests
for the attribute API: filter parsing (including the error paths and the
trailing comma case), the filtering semantics of the speed, module and
is_init attributes including the test case -> suite -> default fallback,
and the print path. The executor level tests in executor_test.c already
cover the integration path through kunit_filter_suites(); this file adds
the missing unit level coverage, including regression tests for both
fixes above.

Testing:

$ ./tools/testing/kunit/kunit.py run --kunitconfig=lib/kunit
...
Testing complete. Ran 133 tests: passed: 126, skipped: 7

Both fixes and the new tests are checkpatch --strict clean. The four
regression tests for patch 1 fail without it, and the module name tests
in patch 3 panic the kernel without patch 2.

This is my first series for KUnit and I am still new to the kernel
community, so I would really appreciate any feedback on the approach, on
how the series is split, or on the way the tests are written. I am happy
to rework anything that does not follow the usual conventions.


Miao Tianzhong (3):
kunit: fix filter attribute list parsing with a trailing comma
kunit: fix NULL pointer dereference when filtering on module
kunit: add tests for the test attribute API

lib/kunit/Makefile | 1 +
lib/kunit/attributes.c | 24 +-
lib/kunit/attributes_test.c | 492 ++++++++++++++++++++++++++++++++++++
3 files changed, 512 insertions(+), 5 deletions(-)
create mode 100644 lib/kunit/attributes_test.c

--
2.56.1