tools/testing/selftests/bpf/prog_tests/libarena.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/libarena.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/libarena.c- Extension
.c- Size
- 6501 bytes
- Lines
- 254
- 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.hunistd.hlibarena/common.hlibarena/asan.hlibarena/buddy.hlibarena/userspace.hlibarena/libarena.skel.h
Detected Declarations
function run_libarena_testfunction run_libarena_parallel_finifunction run_libarena_parallel_test_workersfunction libarena_parallel_test_enabledfunction run_libarena_parallel_testfunction test_libarenafunction bpf_object__for_each_program
Annotated Snippet
if (!ASSERT_LT(ret, sizeof(tdname), "test worker name")) {
err = -ENAMETOOLONG;
break;
}
/*
* We enumerate the worker threads for a given test with __0, __1,
* and so on. The suffixes always start from 0 and are contiguous,
* so if we don't find a program with the requested name we have
* discovered all available worker programs.
*/
tdprog = bpf_object__find_program_by_name(skel->obj, tdname);
if (!tdprog)
break;
/* Bump the alloc array to accommodate the new thread. */
tmp_threads = realloc(threads, (nthreads + 1) * sizeof(*threads));
if (!ASSERT_TRUE(tmp_threads, "realloc")) {
err = -ENOMEM;
break;
}
threads = tmp_threads;
ret = pthread_create(&threads[nthreads], NULL,
run_libarena_parallel_prog,
tdprog);
if (!ASSERT_OK(ret, "pthread_create")) {
err = ret;
break;
}
}
for (i = 0; i < nthreads; i++) {
ret = pthread_join(threads[i], &thread_ret);
if (!ASSERT_OK(ret, "pthread_join")) {
err = err ?: ret;
continue;
}
err = err ?: (long)thread_ret;
}
free(threads);
return err;
}
static bool libarena_parallel_test_enabled(struct libarena *skel,
const char *prefix,
size_t prefixlen)
{
struct bpf_program *prog;
char progname[MAX_PARTEST_NAME];
int ret;
ret = snprintf(progname, sizeof(progname), "%.*s__enabled", (int)prefixlen,
prefix);
if (!ASSERT_LT(ret, sizeof(progname), "partest enabled name"))
return false;
prog = bpf_object__find_program_by_name(skel->obj, progname);
if (!prog)
return true;
ret = libarena_run_prog(bpf_program__fd(prog));
if (ret == -EOPNOTSUPP)
return false;
if (!ASSERT_OK(ret, progname))
return false;
return true;
}
static void run_libarena_parallel_test(struct libarena *skel, struct bpf_program *prog,
const char *name)
{
char testname[MAX_PARTEST_NAME];
size_t prefixlen;
const char *pos;
int ret;
/*
* We annotate the initialization prog with __init. If the current prog does
* not match, it is one of the parallel threads instead and is ignored.
*
* We assume the test writer knows what they are doing and do not add __init
* randomly in the middle of a test name.
*/
pos = strstr(name, "__init");
if (!pos)
Annotation
- Immediate include surface: `test_progs.h`, `unistd.h`, `libarena/common.h`, `libarena/asan.h`, `libarena/buddy.h`, `libarena/userspace.h`, `libarena/libarena.skel.h`.
- Detected declarations: `function run_libarena_test`, `function run_libarena_parallel_fini`, `function run_libarena_parallel_test_workers`, `function libarena_parallel_test_enabled`, `function run_libarena_parallel_test`, `function test_libarena`, `function bpf_object__for_each_program`.
- 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.