diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2014-08-12 22:34:06 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2014-09-25 15:46:53 -0400 |
commit | 54dbfae3007b0c61727abba45af1e4c226908d82 (patch) | |
tree | 123b5f28ad46fb6ff4ea398a2acdc917ccbceafb | |
parent | 1ddec7f0d0ab5b71cf2cc5a782441c20e7afbcfb (diff) |
perf tests: Add test for perf_evlist__filter_pollfd()
That will use a synthetic evlist with just what is touched by this new
method to check that it works as expected.
Output in verbose mode:
$ perf test -v pollfd
33: Filter fds with revents mask in a pollfd array :
--- start ---
filtering all but pollfd[2]:
before: 5 [ 5, 4, 3, 2, 1 ]
after: 1 [ 3 ]
filtering all but (pollfd[0], pollfd[3]):
before: 5 [ 5, 4, 3, 2, 1 ]
after: 2 [ 5, 2 ]
test child finished with 0
---- end ----
Filter fds with revents mask in a pollfd array: Ok
$
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-x7c8liszdvc3ocmanf2cet8p@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/Makefile.perf | 1 | ||||
-rw-r--r-- | tools/perf/tests/builtin-test.c | 4 | ||||
-rw-r--r-- | tools/perf/tests/evlist.c | 103 | ||||
-rw-r--r-- | tools/perf/tests/tests.h | 1 |
4 files changed, 109 insertions, 0 deletions
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf index 171f4e65601b..f287c2522cf5 100644 --- a/tools/perf/Makefile.perf +++ b/tools/perf/Makefile.perf | |||
@@ -400,6 +400,7 @@ LIB_OBJS += $(OUTPUT)tests/open-syscall-tp-fields.o | |||
400 | LIB_OBJS += $(OUTPUT)tests/mmap-basic.o | 400 | LIB_OBJS += $(OUTPUT)tests/mmap-basic.o |
401 | LIB_OBJS += $(OUTPUT)tests/perf-record.o | 401 | LIB_OBJS += $(OUTPUT)tests/perf-record.o |
402 | LIB_OBJS += $(OUTPUT)tests/rdpmc.o | 402 | LIB_OBJS += $(OUTPUT)tests/rdpmc.o |
403 | LIB_OBJS += $(OUTPUT)tests/evlist.o | ||
403 | LIB_OBJS += $(OUTPUT)tests/evsel-roundtrip-name.o | 404 | LIB_OBJS += $(OUTPUT)tests/evsel-roundtrip-name.o |
404 | LIB_OBJS += $(OUTPUT)tests/evsel-tp-sched.o | 405 | LIB_OBJS += $(OUTPUT)tests/evsel-tp-sched.o |
405 | LIB_OBJS += $(OUTPUT)tests/pmu.o | 406 | LIB_OBJS += $(OUTPUT)tests/pmu.o |
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c index 6a4145e5ad2c..41e556edbe02 100644 --- a/tools/perf/tests/builtin-test.c +++ b/tools/perf/tests/builtin-test.c | |||
@@ -158,6 +158,10 @@ static struct test { | |||
158 | .func = test__switch_tracking, | 158 | .func = test__switch_tracking, |
159 | }, | 159 | }, |
160 | { | 160 | { |
161 | .desc = "Filter fds with revents mask in a pollfd array", | ||
162 | .func = test__perf_evlist__filter_pollfd, | ||
163 | }, | ||
164 | { | ||
161 | .func = NULL, | 165 | .func = NULL, |
162 | }, | 166 | }, |
163 | }; | 167 | }; |
diff --git a/tools/perf/tests/evlist.c b/tools/perf/tests/evlist.c new file mode 100644 index 000000000000..77579158f4d9 --- /dev/null +++ b/tools/perf/tests/evlist.c | |||
@@ -0,0 +1,103 @@ | |||
1 | #include "util/evlist.h" | ||
2 | #include "util/debug.h" | ||
3 | #include "tests/tests.h" | ||
4 | |||
5 | static void perf_evlist__init_pollfd(struct perf_evlist *evlist, | ||
6 | int nr_fds_alloc, short revents) | ||
7 | { | ||
8 | int fd; | ||
9 | |||
10 | evlist->nr_fds = nr_fds_alloc; | ||
11 | |||
12 | for (fd = 0; fd < nr_fds_alloc; ++fd) { | ||
13 | evlist->pollfd[fd].fd = nr_fds_alloc - fd; | ||
14 | evlist->pollfd[fd].revents = revents; | ||
15 | } | ||
16 | } | ||
17 | |||
18 | static int perf_evlist__fprintf_pollfd(struct perf_evlist *evlist, | ||
19 | const char *prefix, FILE *fp) | ||
20 | { | ||
21 | int printed = 0, fd; | ||
22 | |||
23 | if (!verbose) | ||
24 | return 0; | ||
25 | |||
26 | printed += fprintf(fp, "\n%s: %3d [ ", prefix, evlist->nr_fds); | ||
27 | for (fd = 0; fd < evlist->nr_fds; ++fd) | ||
28 | printed += fprintf(fp, "%s%d", fd ? ", " : "", evlist->pollfd[fd].fd); | ||
29 | printed += fprintf(fp, " ]"); | ||
30 | return printed; | ||
31 | } | ||
32 | |||
33 | int test__perf_evlist__filter_pollfd(void) | ||
34 | { | ||
35 | const int nr_fds_alloc = 5; | ||
36 | int nr_fds, expected_fd[2], fd; | ||
37 | struct pollfd pollfd[nr_fds_alloc]; | ||
38 | struct perf_evlist evlist_alloc = { | ||
39 | .pollfd = pollfd, | ||
40 | }, *evlist = &evlist_alloc; | ||
41 | |||
42 | perf_evlist__init_pollfd(evlist, nr_fds_alloc, POLLIN); | ||
43 | nr_fds = perf_evlist__filter_pollfd(evlist, POLLHUP); | ||
44 | if (nr_fds != nr_fds_alloc) { | ||
45 | pr_debug("\nperf_evlist__filter_pollfd()=%d != %d shouldn't have filtered anything", | ||
46 | nr_fds, nr_fds_alloc); | ||
47 | return TEST_FAIL; | ||
48 | } | ||
49 | |||
50 | perf_evlist__init_pollfd(evlist, nr_fds_alloc, POLLHUP); | ||
51 | nr_fds = perf_evlist__filter_pollfd(evlist, POLLHUP); | ||
52 | if (nr_fds != 0) { | ||
53 | pr_debug("\nperf_evlist__filter_pollfd()=%d != %d, should have filtered all fds", | ||
54 | nr_fds, nr_fds_alloc); | ||
55 | return TEST_FAIL; | ||
56 | } | ||
57 | |||
58 | perf_evlist__init_pollfd(evlist, nr_fds_alloc, POLLHUP); | ||
59 | pollfd[2].revents = POLLIN; | ||
60 | expected_fd[0] = pollfd[2].fd; | ||
61 | |||
62 | pr_debug("\nfiltering all but pollfd[2]:"); | ||
63 | perf_evlist__fprintf_pollfd(evlist, "before", stderr); | ||
64 | nr_fds = perf_evlist__filter_pollfd(evlist, POLLHUP); | ||
65 | perf_evlist__fprintf_pollfd(evlist, " after", stderr); | ||
66 | if (nr_fds != 1) { | ||
67 | pr_debug("\nperf_evlist__filter_pollfd()=%d != 1, should have left just one event", | ||
68 | nr_fds); | ||
69 | return TEST_FAIL; | ||
70 | } | ||
71 | |||
72 | if (pollfd[0].fd != expected_fd[0]) { | ||
73 | pr_debug("\npollfd[0].fd=%d != %d\n", pollfd[0].fd, expected_fd[0]); | ||
74 | return TEST_FAIL; | ||
75 | } | ||
76 | |||
77 | perf_evlist__init_pollfd(evlist, nr_fds_alloc, POLLHUP); | ||
78 | pollfd[0].revents = POLLIN; | ||
79 | expected_fd[0] = pollfd[0].fd; | ||
80 | pollfd[3].revents = POLLIN; | ||
81 | expected_fd[1] = pollfd[3].fd; | ||
82 | |||
83 | pr_debug("\nfiltering all but (pollfd[0], pollfd[3]):"); | ||
84 | perf_evlist__fprintf_pollfd(evlist, "before", stderr); | ||
85 | nr_fds = perf_evlist__filter_pollfd(evlist, POLLHUP); | ||
86 | perf_evlist__fprintf_pollfd(evlist, " after", stderr); | ||
87 | if (nr_fds != 2) { | ||
88 | pr_debug("\nperf_evlist__filter_pollfd()=%d != 2, should have left just two events", | ||
89 | nr_fds); | ||
90 | return TEST_FAIL; | ||
91 | } | ||
92 | |||
93 | for (fd = 0; fd < 2; ++fd) { | ||
94 | if (pollfd[fd].fd != expected_fd[fd]) { | ||
95 | pr_debug("\npollfd[%d].fd=%d != %d\n", fd, pollfd[fd].fd, expected_fd[fd]); | ||
96 | return TEST_FAIL; | ||
97 | } | ||
98 | } | ||
99 | |||
100 | pr_debug("\n"); | ||
101 | |||
102 | return 0; | ||
103 | } | ||
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h index be8be10e3957..72c4c039bd80 100644 --- a/tools/perf/tests/tests.h +++ b/tools/perf/tests/tests.h | |||
@@ -49,6 +49,7 @@ int test__thread_mg_share(void); | |||
49 | int test__hists_output(void); | 49 | int test__hists_output(void); |
50 | int test__hists_cumulate(void); | 50 | int test__hists_cumulate(void); |
51 | int test__switch_tracking(void); | 51 | int test__switch_tracking(void); |
52 | int test__perf_evlist__filter_pollfd(void); | ||
52 | 53 | ||
53 | #if defined(__x86_64__) || defined(__i386__) || defined(__arm__) | 54 | #if defined(__x86_64__) || defined(__i386__) || defined(__arm__) |
54 | #ifdef HAVE_DWARF_UNWIND_SUPPORT | 55 | #ifdef HAVE_DWARF_UNWIND_SUPPORT |