From patchwork Thu Mar 27 03:05:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Shuah Khan X-Patchwork-Id: 14030774 Received: from mail-il1-f182.google.com (mail-il1-f182.google.com [209.85.166.182]) (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 5EC4F133987 for ; Thu, 27 Mar 2025 03:05:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743044712; cv=none; b=axhA3tAMrXwzW9/qLUyQMANCchObqo68KbI/K4fO6mUtQkFRfQq9IrImse4o28t/okea3K3i7E3i0fsGT7N5Bx2wTnM3AmHGF9BJOO38FktMEvunp3aUvTIiKZxE/kTv8TJxuhPSbnEodzKrySdGTTgwjkhyghqWkBhM0xCUUJ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743044712; c=relaxed/simple; bh=xaiyb+43kpLQiTaQFl7k4Q9WcQ1x12uqBToBSPpceXQ=; h=Content-Type:Message-ID:Date:MIME-Version:From:Subject:To:Cc; b=b9GVVOkc5DFD+vuKBgx94dxSmXnrvS6iZr3E8odJbev5rDp0glXap0nkRPQfvznXCPhdZQdgT21CZ5p62a+s3kpFPcz6kw8t5AXZHH596wOs9dZWNXSIssolnIgA4Kps0BCF4+3sV8Op313lJXYGbMtAPwI121YnGnKaRq0u9rk= 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=TGjJlmSr; arc=none smtp.client-ip=209.85.166.182 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="TGjJlmSr" Received: by mail-il1-f182.google.com with SMTP id e9e14a558f8ab-3d46ef71b6cso3676625ab.3 for ; Wed, 26 Mar 2025 20:05:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; t=1743044709; x=1743649509; 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=vER9VzyQlD5GTKqM8LcyXr9AQyXPj9zGCWDvSyU8x44=; b=TGjJlmSr+hH3ttZwwd0sdSvd+ckS/KmIgxiuBq/TgXR//x64VdpwYP55L7wEltfcKF ST9KXStEaELaFFHfwAsh8fE8XSoipyFkU28FsdhvcOp3alDnm22RIMhjd4YdvBhFWxR2 Ts7SsrwXE69bzrPiS3zCYtE9H2VV1udF9EMrQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743044709; x=1743649509; 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=vER9VzyQlD5GTKqM8LcyXr9AQyXPj9zGCWDvSyU8x44=; b=mLHY9JZ0+JIhmR8DkhO0JcZM65KixWOqoQq3VMEnz1TTuS8ypNnkfqtxPcUnjGx7XY kX0wD2Tamc5IPk373XUJLzsVAsHv2H15INWytEH08ftjC8GbbSuLUUmtPsoW2WQ6ckHQ RgjvhVzRz0mWMrz2Z+qITLl9U11mtM/GW+n2FAFWf0fBg/UVHsghb0coASMZTLY2SoWx dJoai92SDESwYlSWw1VsR21WWsVCmnXlQ+MlxVByLqmBTSt+GHarabmsnoIrKmuKxn6l xsfcysZ5uHqQp21NtbEBvuYxebNCJY36LX563QxPuVvwywn0Wh9tuQXPiEbZbSLs/aUk ACLg== X-Forwarded-Encrypted: i=1; AJvYcCUBzy4A5bOwmc73DD+IXbmoYQwhRqaaG60pXyApCcLBwY0cNmK1o6LkLoF/0+Ad/sinNWqMCf+dIwfFygH99K0=@vger.kernel.org X-Gm-Message-State: AOJu0YziyN41FduC7nOMJsd2lze/zAfYDttq7lVaFlaxq+oi90zXPU8j UtOqB06ESCfaNj92tuzS/4g5nYekP9eCNPr41gkLg2KE8PKhfi9A3wVg39Ubajs= X-Gm-Gg: ASbGnctV/FDxRQN7iIo8T9/IRmzWcivYpLMZkcdNqzNIAk24mweHkWdf5dLVHGm2ask N+zxbXhsZOYwM0QTe+SrOLoPCK/aSvZCw6u1r8JQXjLxSQEe8NzDRNWHCHf/blqFW5kqW1OB0bk y5mcTk30jqplHlXbM3hyE9oL2tPP4Tu+b941JcX+h8zlfd+65sxOZYg6Y24PJvLAeDtviXGa7vM fI6iaacKT8Q0f1ngo0NePo0iFTW9vti6gTJVx/J3Qwi4TbgXDHKCmgNDVflr7Ag9WX0vC9cxxY7 Ir9PvZI/+51K9NMzzxmpeCFCG6e9kwC2fJ1XvzAjhbEwjWSiyvTqm0ldwlR3VYnZMpMr4SQUFRe WTjvn4MF59Byd7FR0+epgigt/TGE= X-Google-Smtp-Source: AGHT+IFvYsmFPjIAvF6zdgV5MREAu/X7Lbn/j8zq0F/eLHT5LR/e210sE+aarUjqFQ9uyYHqnoakdw== X-Received: by 2002:a05:6e02:3e03:b0:3a7:88f2:cfa9 with SMTP id e9e14a558f8ab-3d5ccdde20fmr24199955ab.11.1743044709211; Wed, 26 Mar 2025 20:05:09 -0700 (PDT) Received: from ?IPV6:2607:fb90:350f:48e4:8567:efb1:9883:10ae? ([2607:fb90:350f:48e4:8567:efb1:9883:10ae]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4f2cbdb4728sm3134805173.19.2025.03.26.20.05.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 26 Mar 2025 20:05:08 -0700 (PDT) Message-ID: <2bc29da1-5c77-45a4-ab75-7afc6f9210be@linuxfoundation.org> Date: Wed, 26 Mar 2025 21:05:06 -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.15-rc1 To: Linus Torvalds Cc: Stephen Rothwell , Kees Cook , "kuba@kernel.org" , "David S. Miller" , Paolo Abeni , shuah , Shuah Khan , "open list:KERNEL SELFTEST FRAMEWORK" , Linux Kernel Mailing List , Networking , Linux Next Mailing List Hi Linus, Please pull the following kunit next update for Linux 6.15-rc1. kunit tool: - Changes to kunit tool to use qboot on QEMU x86_64, and build GDB scripts. - Fixes kunit tool bug in parsing test plan. - Adds test to kunit tool to check parsing late test plan. kunit: - Clarifies kunit_skip() argument name. - Adds Kunit check for the longest symbol length. - Changes qemu_configs for sparc to use Zilog console. Conflicts in lib/Makefile between commit: b341f6fd45ab ("blackhole_dev: convert self-test to KUnit") from the net-next tree and commit: c104c16073b7 ("Kunit to check the longest symbol length") The commit c104c16073b7 conflicts with the mainline now with 62f3802332ed ("vdso: add generic time data storage") from kspp is now in the mainline. Stephen has the fixes for these two conflicts in next. (Thank you Stephen) diff is attached. thanks, -- Shuah ---------------------------------------------------------------- The following changes since commit a64dcfb451e254085a7daee5fe51bf22959d52d3: Linux 6.14-rc2 (2025-02-09 12:45:03 -0800) are available in the Git repository at: git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest tags/linux_kselftest-kunit-6.15-rc1 for you to fetch changes up to 2e0cf2b32f72b20b0db5cc665cd8465d0f257278: kunit: tool: add test to check parsing late test plan (2025-03-15 18:13:43 -0600) ---------------------------------------------------------------- linux_kselftest-kunit-6.15-rc1 kunit tool: - Changes to kunit tool to use qboot on QEMU x86_64, and build GDB scripts. - Fixes kunit tool bug in parsing test plan. - Adds test to kunit tool to check parsing late test plan. kunit: - Clarifies kunit_skip() argument name. - Adds Kunit check for the longest symbol length. - Changes qemu_configs for sparc to use Zilog console. ---------------------------------------------------------------- Brendan Jackman (2): kunit: tool: Use qboot on QEMU x86_64 kunit: tool: Build GDB scripts Kevin Brodsky (1): kunit: Clarify kunit_skip() argument name Rae Moar (2): kunit: tool: Fix bug in parsing test plan kunit: tool: add test to check parsing late test plan Sergio González Collado (1): Kunit to check the longest symbol length Thomas Weißschuh (1): kunit: qemu_configs: sparc: use Zilog console arch/x86/tools/insn_decoder_test.c | 3 +- include/kunit/test.h | 20 ++++---- lib/Kconfig.debug | 9 ++++ lib/Makefile | 2 + lib/longest_symbol_kunit.c | 82 ++++++++++++++++++++++++++++++ tools/testing/kunit/kunit_kernel.py | 4 +- tools/testing/kunit/kunit_parser.py | 9 ++-- tools/testing/kunit/kunit_tool_test.py | 11 ++++ tools/testing/kunit/qemu_configs/sparc.py | 5 +- tools/testing/kunit/qemu_configs/x86_64.py | 4 +- 10 files changed, 128 insertions(+), 21 deletions(-) create mode 100644 lib/longest_symbol_kunit.c ---------------------------------------------------------------- diff --git a/arch/x86/tools/insn_decoder_test.c b/arch/x86/tools/insn_decoder_test.c index 472540aeabc2..6c2986d2ad11 100644 --- a/arch/x86/tools/insn_decoder_test.c +++ b/arch/x86/tools/insn_decoder_test.c @@ -10,6 +10,7 @@ #include #include #include +#include #define unlikely(cond) (cond) @@ -106,7 +107,7 @@ static void parse_args(int argc, char **argv) } } -#define BUFSIZE 256 +#define BUFSIZE (256 + KSYM_NAME_LEN) int main(int argc, char **argv) { diff --git a/include/kunit/test.h b/include/kunit/test.h index 58dbab60f853..0ffb97c78566 100644 --- a/include/kunit/test.h +++ b/include/kunit/test.h @@ -553,9 +553,9 @@ void kunit_cleanup(struct kunit *test); void __printf(2, 3) kunit_log_append(struct string_stream *log, const char *fmt, ...); /** - * kunit_mark_skipped() - Marks @test_or_suite as skipped + * kunit_mark_skipped() - Marks @test as skipped * - * @test_or_suite: The test context object. + * @test: The test context object. * @fmt: A printk() style format string. * * Marks the test as skipped. @fmt is given output as the test status @@ -563,18 +563,18 @@ void __printf(2, 3) kunit_log_append(struct string_stream *log, const char *fmt, * * Test execution continues after kunit_mark_skipped() is called. */ -#define kunit_mark_skipped(test_or_suite, fmt, ...) \ +#define kunit_mark_skipped(test, fmt, ...) \ do { \ - WRITE_ONCE((test_or_suite)->status, KUNIT_SKIPPED); \ - scnprintf((test_or_suite)->status_comment, \ + WRITE_ONCE((test)->status, KUNIT_SKIPPED); \ + scnprintf((test)->status_comment, \ KUNIT_STATUS_COMMENT_SIZE, \ fmt, ##__VA_ARGS__); \ } while (0) /** - * kunit_skip() - Marks @test_or_suite as skipped + * kunit_skip() - Marks @test as skipped * - * @test_or_suite: The test context object. + * @test: The test context object. * @fmt: A printk() style format string. * * Skips the test. @fmt is given output as the test status @@ -582,10 +582,10 @@ void __printf(2, 3) kunit_log_append(struct string_stream *log, const char *fmt, * * Test execution is halted after kunit_skip() is called. */ -#define kunit_skip(test_or_suite, fmt, ...) \ +#define kunit_skip(test, fmt, ...) \ do { \ - kunit_mark_skipped((test_or_suite), fmt, ##__VA_ARGS__);\ - kunit_try_catch_throw(&((test_or_suite)->try_catch)); \ + kunit_mark_skipped((test), fmt, ##__VA_ARGS__); \ + kunit_try_catch_throw(&((test)->try_catch)); \ } while (0) /* diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 1af972a92d06..62d43aa9e8f0 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -2838,6 +2838,15 @@ config FORTIFY_KUNIT_TEST by the str*() and mem*() family of functions. For testing runtime traps of FORTIFY_SOURCE, see LKDTM's "FORTIFY_*" tests. +config LONGEST_SYM_KUNIT_TEST + tristate "Test the longest symbol possible" if !KUNIT_ALL_TESTS + depends on KUNIT && KPROBES + default KUNIT_ALL_TESTS + help + Tests the longest symbol possible + + If unsure, say N. + config HW_BREAKPOINT_KUNIT_TEST bool "Test hw_breakpoint constraints accounting" if !KUNIT_ALL_TESTS depends on HAVE_HW_BREAKPOINT diff --git a/lib/Makefile b/lib/Makefile index d5cfc7afbbb8..e8fec9defec2 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -393,6 +393,8 @@ obj-$(CONFIG_FORTIFY_KUNIT_TEST) += fortify_kunit.o obj-$(CONFIG_CRC_KUNIT_TEST) += crc_kunit.o obj-$(CONFIG_SIPHASH_KUNIT_TEST) += siphash_kunit.o obj-$(CONFIG_USERCOPY_KUNIT_TEST) += usercopy_kunit.o +obj-$(CONFIG_LONGEST_SYM_KUNIT_TEST) += longest_symbol_kunit.o +CFLAGS_longest_symbol_kunit.o += $(call cc-disable-warning, missing-prototypes) obj-$(CONFIG_GENERIC_LIB_DEVMEM_IS_ALLOWED) += devmem_is_allowed.o diff --git a/lib/longest_symbol_kunit.c b/lib/longest_symbol_kunit.c new file mode 100644 index 000000000000..e3c28ff1807f --- /dev/null +++ b/lib/longest_symbol_kunit.c @@ -0,0 +1,82 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Test the longest symbol length. Execute with: + * ./tools/testing/kunit/kunit.py run longest-symbol + * --arch=x86_64 --kconfig_add CONFIG_KPROBES=y --kconfig_add CONFIG_MODULES=y + * --kconfig_add CONFIG_RETPOLINE=n --kconfig_add CONFIG_CFI_CLANG=n + * --kconfig_add CONFIG_MITIGATION_RETPOLINE=n + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include +#include + +#define DI(name) s##name##name +#define DDI(name) DI(n##name##name) +#define DDDI(name) DDI(n##name##name) +#define DDDDI(name) DDDI(n##name##name) +#define DDDDDI(name) DDDDI(n##name##name) + +/*Generate a symbol whose name length is 511 */ +#define LONGEST_SYM_NAME DDDDDI(g1h2i3j4k5l6m7n) + +#define RETURN_LONGEST_SYM 0xAAAAA + +noinline int LONGEST_SYM_NAME(void); +noinline int LONGEST_SYM_NAME(void) +{ + return RETURN_LONGEST_SYM; +} + +_Static_assert(sizeof(__stringify(LONGEST_SYM_NAME)) == KSYM_NAME_LEN, +"Incorrect symbol length found. Expected KSYM_NAME_LEN: " +__stringify(KSYM_NAME_LEN) ", but found: " +__stringify(sizeof(LONGEST_SYM_NAME))); + +static void test_longest_symbol(struct kunit *test) +{ + KUNIT_EXPECT_EQ(test, RETURN_LONGEST_SYM, LONGEST_SYM_NAME()); +}; + +static void test_longest_symbol_kallsyms(struct kunit *test) +{ + unsigned long (*kallsyms_lookup_name)(const char *name); + static int (*longest_sym)(void); + + struct kprobe kp = { + .symbol_name = "kallsyms_lookup_name", + }; + + if (register_kprobe(&kp) < 0) { + pr_info("%s: kprobe not registered", __func__); + KUNIT_FAIL(test, "test_longest_symbol kallsyms: kprobe not registered\n"); + return; + } + + kunit_warn(test, "test_longest_symbol kallsyms: kprobe registered\n"); + kallsyms_lookup_name = (unsigned long (*)(const char *name))kp.addr; + unregister_kprobe(&kp); + + longest_sym = + (void *) kallsyms_lookup_name(__stringify(LONGEST_SYM_NAME)); + KUNIT_EXPECT_EQ(test, RETURN_LONGEST_SYM, longest_sym()); +}; + +static struct kunit_case longest_symbol_test_cases[] = { + KUNIT_CASE(test_longest_symbol), + KUNIT_CASE(test_longest_symbol_kallsyms), + {} +}; + +static struct kunit_suite longest_symbol_test_suite = { + .name = "longest-symbol", + .test_cases = longest_symbol_test_cases, +}; +kunit_test_suite(longest_symbol_test_suite); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("Test the longest symbol length"); +MODULE_AUTHOR("Sergio González Collado"); diff --git a/tools/testing/kunit/kunit_kernel.py b/tools/testing/kunit/kunit_kernel.py index d30f90eae9a4..d3f39bc1ceec 100644 --- a/tools/testing/kunit/kunit_kernel.py +++ b/tools/testing/kunit/kunit_kernel.py @@ -72,8 +72,8 @@ class LinuxSourceTreeOperations: raise ConfigError(e.output.decode()) def make(self, jobs: int, build_dir: str, make_options: Optional[List[str]]) -> None: - command = ['make', 'all', 'compile_commands.json', 'ARCH=' + self._linux_arch, - 'O=' + build_dir, '--jobs=' + str(jobs)] + command = ['make', 'all', 'compile_commands.json', 'scripts_gdb', + 'ARCH=' + self._linux_arch, 'O=' + build_dir, '--jobs=' + str(jobs)] if make_options: command.extend(make_options) if self._cross_compile: diff --git a/tools/testing/kunit/kunit_parser.py b/tools/testing/kunit/kunit_parser.py index 29fc27e8949b..da53a709773a 100644 --- a/tools/testing/kunit/kunit_parser.py +++ b/tools/testing/kunit/kunit_parser.py @@ -759,7 +759,7 @@ def parse_test(lines: LineStream, expected_num: int, log: List[str], is_subtest: # If parsing the main/top-level test, parse KTAP version line and # test plan test.name = "main" - ktap_line = parse_ktap_header(lines, test, printer) + parse_ktap_header(lines, test, printer) test.log.extend(parse_diagnostic(lines)) parse_test_plan(lines, test) parent_test = True @@ -768,13 +768,12 @@ def parse_test(lines: LineStream, expected_num: int, log: List[str], is_subtest: # the KTAP version line and/or subtest header line ktap_line = parse_ktap_header(lines, test, printer) subtest_line = parse_test_header(lines, test) + test.log.extend(parse_diagnostic(lines)) + parse_test_plan(lines, test) parent_test = (ktap_line or subtest_line) if parent_test: - # If KTAP version line and/or subtest header is found, attempt - # to parse test plan and print test header - test.log.extend(parse_diagnostic(lines)) - parse_test_plan(lines, test) print_test_header(test, printer) + expected_count = test.expected_count subtests = [] test_num = 1 diff --git a/tools/testing/kunit/kunit_tool_test.py b/tools/testing/kunit/kunit_tool_test.py index 0bcb0cc002f8..5ff4f6ffd873 100755 --- a/tools/testing/kunit/kunit_tool_test.py +++ b/tools/testing/kunit/kunit_tool_test.py @@ -363,6 +363,17 @@ class KUnitParserTest(unittest.TestCase): self.print_mock.assert_any_call(StrContains(' Indented more.')) self.noPrintCallContains('not ok 1 test1') + def test_parse_late_test_plan(self): + output = """ + TAP version 13 + ok 4 test4 + 1..4 + """ + result = kunit_parser.parse_run_tests(output.splitlines(), stdout) + # Missing test results after test plan should alert a suspected test crash. + self.assertEqual(kunit_parser.TestStatus.TEST_CRASHED, result.status) + self.assertEqual(result.counts, kunit_parser.TestCounts(passed=1, crashed=1, errors=1)) + def line_stream_from_strs(strs: Iterable[str]) -> kunit_parser.LineStream: return kunit_parser.LineStream(enumerate(strs, start=1)) diff --git a/tools/testing/kunit/qemu_configs/sparc.py b/tools/testing/kunit/qemu_configs/sparc.py index e975c4331a7c..256d9573b446 100644 --- a/tools/testing/kunit/qemu_configs/sparc.py +++ b/tools/testing/kunit/qemu_configs/sparc.py @@ -2,8 +2,9 @@ from ..qemu_config import QemuArchParams QEMU_ARCH = QemuArchParams(linux_arch='sparc', kconfig=''' -CONFIG_SERIAL_8250=y -CONFIG_SERIAL_8250_CONSOLE=y''', +CONFIG_SERIAL_SUNZILOG=y +CONFIG_SERIAL_SUNZILOG_CONSOLE=y +''', qemu_arch='sparc', kernel_path='arch/sparc/boot/zImage', kernel_command_line='console=ttyS0 mem=256M', diff --git a/tools/testing/kunit/qemu_configs/x86_64.py b/tools/testing/kunit/qemu_configs/x86_64.py index dc7949076863..4a6bf4e048f5 100644 --- a/tools/testing/kunit/qemu_configs/x86_64.py +++ b/tools/testing/kunit/qemu_configs/x86_64.py @@ -7,4 +7,6 @@ CONFIG_SERIAL_8250_CONSOLE=y''', qemu_arch='x86_64', kernel_path='arch/x86/boot/bzImage', kernel_command_line='console=ttyS0', - extra_qemu_params=[]) + # qboot is faster than SeaBIOS and doesn't mess up + # the terminal. + extra_qemu_params=['-bios', 'qboot.rom'])