aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/tests/dso-data.c
diff options
context:
space:
mode:
authorIngo Molnar <mingo@kernel.org>2012-11-13 13:05:09 -0500
committerIngo Molnar <mingo@kernel.org>2012-11-13 13:13:41 -0500
commitccf59d8da119ab03dcbdf95fb5e5adcef6ba51f2 (patch)
treed390f9230edac3d9c42a8ad8b030182890b6e609 /tools/perf/tests/dso-data.c
parent95d18aa2b6c05351181934b3bc34ce038cc7b637 (diff)
parent27f94d52394003d444a383eaf8d4824daf32432e (diff)
Merge tag 'perf-core-for-mingo' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/core
Pull perf/core improvements and fixes from Arnaldo Carvalho de Melo: * Don't show scripts menu for 'perf top', fix from Feng Tang * Add framework for automated perf_event_attr tests, where tools with different command line options will be run from a 'perf test', via python glue, and the perf syscall will be intercepted to verify that the perf_event_attr fields set by the tool are those expected, from Jiri Olsa * Use normalized arch name for searching objdump path. This fixes cases where the system's objdump (e.g. x86_64) supports the architecture in the perf.data file (e.g. i686), but is not the same, fix from Namhyung Kim. * Postpone objdump check until annotation requested, from Namhyung Kim. * Add a 'link' method for hists, so that we can have the leader with buckets for all the entries in all the hists. This new method is now used in the default 'diff' output, making the sum of the 'baseline' column be 100%, eliminating blind spots. Now we need to use this for 'diff' with > 2 perf.data files and for multi event 'report' and 'annotate'. * libtraceevent fixes for compiler warnings trying to make perf it build on some distros, like fedora 14, 32-bit, some of the warnings really pointed to real bugs. * Remove temp dir on failure in 'perf test', fix from Jiri Olsa. * Fixes for handling data, stack mmaps, from Namhyung Kim. * Fix live annotation bug related to recent objdump lookup patches, from Namhyung Kim * Don't try to follow jump target on PLT symbols in the annotation browser, fix from Namhyung Kim. * Fix leak on hist_entry delete, from Namhyung Kim. * Fix a CPU_ALLOC related build error on builtin-test, from Zheng Liu. Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'tools/perf/tests/dso-data.c')
-rw-r--r--tools/perf/tests/dso-data.c154
1 files changed, 154 insertions, 0 deletions
diff --git a/tools/perf/tests/dso-data.c b/tools/perf/tests/dso-data.c
new file mode 100644
index 000000000000..0cd42fc9bc13
--- /dev/null
+++ b/tools/perf/tests/dso-data.c
@@ -0,0 +1,154 @@
1#include "util.h"
2
3#include <stdlib.h>
4#include <sys/types.h>
5#include <sys/stat.h>
6#include <fcntl.h>
7#include <string.h>
8
9#include "machine.h"
10#include "symbol.h"
11
12#define TEST_ASSERT_VAL(text, cond) \
13do { \
14 if (!(cond)) { \
15 pr_debug("FAILED %s:%d %s\n", __FILE__, __LINE__, text); \
16 return -1; \
17 } \
18} while (0)
19
20static char *test_file(int size)
21{
22 static char buf_templ[] = "/tmp/test-XXXXXX";
23 char *templ = buf_templ;
24 int fd, i;
25 unsigned char *buf;
26
27 fd = mkstemp(templ);
28
29 buf = malloc(size);
30 if (!buf) {
31 close(fd);
32 return NULL;
33 }
34
35 for (i = 0; i < size; i++)
36 buf[i] = (unsigned char) ((int) i % 10);
37
38 if (size != write(fd, buf, size))
39 templ = NULL;
40
41 close(fd);
42 return templ;
43}
44
45#define TEST_FILE_SIZE (DSO__DATA_CACHE_SIZE * 20)
46
47struct test_data_offset {
48 off_t offset;
49 u8 data[10];
50 int size;
51};
52
53struct test_data_offset offsets[] = {
54 /* Fill first cache page. */
55 {
56 .offset = 10,
57 .data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
58 .size = 10,
59 },
60 /* Read first cache page. */
61 {
62 .offset = 10,
63 .data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
64 .size = 10,
65 },
66 /* Fill cache boundary pages. */
67 {
68 .offset = DSO__DATA_CACHE_SIZE - DSO__DATA_CACHE_SIZE % 10,
69 .data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
70 .size = 10,
71 },
72 /* Read cache boundary pages. */
73 {
74 .offset = DSO__DATA_CACHE_SIZE - DSO__DATA_CACHE_SIZE % 10,
75 .data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
76 .size = 10,
77 },
78 /* Fill final cache page. */
79 {
80 .offset = TEST_FILE_SIZE - 10,
81 .data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
82 .size = 10,
83 },
84 /* Read final cache page. */
85 {
86 .offset = TEST_FILE_SIZE - 10,
87 .data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
88 .size = 10,
89 },
90 /* Read final cache page. */
91 {
92 .offset = TEST_FILE_SIZE - 3,
93 .data = { 7, 8, 9, 0, 0, 0, 0, 0, 0, 0 },
94 .size = 3,
95 },
96};
97
98int dso__test_data(void)
99{
100 struct machine machine;
101 struct dso *dso;
102 char *file = test_file(TEST_FILE_SIZE);
103 size_t i;
104
105 TEST_ASSERT_VAL("No test file", file);
106
107 memset(&machine, 0, sizeof(machine));
108
109 dso = dso__new((const char *)file);
110
111 /* Basic 10 bytes tests. */
112 for (i = 0; i < ARRAY_SIZE(offsets); i++) {
113 struct test_data_offset *data = &offsets[i];
114 ssize_t size;
115 u8 buf[10];
116
117 memset(buf, 0, 10);
118 size = dso__data_read_offset(dso, &machine, data->offset,
119 buf, 10);
120
121 TEST_ASSERT_VAL("Wrong size", size == data->size);
122 TEST_ASSERT_VAL("Wrong data", !memcmp(buf, data->data, 10));
123 }
124
125 /* Read cross multiple cache pages. */
126 {
127 ssize_t size;
128 int c;
129 u8 *buf;
130
131 buf = malloc(TEST_FILE_SIZE);
132 TEST_ASSERT_VAL("ENOMEM\n", buf);
133
134 /* First iteration to fill caches, second one to read them. */
135 for (c = 0; c < 2; c++) {
136 memset(buf, 0, TEST_FILE_SIZE);
137 size = dso__data_read_offset(dso, &machine, 10,
138 buf, TEST_FILE_SIZE);
139
140 TEST_ASSERT_VAL("Wrong size",
141 size == (TEST_FILE_SIZE - 10));
142
143 for (i = 0; i < (size_t)size; i++)
144 TEST_ASSERT_VAL("Wrong data",
145 buf[i] == (i % 10));
146 }
147
148 free(buf);
149 }
150
151 dso__delete(dso);
152 unlink(file);
153 return 0;
154}