[RFC/PATCH 24/38] perf tools: Add testcase for managing maps with time

2015-10-01 Thread Namhyung Kim
This tests new map_groups__{insert,find}_by_time() API working
correctly by using 3 * 100 maps.

Cc: Stephane Eranian 
Signed-off-by: Namhyung Kim 
---
 tools/perf/tests/Build |  1 +
 tools/perf/tests/builtin-test.c|  4 ++
 tools/perf/tests/tests.h   |  1 +
 tools/perf/tests/thread-map-time.c | 90 ++
 4 files changed, 96 insertions(+)
 create mode 100644 tools/perf/tests/thread-map-time.c

diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build
index d287b99ff3bb..cc4e3af3e0fd 100644
--- a/tools/perf/tests/Build
+++ b/tools/perf/tests/Build
@@ -28,6 +28,7 @@ perf-y += thread-comm.o
 perf-y += thread-mg-share.o
 perf-y += thread-lookup-time.o
 perf-y += thread-mg-time.o
+perf-y += thread-map-time.o
 perf-y += switch-tracking.o
 perf-y += keep-tracking.o
 perf-y += code-reading.o
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 62de08a89e0e..d5f9fcef5571 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -203,6 +203,10 @@ static struct test {
.func = test__thread_mg_time,
},
{
+   .desc = "Test thread map lookup with time",
+   .func = test__thread_map_lookup_time,
+   },
+   {
.func = NULL,
},
 };
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
index 03dcaccb570f..e498b23f1580 100644
--- a/tools/perf/tests/tests.h
+++ b/tools/perf/tests/tests.h
@@ -68,6 +68,7 @@ int test_session_topology(void);
 int test__thread_comm(void);
 int test__thread_lookup_time(void);
 int test__thread_mg_time(void);
+int test__thread_map_lookup_time(void);
 
 #if defined(__x86_64__) || defined(__i386__) || defined(__arm__) || 
defined(__aarch64__)
 #ifdef HAVE_DWARF_UNWIND_SUPPORT
diff --git a/tools/perf/tests/thread-map-time.c 
b/tools/perf/tests/thread-map-time.c
new file mode 100644
index ..6f28975faeb5
--- /dev/null
+++ b/tools/perf/tests/thread-map-time.c
@@ -0,0 +1,90 @@
+#include "debug.h"
+#include "tests.h"
+#include "machine.h"
+#include "thread.h"
+#include "map.h"
+
+#define PERF_MAP_START  0x4
+#define LIBC_MAP_START  0x8
+#define VDSO_MAP_START  0x7F000
+
+#define NR_MAPS  100
+
+static int lookup_maps(struct map_groups *mg)
+{
+   struct map *map;
+   int i, ret = -1;
+   size_t n;
+   struct {
+   const char *path;
+   u64 start;
+   } maps[] = {
+   { "/usr/bin/perf",  PERF_MAP_START },
+   { "/usr/lib/libc.so",   LIBC_MAP_START },
+   { "[vdso]", VDSO_MAP_START },
+   };
+
+   /* this is needed to insert/find map by time */
+   perf_has_index = true;
+
+   for (n = 0; n < ARRAY_SIZE(maps); n++) {
+   for (i = 0; i < NR_MAPS; i++) {
+   map = map__new2(maps[n].start, dso__new(maps[n].path),
+   MAP__FUNCTION, i * 1);
+   if (map == NULL) {
+   pr_debug("memory allocation failed\n");
+   goto out;
+   }
+
+   map->end = map->start + 0x1000;
+   map_groups__insert_by_time(mg, map);
+   }
+   }
+
+   if (verbose > 1)
+   map_groups__fprintf(mg, stderr);
+
+   for (n = 0; n < ARRAY_SIZE(maps); n++) {
+   for (i = 0; i < NR_MAPS; i++) {
+   u64 timestamp = i * 1;
+
+   map = map_groups__find_by_time(mg, MAP__FUNCTION,
+  maps[n].start,
+  timestamp);
+
+   TEST_ASSERT_VAL("cannot find map", map);
+   TEST_ASSERT_VAL("addr not matched",
+   map->start == maps[n].start);
+   TEST_ASSERT_VAL("pathname not matched",
+   !strcmp(map->dso->name, maps[n].path));
+   TEST_ASSERT_VAL("timestamp not matched",
+   map->timestamp == timestamp);
+   }
+   }
+
+   ret = 0;
+out:
+   return ret;
+}
+
+/*
+ * This test creates large number of overlapping maps for increasing
+ * time and find a map based on timestamp.
+ */
+int test__thread_map_lookup_time(void)
+{
+   struct machines machines;
+   struct machine *machine;
+   struct thread *t;
+   int ret;
+
+   machines__init();
+   machine = 
+
+   t = machine__findnew_thread(machine, 0, 0);
+
+   ret = lookup_maps(t->mg);
+
+   machine__delete_threads(machine);
+   return ret;
+}
-- 
2.6.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  

[RFC/PATCH 24/38] perf tools: Add testcase for managing maps with time

2015-10-01 Thread Namhyung Kim
This tests new map_groups__{insert,find}_by_time() API working
correctly by using 3 * 100 maps.

Cc: Stephane Eranian 
Signed-off-by: Namhyung Kim 
---
 tools/perf/tests/Build |  1 +
 tools/perf/tests/builtin-test.c|  4 ++
 tools/perf/tests/tests.h   |  1 +
 tools/perf/tests/thread-map-time.c | 90 ++
 4 files changed, 96 insertions(+)
 create mode 100644 tools/perf/tests/thread-map-time.c

diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build
index d287b99ff3bb..cc4e3af3e0fd 100644
--- a/tools/perf/tests/Build
+++ b/tools/perf/tests/Build
@@ -28,6 +28,7 @@ perf-y += thread-comm.o
 perf-y += thread-mg-share.o
 perf-y += thread-lookup-time.o
 perf-y += thread-mg-time.o
+perf-y += thread-map-time.o
 perf-y += switch-tracking.o
 perf-y += keep-tracking.o
 perf-y += code-reading.o
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 62de08a89e0e..d5f9fcef5571 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -203,6 +203,10 @@ static struct test {
.func = test__thread_mg_time,
},
{
+   .desc = "Test thread map lookup with time",
+   .func = test__thread_map_lookup_time,
+   },
+   {
.func = NULL,
},
 };
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
index 03dcaccb570f..e498b23f1580 100644
--- a/tools/perf/tests/tests.h
+++ b/tools/perf/tests/tests.h
@@ -68,6 +68,7 @@ int test_session_topology(void);
 int test__thread_comm(void);
 int test__thread_lookup_time(void);
 int test__thread_mg_time(void);
+int test__thread_map_lookup_time(void);
 
 #if defined(__x86_64__) || defined(__i386__) || defined(__arm__) || 
defined(__aarch64__)
 #ifdef HAVE_DWARF_UNWIND_SUPPORT
diff --git a/tools/perf/tests/thread-map-time.c 
b/tools/perf/tests/thread-map-time.c
new file mode 100644
index ..6f28975faeb5
--- /dev/null
+++ b/tools/perf/tests/thread-map-time.c
@@ -0,0 +1,90 @@
+#include "debug.h"
+#include "tests.h"
+#include "machine.h"
+#include "thread.h"
+#include "map.h"
+
+#define PERF_MAP_START  0x4
+#define LIBC_MAP_START  0x8
+#define VDSO_MAP_START  0x7F000
+
+#define NR_MAPS  100
+
+static int lookup_maps(struct map_groups *mg)
+{
+   struct map *map;
+   int i, ret = -1;
+   size_t n;
+   struct {
+   const char *path;
+   u64 start;
+   } maps[] = {
+   { "/usr/bin/perf",  PERF_MAP_START },
+   { "/usr/lib/libc.so",   LIBC_MAP_START },
+   { "[vdso]", VDSO_MAP_START },
+   };
+
+   /* this is needed to insert/find map by time */
+   perf_has_index = true;
+
+   for (n = 0; n < ARRAY_SIZE(maps); n++) {
+   for (i = 0; i < NR_MAPS; i++) {
+   map = map__new2(maps[n].start, dso__new(maps[n].path),
+   MAP__FUNCTION, i * 1);
+   if (map == NULL) {
+   pr_debug("memory allocation failed\n");
+   goto out;
+   }
+
+   map->end = map->start + 0x1000;
+   map_groups__insert_by_time(mg, map);
+   }
+   }
+
+   if (verbose > 1)
+   map_groups__fprintf(mg, stderr);
+
+   for (n = 0; n < ARRAY_SIZE(maps); n++) {
+   for (i = 0; i < NR_MAPS; i++) {
+   u64 timestamp = i * 1;
+
+   map = map_groups__find_by_time(mg, MAP__FUNCTION,
+  maps[n].start,
+  timestamp);
+
+   TEST_ASSERT_VAL("cannot find map", map);
+   TEST_ASSERT_VAL("addr not matched",
+   map->start == maps[n].start);
+   TEST_ASSERT_VAL("pathname not matched",
+   !strcmp(map->dso->name, maps[n].path));
+   TEST_ASSERT_VAL("timestamp not matched",
+   map->timestamp == timestamp);
+   }
+   }
+
+   ret = 0;
+out:
+   return ret;
+}
+
+/*
+ * This test creates large number of overlapping maps for increasing
+ * time and find a map based on timestamp.
+ */
+int test__thread_map_lookup_time(void)
+{
+   struct machines machines;
+   struct machine *machine;
+   struct thread *t;
+   int ret;
+
+   machines__init();
+   machine = 
+
+   t = machine__findnew_thread(machine, 0, 0);
+
+   ret = lookup_maps(t->mg);
+
+   machine__delete_threads(machine);
+   return ret;
+}
-- 
2.6.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo