From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755994AbaG3XZV (ORCPT ); Wed, 30 Jul 2014 19:25:21 -0400 Received: from mga11.intel.com ([192.55.52.93]:14666 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751083AbaG3XW4 (ORCPT ); Wed, 30 Jul 2014 19:22:56 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.01,768,1400050800"; d="scan'208";a="569694650" From: Andi Kleen To: jolsa@redhat.com Cc: linux-kernel@vger.kernel.org, namhyung@kernel.org, acme@kernel.org, mingo@kernel.org, peterz@infradead.org, Andi Kleen Subject: [PATCH 09/10] perf, tools, test: Add test case for alias and JSON parsing Date: Wed, 30 Jul 2014 16:22:49 -0700 Message-Id: <1406762570-16694-10-git-send-email-andi@firstfloor.org> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1406762570-16694-1-git-send-email-andi@firstfloor.org> References: <1406762570-16694-1-git-send-email-andi@firstfloor.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andi Kleen Add a simple test case to perf test that parses all the available events, including json events. This needs adding an all event iterator to pmu.c v2: Rename identifiers v3: Only iterate cpu pmu to avoid bogus errors. Move pmu iterator to extra patch v4: Include aliases.c again v5: Include util/debug.h Acked-by: Namhyung Kim Signed-off-by: Andi Kleen --- tools/perf/Makefile.perf | 1 + tools/perf/tests/aliases.c | 59 +++++++++++++++++++++++++++++++++++++++++ tools/perf/tests/builtin-test.c | 4 +++ tools/perf/tests/tests.h | 1 + 4 files changed, 65 insertions(+) create mode 100644 tools/perf/tests/aliases.c diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf index f9cce8e..664c538 100644 --- a/tools/perf/Makefile.perf +++ b/tools/perf/Makefile.perf @@ -422,6 +422,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),$(filter $(ARCH),x86 arm)) 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..4209e51 --- /dev/null +++ b/tools/perf/tests/aliases.c @@ -0,0 +1,59 @@ +/* Check if we can set up all aliases and can read JSON files */ +#include +#include "tests.h" +#include "pmu.h" +#include "evlist.h" +#include "parse-events.h" +#include "util/debug.h" + +static struct perf_evlist *evlist; + +static int num_events; +static int failed; + +static int test__event(const char *pmu, const char *name) +{ + int ret; + + /* Not supported for now */ + if (strcmp(pmu, "cpu")) + return 0; + + ret = parse_events(evlist, name); + + if (ret) { + /* + * We only print on failure because common perf setups + * have events that cannot be parsed. + */ + fprintf(stderr, "invalid or unsupported event: '%s'\n", name); + ret = 0; + failed++; + } else + num_events++; + return ret; +} + +int test__aliases(void) +{ + int err; + + /* Download JSON files */ + /* XXX assumes perf is installed */ + /* For now user must manually download */ + if (0 && 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); + if (failed > 0) + pr_debug(" %d events failed", failed); + perf_evlist__delete(evlist); + return err; +} diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c index 6f8b01b..bb37ac2 100644 --- a/tools/perf/tests/builtin-test.c +++ b/tools/perf/tests/builtin-test.c @@ -154,6 +154,10 @@ static struct test { .func = test__hists_cumulate, }, { + .desc = "Test parsing JSON aliases", + .func = test__aliases, + }, + { .func = NULL, }, }; diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h index ed64790..ab92ad9 100644 --- a/tools/perf/tests/tests.h +++ b/tools/perf/tests/tests.h @@ -48,6 +48,7 @@ int test__mmap_thread_lookup(void); int test__thread_mg_share(void); int test__hists_output(void); int test__hists_cumulate(void); +int test__aliases(void); #if defined(__x86_64__) || defined(__i386__) || defined(__arm__) #ifdef HAVE_DWARF_UNWIND_SUPPORT -- 1.9.3