1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0 2a6e52817SJiri Olsa #include <linux/compiler.h> 3a6e52817SJiri Olsa #include "evlist.h" 4a6e52817SJiri Olsa #include "evsel.h" 5a6e52817SJiri Olsa #include "machine.h" 6a6e52817SJiri Olsa #include "tests.h" 7a6e52817SJiri Olsa #include "debug.h" 8a6e52817SJiri Olsa 9a6e52817SJiri Olsa static int process_event_unit(struct perf_tool *tool __maybe_unused, 10a6e52817SJiri Olsa union perf_event *event, 11a6e52817SJiri Olsa struct perf_sample *sample __maybe_unused, 12a6e52817SJiri Olsa struct machine *machine __maybe_unused) 13a6e52817SJiri Olsa { 14a6e52817SJiri Olsa struct event_update_event *ev = (struct event_update_event *) event; 15a6e52817SJiri Olsa 16a6e52817SJiri Olsa TEST_ASSERT_VAL("wrong id", ev->id == 123); 17a6e52817SJiri Olsa TEST_ASSERT_VAL("wrong id", ev->type == PERF_EVENT_UPDATE__UNIT); 18a6e52817SJiri Olsa TEST_ASSERT_VAL("wrong unit", !strcmp(ev->data, "KRAVA")); 19a6e52817SJiri Olsa return 0; 20a6e52817SJiri Olsa } 21a6e52817SJiri Olsa 22daeecbc0SJiri Olsa static int process_event_scale(struct perf_tool *tool __maybe_unused, 23daeecbc0SJiri Olsa union perf_event *event, 24daeecbc0SJiri Olsa struct perf_sample *sample __maybe_unused, 25daeecbc0SJiri Olsa struct machine *machine __maybe_unused) 26daeecbc0SJiri Olsa { 27daeecbc0SJiri Olsa struct event_update_event *ev = (struct event_update_event *) event; 28daeecbc0SJiri Olsa struct event_update_event_scale *ev_data; 29daeecbc0SJiri Olsa 30daeecbc0SJiri Olsa ev_data = (struct event_update_event_scale *) ev->data; 31daeecbc0SJiri Olsa 32daeecbc0SJiri Olsa TEST_ASSERT_VAL("wrong id", ev->id == 123); 33daeecbc0SJiri Olsa TEST_ASSERT_VAL("wrong id", ev->type == PERF_EVENT_UPDATE__SCALE); 348daef508SColin Ian King TEST_ASSERT_VAL("wrong scale", ev_data->scale == 0.123); 35daeecbc0SJiri Olsa return 0; 36daeecbc0SJiri Olsa } 37daeecbc0SJiri Olsa 38802c9048SJiri Olsa struct event_name { 39802c9048SJiri Olsa struct perf_tool tool; 40802c9048SJiri Olsa const char *name; 41802c9048SJiri Olsa }; 42802c9048SJiri Olsa 43802c9048SJiri Olsa static int process_event_name(struct perf_tool *tool, 44802c9048SJiri Olsa union perf_event *event, 45802c9048SJiri Olsa struct perf_sample *sample __maybe_unused, 46802c9048SJiri Olsa struct machine *machine __maybe_unused) 47802c9048SJiri Olsa { 48802c9048SJiri Olsa struct event_name *tmp = container_of(tool, struct event_name, tool); 49802c9048SJiri Olsa struct event_update_event *ev = (struct event_update_event*) event; 50802c9048SJiri Olsa 51802c9048SJiri Olsa TEST_ASSERT_VAL("wrong id", ev->id == 123); 52802c9048SJiri Olsa TEST_ASSERT_VAL("wrong id", ev->type == PERF_EVENT_UPDATE__NAME); 53802c9048SJiri Olsa TEST_ASSERT_VAL("wrong name", !strcmp(ev->data, tmp->name)); 54802c9048SJiri Olsa return 0; 55802c9048SJiri Olsa } 56802c9048SJiri Olsa 5786ebb09fSJiri Olsa static int process_event_cpus(struct perf_tool *tool __maybe_unused, 5886ebb09fSJiri Olsa union perf_event *event, 5986ebb09fSJiri Olsa struct perf_sample *sample __maybe_unused, 6086ebb09fSJiri Olsa struct machine *machine __maybe_unused) 6186ebb09fSJiri Olsa { 6286ebb09fSJiri Olsa struct event_update_event *ev = (struct event_update_event*) event; 6386ebb09fSJiri Olsa struct event_update_event_cpus *ev_data; 64*f854839bSJiri Olsa struct perf_cpu_map *map; 6586ebb09fSJiri Olsa 6686ebb09fSJiri Olsa ev_data = (struct event_update_event_cpus*) ev->data; 6786ebb09fSJiri Olsa 6886ebb09fSJiri Olsa map = cpu_map__new_data(&ev_data->cpus); 6986ebb09fSJiri Olsa 7086ebb09fSJiri Olsa TEST_ASSERT_VAL("wrong id", ev->id == 123); 7186ebb09fSJiri Olsa TEST_ASSERT_VAL("wrong type", ev->type == PERF_EVENT_UPDATE__CPUS); 7286ebb09fSJiri Olsa TEST_ASSERT_VAL("wrong cpus", map->nr == 3); 7386ebb09fSJiri Olsa TEST_ASSERT_VAL("wrong cpus", map->map[0] == 1); 7486ebb09fSJiri Olsa TEST_ASSERT_VAL("wrong cpus", map->map[1] == 2); 7586ebb09fSJiri Olsa TEST_ASSERT_VAL("wrong cpus", map->map[2] == 3); 7686ebb09fSJiri Olsa cpu_map__put(map); 7786ebb09fSJiri Olsa return 0; 7886ebb09fSJiri Olsa } 7986ebb09fSJiri Olsa 8081f17c90SArnaldo Carvalho de Melo int test__event_update(struct test *test __maybe_unused, int subtest __maybe_unused) 81a6e52817SJiri Olsa { 82a6e52817SJiri Olsa struct perf_evlist *evlist; 83a6e52817SJiri Olsa struct perf_evsel *evsel; 84802c9048SJiri Olsa struct event_name tmp; 85a6e52817SJiri Olsa 86a6e52817SJiri Olsa evlist = perf_evlist__new_default(); 87a6e52817SJiri Olsa TEST_ASSERT_VAL("failed to get evlist", evlist); 88a6e52817SJiri Olsa 89a6e52817SJiri Olsa evsel = perf_evlist__first(evlist); 90a6e52817SJiri Olsa 91a6e52817SJiri Olsa TEST_ASSERT_VAL("failed to allos ids", 92a6e52817SJiri Olsa !perf_evsel__alloc_id(evsel, 1, 1)); 93a6e52817SJiri Olsa 94a6e52817SJiri Olsa perf_evlist__id_add(evlist, evsel, 0, 0, 123); 95a6e52817SJiri Olsa 96a6e52817SJiri Olsa evsel->unit = strdup("KRAVA"); 97a6e52817SJiri Olsa 98a6e52817SJiri Olsa TEST_ASSERT_VAL("failed to synthesize attr update unit", 99a6e52817SJiri Olsa !perf_event__synthesize_event_update_unit(NULL, evsel, process_event_unit)); 100a6e52817SJiri Olsa 101daeecbc0SJiri Olsa evsel->scale = 0.123; 102daeecbc0SJiri Olsa 103daeecbc0SJiri Olsa TEST_ASSERT_VAL("failed to synthesize attr update scale", 104daeecbc0SJiri Olsa !perf_event__synthesize_event_update_scale(NULL, evsel, process_event_scale)); 105daeecbc0SJiri Olsa 106802c9048SJiri Olsa tmp.name = perf_evsel__name(evsel); 107802c9048SJiri Olsa 108802c9048SJiri Olsa TEST_ASSERT_VAL("failed to synthesize attr update name", 109802c9048SJiri Olsa !perf_event__synthesize_event_update_name(&tmp.tool, evsel, process_event_name)); 110802c9048SJiri Olsa 11186ebb09fSJiri Olsa evsel->own_cpus = cpu_map__new("1,2,3"); 11286ebb09fSJiri Olsa 11386ebb09fSJiri Olsa TEST_ASSERT_VAL("failed to synthesize attr update cpus", 11486ebb09fSJiri Olsa !perf_event__synthesize_event_update_cpus(&tmp.tool, evsel, process_event_cpus)); 11586ebb09fSJiri Olsa 11686ebb09fSJiri Olsa cpu_map__put(evsel->own_cpus); 117a6e52817SJiri Olsa return 0; 118a6e52817SJiri Olsa } 119