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

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

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/bpf/prog_tests/bpf_gotox.c
Extension
.c
Size
14706 bytes
Lines
546
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 (!ASSERT_OK(ret, "bpf_obj_get_info_by_fd(map_fd)")) {
			close(map_fd);
			return;
		}

		if (map_info.type == BPF_MAP_TYPE_INSN_ARRAY) {
			if (!ASSERT_EQ(seen, false, "more than one INSN_ARRAY map")) {
				close(map_fd);
				return;
			}
			seen = true;
		}
		close(map_fd);
	}

	ASSERT_EQ(seen, true, "no INSN_ARRAY map");
}

static void check_one_switch(struct bpf_gotox *skel)
{
	__u64 in[]   = {0, 1, 2, 3, 4,  5, 77};
	__u64 out[]  = {2, 3, 4, 5, 7, 19, 19};
	int i;

	for (i = 0; i < ARRAY_SIZE(in); i++)
		check_simple(skel, skel->progs.one_switch, in[i], out[i]);
}

static void check_one_switch_non_zero_sec_off(struct bpf_gotox *skel)
{
	__u64 in[]   = {0, 1, 2, 3, 4,  5, 77};
	__u64 out[]  = {2, 3, 4, 5, 7, 19, 19};
	int i;

	for (i = 0; i < ARRAY_SIZE(in); i++)
		check_simple(skel, skel->progs.one_switch_non_zero_sec_off, in[i], out[i]);
}

static void check_two_switches(struct bpf_gotox *skel)
{
	__u64 in[]   = {0, 1, 2, 3, 4,  5, 77};
	__u64 out[] = {103, 104, 107, 205, 115, 1019, 1019};
	int i;

	for (i = 0; i < ARRAY_SIZE(in); i++)
		check_simple(skel, skel->progs.two_switches, in[i], out[i]);
}

static void check_big_jump_table(struct bpf_gotox *skel)
{
	__u64 in[]  = {0, 11, 27, 31, 22, 45, 99};
	__u64 out[] = {2,  3,  4,  5, 19, 19, 19};
	int i;

	for (i = 0; i < ARRAY_SIZE(in); i++)
		check_simple(skel, skel->progs.big_jump_table, in[i], out[i]);
}

static void check_one_jump_two_maps(struct bpf_gotox *skel)
{
	__u64 in[]  = {0, 1, 2, 3, 4,  5, 77};
	__u64 out[] = {12, 15, 7 , 15, 12, 15, 15};
	int i;

	for (i = 0; i < ARRAY_SIZE(in); i++)
		check_simple(skel, skel->progs.one_jump_two_maps, in[i], out[i]);
}

static void check_static_global(struct bpf_gotox *skel)
{
	__u64 in[]   = {0, 1, 2, 3, 4,  5, 77};
	__u64 out[]  = {2, 3, 4, 5, 7, 19, 19};
	int i;

	for (i = 0; i < ARRAY_SIZE(in); i++)
		check_simple(skel, skel->progs.use_static_global1, in[i], out[i]);
	for (i = 0; i < ARRAY_SIZE(in); i++)
		check_simple(skel, skel->progs.use_static_global2, in[i], out[i]);
}

static void check_nonstatic_global(struct bpf_gotox *skel)
{
	__u64 in[]   = {0, 1, 2, 3, 4,  5, 77};
	__u64 out[]  = {2, 3, 4, 5, 7, 19, 19};
	int i;

	for (i = 0; i < ARRAY_SIZE(in); i++)
		check_simple(skel, skel->progs.use_nonstatic_global1, in[i], out[i]);

	for (i = 0; i < ARRAY_SIZE(in); i++)

Annotation

Implementation Notes