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.
- Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
kunit/test.hlinux/packing.h
Detected Declarations
struct packing_test_casestruct test_datafunction packing_test_packfunction packing_test_unpackfunction packing_test_pack_fieldsfunction packing_test_unpack_fields
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
- Immediate include surface: `kunit/test.h`, `linux/packing.h`.
- Detected declarations: `struct packing_test_case`, `struct test_data`, `function packing_test_pack`, `function packing_test_unpack`, `function packing_test_pack_fields`, `function packing_test_unpack_fields`.
- Atlas domain: Kernel Services / lib.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.