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

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

Pull kunit updates from Shuah Khan:

- Enable qemu_config for riscv32, sparc 64-bit, PowerPC 32-bit BE and
64-bit LE

- Enable CONFIG_SPARC32 to clearly differentiate between sparc 32-bit
and 64-bit configurations

- Enable CONFIG_CPU_BIG_ENDIAN to clearly differentiate between powerpc
LE and BE configurations

- Add feature to list available architectures to kunit tool

- Fixes to bugs and changes to documentation

* tag 'linux_kselftest-kunit-6.16-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest:
kunit: Fix wrong parameter to kunit_deactivate_static_stub()
kunit: tool: add test counts to JSON output
Documentation: kunit: improve example on testing static functions
kunit: executor: Remove const from kunit_filter_suites() allocation type
kunit: qemu_configs: Disable faulting tests on 32-bit SPARC
kunit: qemu_configs: Add 64-bit SPARC configuration
kunit: qemu_configs: sparc: Explicitly enable CONFIG_SPARC32=y
kunit: qemu_configs: Add PowerPC 32-bit BE and 64-bit LE
kunit: qemu_configs: powerpc: Explicitly enable CONFIG_CPU_BIG_ENDIAN=y
kunit: tool: Implement listing of available architectures
kunit: qemu_configs: Add riscv32 config
kunit: configs: Enable CONFIG_INIT_STACK_ALL_PATTERN in all_tests

+120 -10
+2
Documentation/dev-tools/kunit/run_wrapper.rst
··· 182 182 is ignored), the tests will run via UML. Non-UML architectures, 183 183 for example: i386, x86_64, arm and so on; run on qemu. 184 184 185 + ``--arch help`` lists all valid ``--arch`` values. 186 + 185 187 - ``--cross_compile``: Specifies the Kbuild toolchain. It passes the 186 188 same argument as passed to the ``CROSS_COMPILE`` variable used by 187 189 Kbuild. As a reminder, this will be the prefix for the toolchain
+30 -8
Documentation/dev-tools/kunit/usage.rst
··· 670 670 Testing Static Functions 671 671 ------------------------ 672 672 673 - If we do not want to expose functions or variables for testing, one option is to 674 - conditionally export the used symbol. For example: 673 + If you want to test static functions without exposing those functions outside of 674 + testing, one option is conditionally export the symbol. When KUnit is enabled, 675 + the symbol is exposed but remains static otherwise. To use this method, follow 676 + the template below. 675 677 676 678 .. code-block:: c 677 679 678 - /* In my_file.c */ 680 + /* In the file containing functions to test "my_file.c" */ 679 681 680 - VISIBLE_IF_KUNIT int do_interesting_thing(); 682 + #include <kunit/visibility.h> 683 + #include <my_file.h> 684 + ... 685 + VISIBLE_IF_KUNIT int do_interesting_thing() 686 + { 687 + ... 688 + } 681 689 EXPORT_SYMBOL_IF_KUNIT(do_interesting_thing); 682 690 683 - /* In my_file.h */ 691 + /* In the header file "my_file.h" */ 684 692 685 693 #if IS_ENABLED(CONFIG_KUNIT) 686 694 int do_interesting_thing(void); 687 695 #endif 688 696 689 - Alternatively, you could conditionally ``#include`` the test file at the end of 690 - your .c file. For example: 697 + /* In the KUnit test file "my_file_test.c" */ 698 + 699 + #include <kunit/visibility.h> 700 + #include <my_file.h> 701 + ... 702 + MODULE_IMPORT_NS(EXPORTED_FOR_KUNIT_TESTING); 703 + ... 704 + // Use do_interesting_thing() in tests 705 + 706 + For a full example, see this `patch <https://lore.kernel.org/all/20221207014024.340230-3-rmoar@google.com/>`_ 707 + where a test is modified to conditionally expose static functions for testing 708 + using the macros above. 709 + 710 + As an **alternative** to the method above, you could conditionally ``#include`` 711 + the test file at the end of your .c file. This is not recommended but works 712 + if needed. For example: 691 713 692 714 .. code-block:: c 693 715 694 - /* In my_file.c */ 716 + /* In "my_file.c" */ 695 717 696 718 static int do_interesting_thing(); 697 719
+1 -1
lib/kunit/executor.c
··· 177 177 178 178 const size_t max = suite_set->end - suite_set->start; 179 179 180 - copy = kcalloc(max, sizeof(*filtered.start), GFP_KERNEL); 180 + copy = kcalloc(max, sizeof(*copy), GFP_KERNEL); 181 181 if (!copy) { /* won't be able to run anything, return an empty set */ 182 182 return filtered; 183 183 }
+1 -1
lib/kunit/static_stub.c
··· 96 96 97 97 /* If the replacement address is NULL, deactivate the stub. */ 98 98 if (!replacement_addr) { 99 - kunit_deactivate_static_stub(test, replacement_addr); 99 + kunit_deactivate_static_stub(test, real_fn_addr); 100 100 return; 101 101 } 102 102
+1
tools/testing/kunit/configs/all_tests.config
··· 10 10 CONFIG_KUNIT_ALL_TESTS=y 11 11 12 12 CONFIG_FORTIFY_SOURCE=y 13 + CONFIG_INIT_STACK_ALL_PATTERN=y 13 14 14 15 CONFIG_IIO=y 15 16
+10
tools/testing/kunit/kunit_json.py
··· 39 39 status = _status_map.get(subtest.status, "FAIL") 40 40 test_cases.append({"name": subtest.name, "status": status}) 41 41 42 + test_counts = test.counts 43 + counts_json = { 44 + "tests": test_counts.total(), 45 + "passed": test_counts.passed, 46 + "failed": test_counts.failed, 47 + "crashed": test_counts.crashed, 48 + "skipped": test_counts.skipped, 49 + "errors": test_counts.errors, 50 + } 42 51 test_group = { 43 52 "name": test.name, 44 53 "sub_groups": sub_groups, 45 54 "test_cases": test_cases, 55 + "misc": counts_json 46 56 } 47 57 test_group.update(common_fields) 48 58 return test_group
+8
tools/testing/kunit/kunit_kernel.py
··· 14 14 import shlex 15 15 import shutil 16 16 import signal 17 + import sys 17 18 import threading 18 19 from typing import Iterator, List, Optional, Tuple 19 20 from types import FrameType ··· 202 201 return config_path 203 202 204 203 options = [f[:-3] for f in os.listdir(QEMU_CONFIGS_DIR) if f.endswith('.py')] 204 + 205 + if arch == 'help': 206 + print('um') 207 + for option in options: 208 + print(option) 209 + sys.exit() 210 + 205 211 raise ConfigError(arch + ' is not a valid arch, options are ' + str(sorted(options))) 206 212 207 213 def _get_qemu_ops(config_path: str,
+1
tools/testing/kunit/qemu_configs/powerpc.py
··· 3 3 QEMU_ARCH = QemuArchParams(linux_arch='powerpc', 4 4 kconfig=''' 5 5 CONFIG_PPC64=y 6 + CONFIG_CPU_BIG_ENDIAN=y 6 7 CONFIG_SERIAL_8250=y 7 8 CONFIG_SERIAL_8250_CONSOLE=y 8 9 CONFIG_HVC_CONSOLE=y''',
+17
tools/testing/kunit/qemu_configs/powerpc32.py
··· 1 + # SPDX-License-Identifier: GPL-2.0 2 + 3 + from ..qemu_config import QemuArchParams 4 + 5 + QEMU_ARCH = QemuArchParams(linux_arch='powerpc', 6 + kconfig=''' 7 + CONFIG_PPC32=y 8 + CONFIG_CPU_BIG_ENDIAN=y 9 + CONFIG_ADB_CUDA=y 10 + CONFIG_SERIAL_PMACZILOG=y 11 + CONFIG_SERIAL_PMACZILOG_TTYS=y 12 + CONFIG_SERIAL_PMACZILOG_CONSOLE=y 13 + ''', 14 + qemu_arch='ppc', 15 + kernel_path='vmlinux', 16 + kernel_command_line='console=ttyS0', 17 + extra_qemu_params=['-M', 'g3beige', '-cpu', 'max'])
+14
tools/testing/kunit/qemu_configs/powerpcle.py
··· 1 + # SPDX-License-Identifier: GPL-2.0 2 + 3 + from ..qemu_config import QemuArchParams 4 + 5 + QEMU_ARCH = QemuArchParams(linux_arch='powerpc', 6 + kconfig=''' 7 + CONFIG_PPC64=y 8 + CONFIG_CPU_LITTLE_ENDIAN=y 9 + CONFIG_HVC_CONSOLE=y 10 + ''', 11 + qemu_arch='ppc64', 12 + kernel_path='vmlinux', 13 + kernel_command_line='console=ttyS0', 14 + extra_qemu_params=['-M', 'pseries', '-cpu', 'power8'])
+17
tools/testing/kunit/qemu_configs/riscv32.py
··· 1 + # SPDX-License-Identifier: GPL-2.0 2 + 3 + from ..qemu_config import QemuArchParams 4 + 5 + QEMU_ARCH = QemuArchParams(linux_arch='riscv', 6 + kconfig=''' 7 + CONFIG_NONPORTABLE=y 8 + CONFIG_ARCH_RV32I=y 9 + CONFIG_ARCH_VIRT=y 10 + CONFIG_SERIAL_8250=y 11 + CONFIG_SERIAL_8250_CONSOLE=y 12 + CONFIG_SERIAL_OF_PLATFORM=y 13 + ''', 14 + qemu_arch='riscv32', 15 + kernel_path='arch/riscv/boot/Image', 16 + kernel_command_line='console=ttyS0', 17 + extra_qemu_params=['-machine', 'virt'])
+2
tools/testing/kunit/qemu_configs/sparc.py
··· 2 2 3 3 QEMU_ARCH = QemuArchParams(linux_arch='sparc', 4 4 kconfig=''' 5 + CONFIG_KUNIT_FAULT_TEST=n 6 + CONFIG_SPARC32=y 5 7 CONFIG_SERIAL_SUNZILOG=y 6 8 CONFIG_SERIAL_SUNZILOG_CONSOLE=y 7 9 ''',
+16
tools/testing/kunit/qemu_configs/sparc64.py
··· 1 + # SPDX-License-Identifier: GPL-2.0 2 + 3 + from ..qemu_config import QemuArchParams 4 + 5 + QEMU_ARCH = QemuArchParams(linux_arch='sparc', 6 + kconfig=''' 7 + CONFIG_64BIT=y 8 + CONFIG_SPARC64=y 9 + CONFIG_PCI=y 10 + CONFIG_SERIAL_SUNSU=y 11 + CONFIG_SERIAL_SUNSU_CONSOLE=y 12 + ''', 13 + qemu_arch='sparc64', 14 + kernel_path='arch/sparc/boot/image', 15 + kernel_command_line='console=ttyS0 kunit_shutdown=poweroff', 16 + extra_qemu_params=[])