tools/testing/selftests/bpf/prog_tests/find_vma.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/find_vma.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/bpf/prog_tests/find_vma.c
Extension
.c
Size
3163 bytes
Lines
128
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.

Dependency Surface

Detected Declarations

Annotated Snippet

if (pfd == -ENOENT || pfd == -EOPNOTSUPP) {
			printf("%s:SKIP:no PERF_COUNT_HW_CPU_CYCLES\n", __func__);
			test__skip();
			goto cleanup;
		}
		if (!ASSERT_GE(pfd, 0, "perf_event_open"))
			goto cleanup;
	}

	link = bpf_program__attach_perf_event(skel->progs.handle_pe, pfd);
	if (!ASSERT_OK_PTR(link, "attach_perf_event"))
		goto cleanup;

	for (i = 0; i < one_bn && find_vma_pe_condition(skel); ++i)
		++j;

	test_and_reset_skel(skel, -EBUSY /* in nmi, irq_work is busy */, i == one_bn);
cleanup:
	bpf_link__destroy(link);
	close(pfd);
}

static void test_find_vma_kprobe(struct find_vma *skel)
{
	int err;

	err = find_vma__attach(skel);
	if (!ASSERT_OK(err, "get_branch_snapshot__attach"))
		return;

	getpgid(skel->bss->target_pid);
	test_and_reset_skel(skel, -ENOENT /* could not find vma for ptr 0 */, true);
}

static void test_illegal_write_vma(void)
{
	struct find_vma_fail1 *skel;

	skel = find_vma_fail1__open_and_load();
	if (!ASSERT_ERR_PTR(skel, "find_vma_fail1__open_and_load"))
		find_vma_fail1__destroy(skel);
}

static void test_illegal_write_task(void)
{
	struct find_vma_fail2 *skel;

	skel = find_vma_fail2__open_and_load();
	if (!ASSERT_ERR_PTR(skel, "find_vma_fail2__open_and_load"))
		find_vma_fail2__destroy(skel);
}

void serial_test_find_vma(void)
{
	struct find_vma *skel;

	skel = find_vma__open_and_load();
	if (!ASSERT_OK_PTR(skel, "find_vma__open_and_load"))
		return;

	skel->bss->target_pid = getpid();
	skel->bss->addr = (__u64)(uintptr_t)test_find_vma_pe;

	test_find_vma_pe(skel);
	test_find_vma_kprobe(skel);

	find_vma__destroy(skel);
	test_illegal_write_vma();
	test_illegal_write_task();
}

Annotation

Implementation Notes