lib/packing_test.c

Source file repositories/reference/linux-study-clean/lib/packing_test.c

File Facts

System
Linux kernel
Corpus path
lib/packing_test.c
Extension
.c
Size
14503 bytes
Lines
475
Domain
Kernel Services
Bucket
lib
Inferred role
Kernel Services: implementation source
Status
source implementation candidate

Why This File Exists

Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.

Dependency Surface

Detected Declarations

Annotated Snippet

struct packing_test_case {
	const char *desc;
	const u8 *pbuf;
	size_t pbuf_size;
	u64 uval;
	size_t start_bit;
	size_t end_bit;
	u8 quirks;
};

#define NO_QUIRKS	0

/**
 * PBUF - Initialize .pbuf and .pbuf_size
 * @array: elements of constant physical buffer
 *
 * Initializes the .pbuf and .pbuf_size fields of a struct packing_test_case
 * with a constant array of the specified elements.
 */
#define PBUF(array...)					\
	.pbuf = (const u8[]){ array },			\
	.pbuf_size = sizeof((const u8 []){ array })

static const struct packing_test_case cases[] = {
	/* These tests pack and unpack a magic 64-bit value
	 * (0xcafedeadbeefcafe) at a fixed logical offset (32) within an
	 * otherwise zero array of 128 bits (16 bytes). They test all possible
	 * bit layouts of the 128 bit buffer.
	 */
	{
		.desc = "no quirks, 16 bytes",
		PBUF(0x00, 0x00, 0x00, 0x00, 0xca, 0xfe, 0xde, 0xad,
		     0xbe, 0xef, 0xca, 0xfe, 0x00, 0x00, 0x00, 0x00),
		.uval = 0xcafedeadbeefcafe,
		.start_bit = 95,
		.end_bit = 32,
		.quirks = NO_QUIRKS,
	},
	{
		.desc = "lsw32 first, 16 bytes",
		PBUF(0x00, 0x00, 0x00, 0x00, 0xbe, 0xef, 0xca, 0xfe,
		     0xca, 0xfe, 0xde, 0xad, 0x00, 0x00, 0x00, 0x00),
		.uval = 0xcafedeadbeefcafe,
		.start_bit = 95,
		.end_bit = 32,
		.quirks = QUIRK_LSW32_IS_FIRST,
	},
	{
		.desc = "little endian words, 16 bytes",
		PBUF(0x00, 0x00, 0x00, 0x00, 0xad, 0xde, 0xfe, 0xca,
		     0xfe, 0xca, 0xef, 0xbe, 0x00, 0x00, 0x00, 0x00),
		.uval = 0xcafedeadbeefcafe,
		.start_bit = 95,
		.end_bit = 32,
		.quirks = QUIRK_LITTLE_ENDIAN,
	},
	{
		.desc = "lsw32 first + little endian words, 16 bytes",
		PBUF(0x00, 0x00, 0x00, 0x00, 0xfe, 0xca, 0xef, 0xbe,
		     0xad, 0xde, 0xfe, 0xca, 0x00, 0x00, 0x00, 0x00),
		.uval = 0xcafedeadbeefcafe,
		.start_bit = 95,
		.end_bit = 32,
		.quirks = QUIRK_LSW32_IS_FIRST | QUIRK_LITTLE_ENDIAN,
	},
	{
		.desc = "msb right, 16 bytes",
		PBUF(0x00, 0x00, 0x00, 0x00, 0x53, 0x7f, 0x7b, 0xb5,
		     0x7d, 0xf7, 0x53, 0x7f, 0x00, 0x00, 0x00, 0x00),
		.uval = 0xcafedeadbeefcafe,
		.start_bit = 95,
		.end_bit = 32,
		.quirks = QUIRK_MSB_ON_THE_RIGHT,
	},
	{
		.desc = "msb right + lsw32 first, 16 bytes",
		PBUF(0x00, 0x00, 0x00, 0x00, 0x7d, 0xf7, 0x53, 0x7f,
		     0x53, 0x7f, 0x7b, 0xb5, 0x00, 0x00, 0x00, 0x00),
		.uval = 0xcafedeadbeefcafe,
		.start_bit = 95,
		.end_bit = 32,
		.quirks = QUIRK_MSB_ON_THE_RIGHT | QUIRK_LSW32_IS_FIRST,
	},
	{
		.desc = "msb right + little endian words, 16 bytes",
		PBUF(0x00, 0x00, 0x00, 0x00, 0xb5, 0x7b, 0x7f, 0x53,
		     0x7f, 0x53, 0xf7, 0x7d, 0x00, 0x00, 0x00, 0x00),
		.uval = 0xcafedeadbeefcafe,
		.start_bit = 95,
		.end_bit = 32,

Annotation

Implementation Notes