1 #include <linux/compiler.h>
8 static int process_event_unit(struct perf_tool
*tool __maybe_unused
,
9 union perf_event
*event
,
10 struct perf_sample
*sample __maybe_unused
,
11 struct machine
*machine __maybe_unused
)
13 struct event_update_event
*ev
= (struct event_update_event
*) event
;
15 TEST_ASSERT_VAL("wrong id", ev
->id
== 123);
16 TEST_ASSERT_VAL("wrong id", ev
->type
== PERF_EVENT_UPDATE__UNIT
);
17 TEST_ASSERT_VAL("wrong unit", !strcmp(ev
->data
, "KRAVA"));
21 static int process_event_scale(struct perf_tool
*tool __maybe_unused
,
22 union perf_event
*event
,
23 struct perf_sample
*sample __maybe_unused
,
24 struct machine
*machine __maybe_unused
)
26 struct event_update_event
*ev
= (struct event_update_event
*) event
;
27 struct event_update_event_scale
*ev_data
;
29 ev_data
= (struct event_update_event_scale
*) ev
->data
;
31 TEST_ASSERT_VAL("wrong id", ev
->id
== 123);
32 TEST_ASSERT_VAL("wrong id", ev
->type
== PERF_EVENT_UPDATE__SCALE
);
33 TEST_ASSERT_VAL("wrong scale", ev_data
->scale
== 0.123);
38 struct perf_tool tool
;
42 static int process_event_name(struct perf_tool
*tool
,
43 union perf_event
*event
,
44 struct perf_sample
*sample __maybe_unused
,
45 struct machine
*machine __maybe_unused
)
47 struct event_name
*tmp
= container_of(tool
, struct event_name
, tool
);
48 struct event_update_event
*ev
= (struct event_update_event
*) event
;
50 TEST_ASSERT_VAL("wrong id", ev
->id
== 123);
51 TEST_ASSERT_VAL("wrong id", ev
->type
== PERF_EVENT_UPDATE__NAME
);
52 TEST_ASSERT_VAL("wrong name", !strcmp(ev
->data
, tmp
->name
));
56 static int process_event_cpus(struct perf_tool
*tool __maybe_unused
,
57 union perf_event
*event
,
58 struct perf_sample
*sample __maybe_unused
,
59 struct machine
*machine __maybe_unused
)
61 struct event_update_event
*ev
= (struct event_update_event
*) event
;
62 struct event_update_event_cpus
*ev_data
;
65 ev_data
= (struct event_update_event_cpus
*) ev
->data
;
67 map
= cpu_map__new_data(&ev_data
->cpus
);
69 TEST_ASSERT_VAL("wrong id", ev
->id
== 123);
70 TEST_ASSERT_VAL("wrong type", ev
->type
== PERF_EVENT_UPDATE__CPUS
);
71 TEST_ASSERT_VAL("wrong cpus", map
->nr
== 3);
72 TEST_ASSERT_VAL("wrong cpus", map
->map
[0] == 1);
73 TEST_ASSERT_VAL("wrong cpus", map
->map
[1] == 2);
74 TEST_ASSERT_VAL("wrong cpus", map
->map
[2] == 3);
79 int test__event_update(int subtest __maybe_unused
)
81 struct perf_evlist
*evlist
;
82 struct perf_evsel
*evsel
;
83 struct event_name tmp
;
85 evlist
= perf_evlist__new_default();
86 TEST_ASSERT_VAL("failed to get evlist", evlist
);
88 evsel
= perf_evlist__first(evlist
);
90 TEST_ASSERT_VAL("failed to allos ids",
91 !perf_evsel__alloc_id(evsel
, 1, 1));
93 perf_evlist__id_add(evlist
, evsel
, 0, 0, 123);
95 evsel
->unit
= strdup("KRAVA");
97 TEST_ASSERT_VAL("failed to synthesize attr update unit",
98 !perf_event__synthesize_event_update_unit(NULL
, evsel
, process_event_unit
));
100 evsel
->scale
= 0.123;
102 TEST_ASSERT_VAL("failed to synthesize attr update scale",
103 !perf_event__synthesize_event_update_scale(NULL
, evsel
, process_event_scale
));
105 tmp
.name
= perf_evsel__name(evsel
);
107 TEST_ASSERT_VAL("failed to synthesize attr update name",
108 !perf_event__synthesize_event_update_name(&tmp
.tool
, evsel
, process_event_name
));
110 evsel
->own_cpus
= cpu_map__new("1,2,3");
112 TEST_ASSERT_VAL("failed to synthesize attr update cpus",
113 !perf_event__synthesize_event_update_cpus(&tmp
.tool
, evsel
, process_event_cpus
));
115 cpu_map__put(evsel
->own_cpus
);