Merge tag 'locks-v3.16-2' of git://git.samba.org/jlayton/linux
[linux/fpc-iii.git] / tools / perf / tests / parse-no-sample-id-all.c
blob905019f9b7409ecd962d63c94a701f54aadcf715
1 #include <linux/types.h>
2 #include <stddef.h>
4 #include "tests.h"
6 #include "event.h"
7 #include "evlist.h"
8 #include "header.h"
9 #include "util.h"
11 static int process_event(struct perf_evlist **pevlist, union perf_event *event)
13 struct perf_sample sample;
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;
20 return 0;
23 if (event->header.type >= PERF_RECORD_USER_TYPE_START)
24 return -1;
26 if (!*pevlist)
27 return -1;
29 if (perf_evlist__parse_sample(*pevlist, event, &sample)) {
30 pr_debug("perf_evlist__parse_sample failed\n");
31 return -1;
34 return 0;
37 static int process_events(union perf_event **events, size_t count)
39 struct perf_evlist *evlist = NULL;
40 int err = 0;
41 size_t i;
43 for (i = 0; i < count && !err; i++)
44 err = process_event(&evlist, events[i]);
46 if (evlist)
47 perf_evlist__delete(evlist);
49 return err;
52 struct test_attr_event {
53 struct attr_event attr;
54 u64 id;
57 /**
58 * test__parse_no_sample_id_all - test parsing with no sample_id_all bit set.
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.
67 * Return: %0 on success, %-1 if the test fails.
69 int test__parse_no_sample_id_all(void)
71 int err;
73 struct test_attr_event event1 = {
74 .attr = {
75 .header = {
76 .type = PERF_RECORD_HEADER_ATTR,
77 .size = sizeof(struct test_attr_event),
80 .id = 1,
82 struct test_attr_event event2 = {
83 .attr = {
84 .header = {
85 .type = PERF_RECORD_HEADER_ATTR,
86 .size = sizeof(struct test_attr_event),
89 .id = 2,
91 struct mmap_event event3 = {
92 .header = {
93 .type = PERF_RECORD_MMAP,
94 .size = sizeof(struct mmap_event),
97 union perf_event *events[] = {
98 (union perf_event *)&event1,
99 (union perf_event *)&event2,
100 (union perf_event *)&event3,
103 err = process_events(events, ARRAY_SIZE(events));
104 if (err)
105 return -1;
107 return 0;