blob: 91867dcc39f0142544eaef16aea30dc4ca3cf7cb [file] [log] [blame]
Arnaldo Carvalho de Melo877a7a12017-04-17 11:39:06 -03001#include <linux/kernel.h>
Borislav Petkovd944c4e2014-04-25 21:31:02 +02002#include <linux/types.h>
Adrian Hunter53a277e2013-09-04 23:18:16 +03003#include <stddef.h>
4
5#include "tests.h"
6
7#include "event.h"
8#include "evlist.h"
9#include "header.h"
10#include "util.h"
Jiri Olsa84f5d362014-07-14 23:46:48 +020011#include "debug.h"
Adrian Hunter53a277e2013-09-04 23:18:16 +030012
13static int process_event(struct perf_evlist **pevlist, union perf_event *event)
14{
15 struct perf_sample sample;
16
17 if (event->header.type == PERF_RECORD_HEADER_ATTR) {
18 if (perf_event__process_attr(NULL, event, pevlist)) {
19 pr_debug("perf_event__process_attr failed\n");
20 return -1;
21 }
22 return 0;
23 }
24
25 if (event->header.type >= PERF_RECORD_USER_TYPE_START)
26 return -1;
27
28 if (!*pevlist)
29 return -1;
30
31 if (perf_evlist__parse_sample(*pevlist, event, &sample)) {
32 pr_debug("perf_evlist__parse_sample failed\n");
33 return -1;
34 }
35
36 return 0;
37}
38
39static int process_events(union perf_event **events, size_t count)
40{
41 struct perf_evlist *evlist = NULL;
42 int err = 0;
43 size_t i;
44
45 for (i = 0; i < count && !err; i++)
46 err = process_event(&evlist, events[i]);
47
Arnaldo Carvalho de Melo0b04b3d2016-06-21 18:15:45 -030048 perf_evlist__delete(evlist);
Adrian Hunter53a277e2013-09-04 23:18:16 +030049
50 return err;
51}
52
53struct test_attr_event {
Arnaldo Carvalho de Melo423d8562017-02-14 15:04:48 -030054 struct perf_event_header header;
55 struct perf_event_attr attr;
Adrian Hunter53a277e2013-09-04 23:18:16 +030056 u64 id;
57};
58
59/**
60 * test__parse_no_sample_id_all - test parsing with no sample_id_all bit set.
61 *
62 * This function tests parsing data produced on kernel's that do not support the
63 * sample_id_all bit. Without the sample_id_all bit, non-sample events (such as
64 * mmap events) do not have an id sample appended, and consequently logic
65 * designed to determine the id will not work. That case happens when there is
66 * more than one selected event, so this test processes three events: 2
67 * attributes representing the selected events and one mmap event.
68 *
69 * Return: %0 on success, %-1 if the test fails.
70 */
Arnaldo Carvalho de Melo81f17c92017-08-03 15:16:31 -030071int test__parse_no_sample_id_all(struct test *test __maybe_unused, int subtest __maybe_unused)
Adrian Hunter53a277e2013-09-04 23:18:16 +030072{
73 int err;
74
75 struct test_attr_event event1 = {
Arnaldo Carvalho de Melo423d8562017-02-14 15:04:48 -030076 .header = {
77 .type = PERF_RECORD_HEADER_ATTR,
78 .size = sizeof(struct test_attr_event),
Adrian Hunter53a277e2013-09-04 23:18:16 +030079 },
80 .id = 1,
81 };
82 struct test_attr_event event2 = {
Arnaldo Carvalho de Melo423d8562017-02-14 15:04:48 -030083 .header = {
84 .type = PERF_RECORD_HEADER_ATTR,
85 .size = sizeof(struct test_attr_event),
Adrian Hunter53a277e2013-09-04 23:18:16 +030086 },
87 .id = 2,
88 };
89 struct mmap_event event3 = {
90 .header = {
91 .type = PERF_RECORD_MMAP,
92 .size = sizeof(struct mmap_event),
93 },
94 };
95 union perf_event *events[] = {
96 (union perf_event *)&event1,
97 (union perf_event *)&event2,
98 (union perf_event *)&event3,
99 };
100
101 err = process_events(events, ARRAY_SIZE(events));
102 if (err)
103 return -1;
104
105 return 0;
106}