Borislav Petkov | d944c4e | 2014-04-25 21:31:02 +0200 | [diff] [blame] | 1 | #include <linux/types.h> |
Adrian Hunter | 53a277e | 2013-09-04 23:18:16 +0300 | [diff] [blame] | 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" |
Jiri Olsa | 84f5d36 | 2014-07-14 23:46:48 +0200 | [diff] [blame] | 10 | #include "debug.h" |
Adrian Hunter | 53a277e | 2013-09-04 23:18:16 +0300 | [diff] [blame] | 11 | |
| 12 | static int process_event(struct perf_evlist **pevlist, union perf_event *event) |
| 13 | { |
| 14 | struct perf_sample sample; |
| 15 | |
| 16 | if (event->header.type == PERF_RECORD_HEADER_ATTR) { |
| 17 | if (perf_event__process_attr(NULL, event, pevlist)) { |
| 18 | pr_debug("perf_event__process_attr failed\n"); |
| 19 | return -1; |
| 20 | } |
| 21 | return 0; |
| 22 | } |
| 23 | |
| 24 | if (event->header.type >= PERF_RECORD_USER_TYPE_START) |
| 25 | return -1; |
| 26 | |
| 27 | if (!*pevlist) |
| 28 | return -1; |
| 29 | |
| 30 | if (perf_evlist__parse_sample(*pevlist, event, &sample)) { |
| 31 | pr_debug("perf_evlist__parse_sample failed\n"); |
| 32 | return -1; |
| 33 | } |
| 34 | |
| 35 | return 0; |
| 36 | } |
| 37 | |
| 38 | static int process_events(union perf_event **events, size_t count) |
| 39 | { |
| 40 | struct perf_evlist *evlist = NULL; |
| 41 | int err = 0; |
| 42 | size_t i; |
| 43 | |
| 44 | for (i = 0; i < count && !err; i++) |
| 45 | err = process_event(&evlist, events[i]); |
| 46 | |
Arnaldo Carvalho de Melo | 0b04b3d | 2016-06-21 18:15:45 -0300 | [diff] [blame] | 47 | perf_evlist__delete(evlist); |
Adrian Hunter | 53a277e | 2013-09-04 23:18:16 +0300 | [diff] [blame] | 48 | |
| 49 | return err; |
| 50 | } |
| 51 | |
| 52 | struct test_attr_event { |
Arnaldo Carvalho de Melo | 423d856 | 2017-02-14 15:04:48 -0300 | [diff] [blame] | 53 | struct perf_event_header header; |
| 54 | struct perf_event_attr attr; |
Adrian Hunter | 53a277e | 2013-09-04 23:18:16 +0300 | [diff] [blame] | 55 | u64 id; |
| 56 | }; |
| 57 | |
| 58 | /** |
| 59 | * test__parse_no_sample_id_all - test parsing with no sample_id_all bit set. |
| 60 | * |
| 61 | * This function tests parsing data produced on kernel's that do not support the |
| 62 | * sample_id_all bit. Without the sample_id_all bit, non-sample events (such as |
| 63 | * mmap events) do not have an id sample appended, and consequently logic |
| 64 | * designed to determine the id will not work. That case happens when there is |
| 65 | * more than one selected event, so this test processes three events: 2 |
| 66 | * attributes representing the selected events and one mmap event. |
| 67 | * |
| 68 | * Return: %0 on success, %-1 if the test fails. |
| 69 | */ |
Arnaldo Carvalho de Melo | 721a1f5 | 2015-11-19 12:01:48 -0300 | [diff] [blame] | 70 | int test__parse_no_sample_id_all(int subtest __maybe_unused) |
Adrian Hunter | 53a277e | 2013-09-04 23:18:16 +0300 | [diff] [blame] | 71 | { |
| 72 | int err; |
| 73 | |
| 74 | struct test_attr_event event1 = { |
Arnaldo Carvalho de Melo | 423d856 | 2017-02-14 15:04:48 -0300 | [diff] [blame] | 75 | .header = { |
| 76 | .type = PERF_RECORD_HEADER_ATTR, |
| 77 | .size = sizeof(struct test_attr_event), |
Adrian Hunter | 53a277e | 2013-09-04 23:18:16 +0300 | [diff] [blame] | 78 | }, |
| 79 | .id = 1, |
| 80 | }; |
| 81 | struct test_attr_event event2 = { |
Arnaldo Carvalho de Melo | 423d856 | 2017-02-14 15:04:48 -0300 | [diff] [blame] | 82 | .header = { |
| 83 | .type = PERF_RECORD_HEADER_ATTR, |
| 84 | .size = sizeof(struct test_attr_event), |
Adrian Hunter | 53a277e | 2013-09-04 23:18:16 +0300 | [diff] [blame] | 85 | }, |
| 86 | .id = 2, |
| 87 | }; |
| 88 | struct mmap_event event3 = { |
| 89 | .header = { |
| 90 | .type = PERF_RECORD_MMAP, |
| 91 | .size = sizeof(struct mmap_event), |
| 92 | }, |
| 93 | }; |
| 94 | union perf_event *events[] = { |
| 95 | (union perf_event *)&event1, |
| 96 | (union perf_event *)&event2, |
| 97 | (union perf_event *)&event3, |
| 98 | }; |
| 99 | |
| 100 | err = process_events(events, ARRAY_SIZE(events)); |
| 101 | if (err) |
| 102 | return -1; |
| 103 | |
| 104 | return 0; |
| 105 | } |