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

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

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

Pull KUnit updates from Shuah Khan:

 - add vm_mmap() allocation resource manager

 - convert usercopy kselftest to KUnit

 - disable usercopy testing on !CONFIG_MMU

 - add MODULE_DESCRIPTION() to core, list, and usercopy tests

 - add tests for assertion formatting functions - assert.c

 - introduce KUNIT_ASSERT_MEMEQ and KUNIT_ASSERT_MEMNEQ macros

 - fix KUNIT_ASSERT_STRNEQ comments to make it clear that it is an
   assertion

 - rename KUNIT_ASSERT_FAILURE to KUNIT_FAIL_AND_ABORT

* tag 'linux_kselftest-kunit-6.11-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest:
  kunit: Introduce KUNIT_ASSERT_MEMEQ and KUNIT_ASSERT_MEMNEQ macros
  kunit: Rename KUNIT_ASSERT_FAILURE to KUNIT_FAIL_AND_ABORT for readability
  kunit: Fix the comment of KUNIT_ASSERT_STRNEQ as assertion
  kunit: executor: Simplify string allocation handling
  kunit/usercopy: Add missing MODULE_DESCRIPTION()
  kunit/usercopy: Disable testing on !CONFIG_MMU
  usercopy: Convert test_user_copy to KUnit test
  kunit: test: Add vm_mmap() allocation resource manager
  list: test: add the missing MODULE_DESCRIPTION() macro
  kunit: add missing MODULE_DESCRIPTION() macros to core modules
  list: test: remove unused struct 'klist_test_struct'
  kunit: Cover 'assert.c' with tests
parents 9de4ad3b ebf51e46
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -12034,6 +12034,7 @@ F: arch/*/configs/hardening.config
F:	include/linux/overflow.h
F:	include/linux/randomize_kstack.h
F:	kernel/configs/hardening.config
F:	lib/usercopy_kunit.c
F:	mm/usercopy.c
K:	\b(add|choose)_random_kstack_offset\b
K:	\b__check_(object_size|heap_object)\b
+1 −1
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@ static int input_test_init(struct kunit *test)
	ret = input_register_device(input_dev);
	if (ret) {
		input_free_device(input_dev);
		KUNIT_ASSERT_FAILURE(test, "Register device failed: %d", ret);
		KUNIT_FAIL_AND_ABORT(test, "Register device failed: %d", ret);
	}

	test->priv = input_dev;
+12 −1
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ void kunit_assert_prologue(const struct kunit_loc *loc,
 * struct kunit_fail_assert - Represents a plain fail expectation/assertion.
 * @assert: The parent of this type.
 *
 * Represents a simple KUNIT_FAIL/KUNIT_ASSERT_FAILURE that always fails.
 * Represents a simple KUNIT_FAIL/KUNIT_FAIL_AND_ABORT that always fails.
 */
struct kunit_fail_assert {
	struct kunit_assert assert;
@@ -218,4 +218,15 @@ void kunit_mem_assert_format(const struct kunit_assert *assert,
			     const struct va_format *message,
			     struct string_stream *stream);

#if IS_ENABLED(CONFIG_KUNIT)
void kunit_assert_print_msg(const struct va_format *message,
			    struct string_stream *stream);
bool is_literal(const char *text, long long value);
bool is_str_literal(const char *text, const char *value);
void kunit_assert_hexdump(struct string_stream *stream,
			  const void *buf,
			  const void *compared_buf,
			  const size_t len);
#endif

#endif /*  _KUNIT_ASSERT_H */
+85 −3
Original line number Diff line number Diff line
@@ -480,6 +480,23 @@ static inline void *kunit_kcalloc(struct kunit *test, size_t n, size_t size, gfp
	return kunit_kmalloc_array(test, n, size, gfp | __GFP_ZERO);
}

/**
 * kunit_vm_mmap() - Allocate KUnit-tracked vm_mmap() area
 * @test: The test context object.
 * @file: struct file pointer to map from, if any
 * @addr: desired address, if any
 * @len: how many bytes to allocate
 * @prot: mmap PROT_* bits
 * @flag: mmap flags
 * @offset: offset into @file to start mapping from.
 *
 * See vm_mmap() for more information.
 */
unsigned long kunit_vm_mmap(struct kunit *test, struct file *file,
			    unsigned long addr, unsigned long len,
			    unsigned long prot, unsigned long flag,
			    unsigned long offset);

void kunit_cleanup(struct kunit *test);

void __printf(2, 3) kunit_log_append(struct string_stream *log, const char *fmt, ...);
@@ -1211,7 +1228,18 @@ do { \
						fmt,			       \
						##__VA_ARGS__)

#define KUNIT_ASSERT_FAILURE(test, fmt, ...) \
/**
 * KUNIT_FAIL_AND_ABORT() - Always causes a test to fail and abort when evaluated.
 * @test: The test context object.
 * @fmt: an informational message to be printed when the assertion is made.
 * @...: string format arguments.
 *
 * The opposite of KUNIT_SUCCEED(), it is an assertion that always fails. In
 * other words, it always results in a failed assertion, and consequently
 * always causes the test case to fail and abort when evaluated.
 * See KUNIT_ASSERT_TRUE() for more information.
 */
#define KUNIT_FAIL_AND_ABORT(test, fmt, ...) \
	KUNIT_FAIL_ASSERTION(test, KUNIT_ASSERTION, fmt, ##__VA_ARGS__)

/**
@@ -1438,12 +1466,12 @@ do { \
				   ##__VA_ARGS__)

/**
 * KUNIT_ASSERT_STRNEQ() - Expects that strings @left and @right are not equal.
 * KUNIT_ASSERT_STRNEQ() - An assertion that strings @left and @right are not equal.
 * @test: The test context object.
 * @left: an arbitrary expression that evaluates to a null terminated string.
 * @right: an arbitrary expression that evaluates to a null terminated string.
 *
 * Sets an expectation that the values that @left and @right evaluate to are
 * Sets an assertion that the values that @left and @right evaluate to are
 * not equal. This is semantically equivalent to
 * KUNIT_ASSERT_TRUE(@test, strcmp((@left), (@right))). See KUNIT_ASSERT_TRUE()
 * for more information.
@@ -1458,6 +1486,60 @@ do { \
				   fmt,					       \
				   ##__VA_ARGS__)

/**
 * KUNIT_ASSERT_MEMEQ() - Asserts that the first @size bytes of @left and @right are equal.
 * @test: The test context object.
 * @left: An arbitrary expression that evaluates to the specified size.
 * @right: An arbitrary expression that evaluates to the specified size.
 * @size: Number of bytes compared.
 *
 * Sets an assertion that the values that @left and @right evaluate to are
 * equal. This is semantically equivalent to
 * KUNIT_ASSERT_TRUE(@test, !memcmp((@left), (@right), (@size))). See
 * KUNIT_ASSERT_TRUE() for more information.
 *
 * Although this assertion works for any memory block, it is not recommended
 * for comparing more structured data, such as structs. This assertion is
 * recommended for comparing, for example, data arrays.
 */
#define KUNIT_ASSERT_MEMEQ(test, left, right, size) \
	KUNIT_ASSERT_MEMEQ_MSG(test, left, right, size, NULL)

#define KUNIT_ASSERT_MEMEQ_MSG(test, left, right, size, fmt, ...)	       \
	KUNIT_MEM_ASSERTION(test,					       \
			    KUNIT_ASSERTION,				       \
			    left, ==, right,				       \
			    size,					       \
			    fmt,					       \
			    ##__VA_ARGS__)

/**
 * KUNIT_ASSERT_MEMNEQ() - Asserts that the first @size bytes of @left and @right are not equal.
 * @test: The test context object.
 * @left: An arbitrary expression that evaluates to the specified size.
 * @right: An arbitrary expression that evaluates to the specified size.
 * @size: Number of bytes compared.
 *
 * Sets an assertion that the values that @left and @right evaluate to are
 * not equal. This is semantically equivalent to
 * KUNIT_ASSERT_TRUE(@test, memcmp((@left), (@right), (@size))). See
 * KUNIT_ASSERT_TRUE() for more information.
 *
 * Although this assertion works for any memory block, it is not recommended
 * for comparing more structured data, such as structs. This assertion is
 * recommended for comparing, for example, data arrays.
 */
#define KUNIT_ASSERT_MEMNEQ(test, left, right, size) \
	KUNIT_ASSERT_MEMNEQ_MSG(test, left, right, size, NULL)

#define KUNIT_ASSERT_MEMNEQ_MSG(test, left, right, size, fmt, ...)	       \
	KUNIT_MEM_ASSERTION(test,					       \
			    KUNIT_ASSERTION,				       \
			    left, !=, right,				       \
			    size,					       \
			    fmt,					       \
			    ##__VA_ARGS__)

/**
 * KUNIT_ASSERT_NULL() - Asserts that pointers @ptr is null.
 * @test: The test context object.
+3 −0
Original line number Diff line number Diff line
@@ -115,6 +115,8 @@
#define CREATE_TRACE_POINTS
#include <trace/events/task.h>

#include <kunit/visibility.h>

/*
 * Minimum number of threads to boot the kernel
 */
@@ -1328,6 +1330,7 @@ struct mm_struct *mm_alloc(void)
	memset(mm, 0, sizeof(*mm));
	return mm_init(mm, current, current_user_ns());
}
EXPORT_SYMBOL_IF_KUNIT(mm_alloc);

static inline void __mmput(struct mm_struct *mm)
{
Loading