diff options
author | Jiri Olsa <jolsa@redhat.com> | 2012-11-09 19:46:49 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-11-14 14:50:09 -0500 |
commit | dc447eed59037c1c65feab9c72d372b6249af978 (patch) | |
tree | 4fb7b3552da074ff6f741fdd014b0a4333e6dd55 /tools | |
parent | 5e24a0904ed4029f6778a214b6fe41b9265fd620 (diff) |
perf tests: Move test__syscall_open_tp_fields into separate object
Separating test__syscall_open_tp_fields test from the builtin-test into
open-syscall-tp-fields object.
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1352508412-16914-10-git-send-email-jolsa@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/Makefile | 1 | ||||
-rw-r--r-- | tools/perf/tests/builtin-test.c | 112 | ||||
-rw-r--r-- | tools/perf/tests/open-syscall-tp-fields.c | 117 | ||||
-rw-r--r-- | tools/perf/tests/tests.h | 1 |
4 files changed, 119 insertions, 112 deletions
diff --git a/tools/perf/Makefile b/tools/perf/Makefile index e510b53eb8df..1e5055915549 100644 --- a/tools/perf/Makefile +++ b/tools/perf/Makefile | |||
@@ -434,6 +434,7 @@ LIB_OBJS += $(OUTPUT)tests/attr.o | |||
434 | LIB_OBJS += $(OUTPUT)tests/vmlinux-kallsyms.o | 434 | LIB_OBJS += $(OUTPUT)tests/vmlinux-kallsyms.o |
435 | LIB_OBJS += $(OUTPUT)tests/open-syscall.o | 435 | LIB_OBJS += $(OUTPUT)tests/open-syscall.o |
436 | LIB_OBJS += $(OUTPUT)tests/open-syscall-all-cpus.o | 436 | LIB_OBJS += $(OUTPUT)tests/open-syscall-all-cpus.o |
437 | LIB_OBJS += $(OUTPUT)tests/open-syscall-tp-fields.o | ||
437 | LIB_OBJS += $(OUTPUT)tests/mmap-basic.o | 438 | LIB_OBJS += $(OUTPUT)tests/mmap-basic.o |
438 | LIB_OBJS += $(OUTPUT)tests/perf-record.o | 439 | LIB_OBJS += $(OUTPUT)tests/perf-record.o |
439 | LIB_OBJS += $(OUTPUT)tests/rdpmc.o | 440 | LIB_OBJS += $(OUTPUT)tests/rdpmc.o |
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c index c66caa79c622..bab849039852 100644 --- a/tools/perf/tests/builtin-test.c +++ b/tools/perf/tests/builtin-test.c | |||
@@ -35,118 +35,6 @@ static int test__perf_pmu(void) | |||
35 | return perf_pmu__test(); | 35 | return perf_pmu__test(); |
36 | } | 36 | } |
37 | 37 | ||
38 | static int test__syscall_open_tp_fields(void) | ||
39 | { | ||
40 | struct perf_record_opts opts = { | ||
41 | .target = { | ||
42 | .uid = UINT_MAX, | ||
43 | .uses_mmap = true, | ||
44 | }, | ||
45 | .no_delay = true, | ||
46 | .freq = 1, | ||
47 | .mmap_pages = 256, | ||
48 | .raw_samples = true, | ||
49 | }; | ||
50 | const char *filename = "/etc/passwd"; | ||
51 | int flags = O_RDONLY | O_DIRECTORY; | ||
52 | struct perf_evlist *evlist = perf_evlist__new(NULL, NULL); | ||
53 | struct perf_evsel *evsel; | ||
54 | int err = -1, i, nr_events = 0, nr_polls = 0; | ||
55 | |||
56 | if (evlist == NULL) { | ||
57 | pr_debug("%s: perf_evlist__new\n", __func__); | ||
58 | goto out; | ||
59 | } | ||
60 | |||
61 | evsel = perf_evsel__newtp("syscalls", "sys_enter_open", 0); | ||
62 | if (evsel == NULL) { | ||
63 | pr_debug("%s: perf_evsel__newtp\n", __func__); | ||
64 | goto out_delete_evlist; | ||
65 | } | ||
66 | |||
67 | perf_evlist__add(evlist, evsel); | ||
68 | |||
69 | err = perf_evlist__create_maps(evlist, &opts.target); | ||
70 | if (err < 0) { | ||
71 | pr_debug("%s: perf_evlist__create_maps\n", __func__); | ||
72 | goto out_delete_evlist; | ||
73 | } | ||
74 | |||
75 | perf_evsel__config(evsel, &opts, evsel); | ||
76 | |||
77 | evlist->threads->map[0] = getpid(); | ||
78 | |||
79 | err = perf_evlist__open(evlist); | ||
80 | if (err < 0) { | ||
81 | pr_debug("perf_evlist__open: %s\n", strerror(errno)); | ||
82 | goto out_delete_evlist; | ||
83 | } | ||
84 | |||
85 | err = perf_evlist__mmap(evlist, UINT_MAX, false); | ||
86 | if (err < 0) { | ||
87 | pr_debug("perf_evlist__mmap: %s\n", strerror(errno)); | ||
88 | goto out_delete_evlist; | ||
89 | } | ||
90 | |||
91 | perf_evlist__enable(evlist); | ||
92 | |||
93 | /* | ||
94 | * Generate the event: | ||
95 | */ | ||
96 | open(filename, flags); | ||
97 | |||
98 | while (1) { | ||
99 | int before = nr_events; | ||
100 | |||
101 | for (i = 0; i < evlist->nr_mmaps; i++) { | ||
102 | union perf_event *event; | ||
103 | |||
104 | while ((event = perf_evlist__mmap_read(evlist, i)) != NULL) { | ||
105 | const u32 type = event->header.type; | ||
106 | int tp_flags; | ||
107 | struct perf_sample sample; | ||
108 | |||
109 | ++nr_events; | ||
110 | |||
111 | if (type != PERF_RECORD_SAMPLE) | ||
112 | continue; | ||
113 | |||
114 | err = perf_evsel__parse_sample(evsel, event, &sample); | ||
115 | if (err) { | ||
116 | pr_err("Can't parse sample, err = %d\n", err); | ||
117 | goto out_munmap; | ||
118 | } | ||
119 | |||
120 | tp_flags = perf_evsel__intval(evsel, &sample, "flags"); | ||
121 | |||
122 | if (flags != tp_flags) { | ||
123 | pr_debug("%s: Expected flags=%#x, got %#x\n", | ||
124 | __func__, flags, tp_flags); | ||
125 | goto out_munmap; | ||
126 | } | ||
127 | |||
128 | goto out_ok; | ||
129 | } | ||
130 | } | ||
131 | |||
132 | if (nr_events == before) | ||
133 | poll(evlist->pollfd, evlist->nr_fds, 10); | ||
134 | |||
135 | if (++nr_polls > 5) { | ||
136 | pr_debug("%s: no events!\n", __func__); | ||
137 | goto out_munmap; | ||
138 | } | ||
139 | } | ||
140 | out_ok: | ||
141 | err = 0; | ||
142 | out_munmap: | ||
143 | perf_evlist__munmap(evlist); | ||
144 | out_delete_evlist: | ||
145 | perf_evlist__delete(evlist); | ||
146 | out: | ||
147 | return err; | ||
148 | } | ||
149 | |||
150 | static struct test { | 38 | static struct test { |
151 | const char *desc; | 39 | const char *desc; |
152 | int (*func)(void); | 40 | int (*func)(void); |
diff --git a/tools/perf/tests/open-syscall-tp-fields.c b/tools/perf/tests/open-syscall-tp-fields.c new file mode 100644 index 000000000000..b05b6a6f01af --- /dev/null +++ b/tools/perf/tests/open-syscall-tp-fields.c | |||
@@ -0,0 +1,117 @@ | |||
1 | #include "perf.h" | ||
2 | #include "evlist.h" | ||
3 | #include "evsel.h" | ||
4 | #include "thread_map.h" | ||
5 | #include "tests.h" | ||
6 | |||
7 | int test__syscall_open_tp_fields(void) | ||
8 | { | ||
9 | struct perf_record_opts opts = { | ||
10 | .target = { | ||
11 | .uid = UINT_MAX, | ||
12 | .uses_mmap = true, | ||
13 | }, | ||
14 | .no_delay = true, | ||
15 | .freq = 1, | ||
16 | .mmap_pages = 256, | ||
17 | .raw_samples = true, | ||
18 | }; | ||
19 | const char *filename = "/etc/passwd"; | ||
20 | int flags = O_RDONLY | O_DIRECTORY; | ||
21 | struct perf_evlist *evlist = perf_evlist__new(NULL, NULL); | ||
22 | struct perf_evsel *evsel; | ||
23 | int err = -1, i, nr_events = 0, nr_polls = 0; | ||
24 | |||
25 | if (evlist == NULL) { | ||
26 | pr_debug("%s: perf_evlist__new\n", __func__); | ||
27 | goto out; | ||
28 | } | ||
29 | |||
30 | evsel = perf_evsel__newtp("syscalls", "sys_enter_open", 0); | ||
31 | if (evsel == NULL) { | ||
32 | pr_debug("%s: perf_evsel__newtp\n", __func__); | ||
33 | goto out_delete_evlist; | ||
34 | } | ||
35 | |||
36 | perf_evlist__add(evlist, evsel); | ||
37 | |||
38 | err = perf_evlist__create_maps(evlist, &opts.target); | ||
39 | if (err < 0) { | ||
40 | pr_debug("%s: perf_evlist__create_maps\n", __func__); | ||
41 | goto out_delete_evlist; | ||
42 | } | ||
43 | |||
44 | perf_evsel__config(evsel, &opts, evsel); | ||
45 | |||
46 | evlist->threads->map[0] = getpid(); | ||
47 | |||
48 | err = perf_evlist__open(evlist); | ||
49 | if (err < 0) { | ||
50 | pr_debug("perf_evlist__open: %s\n", strerror(errno)); | ||
51 | goto out_delete_evlist; | ||
52 | } | ||
53 | |||
54 | err = perf_evlist__mmap(evlist, UINT_MAX, false); | ||
55 | if (err < 0) { | ||
56 | pr_debug("perf_evlist__mmap: %s\n", strerror(errno)); | ||
57 | goto out_delete_evlist; | ||
58 | } | ||
59 | |||
60 | perf_evlist__enable(evlist); | ||
61 | |||
62 | /* | ||
63 | * Generate the event: | ||
64 | */ | ||
65 | open(filename, flags); | ||
66 | |||
67 | while (1) { | ||
68 | int before = nr_events; | ||
69 | |||
70 | for (i = 0; i < evlist->nr_mmaps; i++) { | ||
71 | union perf_event *event; | ||
72 | |||
73 | while ((event = perf_evlist__mmap_read(evlist, i)) != NULL) { | ||
74 | const u32 type = event->header.type; | ||
75 | int tp_flags; | ||
76 | struct perf_sample sample; | ||
77 | |||
78 | ++nr_events; | ||
79 | |||
80 | if (type != PERF_RECORD_SAMPLE) | ||
81 | continue; | ||
82 | |||
83 | err = perf_evsel__parse_sample(evsel, event, &sample); | ||
84 | if (err) { | ||
85 | pr_err("Can't parse sample, err = %d\n", err); | ||
86 | goto out_munmap; | ||
87 | } | ||
88 | |||
89 | tp_flags = perf_evsel__intval(evsel, &sample, "flags"); | ||
90 | |||
91 | if (flags != tp_flags) { | ||
92 | pr_debug("%s: Expected flags=%#x, got %#x\n", | ||
93 | __func__, flags, tp_flags); | ||
94 | goto out_munmap; | ||
95 | } | ||
96 | |||
97 | goto out_ok; | ||
98 | } | ||
99 | } | ||
100 | |||
101 | if (nr_events == before) | ||
102 | poll(evlist->pollfd, evlist->nr_fds, 10); | ||
103 | |||
104 | if (++nr_polls > 5) { | ||
105 | pr_debug("%s: no events!\n", __func__); | ||
106 | goto out_munmap; | ||
107 | } | ||
108 | } | ||
109 | out_ok: | ||
110 | err = 0; | ||
111 | out_munmap: | ||
112 | perf_evlist__munmap(evlist); | ||
113 | out_delete_evlist: | ||
114 | perf_evlist__delete(evlist); | ||
115 | out: | ||
116 | return err; | ||
117 | } | ||
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h index 1ef265d84a6e..f70f99848a22 100644 --- a/tools/perf/tests/tests.h +++ b/tools/perf/tests/tests.h | |||
@@ -10,6 +10,7 @@ int test__PERF_RECORD(void); | |||
10 | int test__rdpmc(void); | 10 | int test__rdpmc(void); |
11 | int test__perf_evsel__roundtrip_name_test(void); | 11 | int test__perf_evsel__roundtrip_name_test(void); |
12 | int test__perf_evsel__tp_sched_test(void); | 12 | int test__perf_evsel__tp_sched_test(void); |
13 | int test__syscall_open_tp_fields(void); | ||
13 | 14 | ||
14 | /* Util */ | 15 | /* Util */ |
15 | int trace_event__id(const char *evname); | 16 | int trace_event__id(const char *evname); |