accel/amdxdna: Return error when setting clock failed for npu1
[drm/drm-misc.git] / tools / perf / tests / parse-no-sample-id-all.c
blob202f0a9a6796bbb324e8d6d61078aeda9291ee35
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"
11 #include "util/sample.h"
13 static int process_event(struct evlist **pevlist, union perf_event *event)
15 struct perf_sample sample;
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;
22 return 0;
25 if (event->header.type >= PERF_RECORD_USER_TYPE_START)
26 return -1;
28 if (!*pevlist)
29 return -1;
31 if (evlist__parse_sample(*pevlist, event, &sample)) {
32 pr_debug("evlist__parse_sample failed\n");
33 return -1;
36 return 0;
39 static int process_events(union perf_event **events, size_t count)
41 struct evlist *evlist = NULL;
42 int err = 0;
43 size_t i;
45 for (i = 0; i < count && !err; i++)
46 err = process_event(&evlist, events[i]);
48 evlist__delete(evlist);
50 return err;
53 struct test_attr_event {
54 struct perf_event_header header;
55 struct perf_event_attr attr;
56 u64 id;
59 /**
60 * test__parse_no_sample_id_all - test parsing with no sample_id_all bit set.
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.
69 * Return: %0 on success, %-1 if the test fails.
71 static int test__parse_no_sample_id_all(struct test_suite *test __maybe_unused,
72 int subtest __maybe_unused)
74 int err;
76 struct test_attr_event event1 = {
77 .header = {
78 .type = PERF_RECORD_HEADER_ATTR,
79 .size = sizeof(struct test_attr_event),
81 .id = 1,
83 struct test_attr_event event2 = {
84 .header = {
85 .type = PERF_RECORD_HEADER_ATTR,
86 .size = sizeof(struct test_attr_event),
88 .id = 2,
90 struct perf_record_mmap event3 = {
91 .header = {
92 .type = PERF_RECORD_MMAP,
93 .size = sizeof(struct perf_record_mmap),
96 union perf_event *events[] = {
97 (union perf_event *)&event1,
98 (union perf_event *)&event2,
99 (union perf_event *)&event3,
102 err = process_events(events, ARRAY_SIZE(events));
103 if (err)
104 return -1;
106 return 0;
109 DEFINE_SUITE("Parse with no sample_id_all bit set", parse_no_sample_id_all);