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 21daeecbc0SJiri Olsa static int process_event_scale(struct perf_tool *tool __maybe_unused, 22daeecbc0SJiri Olsa union perf_event *event, 23daeecbc0SJiri Olsa struct perf_sample *sample __maybe_unused, 24daeecbc0SJiri Olsa struct machine *machine __maybe_unused) 25daeecbc0SJiri Olsa { 26daeecbc0SJiri Olsa struct event_update_event *ev = (struct event_update_event *) event; 27daeecbc0SJiri Olsa struct event_update_event_scale *ev_data; 28daeecbc0SJiri Olsa 29daeecbc0SJiri Olsa ev_data = (struct event_update_event_scale *) ev->data; 30daeecbc0SJiri Olsa 31daeecbc0SJiri Olsa TEST_ASSERT_VAL("wrong id", ev->id == 123); 32daeecbc0SJiri Olsa TEST_ASSERT_VAL("wrong id", ev->type == PERF_EVENT_UPDATE__SCALE); 33daeecbc0SJiri Olsa TEST_ASSERT_VAL("wrong scale", ev_data->scale = 0.123); 34daeecbc0SJiri Olsa return 0; 35daeecbc0SJiri Olsa } 36daeecbc0SJiri Olsa 37802c9048SJiri Olsa struct event_name { 38802c9048SJiri Olsa struct perf_tool tool; 39802c9048SJiri Olsa const char *name; 40802c9048SJiri Olsa }; 41802c9048SJiri Olsa 42802c9048SJiri Olsa static int process_event_name(struct perf_tool *tool, 43802c9048SJiri Olsa union perf_event *event, 44802c9048SJiri Olsa struct perf_sample *sample __maybe_unused, 45802c9048SJiri Olsa struct machine *machine __maybe_unused) 46802c9048SJiri Olsa { 47802c9048SJiri Olsa struct event_name *tmp = container_of(tool, struct event_name, tool); 48802c9048SJiri Olsa struct event_update_event *ev = (struct event_update_event*) event; 49802c9048SJiri Olsa 50802c9048SJiri Olsa TEST_ASSERT_VAL("wrong id", ev->id == 123); 51802c9048SJiri Olsa TEST_ASSERT_VAL("wrong id", ev->type == PERF_EVENT_UPDATE__NAME); 52802c9048SJiri Olsa TEST_ASSERT_VAL("wrong name", !strcmp(ev->data, tmp->name)); 53802c9048SJiri Olsa return 0; 54802c9048SJiri Olsa } 55802c9048SJiri Olsa 56*86ebb09fSJiri Olsa static int process_event_cpus(struct perf_tool *tool __maybe_unused, 57*86ebb09fSJiri Olsa union perf_event *event, 58*86ebb09fSJiri Olsa struct perf_sample *sample __maybe_unused, 59*86ebb09fSJiri Olsa struct machine *machine __maybe_unused) 60*86ebb09fSJiri Olsa { 61*86ebb09fSJiri Olsa struct event_update_event *ev = (struct event_update_event*) event; 62*86ebb09fSJiri Olsa struct event_update_event_cpus *ev_data; 63*86ebb09fSJiri Olsa struct cpu_map *map; 64*86ebb09fSJiri Olsa 65*86ebb09fSJiri Olsa ev_data = (struct event_update_event_cpus*) ev->data; 66*86ebb09fSJiri Olsa 67*86ebb09fSJiri Olsa map = cpu_map__new_data(&ev_data->cpus); 68*86ebb09fSJiri Olsa 69*86ebb09fSJiri Olsa TEST_ASSERT_VAL("wrong id", ev->id == 123); 70*86ebb09fSJiri Olsa TEST_ASSERT_VAL("wrong type", ev->type == PERF_EVENT_UPDATE__CPUS); 71*86ebb09fSJiri Olsa TEST_ASSERT_VAL("wrong cpus", map->nr == 3); 72*86ebb09fSJiri Olsa TEST_ASSERT_VAL("wrong cpus", map->map[0] == 1); 73*86ebb09fSJiri Olsa TEST_ASSERT_VAL("wrong cpus", map->map[1] == 2); 74*86ebb09fSJiri Olsa TEST_ASSERT_VAL("wrong cpus", map->map[2] == 3); 75*86ebb09fSJiri Olsa cpu_map__put(map); 76*86ebb09fSJiri Olsa return 0; 77*86ebb09fSJiri Olsa } 78*86ebb09fSJiri Olsa 79a6e52817SJiri Olsa int test__event_update(int subtest __maybe_unused) 80a6e52817SJiri Olsa { 81a6e52817SJiri Olsa struct perf_evlist *evlist; 82a6e52817SJiri Olsa struct perf_evsel *evsel; 83802c9048SJiri Olsa struct event_name tmp; 84a6e52817SJiri Olsa 85a6e52817SJiri Olsa evlist = perf_evlist__new_default(); 86a6e52817SJiri Olsa TEST_ASSERT_VAL("failed to get evlist", evlist); 87a6e52817SJiri Olsa 88a6e52817SJiri Olsa evsel = perf_evlist__first(evlist); 89a6e52817SJiri Olsa 90a6e52817SJiri Olsa TEST_ASSERT_VAL("failed to allos ids", 91a6e52817SJiri Olsa !perf_evsel__alloc_id(evsel, 1, 1)); 92a6e52817SJiri Olsa 93a6e52817SJiri Olsa perf_evlist__id_add(evlist, evsel, 0, 0, 123); 94a6e52817SJiri Olsa 95a6e52817SJiri Olsa evsel->unit = strdup("KRAVA"); 96a6e52817SJiri Olsa 97a6e52817SJiri Olsa TEST_ASSERT_VAL("failed to synthesize attr update unit", 98a6e52817SJiri Olsa !perf_event__synthesize_event_update_unit(NULL, evsel, process_event_unit)); 99a6e52817SJiri Olsa 100daeecbc0SJiri Olsa evsel->scale = 0.123; 101daeecbc0SJiri Olsa 102daeecbc0SJiri Olsa TEST_ASSERT_VAL("failed to synthesize attr update scale", 103daeecbc0SJiri Olsa !perf_event__synthesize_event_update_scale(NULL, evsel, process_event_scale)); 104daeecbc0SJiri Olsa 105802c9048SJiri Olsa tmp.name = perf_evsel__name(evsel); 106802c9048SJiri Olsa 107802c9048SJiri Olsa TEST_ASSERT_VAL("failed to synthesize attr update name", 108802c9048SJiri Olsa !perf_event__synthesize_event_update_name(&tmp.tool, evsel, process_event_name)); 109802c9048SJiri Olsa 110*86ebb09fSJiri Olsa evsel->own_cpus = cpu_map__new("1,2,3"); 111*86ebb09fSJiri Olsa 112*86ebb09fSJiri Olsa TEST_ASSERT_VAL("failed to synthesize attr update cpus", 113*86ebb09fSJiri Olsa !perf_event__synthesize_event_update_cpus(&tmp.tool, evsel, process_event_cpus)); 114*86ebb09fSJiri Olsa 115*86ebb09fSJiri Olsa cpu_map__put(evsel->own_cpus); 116a6e52817SJiri Olsa return 0; 117a6e52817SJiri Olsa } 118