From patchwork Fri May 23 19:39:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Shuah Khan X-Patchwork-Id: 892143 Received: from mail-il1-f169.google.com (mail-il1-f169.google.com [209.85.166.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E57F61D54D8 for ; Fri, 23 May 2025 19:39:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748029147; cv=none; b=OmnbuoHWvoVUqnl/iOLc58WTBnTbavGnmgIm6fT8myMAQm5AMnOHdGK7vEL8EaCBgMCgG36Bxo+MKYc7zxiSLmNvSzG1phLzVI04D7oSpCD3uRmGp6EQ35Q5EN8H7FatX+XYNhCJGh8fIcpwVBjO05hvk6RVJ6w6cugh5IoAC9o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748029147; c=relaxed/simple; bh=YNwPytqdIzXCb6Dbj/QZRhK3L6OYlfCpOdYMdfQBCdY=; h=Content-Type:Message-ID:Date:MIME-Version:From:Subject:To:Cc; b=YfpfXBd1K/Sh3B5v0MdNMBjKpWKQtwLlQAxM1L3IPmJkD+6Umus+VtVtGKJ8jtTVUSt4+piWPoa4UMWIyOoFWn+6Byb4qBkLnF0WoeUa1h9sSV+T5lSOBhPehEXgnXTX9P3+O8RYrwtc0xftfUX/idtIfZNiqE5Lt2hKDcQd8Ms= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linuxfoundation.org; spf=pass smtp.mailfrom=linuxfoundation.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=LC69EzI2; arc=none smtp.client-ip=209.85.166.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linuxfoundation.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linuxfoundation.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="LC69EzI2" Received: by mail-il1-f169.google.com with SMTP id e9e14a558f8ab-3da73998419so869005ab.0 for ; Fri, 23 May 2025 12:39:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; t=1748029143; x=1748633943; darn=vger.kernel.org; h=cc:to:subject:from:content-language:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=TSYaT5YyCnlhGvAeQksD3b6RZkgUC/+VazTkW+Ql7Jo=; b=LC69EzI2hbwSunwV25rg76ONuvZnnyySf8AEtcfR96ZUby05PuA3PIo8jZTgK2m3Z9 Yw9HmkhkO3fpWmHWpBmJNO8CQ5JH4Gl1Bn5Fx+cASLTLSzlvbeBqd2BuRfXHDpxOa51s 5IRXmTGBqpzL/sF4zK8fhFFROailAxBhCHhO4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748029143; x=1748633943; h=cc:to:subject:from:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=TSYaT5YyCnlhGvAeQksD3b6RZkgUC/+VazTkW+Ql7Jo=; b=YPXktvOkAavsKb32L9xshyTKiV17MS/Vdv5lQ1GadFvyhLADx+HQtHDVUpE+YKmPkv vx4TKlRXHJnebH3OcG11kYqCAwTXERdFgNE/rCkv01kGui5QNpmL6iY9zjeC3fpe8Yyh M9oAgZ2FgYFwoUXWLcqegf6NLDwWJmnr1Fznq5Pe7ApZ08Jj0e11AT4U9D+PVKbfccgv kjC2xvqy6ll927GFa0Sn9iin53xavLTjeWgGV5mlN83hk8m5wm2Udr6Z4iXOuMxCNK3m CiyiyvTXv3h7kJpVSEzWs4Zyn6xWd0wYoloWGGudCNdKh+404pJFJYEf3YsgCV5M+bWm OZYQ== X-Forwarded-Encrypted: i=1; AJvYcCU0jzBXbSMqsC/YVVUWnuh4D2/Zl1Elem4bNoLDf5Z6nguiAGgFHpOezFrutuBV/0VXDySnLdH1TICYVe+UPKw=@vger.kernel.org X-Gm-Message-State: AOJu0YySlVTO7l/tVnXTQ7dPiUkKo+I6wwhkqFN/M3xSr3i1xyGOkVmd Kms853I7Ehb0LuxKqqNxW05fwRPCiO5jxqbzzZ23DbiDs+v/1RiA+aRbCHNzJRCdHwk= X-Gm-Gg: ASbGncvt+7uo2ub0Tk+Ayi7n7AJw3XCgSmaDlsQmoBUkZPW/xw23FlBlld1t9qzpUxA zQF7ZUkkYoIAV0T6d4SfR/l9JoyeAUWc9hdS5EFSCaNabfLaE+U40VqcMJ0RBXT5e41j4T+nNNo iR/FRbYL+RcbBsYlJd6rWae5rizIHnN735HsuSANr2Jm4CSr0PTUvnp6PThJHga4l6MP9gTNpWB LxVGbJoxKEdB+ya48mcgyZu9ahQyvJ9GeXOqPcWgIb6NTcY9uifZWlaIN9Tcl0IHr1vo51vW+Vv XsFEEe1u6S+gZGvjW38wwJsZKrNuSMyyYCiejQfhCORDCUGJzE5WX9m0ie/wGw== X-Google-Smtp-Source: AGHT+IEtFR96KAft0blY/PutWzL551E5JYiKFBNXI7Q9jh7VeCljH5BFRRRFyvZU58UAeAumrIl4oA== X-Received: by 2002:a05:6e02:1b0e:b0:3db:86fc:d328 with SMTP id e9e14a558f8ab-3dc9b67097cmr3837105ab.5.1748029142916; Fri, 23 May 2025 12:39:02 -0700 (PDT) Received: from [192.168.1.14] ([38.175.170.29]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4fbcc38a56esm3727986173.12.2025.05.23.12.39.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 23 May 2025 12:39:02 -0700 (PDT) Message-ID: Date: Fri, 23 May 2025 13:39:01 -0600 Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US From: Shuah Khan Subject: [GIT PULL] kunit next update for Linux 6.16-rc1 To: Linus Torvalds Cc: shuah , Shuah Khan , Brendan Higgins , David Gow , Rae Moar , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Hi Linus, Please pull the following kunit next update for Linux 6.16-rc1. - Enables qemu_config for riscv32, sparc 64-bit, PowerPC 32-bit BE and 64-bit LE. - Enables CONFIG_SPARC32 to clearly differentiate between sparc 32-bit and 64-bit configurations. - Enables CONFIG_CPU_BIG_ENDIAN to clearly differentiate between powerpc LE and BE configurations. - Adds feature to list available architectures to kunit tool. - Fixes to bugs and changes to documentation. diff is attached. thanks, -- Shuah ---------------------------------------------------------------- The following changes since commit 8ffd015db85fea3e15a77027fda6c02ced4d2444: Linux 6.15-rc2 (2025-04-13 11:54:49 -0700) are available in the Git repository at: git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest tags/linux_kselftest-kunit-6.16-rc1 for you to fetch changes up to 772e50a76ee664e75581624f512df4e45582605a: kunit: Fix wrong parameter to kunit_deactivate_static_stub() (2025-05-21 09:51:23 -0600) ---------------------------------------------------------------- linux_kselftest-kunit-6.16-rc1 - Enables qemu_config for riscv32, sparc 64-bit, PowerPC 32-bit BE and 64-bit LE. - Enables CONFIG_SPARC32 to clearly differentiate between sparc 32-bit and 64-bit configurations. - Enables 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. ---------------------------------------------------------------- David Gow (1): kunit: qemu_configs: Disable faulting tests on 32-bit SPARC Kees Cook (1): kunit: executor: Remove const from kunit_filter_suites() allocation type Rae Moar (2): Documentation: kunit: improve example on testing static functions kunit: tool: add test counts to JSON output Richard Fitzgerald (1): kunit: configs: Enable CONFIG_INIT_STACK_ALL_PATTERN in all_tests Thomas Weißschuh (6): kunit: qemu_configs: Add riscv32 config kunit: tool: Implement listing of available architectures kunit: qemu_configs: powerpc: Explicitly enable CONFIG_CPU_BIG_ENDIAN=y kunit: qemu_configs: Add PowerPC 32-bit BE and 64-bit LE kunit: qemu_configs: sparc: Explicitly enable CONFIG_SPARC32=y kunit: qemu_configs: Add 64-bit SPARC configuration Tzung-Bi Shih (1): kunit: Fix wrong parameter to kunit_deactivate_static_stub() Documentation/dev-tools/kunit/run_wrapper.rst | 2 ++ Documentation/dev-tools/kunit/usage.rst | 38 +++++++++++++++++++++------ lib/kunit/executor.c | 2 +- lib/kunit/static_stub.c | 2 +- tools/testing/kunit/configs/all_tests.config | 1 + tools/testing/kunit/kunit_json.py | 10 +++++++ tools/testing/kunit/kunit_kernel.py | 8 ++++++ tools/testing/kunit/qemu_configs/powerpc.py | 1 + tools/testing/kunit/qemu_configs/powerpc32.py | 17 ++++++++++++ tools/testing/kunit/qemu_configs/powerpcle.py | 14 ++++++++++ tools/testing/kunit/qemu_configs/riscv32.py | 17 ++++++++++++ tools/testing/kunit/qemu_configs/sparc.py | 2 ++ tools/testing/kunit/qemu_configs/sparc64.py | 16 +++++++++++ 13 files changed, 120 insertions(+), 10 deletions(-) create mode 100644 tools/testing/kunit/qemu_configs/powerpc32.py create mode 100644 tools/testing/kunit/qemu_configs/powerpcle.py create mode 100644 tools/testing/kunit/qemu_configs/riscv32.py create mode 100644 tools/testing/kunit/qemu_configs/sparc64.py ---------------------------------------------------------------- diff --git a/Documentation/dev-tools/kunit/run_wrapper.rst b/Documentation/dev-tools/kunit/run_wrapper.rst index 19ddf5e07013..6697c71ee8ca 100644 --- a/Documentation/dev-tools/kunit/run_wrapper.rst +++ b/Documentation/dev-tools/kunit/run_wrapper.rst @@ -182,6 +182,8 @@ via UML. To run tests on qemu, by default it requires two flags: is ignored), the tests will run via UML. Non-UML architectures, for example: i386, x86_64, arm and so on; run on qemu. + ``--arch help`` lists all valid ``--arch`` values. + - ``--cross_compile``: Specifies the Kbuild toolchain. It passes the same argument as passed to the ``CROSS_COMPILE`` variable used by Kbuild. As a reminder, this will be the prefix for the toolchain diff --git a/Documentation/dev-tools/kunit/usage.rst b/Documentation/dev-tools/kunit/usage.rst index 22955d56b379..038f480074fd 100644 --- a/Documentation/dev-tools/kunit/usage.rst +++ b/Documentation/dev-tools/kunit/usage.rst @@ -670,28 +670,50 @@ with ``kunit_remove_action``. Testing Static Functions ------------------------ -If we do not want to expose functions or variables for testing, one option is to -conditionally export the used symbol. For example: +If you want to test static functions without exposing those functions outside of +testing, one option is conditionally export the symbol. When KUnit is enabled, +the symbol is exposed but remains static otherwise. To use this method, follow +the template below. .. code-block:: c - /* In my_file.c */ + /* In the file containing functions to test "my_file.c" */ - VISIBLE_IF_KUNIT int do_interesting_thing(); + #include + #include + ... + VISIBLE_IF_KUNIT int do_interesting_thing() + { + ... + } EXPORT_SYMBOL_IF_KUNIT(do_interesting_thing); - /* In my_file.h */ + /* In the header file "my_file.h" */ #if IS_ENABLED(CONFIG_KUNIT) int do_interesting_thing(void); #endif -Alternatively, you could conditionally ``#include`` the test file at the end of -your .c file. For example: + /* In the KUnit test file "my_file_test.c" */ + + #include + #include + ... + MODULE_IMPORT_NS(EXPORTED_FOR_KUNIT_TESTING); + ... + // Use do_interesting_thing() in tests + +For a full example, see this `patch `_ +where a test is modified to conditionally expose static functions for testing +using the macros above. + +As an **alternative** to the method above, you could conditionally ``#include`` +the test file at the end of your .c file. This is not recommended but works +if needed. For example: .. code-block:: c - /* In my_file.c */ + /* In "my_file.c" */ static int do_interesting_thing(); diff --git a/lib/kunit/executor.c b/lib/kunit/executor.c index 3f39955cb0f1..0061d4c7e351 100644 --- a/lib/kunit/executor.c +++ b/lib/kunit/executor.c @@ -177,7 +177,7 @@ kunit_filter_suites(const struct kunit_suite_set *suite_set, const size_t max = suite_set->end - suite_set->start; - copy = kcalloc(max, sizeof(*filtered.start), GFP_KERNEL); + copy = kcalloc(max, sizeof(*copy), GFP_KERNEL); if (!copy) { /* won't be able to run anything, return an empty set */ return filtered; } diff --git a/lib/kunit/static_stub.c b/lib/kunit/static_stub.c index 92b2cccd5e76..484fd85251b4 100644 --- a/lib/kunit/static_stub.c +++ b/lib/kunit/static_stub.c @@ -96,7 +96,7 @@ void __kunit_activate_static_stub(struct kunit *test, /* If the replacement address is NULL, deactivate the stub. */ if (!replacement_addr) { - kunit_deactivate_static_stub(test, replacement_addr); + kunit_deactivate_static_stub(test, real_fn_addr); return; } diff --git a/tools/testing/kunit/configs/all_tests.config b/tools/testing/kunit/configs/all_tests.config index cdd9782f9646..4a60bb71fe72 100644 --- a/tools/testing/kunit/configs/all_tests.config +++ b/tools/testing/kunit/configs/all_tests.config @@ -10,6 +10,7 @@ CONFIG_KUNIT_EXAMPLE_TEST=y CONFIG_KUNIT_ALL_TESTS=y CONFIG_FORTIFY_SOURCE=y +CONFIG_INIT_STACK_ALL_PATTERN=y CONFIG_IIO=y diff --git a/tools/testing/kunit/kunit_json.py b/tools/testing/kunit/kunit_json.py index 10ff65689dd8..80fa4e354a17 100644 --- a/tools/testing/kunit/kunit_json.py +++ b/tools/testing/kunit/kunit_json.py @@ -39,10 +39,20 @@ def _get_group_json(test: Test, common_fields: JsonObj) -> JsonObj: status = _status_map.get(subtest.status, "FAIL") test_cases.append({"name": subtest.name, "status": status}) + test_counts = test.counts + counts_json = { + "tests": test_counts.total(), + "passed": test_counts.passed, + "failed": test_counts.failed, + "crashed": test_counts.crashed, + "skipped": test_counts.skipped, + "errors": test_counts.errors, + } test_group = { "name": test.name, "sub_groups": sub_groups, "test_cases": test_cases, + "misc": counts_json } test_group.update(common_fields) return test_group diff --git a/tools/testing/kunit/kunit_kernel.py b/tools/testing/kunit/kunit_kernel.py index d3f39bc1ceec..260d8d9aa1db 100644 --- a/tools/testing/kunit/kunit_kernel.py +++ b/tools/testing/kunit/kunit_kernel.py @@ -14,6 +14,7 @@ import os import shlex import shutil import signal +import sys import threading from typing import Iterator, List, Optional, Tuple from types import FrameType @@ -201,6 +202,13 @@ def _default_qemu_config_path(arch: str) -> str: return config_path options = [f[:-3] for f in os.listdir(QEMU_CONFIGS_DIR) if f.endswith('.py')] + + if arch == 'help': + print('um') + for option in options: + print(option) + sys.exit() + raise ConfigError(arch + ' is not a valid arch, options are ' + str(sorted(options))) def _get_qemu_ops(config_path: str, diff --git a/tools/testing/kunit/qemu_configs/powerpc.py b/tools/testing/kunit/qemu_configs/powerpc.py index 7ec38d4131f7..5b4c895d5d5a 100644 --- a/tools/testing/kunit/qemu_configs/powerpc.py +++ b/tools/testing/kunit/qemu_configs/powerpc.py @@ -3,6 +3,7 @@ from ..qemu_config import QemuArchParams QEMU_ARCH = QemuArchParams(linux_arch='powerpc', kconfig=''' CONFIG_PPC64=y +CONFIG_CPU_BIG_ENDIAN=y CONFIG_SERIAL_8250=y CONFIG_SERIAL_8250_CONSOLE=y CONFIG_HVC_CONSOLE=y''', diff --git a/tools/testing/kunit/qemu_configs/powerpc32.py b/tools/testing/kunit/qemu_configs/powerpc32.py new file mode 100644 index 000000000000..88bd60dbb948 --- /dev/null +++ b/tools/testing/kunit/qemu_configs/powerpc32.py @@ -0,0 +1,17 @@ +# SPDX-License-Identifier: GPL-2.0 + +from ..qemu_config import QemuArchParams + +QEMU_ARCH = QemuArchParams(linux_arch='powerpc', + kconfig=''' +CONFIG_PPC32=y +CONFIG_CPU_BIG_ENDIAN=y +CONFIG_ADB_CUDA=y +CONFIG_SERIAL_PMACZILOG=y +CONFIG_SERIAL_PMACZILOG_TTYS=y +CONFIG_SERIAL_PMACZILOG_CONSOLE=y +''', + qemu_arch='ppc', + kernel_path='vmlinux', + kernel_command_line='console=ttyS0', + extra_qemu_params=['-M', 'g3beige', '-cpu', 'max']) diff --git a/tools/testing/kunit/qemu_configs/powerpcle.py b/tools/testing/kunit/qemu_configs/powerpcle.py new file mode 100644 index 000000000000..7ddee8af4bd7 --- /dev/null +++ b/tools/testing/kunit/qemu_configs/powerpcle.py @@ -0,0 +1,14 @@ +# SPDX-License-Identifier: GPL-2.0 + +from ..qemu_config import QemuArchParams + +QEMU_ARCH = QemuArchParams(linux_arch='powerpc', + kconfig=''' +CONFIG_PPC64=y +CONFIG_CPU_LITTLE_ENDIAN=y +CONFIG_HVC_CONSOLE=y +''', + qemu_arch='ppc64', + kernel_path='vmlinux', + kernel_command_line='console=ttyS0', + extra_qemu_params=['-M', 'pseries', '-cpu', 'power8']) diff --git a/tools/testing/kunit/qemu_configs/riscv32.py b/tools/testing/kunit/qemu_configs/riscv32.py new file mode 100644 index 000000000000..b79ba0ae30f8 --- /dev/null +++ b/tools/testing/kunit/qemu_configs/riscv32.py @@ -0,0 +1,17 @@ +# SPDX-License-Identifier: GPL-2.0 + +from ..qemu_config import QemuArchParams + +QEMU_ARCH = QemuArchParams(linux_arch='riscv', + kconfig=''' +CONFIG_NONPORTABLE=y +CONFIG_ARCH_RV32I=y +CONFIG_ARCH_VIRT=y +CONFIG_SERIAL_8250=y +CONFIG_SERIAL_8250_CONSOLE=y +CONFIG_SERIAL_OF_PLATFORM=y +''', + qemu_arch='riscv32', + kernel_path='arch/riscv/boot/Image', + kernel_command_line='console=ttyS0', + extra_qemu_params=['-machine', 'virt']) diff --git a/tools/testing/kunit/qemu_configs/sparc.py b/tools/testing/kunit/qemu_configs/sparc.py index 256d9573b446..2019550a1b69 100644 --- a/tools/testing/kunit/qemu_configs/sparc.py +++ b/tools/testing/kunit/qemu_configs/sparc.py @@ -2,6 +2,8 @@ from ..qemu_config import QemuArchParams QEMU_ARCH = QemuArchParams(linux_arch='sparc', kconfig=''' +CONFIG_KUNIT_FAULT_TEST=n +CONFIG_SPARC32=y CONFIG_SERIAL_SUNZILOG=y CONFIG_SERIAL_SUNZILOG_CONSOLE=y ''', diff --git a/tools/testing/kunit/qemu_configs/sparc64.py b/tools/testing/kunit/qemu_configs/sparc64.py new file mode 100644 index 000000000000..53d4e5a8c972 --- /dev/null +++ b/tools/testing/kunit/qemu_configs/sparc64.py @@ -0,0 +1,16 @@ +# SPDX-License-Identifier: GPL-2.0 + +from ..qemu_config import QemuArchParams + +QEMU_ARCH = QemuArchParams(linux_arch='sparc', + kconfig=''' +CONFIG_64BIT=y +CONFIG_SPARC64=y +CONFIG_PCI=y +CONFIG_SERIAL_SUNSU=y +CONFIG_SERIAL_SUNSU_CONSOLE=y +''', + qemu_arch='sparc64', + kernel_path='arch/sparc/boot/image', + kernel_command_line='console=ttyS0 kunit_shutdown=poweroff', + extra_qemu_params=[])