tools/testing/selftests/bpf/prog_tests/subprogs.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/subprogs.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/subprogs.c- Extension
.c- Size
- 2050 bytes
- Lines
- 97
- 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.htest_subprogs.skel.htest_subprogs_unused.skel.h
Detected Declarations
struct toggler_ctxfunction test_subprogs_with_jit_harden_togglingfunction test_subprogs_alonefunction test_subprogs
Annotated Snippet
struct toggler_ctx {
int fd;
bool stop;
};
static void *toggle_jit_harden(void *arg)
{
struct toggler_ctx *ctx = arg;
char two = '2';
char zero = '0';
while (!ctx->stop) {
lseek(ctx->fd, SEEK_SET, 0);
write(ctx->fd, &two, sizeof(two));
lseek(ctx->fd, SEEK_SET, 0);
write(ctx->fd, &zero, sizeof(zero));
}
return NULL;
}
static void test_subprogs_with_jit_harden_toggling(void)
{
struct toggler_ctx ctx;
pthread_t toggler;
int err;
unsigned int i, loop = 10;
ctx.fd = open("/proc/sys/net/core/bpf_jit_harden", O_RDWR);
if (!ASSERT_GE(ctx.fd, 0, "open bpf_jit_harden"))
return;
ctx.stop = false;
err = pthread_create(&toggler, NULL, toggle_jit_harden, &ctx);
if (!ASSERT_OK(err, "new toggler"))
goto out;
/* Make toggler thread to run */
usleep(1);
for (i = 0; i < loop; i++) {
struct test_subprogs *skel = test_subprogs__open_and_load();
if (!ASSERT_OK_PTR(skel, "skel open"))
break;
test_subprogs__destroy(skel);
}
ctx.stop = true;
pthread_join(toggler, NULL);
out:
close(ctx.fd);
}
static void test_subprogs_alone(void)
{
struct test_subprogs *skel;
struct test_subprogs_unused *skel2;
int err;
skel = test_subprogs__open_and_load();
if (!ASSERT_OK_PTR(skel, "skel_open"))
return;
err = test_subprogs__attach(skel);
if (!ASSERT_OK(err, "skel attach"))
goto cleanup;
usleep(1);
ASSERT_EQ(skel->bss->res1, 12, "res1");
ASSERT_EQ(skel->bss->res2, 17, "res2");
ASSERT_EQ(skel->bss->res3, 19, "res3");
ASSERT_EQ(skel->bss->res4, 36, "res4");
skel2 = test_subprogs_unused__open_and_load();
ASSERT_OK_PTR(skel2, "unused_progs_skel");
test_subprogs_unused__destroy(skel2);
cleanup:
test_subprogs__destroy(skel);
}
void test_subprogs(void)
{
if (test__start_subtest("subprogs_alone"))
test_subprogs_alone();
if (test__start_subtest("subprogs_and_jit_harden"))
test_subprogs_with_jit_harden_toggling();
}
Annotation
- Immediate include surface: `test_progs.h`, `test_subprogs.skel.h`, `test_subprogs_unused.skel.h`.
- Detected declarations: `struct toggler_ctx`, `function test_subprogs_with_jit_harden_toggling`, `function test_subprogs_alone`, `function test_subprogs`.
- 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.