[tip:perf/core] perf test: Add dso data caching tests

2012-07-25 Thread tip-bot for Jiri Olsa
Commit-ID:  f7add556534529ab18501ced98d7f3f2fc7f0621
Gitweb: http://git.kernel.org/tip/f7add556534529ab18501ced98d7f3f2fc7f0621
Author: Jiri Olsa 
AuthorDate: Sun, 22 Jul 2012 14:14:40 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Wed, 25 Jul 2012 11:33:17 -0300

perf test: Add dso data caching tests

Adding automated test for DSO data reading. Testing raw/cached reads
from different file/cache locations.

Signed-off-by: Jiri Olsa 
Cc: Arun Sharma 
Cc: Benjamin Redelings 
Cc: Corey Ashford 
Cc: Cyrill Gorcunov 
Cc: Frank Ch. Eigler 
Cc: Frederic Weisbecker 
Cc: Ingo Molnar 
Cc: Masami Hiramatsu 
Cc: Paul Mackerras 
Cc: Peter Zijlstra 
Cc: Robert Richter 
Cc: Stephane Eranian 
Cc: Tom Zanussi 
Cc: Ulrich Drepper 
Link: 
http://lkml.kernel.org/r/1342959280-5361-18-git-send-email-jo...@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/Makefile |1 +
 tools/perf/builtin-test.c   |4 +
 tools/perf/util/dso-test-data.c |  153 +++
 tools/perf/util/symbol.h|1 +
 4 files changed, 159 insertions(+), 0 deletions(-)

diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 75d74e5..e8f0579 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -354,6 +354,7 @@ LIB_OBJS += $(OUTPUT)util/usage.o
 LIB_OBJS += $(OUTPUT)util/wrapper.o
 LIB_OBJS += $(OUTPUT)util/sigchain.o
 LIB_OBJS += $(OUTPUT)util/symbol.o
+LIB_OBJS += $(OUTPUT)util/dso-test-data.o
 LIB_OBJS += $(OUTPUT)util/color.o
 LIB_OBJS += $(OUTPUT)util/pager.o
 LIB_OBJS += $(OUTPUT)util/header.o
diff --git a/tools/perf/builtin-test.c b/tools/perf/builtin-test.c
index 5ce3030..d909eb7 100644
--- a/tools/perf/builtin-test.c
+++ b/tools/perf/builtin-test.c
@@ -1142,6 +1142,10 @@ static struct test {
.func = test__perf_pmu,
},
{
+   .desc = "Test dso data interface",
+   .func = dso__test_data,
+   },
+   {
.func = NULL,
},
 };
diff --git a/tools/perf/util/dso-test-data.c b/tools/perf/util/dso-test-data.c
new file mode 100644
index 000..541cdc7
--- /dev/null
+++ b/tools/perf/util/dso-test-data.c
@@ -0,0 +1,153 @@
+#include "util.h"
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "symbol.h"
+
+#define TEST_ASSERT_VAL(text, cond) \
+do { \
+   if (!(cond)) { \
+   pr_debug("FAILED %s:%d %s\n", __FILE__, __LINE__, text); \
+   return -1; \
+   } \
+} while (0)
+
+static char *test_file(int size)
+{
+   static char buf_templ[] = "/tmp/test-XX";
+   char *templ = buf_templ;
+   int fd, i;
+   unsigned char *buf;
+
+   fd = mkostemp(templ, O_CREAT|O_WRONLY|O_TRUNC);
+
+   buf = malloc(size);
+   if (!buf) {
+   close(fd);
+   return NULL;
+   }
+
+   for (i = 0; i < size; i++)
+   buf[i] = (unsigned char) ((int) i % 10);
+
+   if (size != write(fd, buf, size))
+   templ = NULL;
+
+   close(fd);
+   return templ;
+}
+
+#define TEST_FILE_SIZE (DSO__DATA_CACHE_SIZE * 20)
+
+struct test_data_offset {
+   off_t offset;
+   u8 data[10];
+   int size;
+};
+
+struct test_data_offset offsets[] = {
+   /* Fill first cache page. */
+   {
+   .offset = 10,
+   .data   = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
+   .size   = 10,
+   },
+   /* Read first cache page. */
+   {
+   .offset = 10,
+   .data   = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
+   .size   = 10,
+   },
+   /* Fill cache boundary pages. */
+   {
+   .offset = DSO__DATA_CACHE_SIZE - DSO__DATA_CACHE_SIZE % 10,
+   .data   = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
+   .size   = 10,
+   },
+   /* Read cache boundary pages. */
+   {
+   .offset = DSO__DATA_CACHE_SIZE - DSO__DATA_CACHE_SIZE % 10,
+   .data   = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
+   .size   = 10,
+   },
+   /* Fill final cache page. */
+   {
+   .offset = TEST_FILE_SIZE - 10,
+   .data   = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
+   .size   = 10,
+   },
+   /* Read final cache page. */
+   {
+   .offset = TEST_FILE_SIZE - 10,
+   .data   = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
+   .size   = 10,
+   },
+   /* Read final cache page. */
+   {
+   .offset = TEST_FILE_SIZE - 3,
+   .data   = { 7, 8, 9, 0, 0, 0, 0, 0, 0, 0 },
+   .size   = 3,
+   },
+};
+
+int dso__test_data(void)
+{
+   struct machine machine;
+   struct dso *dso;
+   char *file = test_file(TEST_FILE_SIZE);
+   size_t i;
+
+   TEST_ASSERT_VAL("No test file", file);
+
+   memset(, 0, sizeof(machine));
+
+   dso = dso__new((const char *)file);
+
+   /* Basic 10 bytes tests. */
+   for (i = 0; i < 

[tip:perf/core] perf test: Add dso data caching tests

2012-07-25 Thread tip-bot for Jiri Olsa
Commit-ID:  f7add556534529ab18501ced98d7f3f2fc7f0621
Gitweb: http://git.kernel.org/tip/f7add556534529ab18501ced98d7f3f2fc7f0621
Author: Jiri Olsa jo...@redhat.com
AuthorDate: Sun, 22 Jul 2012 14:14:40 +0200
Committer:  Arnaldo Carvalho de Melo a...@redhat.com
CommitDate: Wed, 25 Jul 2012 11:33:17 -0300

perf test: Add dso data caching tests

Adding automated test for DSO data reading. Testing raw/cached reads
from different file/cache locations.

Signed-off-by: Jiri Olsa jo...@redhat.com
Cc: Arun Sharma asha...@fb.com
Cc: Benjamin Redelings benjamin.redeli...@nescent.org
Cc: Corey Ashford cjash...@linux.vnet.ibm.com
Cc: Cyrill Gorcunov gorcu...@openvz.org
Cc: Frank Ch. Eigler f...@redhat.com
Cc: Frederic Weisbecker fweis...@gmail.com
Cc: Ingo Molnar mi...@kernel.org
Cc: Masami Hiramatsu masami.hiramatsu...@hitachi.com
Cc: Paul Mackerras pau...@samba.org
Cc: Peter Zijlstra a.p.zijls...@chello.nl
Cc: Robert Richter robert.rich...@amd.com
Cc: Stephane Eranian eran...@google.com
Cc: Tom Zanussi tzanu...@gmail.com
Cc: Ulrich Drepper drep...@gmail.com
Link: 
http://lkml.kernel.org/r/1342959280-5361-18-git-send-email-jo...@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo a...@redhat.com
---
 tools/perf/Makefile |1 +
 tools/perf/builtin-test.c   |4 +
 tools/perf/util/dso-test-data.c |  153 +++
 tools/perf/util/symbol.h|1 +
 4 files changed, 159 insertions(+), 0 deletions(-)

diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 75d74e5..e8f0579 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -354,6 +354,7 @@ LIB_OBJS += $(OUTPUT)util/usage.o
 LIB_OBJS += $(OUTPUT)util/wrapper.o
 LIB_OBJS += $(OUTPUT)util/sigchain.o
 LIB_OBJS += $(OUTPUT)util/symbol.o
+LIB_OBJS += $(OUTPUT)util/dso-test-data.o
 LIB_OBJS += $(OUTPUT)util/color.o
 LIB_OBJS += $(OUTPUT)util/pager.o
 LIB_OBJS += $(OUTPUT)util/header.o
diff --git a/tools/perf/builtin-test.c b/tools/perf/builtin-test.c
index 5ce3030..d909eb7 100644
--- a/tools/perf/builtin-test.c
+++ b/tools/perf/builtin-test.c
@@ -1142,6 +1142,10 @@ static struct test {
.func = test__perf_pmu,
},
{
+   .desc = Test dso data interface,
+   .func = dso__test_data,
+   },
+   {
.func = NULL,
},
 };
diff --git a/tools/perf/util/dso-test-data.c b/tools/perf/util/dso-test-data.c
new file mode 100644
index 000..541cdc7
--- /dev/null
+++ b/tools/perf/util/dso-test-data.c
@@ -0,0 +1,153 @@
+#include util.h
+
+#include stdlib.h
+#include sys/types.h
+#include sys/stat.h
+#include fcntl.h
+#include string.h
+
+#include symbol.h
+
+#define TEST_ASSERT_VAL(text, cond) \
+do { \
+   if (!(cond)) { \
+   pr_debug(FAILED %s:%d %s\n, __FILE__, __LINE__, text); \
+   return -1; \
+   } \
+} while (0)
+
+static char *test_file(int size)
+{
+   static char buf_templ[] = /tmp/test-XX;
+   char *templ = buf_templ;
+   int fd, i;
+   unsigned char *buf;
+
+   fd = mkostemp(templ, O_CREAT|O_WRONLY|O_TRUNC);
+
+   buf = malloc(size);
+   if (!buf) {
+   close(fd);
+   return NULL;
+   }
+
+   for (i = 0; i  size; i++)
+   buf[i] = (unsigned char) ((int) i % 10);
+
+   if (size != write(fd, buf, size))
+   templ = NULL;
+
+   close(fd);
+   return templ;
+}
+
+#define TEST_FILE_SIZE (DSO__DATA_CACHE_SIZE * 20)
+
+struct test_data_offset {
+   off_t offset;
+   u8 data[10];
+   int size;
+};
+
+struct test_data_offset offsets[] = {
+   /* Fill first cache page. */
+   {
+   .offset = 10,
+   .data   = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
+   .size   = 10,
+   },
+   /* Read first cache page. */
+   {
+   .offset = 10,
+   .data   = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
+   .size   = 10,
+   },
+   /* Fill cache boundary pages. */
+   {
+   .offset = DSO__DATA_CACHE_SIZE - DSO__DATA_CACHE_SIZE % 10,
+   .data   = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
+   .size   = 10,
+   },
+   /* Read cache boundary pages. */
+   {
+   .offset = DSO__DATA_CACHE_SIZE - DSO__DATA_CACHE_SIZE % 10,
+   .data   = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
+   .size   = 10,
+   },
+   /* Fill final cache page. */
+   {
+   .offset = TEST_FILE_SIZE - 10,
+   .data   = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
+   .size   = 10,
+   },
+   /* Read final cache page. */
+   {
+   .offset = TEST_FILE_SIZE - 10,
+   .data   = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
+   .size   = 10,
+   },
+   /* Read final cache page. */
+   {
+   .offset = TEST_FILE_SIZE - 3,
+   .data   = { 7, 8, 9, 0, 0, 0, 0, 0, 0, 0 },
+