/* Cleanup test PMU directory. */ staticint test_pmu_put(constchar *dir, struct perf_pmu *hwm)
{ char buf[PATH_MAX + 20]; int ret;
if (scnprintf(buf, sizeof(buf), "rm -fr %s", dir) < 0) {
pr_err("Failure to set up buffer for \"%s\"\n", dir); return -EINVAL;
}
ret = system(buf); if (ret)
pr_err("Failure to \"%s\"\n", buf);
/* * Prepare test PMU directory data, normally exported by kernel at * /sys/class/hwmon/hwmon<number>/. Give as input a buffer to hold the file * path, the result is PMU loaded using that directory.
*/ staticstruct perf_pmu *test_pmu_get(char *dir, size_t sz)
{ constchar *test_hwmon_name_nl = "A test hwmon PMU\n"; constchar *test_hwmon_name = "A test hwmon PMU"; /* Simulated hwmon items. */ conststruct test_item { constchar *name; constchar *value;
} test_items[] = {
{ "temp1_label", "test hwmon event1\n", },
{ "temp1_input", "40000\n", },
{ "temp2_label", "test hwmon event2\n", },
{ "temp2_input", "50000\n", },
}; int hwmon_dirfd = -1, test_dirfd = -1, file; struct perf_pmu *hwm = NULL;
ssize_t len;
/* Create equivalent of sysfs mount point. */
scnprintf(dir, sz, "/tmp/perf-hwmon-pmu-test-XXXXXX"); if (!mkdtemp(dir)) {
pr_err("mkdtemp failed\n");
dir[0] = '\0'; return NULL;
}
test_dirfd = open(dir, O_PATH|O_DIRECTORY); if (test_dirfd < 0) {
pr_err("Failed to open test directory \"%s\"\n", dir); goto err_out;
}
/* Create the test hwmon directory and give it a name. */ if (mkdirat(test_dirfd, "hwmon1234", 0755) < 0) {
pr_err("Failed to mkdir hwmon directory\n"); goto err_out;
}
strncat(dir, "/hwmon1234", sz - strlen(dir));
hwmon_dirfd = open(dir, O_PATH|O_DIRECTORY); if (hwmon_dirfd < 0) {
pr_err("Failed to open test hwmon directory \"%s\"\n", dir); goto err_out;
}
file = openat(hwmon_dirfd, "name", O_WRONLY | O_CREAT, 0600); if (file < 0) {
pr_err("Failed to open for writing file \"name\"\n"); goto err_out;
}
len = strlen(test_hwmon_name_nl); if (write(file, test_hwmon_name_nl, len) < len) {
close(file);
pr_err("Failed to write to 'name' file\n"); goto err_out;
}
close(file);
/* Create test hwmon files. */ for (size_t i = 0; i < ARRAY_SIZE(test_items); i++) { conststruct test_item *item = &test_items[i];
file = openat(hwmon_dirfd, item->name, O_WRONLY | O_CREAT, 0600); 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;
}
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;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.