Merge tag 'ntb-5.11' of git://github.com/jonmason/ntb
[linux/fpc-iii.git] / tools / perf / tests / event_update.c
blob656218179222cc58207a6374600132322f6aafc7
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/compiler.h>
3 #include <perf/cpumap.h>
4 #include <string.h>
5 #include "cpumap.h"
6 #include "evlist.h"
7 #include "evsel.h"
8 #include "header.h"
9 #include "machine.h"
10 #include "util/synthetic-events.h"
11 #include "tool.h"
12 #include "tests.h"
13 #include "debug.h"
15 static int process_event_unit(struct perf_tool *tool __maybe_unused,
16 union perf_event *event,
17 struct perf_sample *sample __maybe_unused,
18 struct machine *machine __maybe_unused)
20 struct perf_record_event_update *ev = (struct perf_record_event_update *)event;
22 TEST_ASSERT_VAL("wrong id", ev->id == 123);
23 TEST_ASSERT_VAL("wrong id", ev->type == PERF_EVENT_UPDATE__UNIT);
24 TEST_ASSERT_VAL("wrong unit", !strcmp(ev->data, "KRAVA"));
25 return 0;
28 static int process_event_scale(struct perf_tool *tool __maybe_unused,
29 union perf_event *event,
30 struct perf_sample *sample __maybe_unused,
31 struct machine *machine __maybe_unused)
33 struct perf_record_event_update *ev = (struct perf_record_event_update *)event;
34 struct perf_record_event_update_scale *ev_data;
36 ev_data = (struct perf_record_event_update_scale *)ev->data;
38 TEST_ASSERT_VAL("wrong id", ev->id == 123);
39 TEST_ASSERT_VAL("wrong id", ev->type == PERF_EVENT_UPDATE__SCALE);
40 TEST_ASSERT_VAL("wrong scale", ev_data->scale == 0.123);
41 return 0;
44 struct event_name {
45 struct perf_tool tool;
46 const char *name;
49 static int process_event_name(struct perf_tool *tool,
50 union perf_event *event,
51 struct perf_sample *sample __maybe_unused,
52 struct machine *machine __maybe_unused)
54 struct event_name *tmp = container_of(tool, struct event_name, tool);
55 struct perf_record_event_update *ev = (struct perf_record_event_update *)event;
57 TEST_ASSERT_VAL("wrong id", ev->id == 123);
58 TEST_ASSERT_VAL("wrong id", ev->type == PERF_EVENT_UPDATE__NAME);
59 TEST_ASSERT_VAL("wrong name", !strcmp(ev->data, tmp->name));
60 return 0;
63 static int process_event_cpus(struct perf_tool *tool __maybe_unused,
64 union perf_event *event,
65 struct perf_sample *sample __maybe_unused,
66 struct machine *machine __maybe_unused)
68 struct perf_record_event_update *ev = (struct perf_record_event_update *)event;
69 struct perf_record_event_update_cpus *ev_data;
70 struct perf_cpu_map *map;
72 ev_data = (struct perf_record_event_update_cpus *) ev->data;
74 map = cpu_map__new_data(&ev_data->cpus);
76 TEST_ASSERT_VAL("wrong id", ev->id == 123);
77 TEST_ASSERT_VAL("wrong type", ev->type == PERF_EVENT_UPDATE__CPUS);
78 TEST_ASSERT_VAL("wrong cpus", map->nr == 3);
79 TEST_ASSERT_VAL("wrong cpus", map->map[0] == 1);
80 TEST_ASSERT_VAL("wrong cpus", map->map[1] == 2);
81 TEST_ASSERT_VAL("wrong cpus", map->map[2] == 3);
82 perf_cpu_map__put(map);
83 return 0;
86 int test__event_update(struct test *test __maybe_unused, int subtest __maybe_unused)
88 struct evsel *evsel;
89 struct event_name tmp;
90 struct evlist *evlist = evlist__new_default();
92 TEST_ASSERT_VAL("failed to get evlist", evlist);
94 evsel = evlist__first(evlist);
96 TEST_ASSERT_VAL("failed to allocate ids",
97 !perf_evsel__alloc_id(&evsel->core, 1, 1));
99 perf_evlist__id_add(&evlist->core, &evsel->core, 0, 0, 123);
101 evsel->unit = strdup("KRAVA");
103 TEST_ASSERT_VAL("failed to synthesize attr update unit",
104 !perf_event__synthesize_event_update_unit(NULL, evsel, process_event_unit));
106 evsel->scale = 0.123;
108 TEST_ASSERT_VAL("failed to synthesize attr update scale",
109 !perf_event__synthesize_event_update_scale(NULL, evsel, process_event_scale));
111 tmp.name = evsel__name(evsel);
113 TEST_ASSERT_VAL("failed to synthesize attr update name",
114 !perf_event__synthesize_event_update_name(&tmp.tool, evsel, process_event_name));
116 evsel->core.own_cpus = perf_cpu_map__new("1,2,3");
118 TEST_ASSERT_VAL("failed to synthesize attr update cpus",
119 !perf_event__synthesize_event_update_cpus(&tmp.tool, evsel, process_event_cpus));
121 perf_cpu_map__put(evsel->core.own_cpus);
122 return 0;