1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0 2a6e52817SJiri Olsa #include <linux/compiler.h> 39c3516d1SJiri Olsa #include <perf/cpumap.h> 4f2a39fe8SArnaldo Carvalho de Melo #include <string.h> 5*87ffb6c6SArnaldo Carvalho de Melo #include "cpumap.h" 6a6e52817SJiri Olsa #include "evlist.h" 7a6e52817SJiri Olsa #include "evsel.h" 8f2a39fe8SArnaldo Carvalho de Melo #include "header.h" 9a6e52817SJiri Olsa #include "machine.h" 104a3cec84SArnaldo Carvalho de Melo #include "tool.h" 11a6e52817SJiri Olsa #include "tests.h" 12a6e52817SJiri Olsa #include "debug.h" 13a6e52817SJiri Olsa 14a6e52817SJiri Olsa static int process_event_unit(struct perf_tool *tool __maybe_unused, 15a6e52817SJiri Olsa union perf_event *event, 16a6e52817SJiri Olsa struct perf_sample *sample __maybe_unused, 17a6e52817SJiri Olsa struct machine *machine __maybe_unused) 18a6e52817SJiri Olsa { 1972932371SJiri Olsa struct perf_record_event_update *ev = (struct perf_record_event_update *)event; 20a6e52817SJiri Olsa 21a6e52817SJiri Olsa TEST_ASSERT_VAL("wrong id", ev->id == 123); 22a6e52817SJiri Olsa TEST_ASSERT_VAL("wrong id", ev->type == PERF_EVENT_UPDATE__UNIT); 23a6e52817SJiri Olsa TEST_ASSERT_VAL("wrong unit", !strcmp(ev->data, "KRAVA")); 24a6e52817SJiri Olsa return 0; 25a6e52817SJiri Olsa } 26a6e52817SJiri Olsa 27daeecbc0SJiri Olsa static int process_event_scale(struct perf_tool *tool __maybe_unused, 28daeecbc0SJiri Olsa union perf_event *event, 29daeecbc0SJiri Olsa struct perf_sample *sample __maybe_unused, 30daeecbc0SJiri Olsa struct machine *machine __maybe_unused) 31daeecbc0SJiri Olsa { 3272932371SJiri Olsa struct perf_record_event_update *ev = (struct perf_record_event_update *)event; 3372932371SJiri Olsa struct perf_record_event_update_scale *ev_data; 34daeecbc0SJiri Olsa 3572932371SJiri Olsa ev_data = (struct perf_record_event_update_scale *)ev->data; 36daeecbc0SJiri Olsa 37daeecbc0SJiri Olsa TEST_ASSERT_VAL("wrong id", ev->id == 123); 38daeecbc0SJiri Olsa TEST_ASSERT_VAL("wrong id", ev->type == PERF_EVENT_UPDATE__SCALE); 398daef508SColin Ian King TEST_ASSERT_VAL("wrong scale", ev_data->scale == 0.123); 40daeecbc0SJiri Olsa return 0; 41daeecbc0SJiri Olsa } 42daeecbc0SJiri Olsa 43802c9048SJiri Olsa struct event_name { 44802c9048SJiri Olsa struct perf_tool tool; 45802c9048SJiri Olsa const char *name; 46802c9048SJiri Olsa }; 47802c9048SJiri Olsa 48802c9048SJiri Olsa static int process_event_name(struct perf_tool *tool, 49802c9048SJiri Olsa union perf_event *event, 50802c9048SJiri Olsa struct perf_sample *sample __maybe_unused, 51802c9048SJiri Olsa struct machine *machine __maybe_unused) 52802c9048SJiri Olsa { 53802c9048SJiri Olsa struct event_name *tmp = container_of(tool, struct event_name, tool); 5472932371SJiri Olsa struct perf_record_event_update *ev = (struct perf_record_event_update *)event; 55802c9048SJiri Olsa 56802c9048SJiri Olsa TEST_ASSERT_VAL("wrong id", ev->id == 123); 57802c9048SJiri Olsa TEST_ASSERT_VAL("wrong id", ev->type == PERF_EVENT_UPDATE__NAME); 58802c9048SJiri Olsa TEST_ASSERT_VAL("wrong name", !strcmp(ev->data, tmp->name)); 59802c9048SJiri Olsa return 0; 60802c9048SJiri Olsa } 61802c9048SJiri Olsa 6286ebb09fSJiri Olsa static int process_event_cpus(struct perf_tool *tool __maybe_unused, 6386ebb09fSJiri Olsa union perf_event *event, 6486ebb09fSJiri Olsa struct perf_sample *sample __maybe_unused, 6586ebb09fSJiri Olsa struct machine *machine __maybe_unused) 6686ebb09fSJiri Olsa { 6772932371SJiri Olsa struct perf_record_event_update *ev = (struct perf_record_event_update *)event; 6872932371SJiri Olsa struct perf_record_event_update_cpus *ev_data; 69f854839bSJiri Olsa struct perf_cpu_map *map; 7086ebb09fSJiri Olsa 7172932371SJiri Olsa ev_data = (struct perf_record_event_update_cpus *) ev->data; 7286ebb09fSJiri Olsa 7386ebb09fSJiri Olsa map = cpu_map__new_data(&ev_data->cpus); 7486ebb09fSJiri Olsa 7586ebb09fSJiri Olsa TEST_ASSERT_VAL("wrong id", ev->id == 123); 7686ebb09fSJiri Olsa TEST_ASSERT_VAL("wrong type", ev->type == PERF_EVENT_UPDATE__CPUS); 7786ebb09fSJiri Olsa TEST_ASSERT_VAL("wrong cpus", map->nr == 3); 7886ebb09fSJiri Olsa TEST_ASSERT_VAL("wrong cpus", map->map[0] == 1); 7986ebb09fSJiri Olsa TEST_ASSERT_VAL("wrong cpus", map->map[1] == 2); 8086ebb09fSJiri Olsa TEST_ASSERT_VAL("wrong cpus", map->map[2] == 3); 8138f01d8dSJiri Olsa perf_cpu_map__put(map); 8286ebb09fSJiri Olsa return 0; 8386ebb09fSJiri Olsa } 8486ebb09fSJiri Olsa 8581f17c90SArnaldo Carvalho de Melo int test__event_update(struct test *test __maybe_unused, int subtest __maybe_unused) 86a6e52817SJiri Olsa { 8763503dbaSJiri Olsa struct evlist *evlist; 8832dcd021SJiri Olsa struct evsel *evsel; 89802c9048SJiri Olsa struct event_name tmp; 90a6e52817SJiri Olsa 91a6e52817SJiri Olsa evlist = perf_evlist__new_default(); 92a6e52817SJiri Olsa TEST_ASSERT_VAL("failed to get evlist", evlist); 93a6e52817SJiri Olsa 94a6e52817SJiri Olsa evsel = perf_evlist__first(evlist); 95a6e52817SJiri Olsa 96a6e52817SJiri Olsa TEST_ASSERT_VAL("failed to allos ids", 97a6e52817SJiri Olsa !perf_evsel__alloc_id(evsel, 1, 1)); 98a6e52817SJiri Olsa 99a6e52817SJiri Olsa perf_evlist__id_add(evlist, evsel, 0, 0, 123); 100a6e52817SJiri Olsa 101a6e52817SJiri Olsa evsel->unit = strdup("KRAVA"); 102a6e52817SJiri Olsa 103a6e52817SJiri Olsa TEST_ASSERT_VAL("failed to synthesize attr update unit", 104a6e52817SJiri Olsa !perf_event__synthesize_event_update_unit(NULL, evsel, process_event_unit)); 105a6e52817SJiri Olsa 106daeecbc0SJiri Olsa evsel->scale = 0.123; 107daeecbc0SJiri Olsa 108daeecbc0SJiri Olsa TEST_ASSERT_VAL("failed to synthesize attr update scale", 109daeecbc0SJiri Olsa !perf_event__synthesize_event_update_scale(NULL, evsel, process_event_scale)); 110daeecbc0SJiri Olsa 111802c9048SJiri Olsa tmp.name = perf_evsel__name(evsel); 112802c9048SJiri Olsa 113802c9048SJiri Olsa TEST_ASSERT_VAL("failed to synthesize attr update name", 114802c9048SJiri Olsa !perf_event__synthesize_event_update_name(&tmp.tool, evsel, process_event_name)); 115802c9048SJiri Olsa 116fe1f61b3SJiri Olsa evsel->core.own_cpus = perf_cpu_map__new("1,2,3"); 11786ebb09fSJiri Olsa 11886ebb09fSJiri Olsa TEST_ASSERT_VAL("failed to synthesize attr update cpus", 11986ebb09fSJiri Olsa !perf_event__synthesize_event_update_cpus(&tmp.tool, evsel, process_event_cpus)); 12086ebb09fSJiri Olsa 121fe1f61b3SJiri Olsa perf_cpu_map__put(evsel->core.own_cpus); 122a6e52817SJiri Olsa return 0; 123a6e52817SJiri Olsa } 124