tools/testing/selftests/bpf/test_loader.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/test_loader.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/test_loader.c- Extension
.c- Size
- 41814 bytes
- Lines
- 1582
- 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
linux/capability.hlinux/err.hstdlib.htest_progs.hbpf/btf.hautoconf_helper.hdisasm_helpers.hunpriv_helpers.hcap_helpers.hjit_disasm_helpers.h
Detected Declarations
struct test_subspecstruct test_specstruct matchstruct cap_stateenum modeenum load_modeenum archfunction tester_initfunction test_loader_finifunction free_msgsfunction free_test_specfunction compile_regexfunction __push_msgfunction clone_msgsfunction push_msgfunction push_disasm_msgfunction parse_intfunction parse_capsfunction parse_retvalfunction update_flagsfunction compare_decl_tagsfunction get_current_archfunction parse_test_specfunction prepare_casefunction emit_verifier_logfunction emit_xlatedfunction emit_jitedfunction emit_stderrfunction verify_stderrfunction verify_test_stderrfunction emit_stdoutfunction count_linesfunction match_positive_msgsfunction match_negative_msgsfunction validate_msgsfunction drop_capabilitiesfunction restore_capabilitiesfunction can_execute_unprivfunction is_unpriv_capable_mapfunction do_prog_test_runfunction should_do_test_runfunction get_xlated_program_textfunction get_streamfunction fixup_btf_from_pathfunction outputfunction process_subtestfunction test_loader__run_subtests
Annotated Snippet
struct test_subspec {
char *name;
char *description;
bool expect_failure;
struct expected_msgs expect_msgs;
struct expected_msgs expect_xlated;
struct expected_msgs jited;
struct expected_msgs stderr;
struct expected_msgs stdout;
int retval;
bool execute;
__u64 caps;
};
struct test_spec {
const char *prog_name;
struct test_subspec priv;
struct test_subspec unpriv;
const char *btf_custom_path;
const char *btf_custom_func_path;
int log_level;
int prog_flags;
int mode_mask;
int arch_mask;
int load_mask;
int linear_sz;
bool auxiliary;
bool valid;
};
static int tester_init(struct test_loader *tester)
{
if (!tester->log_buf) {
tester->log_buf_sz = TEST_LOADER_LOG_BUF_SZ;
tester->log_buf = calloc(tester->log_buf_sz, 1);
if (!ASSERT_OK_PTR(tester->log_buf, "tester_log_buf"))
return -ENOMEM;
}
return 0;
}
void test_loader_fini(struct test_loader *tester)
{
if (!tester)
return;
free(tester->log_buf);
}
void free_msgs(struct expected_msgs *msgs)
{
int i;
for (i = 0; i < msgs->cnt; i++)
if (msgs->patterns[i].is_regex)
regfree(&msgs->patterns[i].regex);
free(msgs->patterns);
msgs->patterns = NULL;
msgs->cnt = 0;
}
static void free_test_spec(struct test_spec *spec)
{
/* Deallocate expect_msgs arrays. */
free_msgs(&spec->priv.expect_msgs);
free_msgs(&spec->unpriv.expect_msgs);
free_msgs(&spec->priv.expect_xlated);
free_msgs(&spec->unpriv.expect_xlated);
free_msgs(&spec->priv.jited);
free_msgs(&spec->unpriv.jited);
free_msgs(&spec->unpriv.stderr);
free_msgs(&spec->priv.stderr);
free_msgs(&spec->unpriv.stdout);
free_msgs(&spec->priv.stdout);
free(spec->priv.name);
free(spec->priv.description);
free(spec->unpriv.name);
free(spec->unpriv.description);
spec->priv.name = NULL;
spec->priv.description = NULL;
spec->unpriv.name = NULL;
spec->unpriv.description = NULL;
}
/* Compiles regular expression matching pattern.
* Pattern has a special syntax:
*
* pattern := (<verbatim text> | regex)*
Annotation
- Immediate include surface: `linux/capability.h`, `linux/err.h`, `stdlib.h`, `test_progs.h`, `bpf/btf.h`, `autoconf_helper.h`, `disasm_helpers.h`, `unpriv_helpers.h`.
- Detected declarations: `struct test_subspec`, `struct test_spec`, `struct match`, `struct cap_state`, `enum mode`, `enum load_mode`, `enum arch`, `function tester_init`, `function test_loader_fini`, `function free_msgs`.
- 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.