Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3f3a2064 authored by Jiri Olsa's avatar Jiri Olsa Committed by Ingo Molnar
Browse files

perf test: Add automated tests for pmu sysfs translated events



Add automated tests for all events found under PMU/events
directory. Tested events are in the 'cpu/event=xxx/u' format,
where 'xxx' is substituted by every event found.

The 'event=xxx' term is translated to the cpu specific term.
We only check that the event is created (not the real config
numbers) and that the modifier is properly set.

Signed-off-by: default avatarJiri Olsa <jolsa@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: default avatarPeter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1349873598-12583-9-git-send-email-jolsa@redhat.com


Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent 1d33d6dc
Loading
Loading
Loading
Loading
+68 −0
Original line number Original line Diff line number Diff line
@@ -443,6 +443,23 @@ static int test__checkevent_pmu_name(struct perf_evlist *evlist)
	return 0;
	return 0;
}
}


static int test__checkevent_pmu_events(struct perf_evlist *evlist)
{
	struct perf_evsel *evsel;

	evsel = list_entry(evlist->entries.next, struct perf_evsel, node);
	TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
	TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
	TEST_ASSERT_VAL("wrong exclude_user",
			!evsel->attr.exclude_user);
	TEST_ASSERT_VAL("wrong exclude_kernel",
			evsel->attr.exclude_kernel);
	TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv);
	TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);

	return 0;
}

static int test__checkterms_simple(struct list_head *terms)
static int test__checkterms_simple(struct list_head *terms)
{
{
	struct parse_events__term *term;
	struct parse_events__term *term;
@@ -1024,6 +1041,51 @@ static int test_pmu(void)
	return !ret;
	return !ret;
}
}


static int test_pmu_events(void)
{
	struct stat st;
	char path[PATH_MAX];
	struct dirent *ent;
	DIR *dir;
	int ret;

	snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/events/",
		 sysfs_find_mountpoint());

	ret = stat(path, &st);
	if (ret) {
		pr_debug("ommiting PMU cpu events tests\n");
		return 0;
	}

	dir = opendir(path);
	if (!dir) {
		pr_debug("can't open pmu event dir");
		return -1;
	}

	while (!ret && (ent = readdir(dir))) {
#define MAX_NAME 100
		struct test__event_st e;
		char name[MAX_NAME];

		if (!strcmp(ent->d_name, ".") ||
		    !strcmp(ent->d_name, ".."))
			continue;

		snprintf(name, MAX_NAME, "cpu/event=%s/u", ent->d_name);

		e.name  = name;
		e.check = test__checkevent_pmu_events;

		ret = test_event(&e);
#undef MAX_NAME
	}

	closedir(dir);
	return ret;
}

int parse_events__test(void)
int parse_events__test(void)
{
{
	int ret1, ret2 = 0;
	int ret1, ret2 = 0;
@@ -1040,6 +1102,12 @@ do { \
	if (test_pmu())
	if (test_pmu())
		TEST_EVENTS(test__events_pmu);
		TEST_EVENTS(test__events_pmu);


	if (test_pmu()) {
		int ret = test_pmu_events();
		if (ret)
			return ret;
	}

	ret1 = test_terms(test__terms, ARRAY_SIZE(test__terms));
	ret1 = test_terms(test__terms, ARRAY_SIZE(test__terms));
	if (!ret2)
	if (!ret2)
		ret2 = ret1;
		ret2 = ret1;