| From: Guenter Roeck <linux@roeck-us.net> |
| Subject: kunit: bug: count suppressed warning backtraces |
| Date: Thu, 13 Mar 2025 11:43:17 +0000 |
| |
| Count suppressed warning backtraces to enable code which suppresses |
| warning backtraces to check if the expected backtrace(s) have been |
| observed. |
| |
| Using atomics for the backtrace count resulted in build errors on some |
| architectures due to include file recursion, so use a plain integer for |
| now. |
| |
| Link: https://lkml.kernel.org/r/20250313114329.284104-3-acarmina@redhat.com |
| Signed-off-by: Alessandro Carminati <acarmina@redhat.com> |
| Acked-by: Dan Carpenter <dan.carpenter@linaro.org> |
| Reviewed-by: Kees Cook <keescook@chromium.org> |
| Tested-by: Linux Kernel Functional Testing <lkft@linaro.org> |
| Signed-off-by: Guenter Roeck <linux@roeck-us.net> |
| Reviewed-by: David Gow <davidgow@google.com> |
| Cc: Albert Ou <aou@eecs.berkeley.edu> |
| Cc: Alexander Gordeev <agordeev@linux.ibm.com> |
| Cc: Arnd Bergmann <arnd@arndb.de> |
| Cc: Arthur Grillo <arthurgrillo@riseup.net> |
| Cc: Borislav Petkov <bp@alien8.de> |
| Cc: Brendan Higgins <brendan.higgins@linux.dev> |
| Cc: Catalin Marinas <catalin.marinas@arm.com> |
| Cc: Charlie Jenkins <charlie@rivosinc.com> |
| Cc: Daniel Diaz <daniel.diaz@linaro.org> |
| Cc: Daniel Vetter <daniel@ffwll.ch> |
| Cc: Dave Airlie <airlied@gmail.com> |
| Cc: Dave Hansen <dave.hansen@linux.intel.com> |
| Cc: Heiko Carstens <hca@linux.ibm.com> |
| Cc: Helge Deller <deller@gmx.de> |
| Cc: Huacai Chen <chenhuacai@kernel.org> |
| Cc: Ingo Molnar <mingo@redhat.com> |
| Cc: Jani Nikula <jani.nikula@intel.com> |
| Cc: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de> |
| Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com> |
| Cc: Maíra Canal <mcanal@igalia.com> |
| Cc: Maxime Ripard <mripard@kernel.org> |
| Cc: Michael Ellerman <mpe@ellerman.id.au> |
| Cc: Naresh Kamboju <naresh.kamboju@linaro.org> |
| Cc: Palmer Dabbelt <palmer@dabbelt.com> |
| Cc: Paul Walmsley <paul.walmsley@sifive.com> |
| Cc: Rae Moar <rmoar@google.com> |
| Cc: Rich Felker <dalias@libc.org> |
| Cc: Simon Horman <horms@kernel.org> |
| Cc: Thomas Gleixner <tglx@linutronix.de> |
| Cc: Thomas Zimemrmann <tzimmermann@suse.de> |
| Cc: Vasily Gorbik <gor@linux.ibm.com> |
| Cc: Ville Syrjala <ville.syrjala@linux.intel.com> |
| Cc: Will Deacon <will@kernel.org> |
| Cc: Yoshinori Sato <ysato@users.sourceforge.jp> |
| Signed-off-by: Andrew Morton <akpm@linux-foundation.org> |
| --- |
| |
| include/kunit/bug.h | 7 ++++++- |
| lib/kunit/bug.c | 4 +++- |
| 2 files changed, 9 insertions(+), 2 deletions(-) |
| |
| --- a/include/kunit/bug.h~kunit-bug-count-suppressed-warning-backtraces |
| +++ a/include/kunit/bug.h |
| @@ -20,6 +20,7 @@ |
| struct __suppressed_warning { |
| struct list_head node; |
| const char *function; |
| + int counter; |
| }; |
| |
| void __kunit_start_suppress_warning(struct __suppressed_warning *warning); |
| @@ -28,7 +29,7 @@ bool __kunit_is_suppressed_warning(const |
| |
| #define DEFINE_SUPPRESSED_WARNING(func) \ |
| struct __suppressed_warning __kunit_suppress_##func = \ |
| - { .function = __stringify(func) } |
| + { .function = __stringify(func), .counter = 0 } |
| |
| #define KUNIT_START_SUPPRESSED_WARNING(func) \ |
| __kunit_start_suppress_warning(&__kunit_suppress_##func) |
| @@ -39,12 +40,16 @@ bool __kunit_is_suppressed_warning(const |
| #define KUNIT_IS_SUPPRESSED_WARNING(func) \ |
| __kunit_is_suppressed_warning(func) |
| |
| +#define SUPPRESSED_WARNING_COUNT(func) \ |
| + (__kunit_suppress_##func.counter) |
| + |
| #else /* CONFIG_KUNIT_SUPPRESS_BACKTRACE */ |
| |
| #define DEFINE_SUPPRESSED_WARNING(func) |
| #define KUNIT_START_SUPPRESSED_WARNING(func) |
| #define KUNIT_END_SUPPRESSED_WARNING(func) |
| #define KUNIT_IS_SUPPRESSED_WARNING(func) (false) |
| +#define SUPPRESSED_WARNING_COUNT(func) (0) |
| |
| #endif /* CONFIG_KUNIT_SUPPRESS_BACKTRACE */ |
| #endif /* __ASSEMBLY__ */ |
| --- a/lib/kunit/bug.c~kunit-bug-count-suppressed-warning-backtraces |
| +++ a/lib/kunit/bug.c |
| @@ -32,8 +32,10 @@ bool __kunit_is_suppressed_warning(const |
| return false; |
| |
| list_for_each_entry(warning, &suppressed_warnings, node) { |
| - if (!strcmp(function, warning->function)) |
| + if (!strcmp(function, warning->function)) { |
| + warning->counter++; |
| return true; |
| + } |
| } |
| return false; |
| } |
| _ |