1a6e52817SJiri Olsa #include <linux/compiler.h> 2a6e52817SJiri Olsa #include "evlist.h" 3a6e52817SJiri Olsa #include "evsel.h" 4a6e52817SJiri Olsa #include "machine.h" 5a6e52817SJiri Olsa #include "tests.h" 6a6e52817SJiri Olsa #include "debug.h" 7a6e52817SJiri Olsa 8a6e52817SJiri Olsa static int process_event_unit(struct perf_tool *tool __maybe_unused, 9a6e52817SJiri Olsa union perf_event *event, 10a6e52817SJiri Olsa struct perf_sample *sample __maybe_unused, 11a6e52817SJiri Olsa struct machine *machine __maybe_unused) 12a6e52817SJiri Olsa { 13a6e52817SJiri Olsa struct event_update_event *ev = (struct event_update_event *) event; 14a6e52817SJiri Olsa 15a6e52817SJiri Olsa TEST_ASSERT_VAL("wrong id", ev->id == 123); 16a6e52817SJiri Olsa TEST_ASSERT_VAL("wrong id", ev->type == PERF_EVENT_UPDATE__UNIT); 17a6e52817SJiri Olsa TEST_ASSERT_VAL("wrong unit", !strcmp(ev->data, "KRAVA")); 18a6e52817SJiri Olsa return 0; 19a6e52817SJiri Olsa } 20a6e52817SJiri Olsa 21*daeecbc0SJiri Olsa static int process_event_scale(struct perf_tool *tool __maybe_unused, 22*daeecbc0SJiri Olsa union perf_event *event, 23*daeecbc0SJiri Olsa struct perf_sample *sample __maybe_unused, 24*daeecbc0SJiri Olsa struct machine *machine __maybe_unused) 25*daeecbc0SJiri Olsa { 26*daeecbc0SJiri Olsa struct event_update_event *ev = (struct event_update_event *) event; 27*daeecbc0SJiri Olsa struct event_update_event_scale *ev_data; 28*daeecbc0SJiri Olsa 29*daeecbc0SJiri Olsa ev_data = (struct event_update_event_scale *) ev->data; 30*daeecbc0SJiri Olsa 31*daeecbc0SJiri Olsa TEST_ASSERT_VAL("wrong id", ev->id == 123); 32*daeecbc0SJiri Olsa TEST_ASSERT_VAL("wrong id", ev->type == PERF_EVENT_UPDATE__SCALE); 33*daeecbc0SJiri Olsa TEST_ASSERT_VAL("wrong scale", ev_data->scale = 0.123); 34*daeecbc0SJiri Olsa return 0; 35*daeecbc0SJiri Olsa } 36*daeecbc0SJiri Olsa 37a6e52817SJiri Olsa int test__event_update(int subtest __maybe_unused) 38a6e52817SJiri Olsa { 39a6e52817SJiri Olsa struct perf_evlist *evlist; 40a6e52817SJiri Olsa struct perf_evsel *evsel; 41a6e52817SJiri Olsa 42a6e52817SJiri Olsa evlist = perf_evlist__new_default(); 43a6e52817SJiri Olsa TEST_ASSERT_VAL("failed to get evlist", evlist); 44a6e52817SJiri Olsa 45a6e52817SJiri Olsa evsel = perf_evlist__first(evlist); 46a6e52817SJiri Olsa 47a6e52817SJiri Olsa TEST_ASSERT_VAL("failed to allos ids", 48a6e52817SJiri Olsa !perf_evsel__alloc_id(evsel, 1, 1)); 49a6e52817SJiri Olsa 50a6e52817SJiri Olsa perf_evlist__id_add(evlist, evsel, 0, 0, 123); 51a6e52817SJiri Olsa 52a6e52817SJiri Olsa evsel->unit = strdup("KRAVA"); 53a6e52817SJiri Olsa 54a6e52817SJiri Olsa TEST_ASSERT_VAL("failed to synthesize attr update unit", 55a6e52817SJiri Olsa !perf_event__synthesize_event_update_unit(NULL, evsel, process_event_unit)); 56a6e52817SJiri Olsa 57*daeecbc0SJiri Olsa evsel->scale = 0.123; 58*daeecbc0SJiri Olsa 59*daeecbc0SJiri Olsa TEST_ASSERT_VAL("failed to synthesize attr update scale", 60*daeecbc0SJiri Olsa !perf_event__synthesize_event_update_scale(NULL, evsel, process_event_scale)); 61*daeecbc0SJiri Olsa 62a6e52817SJiri Olsa return 0; 63a6e52817SJiri Olsa } 64