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

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

File Facts

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

// SPDX-License-Identifier: GPL-2.0

#include <test_progs.h>
#include "struct_ops_private_stack.skel.h"
#include "struct_ops_private_stack_fail.skel.h"
#include "struct_ops_private_stack_recur.skel.h"

#if defined(__x86_64__) || defined(__aarch64__) || defined(__powerpc64__)
static void test_private_stack(void)
{
	struct struct_ops_private_stack *skel;
	struct bpf_link *link;
	int err;

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

	err = struct_ops_private_stack__load(skel);
	if (!ASSERT_OK(err, "struct_ops_private_stack__load"))
		goto cleanup;

	link = bpf_map__attach_struct_ops(skel->maps.testmod_1);
	if (!ASSERT_OK_PTR(link, "attach_struct_ops"))
		goto cleanup;

	ASSERT_OK(trigger_module_test_read(256), "trigger_read");

	ASSERT_EQ(skel->bss->val_i, 3, "val_i");
	ASSERT_EQ(skel->bss->val_j, 8, "val_j");

	bpf_link__destroy(link);

cleanup:
	struct_ops_private_stack__destroy(skel);
}

static void test_private_stack_fail(void)
{
	struct struct_ops_private_stack_fail *skel;
	int err;

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

	err = struct_ops_private_stack_fail__load(skel);
	ASSERT_ERR(err, "struct_ops_private_stack_fail__load");

	struct_ops_private_stack_fail__destroy(skel);
}

static void test_private_stack_recur(void)
{
	struct struct_ops_private_stack_recur *skel;
	struct bpf_link *link;
	int err;

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

	err = struct_ops_private_stack_recur__load(skel);
	if (!ASSERT_OK(err, "struct_ops_private_stack_recur__load"))
		goto cleanup;

	link = bpf_map__attach_struct_ops(skel->maps.testmod_1);
	if (!ASSERT_OK_PTR(link, "attach_struct_ops"))
		goto cleanup;

	ASSERT_OK(trigger_module_test_read(256), "trigger_read");

	ASSERT_EQ(skel->bss->val_j, 3, "val_j");

	bpf_link__destroy(link);

cleanup:
	struct_ops_private_stack_recur__destroy(skel);
}

static void __test_struct_ops_private_stack(void)
{
	if (test__start_subtest("private_stack"))
		test_private_stack();
	if (test__start_subtest("private_stack_fail"))
		test_private_stack_fail();
	if (test__start_subtest("private_stack_recur"))
		test_private_stack_recur();
}
#else

Annotation

Implementation Notes