tools/testing/selftests/bpf/prog_tests/queue_stack_map.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/queue_stack_map.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/queue_stack_map.c- Extension
.c- Size
- 2870 bytes
- Lines
- 109
- 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
test_progs.hnetwork_helpers.h
Detected Declarations
function test_queue_stack_map_by_typefunction test_queue_stack_map
Annotated Snippet
if (type == QUEUE) {
val = vals[i];
pkt_v4.iph.saddr = vals[i] * 5;
} else if (type == STACK) {
val = vals[MAP_SIZE - 1 - i];
pkt_v4.iph.saddr = vals[MAP_SIZE - 1 - i] * 5;
}
topts.data_size_out = sizeof(buf);
err = bpf_prog_test_run_opts(prog_fd, &topts);
if (err || topts.retval ||
topts.data_size_out != sizeof(pkt_v4))
break;
memcpy(&iph, buf + sizeof(struct ethhdr), sizeof(iph));
if (iph.daddr != val)
break;
}
ASSERT_OK(err, "bpf_map_pop_elem");
ASSERT_OK(topts.retval, "bpf_map_pop_elem test retval");
ASSERT_EQ(topts.data_size_out, sizeof(pkt_v4),
"bpf_map_pop_elem data_size_out");
ASSERT_EQ(iph.daddr, val, "bpf_map_pop_elem iph.daddr");
/* Queue is empty, program should return TC_ACT_SHOT */
topts.data_size_out = sizeof(buf);
err = bpf_prog_test_run_opts(prog_fd, &topts);
ASSERT_OK(err, "check-queue-stack-map-empty");
ASSERT_EQ(topts.retval, 2 /* TC_ACT_SHOT */,
"check-queue-stack-map-empty test retval");
ASSERT_EQ(topts.data_size_out, sizeof(pkt_v4),
"check-queue-stack-map-empty data_size_out");
/* Check that the program pushed elements correctly */
for (i = 0; i < MAP_SIZE; i++) {
err = bpf_map_lookup_and_delete_elem(map_out_fd, NULL, &val);
ASSERT_OK(err, "bpf_map_lookup_and_delete_elem");
ASSERT_EQ(val, vals[i] * 5, "bpf_map_push_elem val");
}
out:
pkt_v4.iph.saddr = 0;
bpf_object__close(obj);
}
void test_queue_stack_map(void)
{
test_queue_stack_map_by_type(QUEUE);
test_queue_stack_map_by_type(STACK);
}
Annotation
- Immediate include surface: `test_progs.h`, `network_helpers.h`.
- Detected declarations: `function test_queue_stack_map_by_type`, `function test_queue_stack_map`.
- 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.