Skip to content

Commit e288c35

Browse files
committed
Merge tag 'linux_kselftest-kunit-6.13-rc1-fixed' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest
Pull kunit updates from Shuah Khan: - fix user-after-free (UAF) bug in kunit_init_suite() - add option to kunit tool to print just the summary of test results - add option to kunit tool to print just the failed test results - fix kunit_zalloc_skb() to use user passed in gfp value instead of hardcoding GFP_KERNEL - fixe kunit_zalloc_skb() kernel doc to include allocation flags variable - update KUnit email address for Brendan Higgins - add LoongArch config to qemu_configs - allow overriding the shutdown mode from qemu config - enable shutdown in loongarch qemu_config - fix potential null dereference in kunit_device_driver_test() - fix debugfs to use IS_ERR() for alloc_string_stream() error check * tag 'linux_kselftest-kunit-6.13-rc1-fixed' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: kunit: qemu_configs: loongarch: Enable shutdown kunit: tool: Allow overriding the shutdown mode from qemu config kunit: qemu_configs: Add LoongArch config kunit: debugfs: Use IS_ERR() for alloc_string_stream() error check kunit: Fix potential null dereference in kunit_device_driver_test() MAINTAINERS: Update KUnit email address for Brendan Higgins kunit: string-stream: Fix a UAF bug in kunit_init_suite() kunit: tool: print failed tests only kunit: tool: Only print the summary kunit: skb: add gfp to kernel doc for kunit_zalloc_skb() kunit: skb: use "gfp" variable instead of hardcoding GFP_KERNEL
2 parents 06afb0f + 62adcae commit e288c35

File tree

10 files changed

+183
-91
lines changed

10 files changed

+183
-91
lines changed

MAINTAINERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12473,7 +12473,7 @@ F: fs/smb/common/
1247312473
F: fs/smb/server/
1247412474

1247512475
KERNEL UNIT TESTING FRAMEWORK (KUnit)
12476-
M: Brendan Higgins <brendanhiggins@google.com>
12476+
M: Brendan Higgins <brendan.higgins@linux.dev>
1247712477
M: David Gow <davidgow@google.com>
1247812478
R: Rae Moar <rmoar@google.com>
1247912479
L: linux-kselftest@vger.kernel.org

include/kunit/skbuff.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,17 @@ static void kunit_action_kfree_skb(void *p)
2020
* kunit_zalloc_skb() - Allocate and initialize a resource managed skb.
2121
* @test: The test case to which the skb belongs
2222
* @len: size to allocate
23+
* @gfp: allocation flags
2324
*
24-
* Allocate a new struct sk_buff with GFP_KERNEL, zero fill the give length
25+
* Allocate a new struct sk_buff with gfp flags, zero fill the given length
2526
* and add it as a resource to the kunit test for automatic cleanup.
2627
*
2728
* Returns: newly allocated SKB, or %NULL on error
2829
*/
2930
static inline struct sk_buff *kunit_zalloc_skb(struct kunit *test, int len,
3031
gfp_t gfp)
3132
{
32-
struct sk_buff *res = alloc_skb(len, GFP_KERNEL);
33+
struct sk_buff *res = alloc_skb(len, gfp);
3334

3435
if (!res || skb_pad(res, len))
3536
return NULL;

lib/kunit/debugfs.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,15 +181,15 @@ void kunit_debugfs_create_suite(struct kunit_suite *suite)
181181
* successfully.
182182
*/
183183
stream = alloc_string_stream(GFP_KERNEL);
184-
if (IS_ERR_OR_NULL(stream))
184+
if (IS_ERR(stream))
185185
return;
186186

187187
string_stream_set_append_newlines(stream, true);
188188
suite->log = stream;
189189

190190
kunit_suite_for_each_test_case(suite, test_case) {
191191
stream = alloc_string_stream(GFP_KERNEL);
192-
if (IS_ERR_OR_NULL(stream))
192+
if (IS_ERR(stream))
193193
goto err;
194194

195195
string_stream_set_append_newlines(stream, true);
@@ -212,8 +212,11 @@ void kunit_debugfs_create_suite(struct kunit_suite *suite)
212212

213213
err:
214214
string_stream_destroy(suite->log);
215-
kunit_suite_for_each_test_case(suite, test_case)
215+
suite->log = NULL;
216+
kunit_suite_for_each_test_case(suite, test_case) {
216217
string_stream_destroy(test_case->log);
218+
test_case->log = NULL;
219+
}
217220
}
218221

219222
void kunit_debugfs_destroy_suite(struct kunit_suite *suite)

lib/kunit/kunit-test.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,8 @@ static void kunit_device_driver_test(struct kunit *test)
805805
struct device *test_device;
806806
struct driver_test_state *test_state = kunit_kzalloc(test, sizeof(*test_state), GFP_KERNEL);
807807

808+
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, test_state);
809+
808810
test->priv = test_state;
809811
test_driver = kunit_driver_create(test, "my_driver");
810812

tools/testing/kunit/kunit.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import kunit_json
2424
import kunit_kernel
2525
import kunit_parser
26-
from kunit_printer import stdout
26+
from kunit_printer import stdout, null_printer
2727

2828
class KunitStatus(Enum):
2929
SUCCESS = auto()
@@ -49,6 +49,8 @@ class KunitBuildRequest(KunitConfigRequest):
4949
class KunitParseRequest:
5050
raw_output: Optional[str]
5151
json: Optional[str]
52+
summary: bool
53+
failed: bool
5254

5355
@dataclass
5456
class KunitExecRequest(KunitParseRequest):
@@ -235,11 +237,18 @@ def parse_tests(request: KunitParseRequest, metadata: kunit_json.Metadata, input
235237
parse_time = time.time() - parse_start
236238
return KunitResult(KunitStatus.SUCCESS, parse_time), fake_test
237239

240+
default_printer = stdout
241+
if request.summary or request.failed:
242+
default_printer = null_printer
238243

239244
# Actually parse the test results.
240-
test = kunit_parser.parse_run_tests(input_data)
245+
test = kunit_parser.parse_run_tests(input_data, default_printer)
241246
parse_time = time.time() - parse_start
242247

248+
if request.failed:
249+
kunit_parser.print_test(test, request.failed, stdout)
250+
kunit_parser.print_summary_line(test, stdout)
251+
243252
if request.json:
244253
json_str = kunit_json.get_json_result(
245254
test=test,
@@ -413,6 +422,14 @@ def add_parse_opts(parser: argparse.ArgumentParser) -> None:
413422
help='Prints parsed test results as JSON to stdout or a file if '
414423
'a filename is specified. Does nothing if --raw_output is set.',
415424
type=str, const='stdout', default=None, metavar='FILE')
425+
parser.add_argument('--summary',
426+
help='Prints only the summary line for parsed test results.'
427+
'Does nothing if --raw_output is set.',
428+
action='store_true')
429+
parser.add_argument('--failed',
430+
help='Prints only the failed parsed test results and summary line.'
431+
'Does nothing if --raw_output is set.',
432+
action='store_true')
416433

417434

418435
def tree_from_args(cli_args: argparse.Namespace) -> kunit_kernel.LinuxSourceTree:
@@ -448,6 +465,8 @@ def run_handler(cli_args: argparse.Namespace) -> None:
448465
jobs=cli_args.jobs,
449466
raw_output=cli_args.raw_output,
450467
json=cli_args.json,
468+
summary=cli_args.summary,
469+
failed=cli_args.failed,
451470
timeout=cli_args.timeout,
452471
filter_glob=cli_args.filter_glob,
453472
filter=cli_args.filter,
@@ -495,6 +514,8 @@ def exec_handler(cli_args: argparse.Namespace) -> None:
495514
exec_request = KunitExecRequest(raw_output=cli_args.raw_output,
496515
build_dir=cli_args.build_dir,
497516
json=cli_args.json,
517+
summary=cli_args.summary,
518+
failed=cli_args.failed,
498519
timeout=cli_args.timeout,
499520
filter_glob=cli_args.filter_glob,
500521
filter=cli_args.filter,
@@ -520,7 +541,8 @@ def parse_handler(cli_args: argparse.Namespace) -> None:
520541
# We know nothing about how the result was created!
521542
metadata = kunit_json.Metadata()
522543
request = KunitParseRequest(raw_output=cli_args.raw_output,
523-
json=cli_args.json)
544+
json=cli_args.json, summary=cli_args.summary,
545+
failed=cli_args.failed)
524546
result, _ = parse_tests(request, metadata, kunit_output)
525547
if result.status != KunitStatus.SUCCESS:
526548
sys.exit(1)

tools/testing/kunit/kunit_kernel.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ def __init__(self, qemu_arch_params: qemu_config.QemuArchParams, cross_compile:
105105
self._kconfig = qemu_arch_params.kconfig
106106
self._qemu_arch = qemu_arch_params.qemu_arch
107107
self._kernel_path = qemu_arch_params.kernel_path
108-
self._kernel_command_line = qemu_arch_params.kernel_command_line + ' kunit_shutdown=reboot'
108+
self._kernel_command_line = qemu_arch_params.kernel_command_line
109+
if 'kunit_shutdown=' not in self._kernel_command_line:
110+
self._kernel_command_line += ' kunit_shutdown=reboot'
109111
self._extra_qemu_params = qemu_arch_params.extra_qemu_params
110112
self._serial = qemu_arch_params.serial
111113

0 commit comments

Comments
 (0)