tools/perf/tests/pe-file-parsing.c
Source file repositories/reference/linux-study-clean/tools/perf/tests/pe-file-parsing.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/tests/pe-file-parsing.c- Extension
.c- Size
- 2583 bytes
- Lines
- 102
- 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
stdbool.hinttypes.hstdlib.hstring.hlinux/bitops.hlinux/kernel.hlinux/types.hsys/types.hsys/stat.hunistd.hsubcmd/exec-cmd.hdebug.hutil/build-id.hutil/symbol.hutil/dso.htests.h
Detected Declarations
function run_dirfunction test__pe_file_parsingfunction test__pe_file_parsing
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
#include <stdbool.h>
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
#include <linux/bitops.h>
#include <linux/kernel.h>
#include <linux/types.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <subcmd/exec-cmd.h>
#include "debug.h"
#include "util/build-id.h"
#include "util/symbol.h"
#include "util/dso.h"
#include "tests.h"
#ifdef HAVE_LIBBFD_SUPPORT
static int run_dir(const char *d)
{
char filename[PATH_MAX];
char debugfile[PATH_MAX];
struct build_id bid = { .size = 0, };
char debuglink[PATH_MAX];
char expect_build_id[] = {
0x5a, 0x0f, 0xd8, 0x82, 0xb5, 0x30, 0x84, 0x22,
0x4b, 0xa4, 0x7b, 0x62, 0x4c, 0x55, 0xa4, 0x69,
};
char expect_debuglink[PATH_MAX] = "pe-file.exe.debug";
struct dso *dso;
struct symbol *sym;
int ret;
size_t idx;
scnprintf(filename, PATH_MAX, "%s/pe-file.exe", d);
ret = filename__read_build_id(filename, &bid);
TEST_ASSERT_VAL("Failed to read build_id",
ret == sizeof(expect_build_id));
TEST_ASSERT_VAL("Wrong build_id", !memcmp(bid.data, expect_build_id,
sizeof(expect_build_id)));
ret = filename__read_debuglink(filename, debuglink, PATH_MAX);
TEST_ASSERT_VAL("Failed to read debuglink", ret == 0);
TEST_ASSERT_VAL("Wrong debuglink",
!strcmp(debuglink, expect_debuglink));
scnprintf(debugfile, PATH_MAX, "%s/%s", d, debuglink);
ret = filename__read_build_id(debugfile, &bid);
TEST_ASSERT_VAL("Failed to read debug file build_id",
ret == sizeof(expect_build_id));
TEST_ASSERT_VAL("Wrong build_id", !memcmp(bid.data, expect_build_id,
sizeof(expect_build_id)));
dso = dso__new(filename);
TEST_ASSERT_VAL("Failed to get dso", dso);
ret = dso__load_bfd_symbols(dso, debugfile);
TEST_ASSERT_VAL("Failed to load symbols", ret == 0);
dso__sort_by_name(dso);
sym = dso__find_symbol_by_name(dso, "main", &idx);
TEST_ASSERT_VAL("Failed to find main", sym);
dso__delete(dso);
return TEST_OK;
}
static int test__pe_file_parsing(struct test_suite *test __maybe_unused,
int subtest __maybe_unused)
{
struct stat st;
char path_dir[PATH_MAX];
/* First try development tree tests. */
if (!lstat("./tests", &st))
return run_dir("./tests");
/* Then installed path. */
snprintf(path_dir, PATH_MAX, "%s/tests", get_argv_exec_path());
if (!lstat(path_dir, &st))
return run_dir(path_dir);
return TEST_SKIP;
}
Annotation
- Immediate include surface: `stdbool.h`, `inttypes.h`, `stdlib.h`, `string.h`, `linux/bitops.h`, `linux/kernel.h`, `linux/types.h`, `sys/types.h`.
- Detected declarations: `function run_dir`, `function test__pe_file_parsing`, `function test__pe_file_parsing`.
- 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.