Skip to content

Commit a10c794

Browse files
committed
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
2 parents 8e324a5 + 2e0cf2b commit a10c794

File tree

10 files changed

+130
-21
lines changed

10 files changed

+130
-21
lines changed

arch/x86/tools/insn_decoder_test.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <assert.h>
1111
#include <unistd.h>
1212
#include <stdarg.h>
13+
#include <linux/kallsyms.h>
1314

1415
#define unlikely(cond) (cond)
1516

@@ -106,7 +107,7 @@ static void parse_args(int argc, char **argv)
106107
}
107108
}
108109

109-
#define BUFSIZE 256
110+
#define BUFSIZE (256 + KSYM_NAME_LEN)
110111

111112
int main(int argc, char **argv)
112113
{

include/kunit/test.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -553,39 +553,39 @@ void kunit_cleanup(struct kunit *test);
553553
void __printf(2, 3) kunit_log_append(struct string_stream *log, const char *fmt, ...);
554554

555555
/**
556-
* kunit_mark_skipped() - Marks @test_or_suite as skipped
556+
* kunit_mark_skipped() - Marks @test as skipped
557557
*
558-
* @test_or_suite: The test context object.
558+
* @test: The test context object.
559559
* @fmt: A printk() style format string.
560560
*
561561
* Marks the test as skipped. @fmt is given output as the test status
562562
* comment, typically the reason the test was skipped.
563563
*
564564
* Test execution continues after kunit_mark_skipped() is called.
565565
*/
566-
#define kunit_mark_skipped(test_or_suite, fmt, ...) \
566+
#define kunit_mark_skipped(test, fmt, ...) \
567567
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, \
570570
KUNIT_STATUS_COMMENT_SIZE, \
571571
fmt, ##__VA_ARGS__); \
572572
} while (0)
573573

574574
/**
575-
* kunit_skip() - Marks @test_or_suite as skipped
575+
* kunit_skip() - Marks @test as skipped
576576
*
577-
* @test_or_suite: The test context object.
577+
* @test: The test context object.
578578
* @fmt: A printk() style format string.
579579
*
580580
* Skips the test. @fmt is given output as the test status
581581
* comment, typically the reason the test was skipped.
582582
*
583583
* Test execution is halted after kunit_skip() is called.
584584
*/
585-
#define kunit_skip(test_or_suite, fmt, ...) \
585+
#define kunit_skip(test, fmt, ...) \
586586
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)); \
589589
} while (0)
590590

591591
/*

lib/Kconfig.debug

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2866,6 +2866,15 @@ config FORTIFY_KUNIT_TEST
28662866
by the str*() and mem*() family of functions. For testing runtime
28672867
traps of FORTIFY_SOURCE, see LKDTM's "FORTIFY_*" tests.
28682868

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+
28692878
config HW_BREAKPOINT_KUNIT_TEST
28702879
bool "Test hw_breakpoint constraints accounting" if !KUNIT_ALL_TESTS
28712880
depends on HAVE_HW_BREAKPOINT

lib/tests/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ obj-$(CONFIG_LIST_KUNIT_TEST) += list-test.o
2727
obj-$(CONFIG_KFIFO_KUNIT_TEST) += kfifo_kunit.o
2828
obj-$(CONFIG_TEST_LIST_SORT) += test_list_sort.o
2929
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+
3034
obj-$(CONFIG_MEMCPY_KUNIT_TEST) += memcpy_kunit.o
3135
CFLAGS_overflow_kunit.o = $(call cc-disable-warning, tautological-constant-out-of-range-compare)
3236
obj-$(CONFIG_OVERFLOW_KUNIT_TEST) += overflow_kunit.o

lib/tests/longest_symbol_kunit.c

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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");

tools/testing/kunit/kunit_kernel.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ def make_olddefconfig(self, build_dir: str, make_options: Optional[List[str]]) -
7272
raise ConfigError(e.output.decode())
7373

7474
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)]
7777
if make_options:
7878
command.extend(make_options)
7979
if self._cross_compile:

tools/testing/kunit/kunit_parser.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ def parse_test(lines: LineStream, expected_num: int, log: List[str], is_subtest:
759759
# If parsing the main/top-level test, parse KTAP version line and
760760
# test plan
761761
test.name = "main"
762-
ktap_line = parse_ktap_header(lines, test, printer)
762+
parse_ktap_header(lines, test, printer)
763763
test.log.extend(parse_diagnostic(lines))
764764
parse_test_plan(lines, test)
765765
parent_test = True
@@ -768,13 +768,12 @@ def parse_test(lines: LineStream, expected_num: int, log: List[str], is_subtest:
768768
# the KTAP version line and/or subtest header line
769769
ktap_line = parse_ktap_header(lines, test, printer)
770770
subtest_line = parse_test_header(lines, test)
771+
test.log.extend(parse_diagnostic(lines))
772+
parse_test_plan(lines, test)
771773
parent_test = (ktap_line or subtest_line)
772774
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)
777775
print_test_header(test, printer)
776+
778777
expected_count = test.expected_count
779778
subtests = []
780779
test_num = 1

tools/testing/kunit/kunit_tool_test.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,17 @@ def test_show_test_output_on_failure(self):
363363
self.print_mock.assert_any_call(StrContains(' Indented more.'))
364364
self.noPrintCallContains('not ok 1 test1')
365365

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+
366377
def line_stream_from_strs(strs: Iterable[str]) -> kunit_parser.LineStream:
367378
return kunit_parser.LineStream(enumerate(strs, start=1))
368379

tools/testing/kunit/qemu_configs/sparc.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
QEMU_ARCH = QemuArchParams(linux_arch='sparc',
44
kconfig='''
5-
CONFIG_SERIAL_8250=y
6-
CONFIG_SERIAL_8250_CONSOLE=y''',
5+
CONFIG_SERIAL_SUNZILOG=y
6+
CONFIG_SERIAL_SUNZILOG_CONSOLE=y
7+
''',
78
qemu_arch='sparc',
89
kernel_path='arch/sparc/boot/zImage',
910
kernel_command_line='console=ttyS0 mem=256M',

tools/testing/kunit/qemu_configs/x86_64.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@
77
qemu_arch='x86_64',
88
kernel_path='arch/x86/boot/bzImage',
99
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'])

0 commit comments

Comments
 (0)