mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@redhat.com>
To: kan.liang@intel.com
Cc: acme@kernel.org, jolsa@kernel.org, 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
Subject: Re: [PATCH V2 3/3] perf,tests: Add cpu_map tests
Date: Thu, 2 Jul 2015 18:12:11 +0200	[thread overview]
Message-ID: <20150702161211.GC19742@krava.brq.redhat.com> (raw)
In-Reply-To: <1435820925-51091-3-git-send-email-kan.liang@intel.com>

On Thu, Jul 02, 2015 at 03:08:45AM -0400, kan.liang@intel.com wrote:
> From: Kan Liang <kan.liang@intel.com>
> 
> Adding cpu_map tests to check evlist and evsel cpu map


the test needs to be quiet (unless -v is specified)..

38: Test cpu map                                             :event (null) can only be monitored on CPU 1 18. Other CPUs will be discard.
event (null) can only be monitored on CPU 18. Other CPUs will be discard.
event (null) cannot be monitored on the given cpus.Please check cpumask
 Ok

jirka

> 
> Signed-off-by: Kan Liang <kan.liang@intel.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
> 

  reply	other threads:[~2015-07-02 16:12 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-02  7:08 [PATCH V2 1/3] perf,tools: get correct cpu id for print_aggr kan.liang
2015-07-02  7:08 ` [PATCH V2 2/3] perf,tools: check and re-organize evsel cpu maps kan.liang
2015-07-15 21:14   ` Liang, Kan
2015-07-02  7:08 ` [PATCH V2 3/3] perf,tests: Add cpu_map tests kan.liang
2015-07-02 16:12   ` Jiri Olsa [this message]
2015-07-02 16:58     ` Liang, Kan
2015-07-02 16:13 ` [PATCH V2 1/3] perf,tools: get correct cpu id for print_aggr Jiri Olsa
2015-08-28 13:33   ` Liang, Kan
2015-08-28 14:23     ` acme
2015-08-28 14:39       ` Liang, Kan
2015-08-28 14:45         ` Stephane Eranian
2015-08-28 14:47         ` Arnaldo Carvalho de Melo
2015-08-28 14:51           ` Liang, Kan
2015-08-31  8:27 ` [tip:perf/urgent] perf stat: Get " tip-bot for Kan Liang

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=20150702161211.GC19742@krava.brq.redhat.com \
    --to=jolsa@redhat.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=ak@linux.intel.com \
    --cc=dsahern@gmail.com \
    --cc=eranian@google.com \
    --cc=jolsa@kernel.org \
    --cc=kan.liang@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.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®