diff options
| author | Adrian Hunter <adrian.hunter@intel.com> | 2013-09-04 16:18:16 -0400 |
|---|---|---|
| committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2013-09-05 15:17:46 -0400 |
| commit | 53a277e5c9b55ed3e91345fb98e5f57d6d70efd6 (patch) | |
| tree | eefca32637de51d449727db453d6ebca3543e591 /tools/perf/tests | |
| parent | 20c5f10eb5d1767087dd8eccfe4efe325e61cded (diff) | |
perf tools: Add test for parsing with no sample_id_all bit
Add a test for parsing a non-sample event when there is more than one
selected event but no sample_id_all bit set.
The test fails because of a bug in the evlist logic. That is fixed in a
separate patch.
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1378325897-3840-2-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/tests')
| -rw-r--r-- | tools/perf/tests/builtin-test.c | 4 | ||||
| -rw-r--r-- | tools/perf/tests/parse-no-sample-id-all.c | 108 | ||||
| -rw-r--r-- | tools/perf/tests/tests.h | 1 |
3 files changed, 113 insertions, 0 deletions
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c index 8bbeba322df9..1e67437fb4ca 100644 --- a/tools/perf/tests/builtin-test.c +++ b/tools/perf/tests/builtin-test.c | |||
| @@ -112,6 +112,10 @@ static struct test { | |||
| 112 | .func = test__keep_tracking, | 112 | .func = test__keep_tracking, |
| 113 | }, | 113 | }, |
| 114 | { | 114 | { |
| 115 | .desc = "Test parsing with no sample_id_all bit set", | ||
| 116 | .func = test__parse_no_sample_id_all, | ||
| 117 | }, | ||
| 118 | { | ||
| 115 | .func = NULL, | 119 | .func = NULL, |
| 116 | }, | 120 | }, |
| 117 | }; | 121 | }; |
diff --git a/tools/perf/tests/parse-no-sample-id-all.c b/tools/perf/tests/parse-no-sample-id-all.c new file mode 100644 index 000000000000..e117b6c6a248 --- /dev/null +++ b/tools/perf/tests/parse-no-sample-id-all.c | |||
| @@ -0,0 +1,108 @@ | |||
| 1 | #include <sys/types.h> | ||
| 2 | #include <stddef.h> | ||
| 3 | |||
| 4 | #include "tests.h" | ||
| 5 | |||
| 6 | #include "event.h" | ||
| 7 | #include "evlist.h" | ||
| 8 | #include "header.h" | ||
| 9 | #include "util.h" | ||
| 10 | |||
| 11 | static int process_event(struct perf_evlist **pevlist, union perf_event *event) | ||
| 12 | { | ||
| 13 | struct perf_sample sample; | ||
| 14 | |||
| 15 | if (event->header.type == PERF_RECORD_HEADER_ATTR) { | ||
| 16 | if (perf_event__process_attr(NULL, event, pevlist)) { | ||
| 17 | pr_debug("perf_event__process_attr failed\n"); | ||
| 18 | return -1; | ||
| 19 | } | ||
| 20 | return 0; | ||
| 21 | } | ||
| 22 | |||
| 23 | if (event->header.type >= PERF_RECORD_USER_TYPE_START) | ||
| 24 | return -1; | ||
| 25 | |||
| 26 | if (!*pevlist) | ||
| 27 | return -1; | ||
| 28 | |||
| 29 | if (perf_evlist__parse_sample(*pevlist, event, &sample)) { | ||
| 30 | pr_debug("perf_evlist__parse_sample failed\n"); | ||
| 31 | return -1; | ||
| 32 | } | ||
| 33 | |||
| 34 | return 0; | ||
| 35 | } | ||
| 36 | |||
| 37 | static int process_events(union perf_event **events, size_t count) | ||
| 38 | { | ||
| 39 | struct perf_evlist *evlist = NULL; | ||
| 40 | int err = 0; | ||
| 41 | size_t i; | ||
| 42 | |||
| 43 | for (i = 0; i < count && !err; i++) | ||
| 44 | err = process_event(&evlist, events[i]); | ||
| 45 | |||
| 46 | if (evlist) | ||
| 47 | perf_evlist__delete(evlist); | ||
| 48 | |||
| 49 | return err; | ||
| 50 | } | ||
| 51 | |||
| 52 | struct test_attr_event { | ||
| 53 | struct attr_event attr; | ||
| 54 | u64 id; | ||
| 55 | }; | ||
| 56 | |||
| 57 | /** | ||
| 58 | * test__parse_no_sample_id_all - test parsing with no sample_id_all bit set. | ||
| 59 | * | ||
| 60 | * This function tests parsing data produced on kernel's that do not support the | ||
| 61 | * sample_id_all bit. Without the sample_id_all bit, non-sample events (such as | ||
| 62 | * mmap events) do not have an id sample appended, and consequently logic | ||
| 63 | * designed to determine the id will not work. That case happens when there is | ||
| 64 | * more than one selected event, so this test processes three events: 2 | ||
| 65 | * attributes representing the selected events and one mmap event. | ||
| 66 | * | ||
| 67 | * Return: %0 on success, %-1 if the test fails. | ||
| 68 | */ | ||
| 69 | int test__parse_no_sample_id_all(void) | ||
| 70 | { | ||
| 71 | int err; | ||
| 72 | |||
| 73 | struct test_attr_event event1 = { | ||
| 74 | .attr = { | ||
| 75 | .header = { | ||
| 76 | .type = PERF_RECORD_HEADER_ATTR, | ||
| 77 | .size = sizeof(struct test_attr_event), | ||
| 78 | }, | ||
| 79 | }, | ||
| 80 | .id = 1, | ||
| 81 | }; | ||
| 82 | struct test_attr_event event2 = { | ||
| 83 | .attr = { | ||
| 84 | .header = { | ||
| 85 | .type = PERF_RECORD_HEADER_ATTR, | ||
| 86 | .size = sizeof(struct test_attr_event), | ||
| 87 | }, | ||
| 88 | }, | ||
| 89 | .id = 2, | ||
| 90 | }; | ||
| 91 | struct mmap_event event3 = { | ||
| 92 | .header = { | ||
| 93 | .type = PERF_RECORD_MMAP, | ||
| 94 | .size = sizeof(struct mmap_event), | ||
| 95 | }, | ||
| 96 | }; | ||
| 97 | union perf_event *events[] = { | ||
| 98 | (union perf_event *)&event1, | ||
| 99 | (union perf_event *)&event2, | ||
| 100 | (union perf_event *)&event3, | ||
| 101 | }; | ||
| 102 | |||
| 103 | err = process_events(events, ARRAY_SIZE(events)); | ||
| 104 | if (err) | ||
| 105 | return -1; | ||
| 106 | |||
| 107 | return 0; | ||
| 108 | } | ||
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h index c048b589998a..e0ac713857ba 100644 --- a/tools/perf/tests/tests.h +++ b/tools/perf/tests/tests.h | |||
| @@ -39,5 +39,6 @@ int test__perf_time_to_tsc(void); | |||
| 39 | int test__code_reading(void); | 39 | int test__code_reading(void); |
| 40 | int test__sample_parsing(void); | 40 | int test__sample_parsing(void); |
| 41 | int test__keep_tracking(void); | 41 | int test__keep_tracking(void); |
| 42 | int test__parse_no_sample_id_all(void); | ||
| 42 | 43 | ||
| 43 | #endif /* TESTS_H */ | 44 | #endif /* TESTS_H */ |
