diff options
author | Jiri Olsa <jolsa@redhat.com> | 2012-11-09 19:46:42 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-11-14 14:49:17 -0500 |
commit | d3b59a38bcdab4248134023c2c5dfabee5a4878e (patch) | |
tree | ea7dad332d4fe0ecbf84ffc06cc9660df32effb8 /tools/perf/tests/builtin-test.c | |
parent | 0a4e1ae6808a28a92573550603121b146b11312e (diff) |
perf tests: Move test__open_syscall_event into separate object
Separating test__open_syscall_event test from the builtin-test into
open-syscall object.
Adding util object under tests directory to gather help functions common
to more tests.
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-3-git-send-email-jolsa@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/tests/builtin-test.c')
-rw-r--r-- | tools/perf/tests/builtin-test.c | 84 |
1 files changed, 0 insertions, 84 deletions
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c index 5bc9063bf30f..b6b1e46a51c6 100644 --- a/tools/perf/tests/builtin-test.c +++ b/tools/perf/tests/builtin-test.c | |||
@@ -27,90 +27,6 @@ | |||
27 | 27 | ||
28 | #include "tests.h" | 28 | #include "tests.h" |
29 | 29 | ||
30 | static int trace_event__id(const char *evname) | ||
31 | { | ||
32 | char *filename; | ||
33 | int err = -1, fd; | ||
34 | |||
35 | if (asprintf(&filename, | ||
36 | "%s/syscalls/%s/id", | ||
37 | tracing_events_path, evname) < 0) | ||
38 | return -1; | ||
39 | |||
40 | fd = open(filename, O_RDONLY); | ||
41 | if (fd >= 0) { | ||
42 | char id[16]; | ||
43 | if (read(fd, id, sizeof(id)) > 0) | ||
44 | err = atoi(id); | ||
45 | close(fd); | ||
46 | } | ||
47 | |||
48 | free(filename); | ||
49 | return err; | ||
50 | } | ||
51 | |||
52 | static int test__open_syscall_event(void) | ||
53 | { | ||
54 | int err = -1, fd; | ||
55 | struct thread_map *threads; | ||
56 | struct perf_evsel *evsel; | ||
57 | struct perf_event_attr attr; | ||
58 | unsigned int nr_open_calls = 111, i; | ||
59 | int id = trace_event__id("sys_enter_open"); | ||
60 | |||
61 | if (id < 0) { | ||
62 | pr_debug("is debugfs mounted on /sys/kernel/debug?\n"); | ||
63 | return -1; | ||
64 | } | ||
65 | |||
66 | threads = thread_map__new(-1, getpid(), UINT_MAX); | ||
67 | if (threads == NULL) { | ||
68 | pr_debug("thread_map__new\n"); | ||
69 | return -1; | ||
70 | } | ||
71 | |||
72 | memset(&attr, 0, sizeof(attr)); | ||
73 | attr.type = PERF_TYPE_TRACEPOINT; | ||
74 | attr.config = id; | ||
75 | evsel = perf_evsel__new(&attr, 0); | ||
76 | if (evsel == NULL) { | ||
77 | pr_debug("perf_evsel__new\n"); | ||
78 | goto out_thread_map_delete; | ||
79 | } | ||
80 | |||
81 | if (perf_evsel__open_per_thread(evsel, threads) < 0) { | ||
82 | pr_debug("failed to open counter: %s, " | ||
83 | "tweak /proc/sys/kernel/perf_event_paranoid?\n", | ||
84 | strerror(errno)); | ||
85 | goto out_evsel_delete; | ||
86 | } | ||
87 | |||
88 | for (i = 0; i < nr_open_calls; ++i) { | ||
89 | fd = open("/etc/passwd", O_RDONLY); | ||
90 | close(fd); | ||
91 | } | ||
92 | |||
93 | if (perf_evsel__read_on_cpu(evsel, 0, 0) < 0) { | ||
94 | pr_debug("perf_evsel__read_on_cpu\n"); | ||
95 | goto out_close_fd; | ||
96 | } | ||
97 | |||
98 | if (evsel->counts->cpu[0].val != nr_open_calls) { | ||
99 | pr_debug("perf_evsel__read_on_cpu: expected to intercept %d calls, got %" PRIu64 "\n", | ||
100 | nr_open_calls, evsel->counts->cpu[0].val); | ||
101 | goto out_close_fd; | ||
102 | } | ||
103 | |||
104 | err = 0; | ||
105 | out_close_fd: | ||
106 | perf_evsel__close_fd(evsel, 1, threads->nr); | ||
107 | out_evsel_delete: | ||
108 | perf_evsel__delete(evsel); | ||
109 | out_thread_map_delete: | ||
110 | thread_map__delete(threads); | ||
111 | return err; | ||
112 | } | ||
113 | |||
114 | #include <sched.h> | 30 | #include <sched.h> |
115 | 31 | ||
116 | static int test__open_syscall_event_on_all_cpus(void) | 32 | static int test__open_syscall_event_on_all_cpus(void) |