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> 587ffb6c6SArnaldo 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" 10ea49e01cSArnaldo Carvalho de Melo #include "util/synthetic-events.h" 114a3cec84SArnaldo Carvalho de Melo #include "tool.h" 12a6e52817SJiri Olsa #include "tests.h" 13a6e52817SJiri Olsa #include "debug.h" 14a6e52817SJiri Olsa 15a6e52817SJiri Olsa static int process_event_unit(struct perf_tool *tool __maybe_unused, 16a6e52817SJiri Olsa union perf_event *event, 17a6e52817SJiri Olsa struct perf_sample *sample __maybe_unused, 18a6e52817SJiri Olsa struct machine *machine __maybe_unused) 19a6e52817SJiri Olsa { 2072932371SJiri Olsa struct perf_record_event_update *ev = (struct perf_record_event_update *)event; 21a6e52817SJiri Olsa 22a6e52817SJiri Olsa TEST_ASSERT_VAL("wrong id", ev->id == 123); 23a6e52817SJiri Olsa TEST_ASSERT_VAL("wrong id", ev->type == PERF_EVENT_UPDATE__UNIT); 24a6e52817SJiri Olsa TEST_ASSERT_VAL("wrong unit", !strcmp(ev->data, "KRAVA")); 25a6e52817SJiri Olsa return 0; 26a6e52817SJiri Olsa } 27a6e52817SJiri Olsa 28daeecbc0SJiri Olsa static int process_event_scale(struct perf_tool *tool __maybe_unused, 29daeecbc0SJiri Olsa union perf_event *event, 30daeecbc0SJiri Olsa struct perf_sample *sample __maybe_unused, 31daeecbc0SJiri Olsa struct machine *machine __maybe_unused) 32daeecbc0SJiri Olsa { 3372932371SJiri Olsa struct perf_record_event_update *ev = (struct perf_record_event_update *)event; 3472932371SJiri Olsa struct perf_record_event_update_scale *ev_data; 35daeecbc0SJiri Olsa 3672932371SJiri Olsa ev_data = (struct perf_record_event_update_scale *)ev->data; 37daeecbc0SJiri Olsa 38daeecbc0SJiri Olsa TEST_ASSERT_VAL("wrong id", ev->id == 123); 39daeecbc0SJiri Olsa TEST_ASSERT_VAL("wrong id", ev->type == PERF_EVENT_UPDATE__SCALE); 408daef508SColin Ian King TEST_ASSERT_VAL("wrong scale", ev_data->scale == 0.123); 41daeecbc0SJiri Olsa return 0; 42daeecbc0SJiri Olsa } 43daeecbc0SJiri Olsa 44802c9048SJiri Olsa struct event_name { 45802c9048SJiri Olsa struct perf_tool tool; 46802c9048SJiri Olsa const char *name; 47802c9048SJiri Olsa }; 48802c9048SJiri Olsa 49802c9048SJiri Olsa static int process_event_name(struct perf_tool *tool, 50802c9048SJiri Olsa union perf_event *event, 51802c9048SJiri Olsa struct perf_sample *sample __maybe_unused, 52802c9048SJiri Olsa struct machine *machine __maybe_unused) 53802c9048SJiri Olsa { 54802c9048SJiri Olsa struct event_name *tmp = container_of(tool, struct event_name, tool); 5572932371SJiri Olsa struct perf_record_event_update *ev = (struct perf_record_event_update *)event; 56802c9048SJiri Olsa 57802c9048SJiri Olsa TEST_ASSERT_VAL("wrong id", ev->id == 123); 58802c9048SJiri Olsa TEST_ASSERT_VAL("wrong id", ev->type == PERF_EVENT_UPDATE__NAME); 59802c9048SJiri Olsa TEST_ASSERT_VAL("wrong name", !strcmp(ev->data, tmp->name)); 60802c9048SJiri Olsa return 0; 61802c9048SJiri Olsa } 62802c9048SJiri Olsa 6386ebb09fSJiri Olsa static int process_event_cpus(struct perf_tool *tool __maybe_unused, 6486ebb09fSJiri Olsa union perf_event *event, 6586ebb09fSJiri Olsa struct perf_sample *sample __maybe_unused, 6686ebb09fSJiri Olsa struct machine *machine __maybe_unused) 6786ebb09fSJiri Olsa { 6872932371SJiri Olsa struct perf_record_event_update *ev = (struct perf_record_event_update *)event; 6972932371SJiri Olsa struct perf_record_event_update_cpus *ev_data; 70f854839bSJiri Olsa struct perf_cpu_map *map; 7186ebb09fSJiri Olsa 7272932371SJiri Olsa ev_data = (struct perf_record_event_update_cpus *) ev->data; 7386ebb09fSJiri Olsa 7486ebb09fSJiri Olsa map = cpu_map__new_data(&ev_data->cpus); 7586ebb09fSJiri Olsa 7686ebb09fSJiri Olsa TEST_ASSERT_VAL("wrong id", ev->id == 123); 7786ebb09fSJiri Olsa TEST_ASSERT_VAL("wrong type", ev->type == PERF_EVENT_UPDATE__CPUS); 7886ebb09fSJiri Olsa TEST_ASSERT_VAL("wrong cpus", map->nr == 3); 7986ebb09fSJiri Olsa TEST_ASSERT_VAL("wrong cpus", map->map[0] == 1); 8086ebb09fSJiri Olsa TEST_ASSERT_VAL("wrong cpus", map->map[1] == 2); 8186ebb09fSJiri Olsa TEST_ASSERT_VAL("wrong cpus", map->map[2] == 3); 8238f01d8dSJiri Olsa perf_cpu_map__put(map); 8386ebb09fSJiri Olsa return 0; 8486ebb09fSJiri Olsa } 8586ebb09fSJiri Olsa 8681f17c90SArnaldo Carvalho de Melo int test__event_update(struct test *test __maybe_unused, int subtest __maybe_unused) 87a6e52817SJiri Olsa { 8832dcd021SJiri Olsa struct evsel *evsel; 89802c9048SJiri Olsa struct event_name tmp; 90*606e2c29SArnaldo Carvalho de Melo struct evlist *evlist = evlist__new_default(); 91a6e52817SJiri Olsa 92a6e52817SJiri Olsa TEST_ASSERT_VAL("failed to get evlist", evlist); 93a6e52817SJiri Olsa 94515dbe48SJiri Olsa evsel = evlist__first(evlist); 95a6e52817SJiri Olsa 96ce095c9aSColin Ian King TEST_ASSERT_VAL("failed to allocate ids", 9770c20369SJiri Olsa !perf_evsel__alloc_id(&evsel->core, 1, 1)); 98a6e52817SJiri Olsa 99b0031c22SJiri Olsa perf_evlist__id_add(&evlist->core, &evsel->core, 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 1118ab2e96dSArnaldo Carvalho de Melo tmp.name = 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