From: Andi Kleen <andi@firstfloor.org>
To: acme@infradead.org
Cc: mingo@kernel.org, linux-kernel@vger.kernel.org,
peterz@infradead.org, eranian@google.com, namhyung@kernel.org,
jolsa@redhat.com, Andi Kleen <ak@linux.intel.com>
Subject: [PATCH 8/8] perf, tools, test: Add test case for alias and JSON parsing
Date: Wed, 5 Mar 2014 11:49:38 -0800 [thread overview]
Message-ID: <1394048978-15909-9-git-send-email-andi@firstfloor.org> (raw)
In-Reply-To: <1394048978-15909-1-git-send-email-andi@firstfloor.org>
From: Andi Kleen <ak@linux.intel.com>
Add a simple test case to perf test that runs perf download and parses
all the events. This needs adding an all event iterator to pmu.c
Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
tools/perf/Makefile.perf | 1 +
tools/perf/tests/aliases.c | 41 +++++++++++++++++++++++++++++++++++++++++
tools/perf/tests/builtin-test.c | 4 ++++
tools/perf/tests/tests.h | 1 +
tools/perf/util/pmu.c | 18 ++++++++++++++++++
tools/perf/util/pmu.h | 2 ++
6 files changed, 67 insertions(+)
create mode 100644 tools/perf/tests/aliases.c
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 8c4cc73..51bb490 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -416,6 +416,7 @@ endif
LIB_OBJS += $(OUTPUT)tests/code-reading.o
LIB_OBJS += $(OUTPUT)tests/sample-parsing.o
LIB_OBJS += $(OUTPUT)tests/parse-no-sample-id-all.o
+LIB_OBJS += $(OUTPUT)tests/aliases.o
ifndef NO_DWARF_UNWIND
ifeq ($(ARCH),x86)
LIB_OBJS += $(OUTPUT)tests/dwarf-unwind.o
diff --git a/tools/perf/tests/aliases.c b/tools/perf/tests/aliases.c
new file mode 100644
index 0000000..acded28
--- /dev/null
+++ b/tools/perf/tests/aliases.c
@@ -0,0 +1,41 @@
+/* Check if we can set up all aliases and can read JSON files */
+#include <stdlib.h>
+#include "tests.h"
+#include "pmu.h"
+#include "evlist.h"
+#include "parse-events.h"
+
+static struct perf_evlist *evlist;
+
+static int num_events;
+
+static int test_event(const char *name)
+{
+ int ret = parse_events(evlist, name);
+
+ if (ret)
+ fprintf(stderr, "invalid or unsupported event: '%s'\n", name);
+ else
+ num_events++;
+ return ret;
+}
+
+int test__aliases(void)
+{
+ int err;
+
+ /* Download JSON files */
+ /* XXX assumes perf is installed */
+ if (system("perf download > /dev/null") < 0) {
+ /* Don't error out for this for now */
+ fprintf(stderr, "perf download failed\n");
+ }
+
+ evlist = perf_evlist__new();
+ if (evlist == NULL)
+ return -ENOMEM;
+
+ err = pmu_iterate_events(test_event);
+ fprintf(stderr, " Parsed %d events: ", num_events);
+ return err;
+}
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index b11bf8a..b77468d 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -115,6 +115,10 @@ static struct test {
.desc = "Test parsing with no sample_id_all bit set",
.func = test__parse_no_sample_id_all,
},
+ {
+ .desc = "Test parsing JSON aliases",
+ .func = test__aliases,
+ },
#if defined(__x86_64__) || defined(__i386__)
#ifdef HAVE_DWARF_UNWIND_SUPPORT
{
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
index a24795c..d090866 100644
--- a/tools/perf/tests/tests.h
+++ b/tools/perf/tests/tests.h
@@ -41,6 +41,7 @@ int test__sample_parsing(void);
int test__keep_tracking(void);
int test__parse_no_sample_id_all(void);
int test__dwarf_unwind(void);
+int test__aliases(void);
#if defined(__x86_64__) || defined(__i386__)
#ifdef HAVE_DWARF_UNWIND_SUPPORT
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index a26ec85..652b025 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -879,3 +879,21 @@ bool pmu_have_event(const char *pname, const char *name)
}
return false;
}
+
+int pmu_iterate_events(int (*func)(const char *name))
+{
+ int ret = 0;
+ struct perf_pmu *pmu;
+ struct perf_pmu_alias *alias;
+
+ perf_pmu__find("cpu"); /* Load PMUs */
+ pmu = NULL;
+ while ((pmu = perf_pmu__scan(pmu)) != NULL) {
+ list_for_each_entry(alias, &pmu->aliases, list) {
+ ret = func(alias->name);
+ if (ret != 0)
+ break;
+ }
+ }
+ return ret;
+}
diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h
index 62255bb..b885c55 100644
--- a/tools/perf/util/pmu.h
+++ b/tools/perf/util/pmu.h
@@ -47,5 +47,7 @@ bool pmu_have_event(const char *pname, const char *name);
int perf_pmu__test(void);
+int pmu_iterate_events(int (*func)(const char *name));
+
extern const char *json_file;
#endif /* __PMU_H */
--
1.8.5.3
next prev parent reply other threads:[~2014-03-05 19:51 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-05 19:49 perf: Add support for full Intel event lists Andi Kleen
2014-03-05 19:49 ` [PATCH 1/8] perf, tools: Add jsmn `jasmine' JSON parser Andi Kleen
2014-03-11 10:23 ` Jiri Olsa
2014-03-11 13:37 ` Jiri Olsa
2014-03-11 13:38 ` Jiri Olsa
2014-03-13 20:06 ` Andi Kleen
2014-03-11 13:38 ` Jiri Olsa
2014-03-13 20:07 ` Andi Kleen
2014-03-11 13:38 ` Jiri Olsa
2014-03-05 19:49 ` [PATCH 2/8] perf, tools: Add support for reading JSON event files Andi Kleen
2014-03-11 13:37 ` Jiri Olsa
2014-03-05 19:49 ` [PATCH 3/8] perf, tools: Automatically look for event file name for cpu Andi Kleen
2014-03-11 13:37 ` Jiri Olsa
2014-03-05 19:49 ` [PATCH 4/8] perf, tools: Add perf download to download event files Andi Kleen
2014-03-05 19:49 ` [PATCH 5/8] perf, tools: Allow events with dot Andi Kleen
2014-03-05 19:49 ` [PATCH 6/8] perf, tools: Query terminal width and use in perf list Andi Kleen
2014-03-11 13:41 ` Jiri Olsa
2014-03-05 19:49 ` [PATCH 7/8] perf, tools, record: Always allow to overide default period Andi Kleen
2014-03-11 14:26 ` Jiri Olsa
2014-03-05 19:49 ` Andi Kleen [this message]
2014-03-11 14:31 ` [PATCH 8/8] perf, tools, test: Add test case for alias and JSON parsing Jiri Olsa
2014-03-14 21:12 ` Andi Kleen
2014-03-06 9:37 ` perf: Add support for full Intel event lists Jiri Olsa
2014-03-10 19:39 ` Ben Hutchings
2014-03-10 22:14 ` Andi Kleen
2014-03-10 23:13 ` Ben Hutchings
2014-03-10 23:31 ` Andi Kleen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1394048978-15909-9-git-send-email-andi@firstfloor.org \
--to=andi@firstfloor.org \
--cc=acme@infradead.org \
--cc=ak@linux.intel.com \
--cc=eranian@google.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®