tools/testing/selftests/bpf/prog_tests/string_kfuncs.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/string_kfuncs.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/string_kfuncs.c- Extension
.c- Size
- 1588 bytes
- Lines
- 70
- 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.hstring_kfuncs_success.skel.hstring_kfuncs_failure1.skel.hstring_kfuncs_failure2.skel.hsys/mman.h
Detected Declarations
function run_too_long_testsfunction test_string_kfuncs
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/* Copyright (C) 2025 Red Hat, Inc.*/
#include <test_progs.h>
#include "string_kfuncs_success.skel.h"
#include "string_kfuncs_failure1.skel.h"
#include "string_kfuncs_failure2.skel.h"
#include <sys/mman.h>
static const char * const test_cases[] = {
"strcmp",
"strcasecmp",
"strncasecmp",
"strchr",
"strchrnul",
"strnchr",
"strrchr",
"strlen",
"strnlen",
"strspn_str",
"strspn_accept",
"strcspn_str",
"strcspn_reject",
"strstr",
"strcasestr",
"strnstr",
"strncasestr",
};
void run_too_long_tests(void)
{
struct string_kfuncs_failure2 *skel;
struct bpf_program *prog;
char test_name[256];
int err, i;
skel = string_kfuncs_failure2__open_and_load();
if (!ASSERT_OK_PTR(skel, "string_kfuncs_failure2__open_and_load"))
return;
memset(skel->bss->long_str, 'a', sizeof(skel->bss->long_str));
for (i = 0; i < ARRAY_SIZE(test_cases); i++) {
sprintf(test_name, "test_%s_too_long", test_cases[i]);
if (!test__start_subtest(test_name))
continue;
prog = bpf_object__find_program_by_name(skel->obj, test_name);
if (!ASSERT_OK_PTR(prog, "bpf_object__find_program_by_name"))
goto cleanup;
LIBBPF_OPTS(bpf_test_run_opts, topts);
err = bpf_prog_test_run_opts(bpf_program__fd(prog), &topts);
if (!ASSERT_OK(err, "bpf_prog_test_run"))
goto cleanup;
ASSERT_EQ(topts.retval, -E2BIG, "reading too long string fails with -E2BIG");
}
cleanup:
string_kfuncs_failure2__destroy(skel);
}
void test_string_kfuncs(void)
{
RUN_TESTS(string_kfuncs_success);
RUN_TESTS(string_kfuncs_failure1);
run_too_long_tests();
}
Annotation
- Immediate include surface: `test_progs.h`, `string_kfuncs_success.skel.h`, `string_kfuncs_failure1.skel.h`, `string_kfuncs_failure2.skel.h`, `sys/mman.h`.
- Detected declarations: `function run_too_long_tests`, `function test_string_kfuncs`.
- 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.