tools/perf/tests/hwmon_pmu.c
Source file repositories/reference/linux-study-clean/tools/perf/tests/hwmon_pmu.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/tests/hwmon_pmu.c- Extension
.c- Size
- 8527 bytes
- Lines
- 358
- 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
debug.hevlist.hhwmon_pmu.hparse-events.htests.herrno.hfcntl.hsys/stat.hlinux/compiler.hlinux/kernel.hlinux/string.h
Detected Declarations
function test_pmu_putfunction do_testfunction evlist__for_each_entryfunction test__hwmon_pmufunction test__hwmon_pmu_without_pmufunction test__hwmon_pmu_with_pmufunction test__parse_hwmon_filename
Annotated Snippet
if (file < 0) {
pr_err("Failed to open for writing file \"%s\"\n", item->name);
goto err_out;
}
if (write(file, item->value, strlen(item->value)) < 0) {
pr_err("Failed to write to file \"%s\"\n", item->name);
close(file);
goto err_out;
}
close(file);
}
/* Make the PMU reading the files created above. */
hwm = perf_pmus__add_test_hwmon_pmu(dir, "hwmon1234", test_hwmon_name);
if (!hwm)
pr_err("Test hwmon creation failed\n");
err_out:
if (!hwm) {
test_pmu_put(dir, hwm);
}
if (test_dirfd >= 0)
close(test_dirfd);
if (hwmon_dirfd >= 0)
close(hwmon_dirfd);
return hwm;
}
static int do_test(size_t i, bool with_pmu, bool with_alias)
{
const char *test_event = with_alias ? test_events[i].alias : test_events[i].name;
struct evlist *evlist = evlist__new();
struct evsel *evsel;
struct parse_events_error err;
int ret;
char str[128];
bool found = false;
if (!evlist) {
pr_err("evlist allocation failed\n");
return TEST_FAIL;
}
if (with_pmu)
snprintf(str, sizeof(str), "hwmon_a_test_hwmon_pmu/%s/", test_event);
else
strlcpy(str, test_event, sizeof(str));
pr_debug("Testing '%s'\n", str);
parse_events_error__init(&err);
ret = parse_events(evlist, str, &err);
if (ret) {
pr_debug("FAILED %s:%d failed to parse event '%s', err %d\n",
__FILE__, __LINE__, str, ret);
parse_events_error__print(&err, str);
ret = TEST_FAIL;
goto out;
}
ret = TEST_OK;
if (with_pmu ? (evlist->core.nr_entries != 1) : (evlist->core.nr_entries < 1)) {
pr_debug("FAILED %s:%d Unexpected number of events for '%s' of %d\n",
__FILE__, __LINE__, str, evlist->core.nr_entries);
ret = TEST_FAIL;
goto out;
}
evlist__for_each_entry(evlist, evsel) {
if (!evsel->pmu || !evsel->pmu->name ||
strcmp(evsel->pmu->name, "hwmon_a_test_hwmon_pmu"))
continue;
if (evsel->core.attr.config != (u64)test_events[i].key.type_and_num) {
pr_debug("FAILED %s:%d Unexpected config for '%s', %lld != %ld\n",
__FILE__, __LINE__, str,
evsel->core.attr.config,
test_events[i].key.type_and_num);
ret = TEST_FAIL;
goto out;
}
found = true;
}
if (!found) {
pr_debug("FAILED %s:%d Didn't find hwmon event '%s' in parsed evsels\n",
__FILE__, __LINE__, str);
ret = TEST_FAIL;
}
Annotation
- Immediate include surface: `debug.h`, `evlist.h`, `hwmon_pmu.h`, `parse-events.h`, `tests.h`, `errno.h`, `fcntl.h`, `sys/stat.h`.
- Detected declarations: `function test_pmu_put`, `function do_test`, `function evlist__for_each_entry`, `function test__hwmon_pmu`, `function test__hwmon_pmu_without_pmu`, `function test__hwmon_pmu_with_pmu`, `function test__parse_hwmon_filename`.
- 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.