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.

Merge tag 'linux_kselftest-kunit-6.12-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest

Pull kunit updates from Shuah Khan:

- a new int_pow test suite

- documentation update to clarify filename best practices

- kernel-doc fix for EXPORT_SYMBOL_IF_KUNIT

- change to build compile_commands.json automatically instead of
requiring a manual build

* tag 'linux_kselftest-kunit-6.12-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest:
lib/math: Add int_pow test suite
kunit: tool: Build compile_commands.json
kunit: Fix kernel-doc for EXPORT_SYMBOL_IF_KUNIT
Documentation: KUnit: Update filename best practices

+95 -10
+20 -9
Documentation/dev-tools/kunit/style.rst
··· 188 188 Test File and Module Names 189 189 ========================== 190 190 191 - KUnit tests can often be compiled as a module. These modules should be named 192 - after the test suite, followed by ``_test``. If this is likely to conflict with 193 - non-KUnit tests, the suffix ``_kunit`` can also be used. 191 + KUnit tests are often compiled as a separate module. To avoid conflicting 192 + with regular modules, KUnit modules should be named after the test suite, 193 + followed by ``_kunit`` (e.g. if "foobar" is the core module, then 194 + "foobar_kunit" is the KUnit test module). 194 195 195 - The easiest way of achieving this is to name the file containing the test suite 196 - ``<suite>_test.c`` (or, as above, ``<suite>_kunit.c``). This file should be 197 - placed next to the code under test. 196 + Test source files, whether compiled as a separate module or an 197 + ``#include`` in another source file, are best kept in a ``tests/`` 198 + subdirectory to not conflict with other source files (e.g. for 199 + tab-completion). 200 + 201 + Note that the ``_test`` suffix has also been used in some existing 202 + tests. The ``_kunit`` suffix is preferred, as it makes the distinction 203 + between KUnit and non-KUnit tests clearer. 204 + 205 + So for the common case, name the file containing the test suite 206 + ``tests/<suite>_kunit.c``. The ``tests`` directory should be placed at 207 + the same level as the code under test. For example, tests for 208 + ``lib/string.c`` live in ``lib/tests/string_kunit.c``. 198 209 199 210 If the suite name contains some or all of the name of the test's parent 200 - directory, it may make sense to modify the source filename to reduce redundancy. 201 - For example, a ``foo_firmware`` suite could be in the ``foo/firmware_test.c`` 202 - file. 211 + directory, it may make sense to modify the source filename to reduce 212 + redundancy. For example, a ``foo_firmware`` suite could be in the 213 + ``foo/tests/firmware_kunit.c`` file.
+1
include/kunit/visibility.h
··· 22 22 * EXPORTED_FOR_KUNIT_TESTING namespace only if CONFIG_KUNIT is 23 23 * enabled. Must use MODULE_IMPORT_NS(EXPORTED_FOR_KUNIT_TESTING) 24 24 * in test file in order to use symbols. 25 + * @symbol: the symbol identifier to export 25 26 */ 26 27 #define EXPORT_SYMBOL_IF_KUNIT(symbol) EXPORT_SYMBOL_NS(symbol, \ 27 28 EXPORTED_FOR_KUNIT_TESTING)
+16
lib/Kconfig.debug
··· 3059 3059 endmenu # "Rust" 3060 3060 3061 3061 endmenu # Kernel hacking 3062 + 3063 + config INT_POW_TEST 3064 + tristate "Integer exponentiation (int_pow) test" if !KUNIT_ALL_TESTS 3065 + depends on KUNIT 3066 + default KUNIT_ALL_TESTS 3067 + help 3068 + This option enables the KUnit test suite for the int_pow function, 3069 + which performs integer exponentiation. The test suite is designed to 3070 + verify that the implementation of int_pow correctly computes the power 3071 + of a given base raised to a given exponent. 3072 + 3073 + Enabling this option will include tests that check various scenarios 3074 + and edge cases to ensure the accuracy and reliability of the exponentiation 3075 + function. 3076 + 3077 + If unsure, say N
+1
lib/math/Makefile
··· 5 5 obj-$(CONFIG_PRIME_NUMBERS) += prime_numbers.o 6 6 obj-$(CONFIG_RATIONAL) += rational.o 7 7 8 + obj-$(CONFIG_INT_POW_TEST) += tests/int_pow_kunit.o 8 9 obj-$(CONFIG_TEST_DIV64) += test_div64.o 9 10 obj-$(CONFIG_RATIONAL_KUNIT_TEST) += rational-test.o
+3
lib/math/tests/Makefile
··· 1 + # SPDX-License-Identifier: GPL-2.0-only 2 + 3 + obj-$(CONFIG_INT_POW_TEST) += int_pow_kunit.o
+52
lib/math/tests/int_pow_kunit.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + 3 + #include <kunit/test.h> 4 + #include <linux/math.h> 5 + 6 + struct test_case_params { 7 + u64 base; 8 + unsigned int exponent; 9 + u64 expected_result; 10 + const char *name; 11 + }; 12 + 13 + static const struct test_case_params params[] = { 14 + { 64, 0, 1, "Power of zero" }, 15 + { 64, 1, 64, "Power of one"}, 16 + { 0, 5, 0, "Base zero" }, 17 + { 1, 64, 1, "Base one" }, 18 + { 2, 2, 4, "Two squared"}, 19 + { 2, 3, 8, "Two cubed"}, 20 + { 5, 5, 3125, "Five raised to the fifth power" }, 21 + { U64_MAX, 1, U64_MAX, "Max base" }, 22 + { 2, 63, 9223372036854775808ULL, "Large result"}, 23 + }; 24 + 25 + static void get_desc(const struct test_case_params *tc, char *desc) 26 + { 27 + strscpy(desc, tc->name, KUNIT_PARAM_DESC_SIZE); 28 + } 29 + 30 + KUNIT_ARRAY_PARAM(int_pow, params, get_desc); 31 + 32 + static void int_pow_test(struct kunit *test) 33 + { 34 + const struct test_case_params *tc = (const struct test_case_params *)test->param_value; 35 + 36 + KUNIT_EXPECT_EQ(test, tc->expected_result, int_pow(tc->base, tc->exponent)); 37 + } 38 + 39 + static struct kunit_case math_int_pow_test_cases[] = { 40 + KUNIT_CASE_PARAM(int_pow_test, int_pow_gen_params), 41 + {} 42 + }; 43 + 44 + static struct kunit_suite int_pow_test_suite = { 45 + .name = "math-int_pow", 46 + .test_cases = math_int_pow_test_cases, 47 + }; 48 + 49 + kunit_test_suites(&int_pow_test_suite); 50 + 51 + MODULE_DESCRIPTION("math.int_pow KUnit test suite"); 52 + MODULE_LICENSE("GPL");
+2 -1
tools/testing/kunit/kunit_kernel.py
··· 72 72 raise ConfigError(e.output.decode()) 73 73 74 74 def make(self, jobs: int, build_dir: str, make_options: Optional[List[str]]) -> None: 75 - command = ['make', 'ARCH=' + self._linux_arch, 'O=' + build_dir, '--jobs=' + str(jobs)] 75 + command = ['make', 'all', 'compile_commands.json', 'ARCH=' + self._linux_arch, 76 + 'O=' + build_dir, '--jobs=' + str(jobs)] 76 77 if make_options: 77 78 command.extend(make_options) 78 79 if self._cross_compile: