Re: [PATCH 2/2] lib/tests: Add KUnit test for struct stack_trace __counted_by_ptr attribute

From: Thomas Weißschuh

Date: Mon Sep 28 2026 - 04:32:30 EST


Hi Bill,

sorry for the long delay.

On Thu, Sep 10, 2026 at 12:48:51PM -0700, Bill Wendling wrote:
> On Sun, Aug 23, 2026 at 11:41 PM Thomas Weißschuh
> <thomas.weissschuh@xxxxxxxxxxxxx> wrote:
> >
> > On Sun, Aug 23, 2026 at 12:35:33PM +0000, Bill Wendling wrote:
> > > Add a custom KUnit test suite 'stacktrace_counted_by' to verify that the
> > > __counted_by_ptr annotation on the 'entries' field of 'struct stack_trace'
> > > behaves correctly.
> >
> > The implementation of __counted_by_ptr should be tested by a dedicated unittest
> > for that feature. And I am fairly sure that already exists. It should not be
> > tested in random subsystems.
> >
> I'm looking at `tools/unittests` and...what in the world is it
> supposed to be testing?

This seems to be testing the documentation generator.
An assumption which is corroborated by 'git log'.

> It looks like it's testing absolutely nothing of substance.

Debatable...

> I assume you want there to be a test that runs and
> produces a stack trace triggered by an invalid access, right?

Correct.

> I'm unable to find any tests in `tools/unittests` that do anything like
> that...maybe I'm missing something?

Look for KUnit tests instead. For example lib/tests/fortify_kunit.c.
Or non-KUnit tests in lib/test_fortify/.
Or LKDTM tests in drivers/misc/lkdtm/.

Also see Kees' recent message about testing traps with KUnit [0].
Apparently it is not so easy to test this from KUnit. But your proposed
stack_trace-specific test would have run into the same issues.


[0] https://lore.kernel.org/lkml/202609041620.81446C2A@keescook/

(...)


Thomas