tools/testing/vma/tests/vma.c
Source file repositories/reference/linux-study-clean/tools/testing/vma/tests/vma.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/vma/tests/vma.c- Extension
.c- Size
- 18775 bytes
- Lines
- 657
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
function compare_legacy_flagsfunction test_copy_vmafunction test_vma_flags_unchangedfunction test_vma_flags_clearedfunction test_vma_flags_wordfunction test_vma_flags_testfunction test_vma_flags_test_anyfunction test_vma_flags_clearfunction test_vma_flags_emptyfunction test_vma_flags_difffunction test_vma_flags_andfunction test_append_vma_flagsfunction test_vma_flags_countfunction run_vma_tests
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-or-later
static bool compare_legacy_flags(vm_flags_t legacy_flags, vma_flags_t flags)
{
const unsigned long legacy_val = legacy_flags;
/* The lower word should contain the precise same value. */
const unsigned long flags_lower = flags.__vma_flags[0];
vma_flags_t converted_flags;
#if NUM_VMA_FLAG_BITS > BITS_PER_LONG
int i;
/* All bits in higher flag values should be zero. */
for (i = 1; i < NUM_VMA_FLAG_BITS / BITS_PER_LONG; i++) {
if (flags.__vma_flags[i] != 0)
return false;
}
#endif
static_assert(sizeof(legacy_flags) == sizeof(unsigned long));
/* Assert that legacy flag helpers work correctly. */
converted_flags = legacy_to_vma_flags(legacy_flags);
ASSERT_FLAGS_SAME_MASK(&converted_flags, flags);
ASSERT_EQ(vma_flags_to_legacy(flags), legacy_flags);
return legacy_val == flags_lower;
}
static bool test_copy_vma(void)
{
vma_flags_t vma_flags = mk_vma_flags(VMA_READ_BIT, VMA_WRITE_BIT,
VMA_MAYREAD_BIT, VMA_MAYWRITE_BIT);
struct mm_struct mm = {};
bool need_locks = false;
VMA_ITERATOR(vmi, &mm, 0);
struct vm_area_struct *vma, *vma_new, *vma_next;
/* Move backwards and do not merge. */
vma = alloc_and_link_vma(&mm, 0x3000, 0x5000, 3, vma_flags);
vma_new = copy_vma(&vma, 0, 0x2000, 0, &need_locks);
ASSERT_NE(vma_new, vma);
ASSERT_EQ(vma_new->vm_start, 0);
ASSERT_EQ(vma_new->vm_end, 0x2000);
ASSERT_EQ(vma_new->vm_pgoff, 0);
vma_assert_attached(vma_new);
cleanup_mm(&mm, &vmi);
/* Move a VMA into position next to another and merge the two. */
vma = alloc_and_link_vma(&mm, 0, 0x2000, 0, vma_flags);
vma_next = alloc_and_link_vma(&mm, 0x6000, 0x8000, 6, vma_flags);
vma_new = copy_vma(&vma, 0x4000, 0x2000, 4, &need_locks);
vma_assert_attached(vma_new);
ASSERT_EQ(vma_new, vma_next);
cleanup_mm(&mm, &vmi);
return true;
}
static bool test_vma_flags_unchanged(void)
{
vma_flags_t flags = EMPTY_VMA_FLAGS;
vm_flags_t legacy_flags = 0;
int bit;
struct vm_area_struct vma;
struct vm_area_desc desc;
vma.flags = EMPTY_VMA_FLAGS;
desc.vma_flags = EMPTY_VMA_FLAGS;
for (bit = 0; bit < BITS_PER_LONG; bit++) {
vma_flags_t mask = mk_vma_flags(bit);
legacy_flags |= (1UL << bit);
/* Individual flags. */
vma_flags_set(&flags, bit);
ASSERT_TRUE(compare_legacy_flags(legacy_flags, flags));
/* Via mask. */
vma_flags_set_mask(&flags, mask);
ASSERT_TRUE(compare_legacy_flags(legacy_flags, flags));
/* Same for VMA. */
vma_set_flags(&vma, bit);
ASSERT_TRUE(compare_legacy_flags(legacy_flags, vma.flags));
vma_set_flags_mask(&vma, mask);
Annotation
- Detected declarations: `function compare_legacy_flags`, `function test_copy_vma`, `function test_vma_flags_unchanged`, `function test_vma_flags_cleared`, `function test_vma_flags_word`, `function test_vma_flags_test`, `function test_vma_flags_test_any`, `function test_vma_flags_clear`, `function test_vma_flags_empty`, `function test_vma_flags_diff`.
- Atlas domain: Support Tooling And Documentation / tools.
- 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.