Commit e288c352 authored by Linus Torvalds's avatar Linus Torvalds
Browse files

Merge tag 'linux_kselftest-kunit-6.13-rc1-fixed' of...

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
parents 06afb0f3 62adcae4
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -12473,7 +12473,7 @@ F: fs/smb/common/
F:	fs/smb/server/
KERNEL UNIT TESTING FRAMEWORK (KUnit)
M:	Brendan Higgins <brendanhiggins@google.com>
M:	Brendan Higgins <brendan.higgins@linux.dev>
M:	David Gow <davidgow@google.com>
R:	Rae Moar <rmoar@google.com>
L:	linux-kselftest@vger.kernel.org
+3 −2
Original line number Diff line number Diff line
@@ -20,8 +20,9 @@ static void kunit_action_kfree_skb(void *p)
 * kunit_zalloc_skb() - Allocate and initialize a resource managed skb.
 * @test: The test case to which the skb belongs
 * @len: size to allocate
 * @gfp: allocation flags
 *
 * Allocate a new struct sk_buff with GFP_KERNEL, zero fill the give length
 * Allocate a new struct sk_buff with gfp flags, zero fill the given length
 * and add it as a resource to the kunit test for automatic cleanup.
 *
 * Returns: newly allocated SKB, or %NULL on error
@@ -29,7 +30,7 @@ static void kunit_action_kfree_skb(void *p)
static inline struct sk_buff *kunit_zalloc_skb(struct kunit *test, int len,
					       gfp_t gfp)
{
	struct sk_buff *res = alloc_skb(len, GFP_KERNEL);
	struct sk_buff *res = alloc_skb(len, gfp);

	if (!res || skb_pad(res, len))
		return NULL;
+6 −3
Original line number Diff line number Diff line
@@ -181,7 +181,7 @@ void kunit_debugfs_create_suite(struct kunit_suite *suite)
	 * successfully.
	 */
	stream = alloc_string_stream(GFP_KERNEL);
	if (IS_ERR_OR_NULL(stream))
	if (IS_ERR(stream))
		return;

	string_stream_set_append_newlines(stream, true);
@@ -189,7 +189,7 @@ void kunit_debugfs_create_suite(struct kunit_suite *suite)

	kunit_suite_for_each_test_case(suite, test_case) {
		stream = alloc_string_stream(GFP_KERNEL);
		if (IS_ERR_OR_NULL(stream))
		if (IS_ERR(stream))
			goto err;

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

err:
	string_stream_destroy(suite->log);
	kunit_suite_for_each_test_case(suite, test_case)
	suite->log = NULL;
	kunit_suite_for_each_test_case(suite, test_case) {
		string_stream_destroy(test_case->log);
		test_case->log = NULL;
	}
}

void kunit_debugfs_destroy_suite(struct kunit_suite *suite)
+2 −0
Original line number Diff line number Diff line
@@ -805,6 +805,8 @@ static void kunit_device_driver_test(struct kunit *test)
	struct device *test_device;
	struct driver_test_state *test_state = kunit_kzalloc(test, sizeof(*test_state), GFP_KERNEL);

	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, test_state);

	test->priv = test_state;
	test_driver = kunit_driver_create(test, "my_driver");

+25 −3
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ from typing import Iterable, List, Optional, Sequence, Tuple
import kunit_json
import kunit_kernel
import kunit_parser
from kunit_printer import stdout
from kunit_printer import stdout, null_printer

class KunitStatus(Enum):
	SUCCESS = auto()
@@ -49,6 +49,8 @@ class KunitBuildRequest(KunitConfigRequest):
class KunitParseRequest:
	raw_output: Optional[str]
	json: Optional[str]
	summary: bool
	failed: bool

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

	default_printer = stdout
	if request.summary or request.failed:
		default_printer = null_printer

	# Actually parse the test results.
	test = kunit_parser.parse_run_tests(input_data)
	test = kunit_parser.parse_run_tests(input_data, default_printer)
	parse_time = time.time() - parse_start

	if request.failed:
		kunit_parser.print_test(test, request.failed, stdout)
	kunit_parser.print_summary_line(test, stdout)

	if request.json:
		json_str = kunit_json.get_json_result(
					test=test,
@@ -413,6 +422,14 @@ def add_parse_opts(parser: argparse.ArgumentParser) -> None:
			    help='Prints parsed test results as JSON to stdout or a file if '
			    'a filename is specified. Does nothing if --raw_output is set.',
			    type=str, const='stdout', default=None, metavar='FILE')
	parser.add_argument('--summary',
			    help='Prints only the summary line for parsed test results.'
				'Does nothing if --raw_output is set.',
			    action='store_true')
	parser.add_argument('--failed',
			    help='Prints only the failed parsed test results and summary line.'
				'Does nothing if --raw_output is set.',
			    action='store_true')


def tree_from_args(cli_args: argparse.Namespace) -> kunit_kernel.LinuxSourceTree:
@@ -448,6 +465,8 @@ def run_handler(cli_args: argparse.Namespace) -> None:
					jobs=cli_args.jobs,
					raw_output=cli_args.raw_output,
					json=cli_args.json,
					summary=cli_args.summary,
					failed=cli_args.failed,
					timeout=cli_args.timeout,
					filter_glob=cli_args.filter_glob,
					filter=cli_args.filter,
@@ -495,6 +514,8 @@ def exec_handler(cli_args: argparse.Namespace) -> None:
	exec_request = KunitExecRequest(raw_output=cli_args.raw_output,
					build_dir=cli_args.build_dir,
					json=cli_args.json,
					summary=cli_args.summary,
					failed=cli_args.failed,
					timeout=cli_args.timeout,
					filter_glob=cli_args.filter_glob,
					filter=cli_args.filter,
@@ -520,7 +541,8 @@ def parse_handler(cli_args: argparse.Namespace) -> None:
	# We know nothing about how the result was created!
	metadata = kunit_json.Metadata()
	request = KunitParseRequest(raw_output=cli_args.raw_output,
					json=cli_args.json)
					json=cli_args.json, summary=cli_args.summary,
					failed=cli_args.failed)
	result, _ = parse_tests(request, metadata, kunit_output)
	if result.status != KunitStatus.SUCCESS:
		sys.exit(1)
Loading