mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git
synced 2026-10-28 12:53:14 +01:00
Add a KUnit test suite for the new private list primitives. The test defines a struct with a __private list_head and exercises every macro defined in <linux/list_private.h>. This ensures that the macros correctly handle the ACCESS_PRIVATE() abstraction and compile without warnings when acting on private members, verifying that qualifiers are stripped and offsets are calculated correctly. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Pasha Tatashin <[email protected]> Reviewed-by: David Gow <[email protected]> Cc: Alexander Graf <[email protected]> Cc: David Matlack <[email protected]> Cc: David Rientjes <[email protected]> Cc: Jonathan Corbet <[email protected]> Cc: Kees Cook <[email protected]> Cc: Mike Rapoport <[email protected]> Cc: Petr Mladek <[email protected]> Cc: Pratyush Yadav <[email protected]> Cc: Samiullah Khawaja <[email protected]> Cc: Tamir Duberstein <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
77 lines
2.4 KiB
C
77 lines
2.4 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* KUnit compilation/smoke test for Private list primitives.
|
|
*
|
|
* Copyright (c) 2025, Google LLC.
|
|
* Pasha Tatashin <[email protected]>
|
|
*/
|
|
#include <linux/list_private.h>
|
|
#include <kunit/test.h>
|
|
|
|
/*
|
|
* This forces compiler to warn if you access it directly, because list
|
|
* primitives expect (struct list_head *), not (volatile struct list_head *).
|
|
*/
|
|
#undef __private
|
|
#define __private volatile
|
|
|
|
/* Redefine ACCESS_PRIVATE for this test. */
|
|
#undef ACCESS_PRIVATE
|
|
#define ACCESS_PRIVATE(p, member) \
|
|
(*((struct list_head *)((unsigned long)&((p)->member))))
|
|
|
|
struct list_test_struct {
|
|
int data;
|
|
struct list_head __private list;
|
|
};
|
|
|
|
static void list_private_compile_test(struct kunit *test)
|
|
{
|
|
struct list_test_struct entry;
|
|
struct list_test_struct *pos, *n;
|
|
LIST_HEAD(head);
|
|
|
|
INIT_LIST_HEAD(&ACCESS_PRIVATE(&entry, list));
|
|
list_add(&ACCESS_PRIVATE(&entry, list), &head);
|
|
pos = &entry;
|
|
|
|
pos = list_private_entry(&ACCESS_PRIVATE(&entry, list), struct list_test_struct, list);
|
|
pos = list_private_first_entry(&head, struct list_test_struct, list);
|
|
pos = list_private_last_entry(&head, struct list_test_struct, list);
|
|
pos = list_private_next_entry(pos, list);
|
|
pos = list_private_prev_entry(pos, list);
|
|
pos = list_private_next_entry_circular(pos, &head, list);
|
|
pos = list_private_prev_entry_circular(pos, &head, list);
|
|
|
|
if (list_private_entry_is_head(pos, &head, list))
|
|
return;
|
|
|
|
list_private_for_each_entry(pos, &head, list) { }
|
|
list_private_for_each_entry_reverse(pos, &head, list) { }
|
|
list_private_for_each_entry_continue(pos, &head, list) { }
|
|
list_private_for_each_entry_continue_reverse(pos, &head, list) { }
|
|
list_private_for_each_entry_from(pos, &head, list) { }
|
|
list_private_for_each_entry_from_reverse(pos, &head, list) { }
|
|
|
|
list_private_for_each_entry_safe(pos, n, &head, list)
|
|
list_private_safe_reset_next(pos, n, list);
|
|
list_private_for_each_entry_safe_continue(pos, n, &head, list) { }
|
|
list_private_for_each_entry_safe_from(pos, n, &head, list) { }
|
|
list_private_for_each_entry_safe_reverse(pos, n, &head, list) { }
|
|
}
|
|
|
|
static struct kunit_case list_private_test_cases[] = {
|
|
KUNIT_CASE(list_private_compile_test),
|
|
{},
|
|
};
|
|
|
|
static struct kunit_suite list_private_test_module = {
|
|
.name = "list-private-kunit-test",
|
|
.test_cases = list_private_test_cases,
|
|
};
|
|
|
|
kunit_test_suite(list_private_test_module);
|
|
|
|
MODULE_DESCRIPTION("KUnit compilation test for private list primitives");
|
|
MODULE_LICENSE("GPL");
|