1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/compiler.h>
3 #include <perf/cpumap.h>
10 static int process_event_unit(struct perf_tool *tool __maybe_unused,
11 union perf_event *event,
12 struct perf_sample *sample __maybe_unused,
13 struct machine *machine __maybe_unused)
15 struct event_update_event *ev = (struct event_update_event *) event;
17 TEST_ASSERT_VAL("wrong id", ev->id == 123);
18 TEST_ASSERT_VAL("wrong id", ev->type == PERF_EVENT_UPDATE__UNIT);
19 TEST_ASSERT_VAL("wrong unit", !strcmp(ev->data, "KRAVA"));
23 static int process_event_scale(struct perf_tool *tool __maybe_unused,
24 union perf_event *event,
25 struct perf_sample *sample __maybe_unused,
26 struct machine *machine __maybe_unused)
28 struct event_update_event *ev = (struct event_update_event *) event;
29 struct event_update_event_scale *ev_data;
31 ev_data = (struct event_update_event_scale *) ev->data;
33 TEST_ASSERT_VAL("wrong id", ev->id == 123);
34 TEST_ASSERT_VAL("wrong id", ev->type == PERF_EVENT_UPDATE__SCALE);
35 TEST_ASSERT_VAL("wrong scale", ev_data->scale == 0.123);
40 struct perf_tool tool;
44 static int process_event_name(struct perf_tool *tool,
45 union perf_event *event,
46 struct perf_sample *sample __maybe_unused,
47 struct machine *machine __maybe_unused)
49 struct event_name *tmp = container_of(tool, struct event_name, tool);
50 struct event_update_event *ev = (struct event_update_event*) event;
52 TEST_ASSERT_VAL("wrong id", ev->id == 123);
53 TEST_ASSERT_VAL("wrong id", ev->type == PERF_EVENT_UPDATE__NAME);
54 TEST_ASSERT_VAL("wrong name", !strcmp(ev->data, tmp->name));
58 static int process_event_cpus(struct perf_tool *tool __maybe_unused,
59 union perf_event *event,
60 struct perf_sample *sample __maybe_unused,
61 struct machine *machine __maybe_unused)
63 struct event_update_event *ev = (struct event_update_event*) event;
64 struct event_update_event_cpus *ev_data;
65 struct perf_cpu_map *map;
67 ev_data = (struct event_update_event_cpus*) ev->data;
69 map = cpu_map__new_data(&ev_data->cpus);
71 TEST_ASSERT_VAL("wrong id", ev->id == 123);
72 TEST_ASSERT_VAL("wrong type", ev->type == PERF_EVENT_UPDATE__CPUS);
73 TEST_ASSERT_VAL("wrong cpus", map->nr == 3);
74 TEST_ASSERT_VAL("wrong cpus", map->map[0] == 1);
75 TEST_ASSERT_VAL("wrong cpus", map->map[1] == 2);
76 TEST_ASSERT_VAL("wrong cpus", map->map[2] == 3);
77 perf_cpu_map__put(map);
81 int test__event_update(struct test *test __maybe_unused, int subtest __maybe_unused)
83 struct evlist *evlist;
85 struct event_name tmp;
87 evlist = perf_evlist__new_default();
88 TEST_ASSERT_VAL("failed to get evlist", evlist);
90 evsel = perf_evlist__first(evlist);
92 TEST_ASSERT_VAL("failed to allos ids",
93 !perf_evsel__alloc_id(evsel, 1, 1));
95 perf_evlist__id_add(evlist, evsel, 0, 0, 123);
97 evsel->unit = strdup("KRAVA");
99 TEST_ASSERT_VAL("failed to synthesize attr update unit",
100 !perf_event__synthesize_event_update_unit(NULL, evsel, process_event_unit));
102 evsel->scale = 0.123;
104 TEST_ASSERT_VAL("failed to synthesize attr update scale",
105 !perf_event__synthesize_event_update_scale(NULL, evsel, process_event_scale));
107 tmp.name = perf_evsel__name(evsel);
109 TEST_ASSERT_VAL("failed to synthesize attr update name",
110 !perf_event__synthesize_event_update_name(&tmp.tool, evsel, process_event_name));
112 evsel->core.own_cpus = perf_cpu_map__new("1,2,3");
114 TEST_ASSERT_VAL("failed to synthesize attr update cpus",
115 !perf_event__synthesize_event_update_cpus(&tmp.tool, evsel, process_event_cpus));
117 perf_cpu_map__put(evsel->core.own_cpus);