Commit 896d3fce authored by Linus Torvalds's avatar Linus Torvalds
Browse files

Merge tag 'linux_kselftest-kunit-6.10-rc1' of...

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

Pull kunit updates from Shuah Khan:

 - fix race condition in try-catch completion

 - change __kunit_test_suites_init() to exit early if there is
   nothing to test

 - change string-stream-test to use KUNIT_DEFINE_ACTION_WRAPPER

 - move fault tests behind KUNIT_FAULT_TEST Kconfig option

 - kthread test fixes and improvements

 - iov_iter test fixes

* tag 'linux_kselftest-kunit-6.10-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest:
  kunit: bail out early in __kunit_test_suites_init() if there are no suites to test
  kunit: string-stream-test: use KUNIT_DEFINE_ACTION_WRAPPER
  kunit: test: Move fault tests behind KUNIT_FAULT_TEST Kconfig option
  kunit: unregister the device on error
  kunit: Fix race condition in try-catch completion
  kunit: Add tests for fault
  kunit: Print last test location on fault
  kunit: Fix KUNIT_SUCCESS() calls in iov_iter tests
  kunit: Handle test faults
  kunit: Fix timeout message
  kunit: Fix kthread reference
  kunit: Handle thread creation error
parents 4b768bf0 5496b9b7
Loading
Loading
Loading
Loading
+21 −3
Original line number Diff line number Diff line
@@ -301,6 +301,8 @@ struct kunit {
	struct list_head resources; /* Protected by lock. */

	char status_comment[KUNIT_STATUS_COMMENT_SIZE];
	/* Saves the last seen test. Useful to help with faults. */
	struct kunit_loc last_seen;
};

static inline void kunit_set_failure(struct kunit *test)
@@ -567,6 +569,15 @@ void __printf(2, 3) kunit_log_append(struct string_stream *log, const char *fmt,
#define kunit_err(test, fmt, ...) \
	kunit_printk(KERN_ERR, test, fmt, ##__VA_ARGS__)

/*
 * Must be called at the beginning of each KUNIT_*_ASSERTION().
 * Cf. KUNIT_CURRENT_LOC.
 */
#define _KUNIT_SAVE_LOC(test) do {					       \
	WRITE_ONCE(test->last_seen.file, __FILE__);			       \
	WRITE_ONCE(test->last_seen.line, __LINE__);			       \
} while (0)

/**
 * KUNIT_SUCCEED() - A no-op expectation. Only exists for code clarity.
 * @test: The test context object.
@@ -575,7 +586,7 @@ void __printf(2, 3) kunit_log_append(struct string_stream *log, const char *fmt,
 * words, it does nothing and only exists for code clarity. See
 * KUNIT_EXPECT_TRUE() for more information.
 */
#define KUNIT_SUCCEED(test) do {} while (0)
#define KUNIT_SUCCEED(test) _KUNIT_SAVE_LOC(test)

void __noreturn __kunit_abort(struct kunit *test);

@@ -601,14 +612,16 @@ void __printf(6, 7) __kunit_do_failed_assertion(struct kunit *test,
} while (0)


#define KUNIT_FAIL_ASSERTION(test, assert_type, fmt, ...)		       \
#define KUNIT_FAIL_ASSERTION(test, assert_type, fmt, ...) do {		       \
	_KUNIT_SAVE_LOC(test);						       \
	_KUNIT_FAILED(test,						       \
		      assert_type,					       \
		      kunit_fail_assert,				       \
		      kunit_fail_assert_format,				       \
		      {},						       \
		      fmt,						       \
		      ##__VA_ARGS__)
		      ##__VA_ARGS__);					       \
} while (0)

/**
 * KUNIT_FAIL() - Always causes a test to fail when evaluated.
@@ -637,6 +650,7 @@ void __printf(6, 7) __kunit_do_failed_assertion(struct kunit *test,
			      fmt,					       \
			      ...)					       \
do {									       \
	_KUNIT_SAVE_LOC(test);						       \
	if (likely(!!(condition_) == !!expected_true_))			       \
		break;							       \
									       \
@@ -698,6 +712,7 @@ do { \
		.right_text = #right,					       \
	};								       \
									       \
	_KUNIT_SAVE_LOC(test);						       \
	if (likely(__left op __right))					       \
		break;							       \
									       \
@@ -758,6 +773,7 @@ do { \
		.right_text = #right,					       \
	};								       \
									       \
	_KUNIT_SAVE_LOC(test);						       \
	if (likely((__left) && (__right) && (strcmp(__left, __right) op 0)))   \
		break;							       \
									       \
@@ -791,6 +807,7 @@ do { \
		.right_text = #right,					       \
	};								       \
									       \
	_KUNIT_SAVE_LOC(test);						       \
	if (likely(__left && __right))					       \
		if (likely(memcmp(__left, __right, __size) op 0))	       \
			break;						       \
@@ -815,6 +832,7 @@ do { \
do {									       \
	const typeof(ptr) __ptr = (ptr);				       \
									       \
	_KUNIT_SAVE_LOC(test);						       \
	if (!IS_ERR_OR_NULL(__ptr))					       \
		break;							       \
									       \
+0 −3
Original line number Diff line number Diff line
@@ -14,13 +14,11 @@

typedef void (*kunit_try_catch_func_t)(void *);

struct completion;
struct kunit;

/**
 * struct kunit_try_catch - provides a generic way to run code which might fail.
 * @test: The test case that is currently being executed.
 * @try_completion: Completion that the control thread waits on while test runs.
 * @try_result: Contains any errno obtained while running test case.
 * @try: The function, the test case, to attempt to run.
 * @catch: The function called if @try bails out.
@@ -46,7 +44,6 @@ struct kunit;
struct kunit_try_catch {
	/* private: internal use only. */
	struct kunit *test;
	struct completion *try_completion;
	int try_result;
	kunit_try_catch_func_t try;
	kunit_try_catch_func_t catch;
+1 −0
Original line number Diff line number Diff line
@@ -315,6 +315,7 @@ void __noreturn kthread_exit(long result)
	kthread->result = result;
	do_exit(0);
}
EXPORT_SYMBOL(kthread_exit);

/**
 * kthread_complete_and_exit - Exit the current kthread.
+11 −0
Original line number Diff line number Diff line
@@ -24,6 +24,17 @@ config KUNIT_DEBUGFS
	  test suite, which allow users to see results of the last test suite
	  run that occurred.

config KUNIT_FAULT_TEST
	bool "Enable KUnit tests which print BUG stacktraces"
	depends on KUNIT_TEST
	depends on !UML
	default y
	help
	  Enables fault handling tests for the KUnit framework. These tests may
	  trigger a kernel BUG(), and the associated stack trace, even when they
	  pass. If this conflicts with your test infrastrcture (or is confusing
	  or annoying), they can be disabled by setting this to N.

config KUNIT_TEST
	tristate "KUnit test for KUnit" if !KUNIT_ALL_TESTS
	default KUNIT_ALL_TESTS
+1 −1
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@ int kunit_bus_init(void)

	error = bus_register(&kunit_bus_type);
	if (error)
		bus_unregister(&kunit_bus_type);
		root_device_unregister(kunit_bus_device);
	return error;
}

Loading