1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/compiler.h>
3 #include <perf/cpumap.h>
10 #include "util/synthetic-events.h"
15 static int process_event_unit(const 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
->unit
, "KRAVA"));
28 static int process_event_scale(const 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
;
35 TEST_ASSERT_VAL("wrong id", ev
->id
== 123);
36 TEST_ASSERT_VAL("wrong id", ev
->type
== PERF_EVENT_UPDATE__SCALE
);
37 TEST_ASSERT_VAL("wrong scale", ev
->scale
.scale
== 0.123);
42 struct perf_tool tool
;
46 static int process_event_name(const struct perf_tool
*tool
,
47 union perf_event
*event
,
48 struct perf_sample
*sample __maybe_unused
,
49 struct machine
*machine __maybe_unused
)
51 struct event_name
*tmp
= container_of(tool
, struct event_name
, tool
);
52 struct perf_record_event_update
*ev
= (struct perf_record_event_update
*)event
;
54 TEST_ASSERT_VAL("wrong id", ev
->id
== 123);
55 TEST_ASSERT_VAL("wrong id", ev
->type
== PERF_EVENT_UPDATE__NAME
);
56 TEST_ASSERT_VAL("wrong name", !strcmp(ev
->name
, tmp
->name
));
60 static int process_event_cpus(const struct perf_tool
*tool __maybe_unused
,
61 union perf_event
*event
,
62 struct perf_sample
*sample __maybe_unused
,
63 struct machine
*machine __maybe_unused
)
65 struct perf_record_event_update
*ev
= (struct perf_record_event_update
*)event
;
66 struct perf_cpu_map
*map
;
68 map
= cpu_map__new_data(&ev
->cpus
.cpus
);
70 TEST_ASSERT_VAL("wrong id", ev
->id
== 123);
71 TEST_ASSERT_VAL("wrong type", ev
->type
== PERF_EVENT_UPDATE__CPUS
);
72 TEST_ASSERT_VAL("wrong cpus", perf_cpu_map__nr(map
) == 3);
73 TEST_ASSERT_VAL("wrong cpus", perf_cpu_map__cpu(map
, 0).cpu
== 1);
74 TEST_ASSERT_VAL("wrong cpus", perf_cpu_map__cpu(map
, 1).cpu
== 2);
75 TEST_ASSERT_VAL("wrong cpus", perf_cpu_map__cpu(map
, 2).cpu
== 3);
76 perf_cpu_map__put(map
);
80 static int test__event_update(struct test_suite
*test __maybe_unused
, int subtest __maybe_unused
)
83 struct event_name tmp
;
84 struct evlist
*evlist
= evlist__new_default();
86 TEST_ASSERT_VAL("failed to get evlist", evlist
);
88 evsel
= evlist__first(evlist
);
90 TEST_ASSERT_VAL("failed to allocate ids",
91 !perf_evsel__alloc_id(&evsel
->core
, 1, 1));
93 perf_evlist__id_add(&evlist
->core
, &evsel
->core
, 0, 0, 123);
95 free((char *)evsel
->unit
);
96 evsel
->unit
= strdup("KRAVA");
98 TEST_ASSERT_VAL("failed to synthesize attr update unit",
99 !perf_event__synthesize_event_update_unit(NULL
, evsel
, process_event_unit
));
101 evsel
->scale
= 0.123;
103 TEST_ASSERT_VAL("failed to synthesize attr update scale",
104 !perf_event__synthesize_event_update_scale(NULL
, evsel
, process_event_scale
));
106 perf_tool__init(&tmp
.tool
, /*ordered_events=*/false);
107 tmp
.name
= 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 evlist__delete(evlist
);
121 DEFINE_SUITE("Synthesize attr update", event_update
);