drivers/gpu/drm/tests/drm_mm_test.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/tests/drm_mm_test.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/tests/drm_mm_test.c- Extension
.c- Size
- 8418 bytes
- Lines
- 360
- Domain
- Driver Families
- Bucket
- drivers/gpu
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- 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/prime_numbers.hlinux/slab.hlinux/random.hlinux/vmalloc.hlinux/ktime.hdrm/drm_mm.hdrm/drm_print.h
Detected Declarations
function assert_no_holesfunction drm_mm_for_each_nodefunction assert_one_holefunction misalignmentfunction assert_nodefunction drm_test_mm_initfunction drm_test_mm_debugfunction expect_insertfunction drm_test_mm_align_potfunction drm_test_mm_align32function drm_test_mm_align64function drm_test_mm_oncefunction drm_test_mm_lowestfunction drm_test_mm_highest
Annotated Snippet
if (drm_mm_hole_follows(hole)) {
KUNIT_FAIL(test, "Hole follows node, expected none!\n");
return false;
}
}
return true;
}
static bool assert_one_hole(struct kunit *test, const struct drm_mm *mm, u64 start, u64 end)
{
struct drm_mm_node *hole;
u64 hole_start, hole_end;
unsigned long count;
bool ok = true;
if (end <= start)
return true;
count = 0;
drm_mm_for_each_hole(hole, mm, hole_start, hole_end) {
if (start != hole_start || end != hole_end) {
if (ok)
KUNIT_FAIL(test,
"empty mm has incorrect hole, found (%llx, %llx), expect (%llx, %llx)\n",
hole_start, hole_end, start, end);
ok = false;
}
count++;
}
if (count != 1) {
KUNIT_FAIL(test, "Expected to find one hole, found %lu instead\n", count);
ok = false;
}
return ok;
}
static u64 misalignment(struct drm_mm_node *node, u64 alignment)
{
u64 rem;
if (!alignment)
return 0;
div64_u64_rem(node->start, alignment, &rem);
return rem;
}
static bool assert_node(struct kunit *test, struct drm_mm_node *node, struct drm_mm *mm,
u64 size, u64 alignment, unsigned long color)
{
bool ok = true;
if (!drm_mm_node_allocated(node) || node->mm != mm) {
KUNIT_FAIL(test, "node not allocated\n");
ok = false;
}
if (node->size != size) {
KUNIT_FAIL(test, "node has wrong size, found %llu, expected %llu\n",
node->size, size);
ok = false;
}
if (misalignment(node, alignment)) {
KUNIT_FAIL(test,
"node is misaligned, start %llx rem %llu, expected alignment %llu\n",
node->start, misalignment(node, alignment), alignment);
ok = false;
}
if (node->color != color) {
KUNIT_FAIL(test, "node has wrong color, found %lu, expected %lu\n",
node->color, color);
ok = false;
}
return ok;
}
static void drm_test_mm_init(struct kunit *test)
{
const unsigned int size = 4096;
struct drm_mm mm;
struct drm_mm_node tmp;
/* Start with some simple checks on initialising the struct drm_mm */
memset(&mm, 0, sizeof(mm));
KUNIT_ASSERT_FALSE_MSG(test, drm_mm_initialized(&mm),
Annotation
- Immediate include surface: `kunit/test.h`, `linux/prime_numbers.h`, `linux/slab.h`, `linux/random.h`, `linux/vmalloc.h`, `linux/ktime.h`, `drm/drm_mm.h`, `drm/drm_print.h`.
- Detected declarations: `function assert_no_holes`, `function drm_mm_for_each_node`, `function assert_one_hole`, `function misalignment`, `function assert_node`, `function drm_test_mm_init`, `function drm_test_mm_debug`, `function expect_insert`, `function drm_test_mm_align_pot`, `function drm_test_mm_align32`.
- Atlas domain: Driver Families / drivers/gpu.
- 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.