tools/testing/selftests/bpf/prog_tests/atomics.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/atomics.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/atomics.c- Extension
.c- Size
- 6098 bytes
- Lines
- 205
- 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.hatomics.lskel.h
Detected Declarations
function test_addfunction test_subfunction test_andfunction test_orfunction test_xorfunction test_cmpxchgfunction test_xchgfunction test_atomics
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
#include <test_progs.h>
#include "atomics.lskel.h"
static void test_add(struct atomics_lskel *skel)
{
int err, prog_fd;
LIBBPF_OPTS(bpf_test_run_opts, topts);
/* No need to attach it, just run it directly */
prog_fd = skel->progs.add.prog_fd;
err = bpf_prog_test_run_opts(prog_fd, &topts);
if (!ASSERT_OK(err, "test_run_opts err"))
return;
if (!ASSERT_OK(topts.retval, "test_run_opts retval"))
return;
ASSERT_EQ(skel->data->add64_value, 3, "add64_value");
ASSERT_EQ(skel->bss->add64_result, 1, "add64_result");
ASSERT_EQ(skel->data->add32_value, 3, "add32_value");
ASSERT_EQ(skel->bss->add32_result, 1, "add32_result");
ASSERT_EQ(skel->bss->add_stack_value_copy, 3, "add_stack_value");
ASSERT_EQ(skel->bss->add_stack_result, 1, "add_stack_result");
ASSERT_EQ(skel->data->add_noreturn_value, 3, "add_noreturn_value");
}
static void test_sub(struct atomics_lskel *skel)
{
int err, prog_fd;
LIBBPF_OPTS(bpf_test_run_opts, topts);
/* No need to attach it, just run it directly */
prog_fd = skel->progs.sub.prog_fd;
err = bpf_prog_test_run_opts(prog_fd, &topts);
if (!ASSERT_OK(err, "test_run_opts err"))
return;
if (!ASSERT_OK(topts.retval, "test_run_opts retval"))
return;
ASSERT_EQ(skel->data->sub64_value, -1, "sub64_value");
ASSERT_EQ(skel->bss->sub64_result, 1, "sub64_result");
ASSERT_EQ(skel->data->sub32_value, -1, "sub32_value");
ASSERT_EQ(skel->bss->sub32_result, 1, "sub32_result");
ASSERT_EQ(skel->bss->sub_stack_value_copy, -1, "sub_stack_value");
ASSERT_EQ(skel->bss->sub_stack_result, 1, "sub_stack_result");
ASSERT_EQ(skel->data->sub_noreturn_value, -1, "sub_noreturn_value");
}
static void test_and(struct atomics_lskel *skel)
{
int err, prog_fd;
LIBBPF_OPTS(bpf_test_run_opts, topts);
/* No need to attach it, just run it directly */
prog_fd = skel->progs.and.prog_fd;
err = bpf_prog_test_run_opts(prog_fd, &topts);
if (!ASSERT_OK(err, "test_run_opts err"))
return;
if (!ASSERT_OK(topts.retval, "test_run_opts retval"))
return;
ASSERT_EQ(skel->data->and64_value, 0x010ull << 32, "and64_value");
ASSERT_EQ(skel->bss->and64_result, 0x110ull << 32, "and64_result");
ASSERT_EQ(skel->data->and32_value, 0x010, "and32_value");
ASSERT_EQ(skel->bss->and32_result, 0x110, "and32_result");
ASSERT_EQ(skel->data->and_noreturn_value, 0x010ull << 32, "and_noreturn_value");
}
static void test_or(struct atomics_lskel *skel)
{
int err, prog_fd;
LIBBPF_OPTS(bpf_test_run_opts, topts);
/* No need to attach it, just run it directly */
prog_fd = skel->progs.or.prog_fd;
err = bpf_prog_test_run_opts(prog_fd, &topts);
if (!ASSERT_OK(err, "test_run_opts err"))
return;
if (!ASSERT_OK(topts.retval, "test_run_opts retval"))
return;
Annotation
- Immediate include surface: `test_progs.h`, `atomics.lskel.h`.
- Detected declarations: `function test_add`, `function test_sub`, `function test_and`, `function test_or`, `function test_xor`, `function test_cmpxchg`, `function test_xchg`, `function test_atomics`.
- 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.