diff options
| author | Jiri Olsa <jolsa@kernel.org> | 2014-03-17 09:39:00 -0400 |
|---|---|---|
| committer | Jiri Olsa <jolsa@kernel.org> | 2014-04-28 07:43:40 -0400 |
| commit | fabf01238289e9ae009499594fc54642f5802a24 (patch) | |
| tree | fbfa52100f795fd9f048d7c08050f4f733bd7fa1 | |
| parent | cddcef607782966f1601808c17fe9c4c5f79f9f4 (diff) | |
perf tests: Add map groups sharing with thread object test
This test create 2 processes abstractions, with several threads
and checks they properly share and maintain map groups info.
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1397490723-1992-6-git-send-email-jolsa@redhat.com
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
| -rw-r--r-- | tools/perf/Makefile.perf | 1 | ||||
| -rw-r--r-- | tools/perf/tests/builtin-test.c | 4 | ||||
| -rw-r--r-- | tools/perf/tests/tests.h | 1 | ||||
| -rw-r--r-- | tools/perf/tests/thread-mg-share.c | 90 |
4 files changed, 96 insertions, 0 deletions
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf index 16d4f4ee8a69..46e0c32ad23b 100644 --- a/tools/perf/Makefile.perf +++ b/tools/perf/Makefile.perf | |||
| @@ -417,6 +417,7 @@ LIB_OBJS += $(OUTPUT)tests/dwarf-unwind.o | |||
| 417 | endif | 417 | endif |
| 418 | endif | 418 | endif |
| 419 | LIB_OBJS += $(OUTPUT)tests/mmap-thread-lookup.o | 419 | LIB_OBJS += $(OUTPUT)tests/mmap-thread-lookup.o |
| 420 | LIB_OBJS += $(OUTPUT)tests/thread-mg-share.o | ||
| 420 | 421 | ||
| 421 | BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o | 422 | BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o |
| 422 | BUILTIN_OBJS += $(OUTPUT)builtin-bench.o | 423 | BUILTIN_OBJS += $(OUTPUT)builtin-bench.o |
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c index bb6079233ef8..0d5afaf72944 100644 --- a/tools/perf/tests/builtin-test.c +++ b/tools/perf/tests/builtin-test.c | |||
| @@ -132,6 +132,10 @@ static struct test { | |||
| 132 | .func = test__mmap_thread_lookup, | 132 | .func = test__mmap_thread_lookup, |
| 133 | }, | 133 | }, |
| 134 | { | 134 | { |
| 135 | .desc = "Test thread mg sharing", | ||
| 136 | .func = test__thread_mg_share, | ||
| 137 | }, | ||
| 138 | { | ||
| 135 | .func = NULL, | 139 | .func = NULL, |
| 136 | }, | 140 | }, |
| 137 | }; | 141 | }; |
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h index 82e8061df46e..a9d7cb019f9e 100644 --- a/tools/perf/tests/tests.h +++ b/tools/perf/tests/tests.h | |||
| @@ -43,6 +43,7 @@ int test__parse_no_sample_id_all(void); | |||
| 43 | int test__dwarf_unwind(void); | 43 | int test__dwarf_unwind(void); |
| 44 | int test__hists_filter(void); | 44 | int test__hists_filter(void); |
| 45 | int test__mmap_thread_lookup(void); | 45 | int test__mmap_thread_lookup(void); |
| 46 | int test__thread_mg_share(void); | ||
| 46 | 47 | ||
| 47 | #if defined(__x86_64__) || defined(__i386__) | 48 | #if defined(__x86_64__) || defined(__i386__) |
| 48 | #ifdef HAVE_DWARF_UNWIND_SUPPORT | 49 | #ifdef HAVE_DWARF_UNWIND_SUPPORT |
diff --git a/tools/perf/tests/thread-mg-share.c b/tools/perf/tests/thread-mg-share.c new file mode 100644 index 000000000000..2b2e0dbe114f --- /dev/null +++ b/tools/perf/tests/thread-mg-share.c | |||
| @@ -0,0 +1,90 @@ | |||
| 1 | #include "tests.h" | ||
| 2 | #include "machine.h" | ||
| 3 | #include "thread.h" | ||
| 4 | #include "map.h" | ||
| 5 | |||
| 6 | int test__thread_mg_share(void) | ||
| 7 | { | ||
| 8 | struct machines machines; | ||
| 9 | struct machine *machine; | ||
| 10 | |||
| 11 | /* thread group */ | ||
| 12 | struct thread *leader; | ||
| 13 | struct thread *t1, *t2, *t3; | ||
| 14 | struct map_groups *mg; | ||
| 15 | |||
| 16 | /* other process */ | ||
| 17 | struct thread *other, *other_leader; | ||
| 18 | struct map_groups *other_mg; | ||
| 19 | |||
| 20 | /* | ||
| 21 | * This test create 2 processes abstractions (struct thread) | ||
| 22 | * with several threads and checks they properly share and | ||
| 23 | * maintain map groups info (struct map_groups). | ||
| 24 | * | ||
| 25 | * thread group (pid: 0, tids: 0, 1, 2, 3) | ||
| 26 | * other group (pid: 4, tids: 4, 5) | ||
| 27 | */ | ||
| 28 | |||
| 29 | machines__init(&machines); | ||
| 30 | machine = &machines.host; | ||
| 31 | |||
| 32 | /* create process with 4 threads */ | ||
| 33 | leader = machine__findnew_thread(machine, 0, 0); | ||
| 34 | t1 = machine__findnew_thread(machine, 0, 1); | ||
| 35 | t2 = machine__findnew_thread(machine, 0, 2); | ||
| 36 | t3 = machine__findnew_thread(machine, 0, 3); | ||
| 37 | |||
| 38 | /* and create 1 separated process, without thread leader */ | ||
| 39 | other = machine__findnew_thread(machine, 4, 5); | ||
| 40 | |||
| 41 | TEST_ASSERT_VAL("failed to create threads", | ||
| 42 | leader && t1 && t2 && t3 && other); | ||
| 43 | |||
| 44 | mg = leader->mg; | ||
| 45 | TEST_ASSERT_VAL("wrong refcnt", mg->refcnt == 4); | ||
| 46 | |||
| 47 | /* test the map groups pointer is shared */ | ||
| 48 | TEST_ASSERT_VAL("map groups don't match", mg == t1->mg); | ||
| 49 | TEST_ASSERT_VAL("map groups don't match", mg == t2->mg); | ||
| 50 | TEST_ASSERT_VAL("map groups don't match", mg == t3->mg); | ||
| 51 | |||
| 52 | /* | ||
| 53 | * Verify the other leader was created by previous call. | ||
| 54 | * It should have shared map groups with no change in | ||
| 55 | * refcnt. | ||
| 56 | */ | ||
| 57 | other_leader = machine__find_thread(machine, 4, 4); | ||
| 58 | TEST_ASSERT_VAL("failed to find other leader", other_leader); | ||
| 59 | |||
| 60 | other_mg = other->mg; | ||
| 61 | TEST_ASSERT_VAL("wrong refcnt", other_mg->refcnt == 2); | ||
| 62 | |||
| 63 | TEST_ASSERT_VAL("map groups don't match", other_mg == other_leader->mg); | ||
| 64 | |||
| 65 | /* release thread group */ | ||
| 66 | thread__delete(leader); | ||
| 67 | TEST_ASSERT_VAL("wrong refcnt", mg->refcnt == 3); | ||
| 68 | |||
| 69 | thread__delete(t1); | ||
| 70 | TEST_ASSERT_VAL("wrong refcnt", mg->refcnt == 2); | ||
| 71 | |||
| 72 | thread__delete(t2); | ||
| 73 | TEST_ASSERT_VAL("wrong refcnt", mg->refcnt == 1); | ||
| 74 | |||
| 75 | thread__delete(t3); | ||
| 76 | |||
| 77 | /* release other group */ | ||
| 78 | thread__delete(other_leader); | ||
| 79 | TEST_ASSERT_VAL("wrong refcnt", other_mg->refcnt == 1); | ||
| 80 | |||
| 81 | thread__delete(other); | ||
| 82 | |||
| 83 | /* | ||
| 84 | * Cannot call machine__delete_threads(machine) now, | ||
| 85 | * because we've already released all the threads. | ||
| 86 | */ | ||
| 87 | |||
| 88 | machines__exit(&machines); | ||
| 89 | return 0; | ||
| 90 | } | ||
