Merge tag 'powerpc-5.11-3' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc...
[linux/fpc-iii.git] / tools / perf / tests / parse-no-sample-id-all.c
blob471273676701bab792d15d28da9fff99048a5535
1 #include <linux/kernel.h>
2 #include <linux/types.h>
3 #include <stddef.h>
5 #include "tests.h"
7 #include "event.h"
8 #include "evlist.h"
9 #include "header.h"
10 #include "debug.h"
12 static int process_event(struct evlist **pevlist, union perf_event *event)
14 struct perf_sample sample;
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;
21 return 0;
24 if (event->header.type >= PERF_RECORD_USER_TYPE_START)
25 return -1;
27 if (!*pevlist)
28 return -1;
30 if (evlist__parse_sample(*pevlist, event, &sample)) {
31 pr_debug("evlist__parse_sample failed\n");
32 return -1;
35 return 0;
38 static int process_events(union perf_event **events, size_t count)
40 struct evlist *evlist = NULL;
41 int err = 0;
42 size_t i;
44 for (i = 0; i < count && !err; i++)
45 err = process_event(&evlist, events[i]);
47 evlist__delete(evlist);
49 return err;
52 struct test_attr_event {
53 struct perf_event_header header;
54 struct perf_event_attr attr;
55 u64 id;
58 /**
59 * test__parse_no_sample_id_all - test parsing with no sample_id_all bit set.
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.
68 * Return: %0 on success, %-1 if the test fails.
70 int test__parse_no_sample_id_all(struct test *test __maybe_unused, int subtest __maybe_unused)
72 int err;
74 struct test_attr_event event1 = {
75 .header = {
76 .type = PERF_RECORD_HEADER_ATTR,
77 .size = sizeof(struct test_attr_event),
79 .id = 1,
81 struct test_attr_event event2 = {
82 .header = {
83 .type = PERF_RECORD_HEADER_ATTR,
84 .size = sizeof(struct test_attr_event),
86 .id = 2,
88 struct perf_record_mmap event3 = {
89 .header = {
90 .type = PERF_RECORD_MMAP,
91 .size = sizeof(struct perf_record_mmap),
94 union perf_event *events[] = {
95 (union perf_event *)&event1,
96 (union perf_event *)&event2,
97 (union perf_event *)&event3,
100 err = process_events(events, ARRAY_SIZE(events));
101 if (err)
102 return -1;
104 return 0;