[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1435820925-51091-3-git-send-email-kan.liang@intel.com>
Date: Thu, 2 Jul 2015 03:08:45 -0400
From: kan.liang@...el.com
To: acme@...nel.org, jolsa@...nel.org
Cc: ak@...ux.intel.com, namhyung@...nel.org, eranian@...gle.com,
adrian.hunter@...el.com, dsahern@...il.com, a.p.zijlstra@...llo.nl,
mingo@...hat.com, linux-kernel@...r.kernel.org,
Kan Liang <kan.liang@...el.com>
Subject: [PATCH V2 3/3] perf,tests: Add cpu_map tests
From: Kan Liang <kan.liang@...el.com>
Adding cpu_map tests to check evlist and evsel cpu map
Signed-off-by: Kan Liang <kan.liang@...el.com>
---
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 <sys/types.h>
+#include <unistd.h>
+#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@...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