Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

compiler-context-analysis: Add test stub

Add a simple test stub where we will add common supported patterns that
should not generate false positives for each new supported context lock.

Signed-off-by: Marco Elver <elver@google.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://patch.msgid.link/20251219154418.3592607-4-elver@google.com

authored by

Marco Elver and committed by
Peter Zijlstra
9b00c160 3269701c

+35
+14
lib/Kconfig.debug
··· 2835 2835 2836 2836 If unsure, say N. 2837 2837 2838 + config CONTEXT_ANALYSIS_TEST 2839 + bool "Compiler context-analysis warnings test" 2840 + depends on EXPERT 2841 + help 2842 + This builds the test for compiler-based context analysis. The test 2843 + does not add executable code to the kernel, but is meant to test that 2844 + common patterns supported by the analysis do not result in false 2845 + positive warnings. 2846 + 2847 + When adding support for new context locks, it is strongly recommended 2848 + to add supported patterns to this test. 2849 + 2850 + If unsure, say N. 2851 + 2838 2852 config CMDLINE_KUNIT_TEST 2839 2853 tristate "KUnit test for cmdline API" if !KUNIT_ALL_TESTS 2840 2854 depends on KUNIT
+3
lib/Makefile
··· 331 331 332 332 obj-$(CONFIG_FIRMWARE_TABLE) += fw_table.o 333 333 334 + CONTEXT_ANALYSIS_test_context-analysis.o := y 335 + obj-$(CONFIG_CONTEXT_ANALYSIS_TEST) += test_context-analysis.o 336 + 334 337 subdir-$(CONFIG_FORTIFY_SOURCE) += test_fortify
+18
lib/test_context-analysis.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Compile-only tests for common patterns that should not generate false 4 + * positive errors when compiled with Clang's context analysis. 5 + */ 6 + 7 + #include <linux/build_bug.h> 8 + 9 + /* 10 + * Test that helper macros work as expected. 11 + */ 12 + static void __used test_common_helpers(void) 13 + { 14 + BUILD_BUG_ON(context_unsafe(3) != 3); /* plain expression */ 15 + BUILD_BUG_ON(context_unsafe((void)2; 3) != 3); /* does not swallow semi-colon */ 16 + BUILD_BUG_ON(context_unsafe((void)2, 3) != 3); /* does not swallow commas */ 17 + context_unsafe(do { } while (0)); /* works with void statements */ 18 + }