lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1341352848-11833-11-git-send-email-jolsa@redhat.com>
Date:	Wed,  4 Jul 2012 00:00:48 +0200
From:	Jiri Olsa <jolsa@...hat.com>
To:	acme@...hat.com, a.p.zijlstra@...llo.nl, mingo@...e.hu,
	paulus@...ba.org, cjashfor@...ux.vnet.ibm.com, fweisbec@...il.com,
	eranian@...gle.com
Cc:	linux-kernel@...r.kernel.org, Jiri Olsa <jolsa@...hat.com>
Subject: [PATCH 10/10] perf, test: Add automated tests for pmu sysfs translated events

Addint automated tests for following events:
  cpu/event=cycles/u
  cpu/event=instructions/u
  cpu/event=branch_instructions/u
  cpu/event=branch_misses/u
  cpu/event=bus_cycles/u
  cpu/event=cache_misses/u
  cpu/event=cache_references/u
  cpu/event=ref_cycles/u
  cpu/event=stalled_cycles_backend/u
  cpu/event=stalled_cycles_frontend/u
  /* dash variants */
  cpu/event=branch-instructions/u
  cpu/event=branch-misses/u
  cpu/event=bus-cycles/u
  cpu/event=cache-misses/u
  cpu/event=cache-references/u
  cpu/event=ref-cycles/u
  cpu/event=stalled-cycles-backend/u
  cpu/event=stalled-cycles-frontend/u

The 'event=xxx' term is translated to the cpu specific term.
We check the final perf_event_attr::config to follow this term.

Signed-off-by: Jiri Olsa <jolsa@...hat.com>
---
 tools/perf/util/parse-events-test.c |  133 +++++++++++++++++++++++++++++++++++
 1 file changed, 133 insertions(+)

diff --git a/tools/perf/util/parse-events-test.c b/tools/perf/util/parse-events-test.c
index ef5cce0..95a501d 100644
--- a/tools/perf/util/parse-events-test.c
+++ b/tools/perf/util/parse-events-test.c
@@ -431,6 +431,45 @@ static int test__checkevent_pmu_name(struct perf_evlist *evlist)
 	return 0;
 }
 
+static __u64 get_config(const char *file)
+{
+#define DATASIZE 64
+	char data[DATASIZE];
+	u64 config;
+
+	TEST_ASSERT_VAL("cannot read sysfs events data",
+			!sysfs_read_file(file, data, DATASIZE));
+
+	TEST_ASSERT_VAL("cannot parse sysfs events data",
+			1 == sscanf(data, "config=0x%" PRIx64 "\n", &config));
+
+	return config;
+#undef DATASIZE
+}
+
+#define TEST__CHECKEVENT_PMU_EVENTS(event)				     \
+static int  test__checkevent_pmu_events_##event(struct perf_evlist *evlist)  \
+{									     \
+	struct perf_evsel *evsel;					     \
+	u64 config = get_config("devices/cpu/events/" # event);		     \
+	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 config", evsel->attr.config == config);	     \
+	return 0;							     \
+}
+
+TEST__CHECKEVENT_PMU_EVENTS(cycles)
+TEST__CHECKEVENT_PMU_EVENTS(instructions)
+TEST__CHECKEVENT_PMU_EVENTS(branch_instructions)
+TEST__CHECKEVENT_PMU_EVENTS(branch_misses)
+TEST__CHECKEVENT_PMU_EVENTS(bus_cycles)
+TEST__CHECKEVENT_PMU_EVENTS(cache_misses)
+TEST__CHECKEVENT_PMU_EVENTS(cache_references)
+TEST__CHECKEVENT_PMU_EVENTS(ref_cycles)
+TEST__CHECKEVENT_PMU_EVENTS(stalled_cycles_backend)
+TEST__CHECKEVENT_PMU_EVENTS(stalled_cycles_frontend)
+
 static int test__checkterms_simple(struct list_head *terms)
 {
 	struct parse_events__term *term;
@@ -598,6 +637,82 @@ static struct test__event_st test__events_pmu[] = {
 	},
 };
 
+static struct test__event_st test__events_pmu_events[] = {
+	[0] = {
+		.name  = "cpu/event=cycles/u",
+		.check = test__checkevent_pmu_events_cycles,
+	},
+	[1] = {
+		.name  = "cpu/event=instructions/u",
+		.check = test__checkevent_pmu_events_instructions,
+	},
+	[2] = {
+		.name  = "cpu/event=branch_instructions/u",
+		.check = test__checkevent_pmu_events_branch_instructions,
+	},
+	[3] = {
+		.name  = "cpu/event=branch_misses/u",
+		.check = test__checkevent_pmu_events_branch_misses,
+	},
+	[4] = {
+		.name  = "cpu/event=bus_cycles/u",
+		.check = test__checkevent_pmu_events_bus_cycles,
+	},
+	[5] = {
+		.name  = "cpu/event=cache_misses/u",
+		.check = test__checkevent_pmu_events_cache_misses,
+	},
+	[6] = {
+		.name  = "cpu/event=cache_references/u",
+		.check = test__checkevent_pmu_events_cache_references,
+	},
+	[7] = {
+		.name  = "cpu/event=ref_cycles/u",
+		.check = test__checkevent_pmu_events_ref_cycles,
+	},
+	[8] = {
+		.name  = "cpu/event=stalled_cycles_backend/u",
+		.check = test__checkevent_pmu_events_stalled_cycles_backend,
+	},
+	[9] = {
+		.name  = "cpu/event=stalled_cycles_frontend/u",
+		.check = test__checkevent_pmu_events_stalled_cycles_frontend,
+	},
+	/* dash variants */
+	[10] = {
+		.name  = "cpu/event=branch-instructions/u",
+		.check = test__checkevent_pmu_events_branch_instructions,
+	},
+	[11] = {
+		.name  = "cpu/event=branch-misses/u",
+		.check = test__checkevent_pmu_events_branch_misses,
+	},
+	[12] = {
+		.name  = "cpu/event=bus-cycles/u",
+		.check = test__checkevent_pmu_events_bus_cycles,
+	},
+	[13] = {
+		.name  = "cpu/event=cache-misses/u",
+		.check = test__checkevent_pmu_events_cache_misses,
+	},
+	[14] = {
+		.name  = "cpu/event=cache-references/u",
+		.check = test__checkevent_pmu_events_cache_references,
+	},
+	[15] = {
+		.name  = "cpu/event=ref-cycles/u",
+		.check = test__checkevent_pmu_events_ref_cycles,
+	},
+	[16] = {
+		.name  = "cpu/event=stalled-cycles-backend/u",
+		.check = test__checkevent_pmu_events_stalled_cycles_backend,
+	},
+	[17] = {
+		.name  = "cpu/event=stalled-cycles-frontend/u",
+		.check = test__checkevent_pmu_events_stalled_cycles_frontend,
+	},
+};
+
 struct test__term {
 	const char *str;
 	__u32 type;
@@ -709,6 +824,21 @@ static int test_pmu(void)
 	return !ret;
 }
 
+static int test_pmu_events(void)
+{
+	struct stat st;
+	char path[PATH_MAX];
+	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 !ret;
+}
+
 int parse_events__test(void)
 {
 	int ret;
@@ -725,5 +855,8 @@ do {							\
 	if (test_pmu())
 		TEST_EVENTS(test__events_pmu);
 
+	if (test_pmu() && test_pmu_events())
+		TEST_EVENTS(test__events_pmu_events);
+
 	return test_terms(test__terms, ARRAY_SIZE(test__terms));
 }
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ