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.

Dependency Surface

Detected Declarations

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

Implementation Notes