Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753537AbbGBOXT (ORCPT ); Thu, 2 Jul 2015 10:23:19 -0400 Received: from mga02.intel.com ([134.134.136.20]:60436 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753372AbbGBOW6 (ORCPT ); Thu, 2 Jul 2015 10:22:58 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,393,1432623600"; d="scan'208";a="598948279" From: kan.liang@intel.com To: acme@kernel.org, jolsa@kernel.org Cc: ak@linux.intel.com, namhyung@kernel.org, eranian@google.com, adrian.hunter@intel.com, dsahern@gmail.com, a.p.zijlstra@chello.nl, mingo@redhat.com, linux-kernel@vger.kernel.org, Kan Liang Subject: [PATCH V2 3/3] perf,tests: Add cpu_map tests Date: Thu, 2 Jul 2015 03:08:45 -0400 Message-Id: <1435820925-51091-3-git-send-email-kan.liang@intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1435820925-51091-1-git-send-email-kan.liang@intel.com> References: <1435820925-51091-1-git-send-email-kan.liang@intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5519 Lines: 179 From: Kan Liang Adding cpu_map tests to check evlist and evsel cpu map Signed-off-by: Kan Liang --- tools/perf/tests/Build | 1 + tools/perf/tests/builtin-test.c | 4 ++ tools/perf/tests/cpu-map.c | 113 ++++++++++++++++++++++++++++++++++++++++ tools/perf/tests/tests.h | 1 + 4 files changed, 119 insertions(+) create mode 100644 tools/perf/tests/cpu-map.c diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build index d20d6e6..abc848e 100644 --- a/tools/perf/tests/Build +++ b/tools/perf/tests/Build @@ -32,6 +32,7 @@ perf-y += sample-parsing.o perf-y += parse-no-sample-id-all.o perf-y += kmod-path.o perf-y += thread-map.o +perf-y += cpu-map.o perf-$(CONFIG_X86) += perf-time-to-tsc.o diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c index c1dde73..5f279e1 100644 --- a/tools/perf/tests/builtin-test.c +++ b/tools/perf/tests/builtin-test.c @@ -175,6 +175,10 @@ static struct test { .func = test__thread_map, }, { + .desc = "Test cpu map", + .func = test__cpu_map, + }, + { .func = NULL, }, }; diff --git a/tools/perf/tests/cpu-map.c b/tools/perf/tests/cpu-map.c new file mode 100644 index 0000000..fa69aca --- /dev/null +++ b/tools/perf/tests/cpu-map.c @@ -0,0 +1,113 @@ +#include +#include +#include "evsel.h" +#include "evlist.h" +#include "tests.h" +#include "debug.h" + +static int do_cpumap(struct target *target, + struct perf_evlist *evlist, + const char *cpu_list) +{ + struct perf_evsel *evsel; + + evsel = zalloc(sizeof(struct perf_evsel)); + if (evsel == NULL) { + pr_debug("failed to alloc evsel\n"); + return -1; + } + perf_evlist__add(evlist, evsel); + if (cpu_list != NULL) + evsel->cpus = cpu_map__new(cpu_list); + else + evsel->cpus = NULL; + + if (perf_evlist__create_maps(evlist, target) < 0) + return -1; + + return 0; +} + +int test__cpu_map(void) +{ + struct perf_evlist *evlist; + struct perf_evsel *evsel; + struct target target = { + .uid = UINT_MAX, + }; + int i, err; + + /* system wide */ + evlist = perf_evlist__new(); + target.system_wide = true; + err = do_cpumap(&target, evlist, NULL); + TEST_ASSERT_VAL("wrong ret of do_cpumap", 0 == err); + + evsel = perf_evlist__first(evlist); + TEST_ASSERT_VAL("wrong number of cpu", cpu_map__nr(evlist->cpus) == cpu_map__nr(evsel->cpus)); + for (i = 0; i < cpu_map__nr(evsel->cpus); i++) + TEST_ASSERT_VAL("wrong cpu map", evlist->cpus->map[i] == evsel->cpus->map[i]); + perf_evlist__delete(evlist); + + + /* system wide + evsel cpumask */ + evlist = perf_evlist__new(); + target.system_wide = true; + err = do_cpumap(&target, evlist, "0"); + + evsel = perf_evlist__first(evlist); + TEST_ASSERT_VAL("wrong number of cpu", 1 == cpu_map__nr(evsel->cpus)); + TEST_ASSERT_VAL("wrong cpu map", 0 == evsel->cpus->map[0]); + perf_evlist__delete(evlist); + + + /* defined cpu list */ + evlist = perf_evlist__new(); + target.cpu_list = "0,1,18,26"; + err = do_cpumap(&target, evlist, NULL); + TEST_ASSERT_VAL("wrong ret of do_cpumap", 0 == err); + + evsel = perf_evlist__first(evlist); + TEST_ASSERT_VAL("wrong number of cpu", 4 == cpu_map__nr(evlist->cpus)); + TEST_ASSERT_VAL("wrong number of cpu", cpu_map__nr(evlist->cpus) == cpu_map__nr(evsel->cpus)); + for (i = 0; i < cpu_map__nr(evsel->cpus); i++) + TEST_ASSERT_VAL("wrong cpu map", evlist->cpus->map[i] == evsel->cpus->map[i]); + perf_evlist__delete(evlist); + + + /* defined cpu list + evsel cpumask (all match) */ + evlist = perf_evlist__new(); + target.cpu_list = "0,1,18,26"; + err = do_cpumap(&target, evlist, "1,18"); + TEST_ASSERT_VAL("wrong ret of do_cpumap", 0 == err); + + evsel = perf_evlist__first(evlist); + TEST_ASSERT_VAL("wrong number of cpu", 4 == cpu_map__nr(evlist->cpus)); + TEST_ASSERT_VAL("wrong number of cpu", 2 == cpu_map__nr(evsel->cpus)); + TEST_ASSERT_VAL("wrong cpu map", 1 == evsel->cpus->map[0]); + TEST_ASSERT_VAL("wrong cpu map", 18 == evsel->cpus->map[1]); + perf_evlist__delete(evlist); + + + /* defined cpu list + evsel cpumask (partial match) */ + evlist = perf_evlist__new(); + target.cpu_list = "0,1,18,26"; + err = do_cpumap(&target, evlist, "2,18,30"); + TEST_ASSERT_VAL("wrong ret of do_cpumap", 0 == err); + + evsel = perf_evlist__first(evlist); + TEST_ASSERT_VAL("wrong number of cpu", 4 == cpu_map__nr(evlist->cpus)); + TEST_ASSERT_VAL("wrong number of cpu", 1 == cpu_map__nr(evsel->cpus)); + TEST_ASSERT_VAL("wrong cpu map", 18 == evsel->cpus->map[0]); + perf_evlist__delete(evlist); + + + /* defined cpu list + evsel cpumask (not match) */ + evlist = perf_evlist__new(); + target.cpu_list = "0,1,18,26"; + err = do_cpumap(&target, evlist, "2,9,30"); + TEST_ASSERT_VAL("wrong ret of do_cpumap", 0 != err); + perf_evlist__delete(evlist); + + return 0; +} diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h index ebb47d9..cb6b994 100644 --- a/tools/perf/tests/tests.h +++ b/tools/perf/tests/tests.h @@ -62,6 +62,7 @@ int test__fdarray__filter(void); int test__fdarray__add(void); int test__kmod_path__parse(void); int test__thread_map(void); +int test__cpu_map(void); #if defined(__x86_64__) || defined(__i386__) || defined(__arm__) || defined(__aarch64__) #ifdef HAVE_DWARF_UNWIND_SUPPORT -- 1.8.3.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/