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 { 8863503dbaSJiri Olsa struct evlist *evlist; 8932dcd021SJiri Olsa struct evsel *evsel; 90802c9048SJiri Olsa struct event_name tmp; 91a6e52817SJiri Olsa 92a6e52817SJiri Olsa evlist = perf_evlist__new_default(); 93a6e52817SJiri Olsa TEST_ASSERT_VAL("failed to get evlist", evlist); 94a6e52817SJiri Olsa 95*515dbe48SJiri Olsa evsel = evlist__first(evlist); 96a6e52817SJiri Olsa 97ce095c9aSColin Ian King TEST_ASSERT_VAL("failed to allocate ids", 9870c20369SJiri Olsa !perf_evsel__alloc_id(&evsel->core, 1, 1)); 99a6e52817SJiri Olsa 100a6e52817SJiri Olsa perf_evlist__id_add(evlist, evsel, 0, 0, 123); 101a6e52817SJiri Olsa 102a6e52817SJiri Olsa evsel->unit = strdup("KRAVA"); 103a6e52817SJiri Olsa 104a6e52817SJiri Olsa TEST_ASSERT_VAL("failed to synthesize attr update unit", 105a6e52817SJiri Olsa !perf_event__synthesize_event_update_unit(NULL, evsel, process_event_unit)); 106a6e52817SJiri Olsa 107daeecbc0SJiri Olsa evsel->scale = 0.123; 108daeecbc0SJiri Olsa 109daeecbc0SJiri Olsa TEST_ASSERT_VAL("failed to synthesize attr update scale", 110daeecbc0SJiri Olsa !perf_event__synthesize_event_update_scale(NULL, evsel, process_event_scale)); 111daeecbc0SJiri Olsa 112802c9048SJiri Olsa tmp.name = perf_evsel__name(evsel); 113802c9048SJiri Olsa 114802c9048SJiri Olsa TEST_ASSERT_VAL("failed to synthesize attr update name", 115802c9048SJiri Olsa !perf_event__synthesize_event_update_name(&tmp.tool, evsel, process_event_name)); 116802c9048SJiri Olsa 117fe1f61b3SJiri Olsa evsel->core.own_cpus = perf_cpu_map__new("1,2,3"); 11886ebb09fSJiri Olsa 11986ebb09fSJiri Olsa TEST_ASSERT_VAL("failed to synthesize attr update cpus", 12086ebb09fSJiri Olsa !perf_event__synthesize_event_update_cpus(&tmp.tool, evsel, process_event_cpus)); 12186ebb09fSJiri Olsa 122fe1f61b3SJiri Olsa perf_cpu_map__put(evsel->core.own_cpus); 123a6e52817SJiri Olsa return 0; 124a6e52817SJiri Olsa } 125