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.15-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest

Pull kunit updates from Shuah Khan:
"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"

* tag 'linux_kselftest-kunit-6.15-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest:
kunit: tool: add test to check parsing late test plan
kunit: tool: Fix bug in parsing test plan
Kunit to check the longest symbol length
kunit: Clarify kunit_skip() argument name
kunit: tool: Build GDB scripts
kunit: qemu_configs: sparc: use Zilog console
kunit: tool: Use qboot on QEMU x86_64

+130 -21
+2 -1
arch/x86/tools/insn_decoder_test.c
··· 10 10 #include <assert.h> 11 11 #include <unistd.h> 12 12 #include <stdarg.h> 13 + #include <linux/kallsyms.h> 13 14 14 15 #define unlikely(cond) (cond) 15 16 ··· 107 106 } 108 107 } 109 108 110 - #define BUFSIZE 256 109 + #define BUFSIZE (256 + KSYM_NAME_LEN) 111 110 112 111 int main(int argc, char **argv) 113 112 {
+10 -10
include/kunit/test.h
··· 553 553 void __printf(2, 3) kunit_log_append(struct string_stream *log, const char *fmt, ...); 554 554 555 555 /** 556 - * kunit_mark_skipped() - Marks @test_or_suite as skipped 556 + * kunit_mark_skipped() - Marks @test as skipped 557 557 * 558 - * @test_or_suite: The test context object. 558 + * @test: The test context object. 559 559 * @fmt: A printk() style format string. 560 560 * 561 561 * Marks the test as skipped. @fmt is given output as the test status ··· 563 563 * 564 564 * Test execution continues after kunit_mark_skipped() is called. 565 565 */ 566 - #define kunit_mark_skipped(test_or_suite, fmt, ...) \ 566 + #define kunit_mark_skipped(test, fmt, ...) \ 567 567 do { \ 568 - WRITE_ONCE((test_or_suite)->status, KUNIT_SKIPPED); \ 569 - scnprintf((test_or_suite)->status_comment, \ 568 + WRITE_ONCE((test)->status, KUNIT_SKIPPED); \ 569 + scnprintf((test)->status_comment, \ 570 570 KUNIT_STATUS_COMMENT_SIZE, \ 571 571 fmt, ##__VA_ARGS__); \ 572 572 } while (0) 573 573 574 574 /** 575 - * kunit_skip() - Marks @test_or_suite as skipped 575 + * kunit_skip() - Marks @test as skipped 576 576 * 577 - * @test_or_suite: The test context object. 577 + * @test: The test context object. 578 578 * @fmt: A printk() style format string. 579 579 * 580 580 * Skips the test. @fmt is given output as the test status ··· 582 582 * 583 583 * Test execution is halted after kunit_skip() is called. 584 584 */ 585 - #define kunit_skip(test_or_suite, fmt, ...) \ 585 + #define kunit_skip(test, fmt, ...) \ 586 586 do { \ 587 - kunit_mark_skipped((test_or_suite), fmt, ##__VA_ARGS__);\ 588 - kunit_try_catch_throw(&((test_or_suite)->try_catch)); \ 587 + kunit_mark_skipped((test), fmt, ##__VA_ARGS__); \ 588 + kunit_try_catch_throw(&((test)->try_catch)); \ 589 589 } while (0) 590 590 591 591 /*
+9
lib/Kconfig.debug
··· 2866 2866 by the str*() and mem*() family of functions. For testing runtime 2867 2867 traps of FORTIFY_SOURCE, see LKDTM's "FORTIFY_*" tests. 2868 2868 2869 + config LONGEST_SYM_KUNIT_TEST 2870 + tristate "Test the longest symbol possible" if !KUNIT_ALL_TESTS 2871 + depends on KUNIT && KPROBES 2872 + default KUNIT_ALL_TESTS 2873 + help 2874 + Tests the longest symbol possible 2875 + 2876 + If unsure, say N. 2877 + 2869 2878 config HW_BREAKPOINT_KUNIT_TEST 2870 2879 bool "Test hw_breakpoint constraints accounting" if !KUNIT_ALL_TESTS 2871 2880 depends on HAVE_HW_BREAKPOINT
+4
lib/tests/Makefile
··· 27 27 obj-$(CONFIG_KFIFO_KUNIT_TEST) += kfifo_kunit.o 28 28 obj-$(CONFIG_TEST_LIST_SORT) += test_list_sort.o 29 29 obj-$(CONFIG_LINEAR_RANGES_TEST) += test_linear_ranges.o 30 + 31 + CFLAGS_longest_symbol_kunit.o += $(call cc-disable-warning, missing-prototypes) 32 + obj-$(CONFIG_LONGEST_SYM_KUNIT_TEST) += longest_symbol_kunit.o 33 + 30 34 obj-$(CONFIG_MEMCPY_KUNIT_TEST) += memcpy_kunit.o 31 35 CFLAGS_overflow_kunit.o = $(call cc-disable-warning, tautological-constant-out-of-range-compare) 32 36 obj-$(CONFIG_OVERFLOW_KUNIT_TEST) += overflow_kunit.o
+82
lib/tests/longest_symbol_kunit.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Test the longest symbol length. Execute with: 4 + * ./tools/testing/kunit/kunit.py run longest-symbol 5 + * --arch=x86_64 --kconfig_add CONFIG_KPROBES=y --kconfig_add CONFIG_MODULES=y 6 + * --kconfig_add CONFIG_RETPOLINE=n --kconfig_add CONFIG_CFI_CLANG=n 7 + * --kconfig_add CONFIG_MITIGATION_RETPOLINE=n 8 + */ 9 + 10 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 11 + 12 + #include <kunit/test.h> 13 + #include <linux/stringify.h> 14 + #include <linux/kprobes.h> 15 + #include <linux/kallsyms.h> 16 + 17 + #define DI(name) s##name##name 18 + #define DDI(name) DI(n##name##name) 19 + #define DDDI(name) DDI(n##name##name) 20 + #define DDDDI(name) DDDI(n##name##name) 21 + #define DDDDDI(name) DDDDI(n##name##name) 22 + 23 + /*Generate a symbol whose name length is 511 */ 24 + #define LONGEST_SYM_NAME DDDDDI(g1h2i3j4k5l6m7n) 25 + 26 + #define RETURN_LONGEST_SYM 0xAAAAA 27 + 28 + noinline int LONGEST_SYM_NAME(void); 29 + noinline int LONGEST_SYM_NAME(void) 30 + { 31 + return RETURN_LONGEST_SYM; 32 + } 33 + 34 + _Static_assert(sizeof(__stringify(LONGEST_SYM_NAME)) == KSYM_NAME_LEN, 35 + "Incorrect symbol length found. Expected KSYM_NAME_LEN: " 36 + __stringify(KSYM_NAME_LEN) ", but found: " 37 + __stringify(sizeof(LONGEST_SYM_NAME))); 38 + 39 + static void test_longest_symbol(struct kunit *test) 40 + { 41 + KUNIT_EXPECT_EQ(test, RETURN_LONGEST_SYM, LONGEST_SYM_NAME()); 42 + }; 43 + 44 + static void test_longest_symbol_kallsyms(struct kunit *test) 45 + { 46 + unsigned long (*kallsyms_lookup_name)(const char *name); 47 + static int (*longest_sym)(void); 48 + 49 + struct kprobe kp = { 50 + .symbol_name = "kallsyms_lookup_name", 51 + }; 52 + 53 + if (register_kprobe(&kp) < 0) { 54 + pr_info("%s: kprobe not registered", __func__); 55 + KUNIT_FAIL(test, "test_longest_symbol kallsyms: kprobe not registered\n"); 56 + return; 57 + } 58 + 59 + kunit_warn(test, "test_longest_symbol kallsyms: kprobe registered\n"); 60 + kallsyms_lookup_name = (unsigned long (*)(const char *name))kp.addr; 61 + unregister_kprobe(&kp); 62 + 63 + longest_sym = 64 + (void *) kallsyms_lookup_name(__stringify(LONGEST_SYM_NAME)); 65 + KUNIT_EXPECT_EQ(test, RETURN_LONGEST_SYM, longest_sym()); 66 + }; 67 + 68 + static struct kunit_case longest_symbol_test_cases[] = { 69 + KUNIT_CASE(test_longest_symbol), 70 + KUNIT_CASE(test_longest_symbol_kallsyms), 71 + {} 72 + }; 73 + 74 + static struct kunit_suite longest_symbol_test_suite = { 75 + .name = "longest-symbol", 76 + .test_cases = longest_symbol_test_cases, 77 + }; 78 + kunit_test_suite(longest_symbol_test_suite); 79 + 80 + MODULE_LICENSE("GPL"); 81 + MODULE_DESCRIPTION("Test the longest symbol length"); 82 + MODULE_AUTHOR("Sergio González Collado");
+2 -2
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', 'all', 'compile_commands.json', 'ARCH=' + self._linux_arch, 76 - 'O=' + build_dir, '--jobs=' + str(jobs)] 75 + command = ['make', 'all', 'compile_commands.json', 'scripts_gdb', 76 + 'ARCH=' + self._linux_arch, 'O=' + build_dir, '--jobs=' + str(jobs)] 77 77 if make_options: 78 78 command.extend(make_options) 79 79 if self._cross_compile:
+4 -5
tools/testing/kunit/kunit_parser.py
··· 759 759 # If parsing the main/top-level test, parse KTAP version line and 760 760 # test plan 761 761 test.name = "main" 762 - ktap_line = parse_ktap_header(lines, test, printer) 762 + parse_ktap_header(lines, test, printer) 763 763 test.log.extend(parse_diagnostic(lines)) 764 764 parse_test_plan(lines, test) 765 765 parent_test = True ··· 768 768 # the KTAP version line and/or subtest header line 769 769 ktap_line = parse_ktap_header(lines, test, printer) 770 770 subtest_line = parse_test_header(lines, test) 771 + test.log.extend(parse_diagnostic(lines)) 772 + parse_test_plan(lines, test) 771 773 parent_test = (ktap_line or subtest_line) 772 774 if parent_test: 773 - # If KTAP version line and/or subtest header is found, attempt 774 - # to parse test plan and print test header 775 - test.log.extend(parse_diagnostic(lines)) 776 - parse_test_plan(lines, test) 777 775 print_test_header(test, printer) 776 + 778 777 expected_count = test.expected_count 779 778 subtests = [] 780 779 test_num = 1
+11
tools/testing/kunit/kunit_tool_test.py
··· 363 363 self.print_mock.assert_any_call(StrContains(' Indented more.')) 364 364 self.noPrintCallContains('not ok 1 test1') 365 365 366 + def test_parse_late_test_plan(self): 367 + output = """ 368 + TAP version 13 369 + ok 4 test4 370 + 1..4 371 + """ 372 + result = kunit_parser.parse_run_tests(output.splitlines(), stdout) 373 + # Missing test results after test plan should alert a suspected test crash. 374 + self.assertEqual(kunit_parser.TestStatus.TEST_CRASHED, result.status) 375 + self.assertEqual(result.counts, kunit_parser.TestCounts(passed=1, crashed=1, errors=1)) 376 + 366 377 def line_stream_from_strs(strs: Iterable[str]) -> kunit_parser.LineStream: 367 378 return kunit_parser.LineStream(enumerate(strs, start=1)) 368 379
+3 -2
tools/testing/kunit/qemu_configs/sparc.py
··· 2 2 3 3 QEMU_ARCH = QemuArchParams(linux_arch='sparc', 4 4 kconfig=''' 5 - CONFIG_SERIAL_8250=y 6 - CONFIG_SERIAL_8250_CONSOLE=y''', 5 + CONFIG_SERIAL_SUNZILOG=y 6 + CONFIG_SERIAL_SUNZILOG_CONSOLE=y 7 + ''', 7 8 qemu_arch='sparc', 8 9 kernel_path='arch/sparc/boot/zImage', 9 10 kernel_command_line='console=ttyS0 mem=256M',
+3 -1
tools/testing/kunit/qemu_configs/x86_64.py
··· 7 7 qemu_arch='x86_64', 8 8 kernel_path='arch/x86/boot/bzImage', 9 9 kernel_command_line='console=ttyS0', 10 - extra_qemu_params=[]) 10 + # qboot is faster than SeaBIOS and doesn't mess up 11 + # the terminal. 12 + extra_qemu_params=['-bios', 'qboot.rom'])