Commit 1be89faa authored by Linus Torvalds's avatar Linus Torvalds
Browse files

Merge tag 'linux-kselftest-kunit-6.4-rc1' of...

Merge tag 'linux-kselftest-kunit-6.4-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest

Pull KUnit updates from Shuah Khan:

 - several fixes to kunit tool

 - new klist structure test

 - support for m68k under QEMU

 - support for overriding the QEMU serial port

 - support for SH under QEMU

* tag 'linux-kselftest-kunit-6.4-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest:
  kunit: add tests for using current KUnit test field
  kunit: tool: Add support for SH under QEMU
  kunit: tool: Add support for overriding the QEMU serial port
  .gitignore: Unignore .kunitconfig
  list: test: Test the klist structure
  kunit: increase KUNIT_LOG_SIZE to 2048 bytes
  kunit: Use gfp in kunit_alloc_resource() kernel-doc
  kunit: tool: fix pre-existing `mypy --strict` errors and update run_checks.py
  kunit: tool: remove unused imports and variables
  kunit: tool: add subscripts for type annotations where appropriate
  kunit: fix bug of extra newline characters in debugfs logs
  kunit: fix bug in the order of lines in debugfs logs
  kunit: fix bug in debugfs logs of parameterized tests
  kunit: tool: Add support for m68k under QEMU
parents 0f50767d a42077b7
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -103,6 +103,7 @@ modules.order
!.get_maintainer.ignore
!.gitattributes
!.gitignore
!.kunitconfig
!.mailmap
!.rustfmt.toml

+1 −1
Original line number Diff line number Diff line
@@ -72,7 +72,7 @@ typedef void (*kunit_resource_free_t)(struct kunit_resource *);
 *		params.gfp = gfp;
 *
 *		return kunit_alloc_resource(test, kunit_kmalloc_init,
 *			kunit_kmalloc_free, &params);
 *			kunit_kmalloc_free, gfp, &params);
 *	}
 *
 * Resources can also be named, with lookup/removal done on a name
+2 −2
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@ DECLARE_STATIC_KEY_FALSE(kunit_running);
struct kunit;

/* Size of log associated with test. */
#define KUNIT_LOG_SIZE	512
#define KUNIT_LOG_SIZE 2048

/* Maximum size of parameter description string. */
#define KUNIT_PARAM_DESC_SIZE 128
@@ -420,7 +420,7 @@ void __printf(2, 3) kunit_log_append(char *log, const char *fmt, ...);
#define kunit_log(lvl, test_or_suite, fmt, ...)				\
	do {								\
		printk(lvl fmt, ##__VA_ARGS__);				\
		kunit_log_append((test_or_suite)->log,	fmt "\n",	\
		kunit_log_append((test_or_suite)->log,	fmt,		\
				 ##__VA_ARGS__);			\
	} while (0)

+12 −2
Original line number Diff line number Diff line
@@ -55,14 +55,24 @@ static int debugfs_print_results(struct seq_file *seq, void *v)
	enum kunit_status success = kunit_suite_has_succeeded(suite);
	struct kunit_case *test_case;

	if (!suite || !suite->log)
	if (!suite)
		return 0;

	seq_printf(seq, "%s", suite->log);
	/* Print KTAP header so the debugfs log can be parsed as valid KTAP. */
	seq_puts(seq, "KTAP version 1\n");
	seq_puts(seq, "1..1\n");

	/* Print suite header because it is not stored in the test logs. */
	seq_puts(seq, KUNIT_SUBTEST_INDENT "KTAP version 1\n");
	seq_printf(seq, KUNIT_SUBTEST_INDENT "# Subtest: %s\n", suite->name);
	seq_printf(seq, KUNIT_SUBTEST_INDENT "1..%zd\n", kunit_suite_num_test_cases(suite));

	kunit_suite_for_each_test_case(suite, test_case)
		debugfs_print_result(seq, suite, test_case);

	if (suite->log)
		seq_printf(seq, "%s", suite->log);

	seq_printf(seq, "%s %d %s\n",
		   kunit_status_to_ok_not_ok(success), 1, suite->name);
	return 0;
+64 −13
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@
 * Author: Brendan Higgins <brendanhiggins@google.com>
 */
#include <kunit/test.h>
#include <kunit/test-bug.h>

#include "try-catch-impl.h"

@@ -443,18 +444,6 @@ static struct kunit_suite kunit_resource_test_suite = {
	.test_cases = kunit_resource_test_cases,
};

static void kunit_log_test(struct kunit *test);

static struct kunit_case kunit_log_test_cases[] = {
	KUNIT_CASE(kunit_log_test),
	{}
};

static struct kunit_suite kunit_log_test_suite = {
	.name = "kunit-log-test",
	.test_cases = kunit_log_test_cases,
};

static void kunit_log_test(struct kunit *test)
{
	struct kunit_suite suite;
@@ -481,6 +470,29 @@ static void kunit_log_test(struct kunit *test)
#endif
}

static void kunit_log_newline_test(struct kunit *test)
{
	kunit_info(test, "Add newline\n");
	if (test->log) {
		KUNIT_ASSERT_NOT_NULL_MSG(test, strstr(test->log, "Add newline\n"),
			"Missing log line, full log:\n%s", test->log);
		KUNIT_EXPECT_NULL(test, strstr(test->log, "Add newline\n\n"));
	} else {
		kunit_skip(test, "only useful when debugfs is enabled");
	}
}

static struct kunit_case kunit_log_test_cases[] = {
	KUNIT_CASE(kunit_log_test),
	KUNIT_CASE(kunit_log_newline_test),
	{}
};

static struct kunit_suite kunit_log_test_suite = {
	.name = "kunit-log-test",
	.test_cases = kunit_log_test_cases,
};

static void kunit_status_set_failure_test(struct kunit *test)
{
	struct kunit fake;
@@ -521,7 +533,46 @@ static struct kunit_suite kunit_status_test_suite = {
	.test_cases = kunit_status_test_cases,
};

static void kunit_current_test(struct kunit *test)
{
	/* Check results of both current->kunit_test and
	 * kunit_get_current_test() are equivalent to current test.
	 */
	KUNIT_EXPECT_PTR_EQ(test, test, current->kunit_test);
	KUNIT_EXPECT_PTR_EQ(test, test, kunit_get_current_test());
}

static void kunit_current_fail_test(struct kunit *test)
{
	struct kunit fake;

	kunit_init_test(&fake, "fake test", NULL);
	KUNIT_EXPECT_EQ(test, fake.status, KUNIT_SUCCESS);

	/* Set current->kunit_test to fake test. */
	current->kunit_test = &fake;

	kunit_fail_current_test("This should make `fake` test fail.");
	KUNIT_EXPECT_EQ(test, fake.status, (enum kunit_status)KUNIT_FAILURE);
	kunit_cleanup(&fake);

	/* Reset current->kunit_test to current test. */
	current->kunit_test = test;
}

static struct kunit_case kunit_current_test_cases[] = {
	KUNIT_CASE(kunit_current_test),
	KUNIT_CASE(kunit_current_fail_test),
	{}
};

static struct kunit_suite kunit_current_test_suite = {
	.name = "kunit_current",
	.test_cases = kunit_current_test_cases,
};

kunit_test_suites(&kunit_try_catch_test_suite, &kunit_resource_test_suite,
		  &kunit_log_test_suite, &kunit_status_test_suite);
		  &kunit_log_test_suite, &kunit_status_test_suite,
		  &kunit_current_test_suite);

MODULE_LICENSE("GPL v2");
Loading