From: Guenter Roeck Date: Thu, 13 Mar 2025 11:43:17 +0000 (+0000) Subject: kunit: bug: count suppressed warning backtraces X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=cd164932c7cedd71fd007b87f7a7cb6acb90e5b8;p=users%2Fwilly%2Fpagecache.git kunit: bug: count suppressed warning backtraces 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 Acked-by: Dan Carpenter Reviewed-by: Kees Cook Tested-by: Linux Kernel Functional Testing Signed-off-by: Guenter Roeck Reviewed-by: David Gow Cc: Albert Ou Cc: Alexander Gordeev Cc: Arnd Bergmann Cc: Arthur Grillo Cc: Borislav Petkov Cc: Brendan Higgins Cc: Catalin Marinas Cc: Charlie Jenkins Cc: Daniel Diaz Cc: Daniel Vetter Cc: Dave Airlie Cc: Dave Hansen Cc: Heiko Carstens Cc: Helge Deller Cc: Huacai Chen Cc: Ingo Molnar Cc: Jani Nikula Cc: John Paul Adrian Glaubitz Cc: Maarten Lankhorst Cc: MaĆ­ra Canal Cc: Maxime Ripard Cc: Michael Ellerman Cc: Naresh Kamboju Cc: Palmer Dabbelt Cc: Paul Walmsley Cc: Rae Moar Cc: Rich Felker Cc: Simon Horman Cc: Thomas Gleixner Cc: Thomas Zimemrmann Cc: Vasily Gorbik Cc: Ville Syrjala Cc: Will Deacon Cc: Yoshinori Sato Signed-off-by: Andrew Morton --- diff --git a/include/kunit/bug.h b/include/kunit/bug.h index 0a8e62c1fcaf4..44efa7d5c9023 100644 --- a/include/kunit/bug.h +++ b/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 char *function); #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 char *function); #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__ */ diff --git a/lib/kunit/bug.c b/lib/kunit/bug.c index 351f9a595a71d..84c05b1a9e8b4 100644 --- a/lib/kunit/bug.c +++ b/lib/kunit/bug.c @@ -32,8 +32,10 @@ bool __kunit_is_suppressed_warning(const char *function) 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; }